-
Notifications
You must be signed in to change notification settings - Fork 49
feat: shutter support in dispute commiting & appeal #1994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alcercu
merged 18 commits into
feat/shutter-dispute-kit
from
feat(web)/shutter-frontend-rendering
May 29, 2025
+781
−15
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5ac64f5
feat: shutter support in dispute commiting
kemuru 724a949
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 8a5b2f4
feat: shutter appeal support
kemuru 6b240a6
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 05711fe
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 729777d
feat: postinstall script, use correct commit function
kemuru 8bf3772
fix: vote hashing during commitment must follow DisputeKitShutter.has…
jaybuidl 8c74d4a
feat: decryption delay is the remaining of the commit period
kemuru 47049eb
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
jaybuidl bae8db4
chore: remove postinstall script, tell vite where to find it
kemuru e983fdd
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 2e5d2a7
feat: support for revealing shutter commit from the frontend
kemuru bf7a3c0
chore: remove console logs, few code smells
kemuru c8bf188
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 04605db
chore: extra 5 min decryptiondelay
kemuru b3817bd
fix: trycatch in case voting fails
kemuru f816ca3
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru 4e2dea9
Merge branch 'feat/shutter-dispute-kit' into feat(web)/shutter-fronte…
kemuru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
102 changes: 102 additions & 0 deletions
102
web/src/pages/Cases/CaseDetails/Voting/Shutter/Commit.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React, { useCallback, useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { useParams } from "react-router-dom"; | ||
import { useLocalStorage } from "react-use"; | ||
import { keccak256, encodePacked } from "viem"; | ||
import { useWalletClient, usePublicClient, useConfig } from "wagmi"; | ||
|
||
import { simulateDisputeKitShutterCastCommit } from "hooks/contracts/generated"; | ||
import useSigningAccount from "hooks/useSigningAccount"; | ||
import { isUndefined } from "utils/index"; | ||
import { wrapWithToast } from "utils/wrapWithToast"; | ||
import { encrypt } from "utils/shutter"; | ||
import OptionsContainer from "../OptionsContainer"; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
height: auto; | ||
`; | ||
|
||
interface ICommit { | ||
arbitrable: `0x${string}`; | ||
voteIDs: string[]; | ||
setIsOpen: (val: boolean) => void; | ||
refetch: () => void; | ||
} | ||
|
||
const SEPARATOR = "␟"; | ||
|
||
const Commit: React.FC<ICommit> = ({ arbitrable, voteIDs, setIsOpen, refetch }) => { | ||
const { id } = useParams(); | ||
const parsedDisputeID = useMemo(() => BigInt(id ?? 0), [id]); | ||
const parsedVoteIDs = useMemo(() => voteIDs.map((voteID) => BigInt(voteID)), [voteIDs]); | ||
const { data: walletClient } = useWalletClient(); | ||
const publicClient = usePublicClient(); | ||
const wagmiConfig = useConfig(); | ||
const { signingAccount, generateSigningAccount } = useSigningAccount(); | ||
const [justification, setJustification] = useState(""); | ||
const saltKey = useMemo(() => `shutter-dispute-${id}-voteids-${voteIDs}`, [id, voteIDs]); | ||
const [_, setSalt] = useLocalStorage(saltKey); | ||
|
||
const handleCommit = useCallback( | ||
async (choice: bigint) => { | ||
const message = { message: saltKey }; | ||
const rawSalt = !isUndefined(signingAccount) | ||
? await signingAccount.signMessage(message) | ||
: await (async () => { | ||
const account = await generateSigningAccount(); | ||
return await account?.signMessage(message); | ||
})(); | ||
if (isUndefined(rawSalt)) return; | ||
|
||
const salt = keccak256(rawSalt); | ||
setSalt(JSON.stringify({ salt, choice: choice.toString(), justification })); | ||
|
||
const encodedMessage = `${choice.toString()}${SEPARATOR}${salt}${SEPARATOR}${justification}`; | ||
const { encryptedCommitment, identity } = await encrypt(encodedMessage); | ||
|
||
const commitHash = keccak256( | ||
encodePacked(["uint256", "uint256", "string"], [choice, BigInt(salt), justification]) | ||
); | ||
|
||
const { request } = await simulateDisputeKitShutterCastCommit(wagmiConfig, { | ||
args: [parsedDisputeID, parsedVoteIDs, commitHash, identity as `0x${string}`, encryptedCommitment], | ||
}); | ||
if (walletClient && publicClient) { | ||
await wrapWithToast(async () => await walletClient.writeContract(request), publicClient).then(({ status }) => { | ||
setIsOpen(status); | ||
}); | ||
} | ||
refetch(); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
[ | ||
wagmiConfig, | ||
justification, | ||
saltKey, | ||
setSalt, | ||
parsedVoteIDs, | ||
parsedDisputeID, | ||
publicClient, | ||
setIsOpen, | ||
walletClient, | ||
generateSigningAccount, | ||
signingAccount, | ||
refetch, | ||
] | ||
); | ||
|
||
return id ? ( | ||
<Container> | ||
<OptionsContainer | ||
{...{ | ||
arbitrable, | ||
justification, | ||
setJustification, | ||
handleSelection: handleCommit, | ||
}} | ||
/> | ||
</Container> | ||
) : null; | ||
}; | ||
|
||
export default Commit; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import React from "react"; | ||
|
||
const Vote: React.FC = () => null; | ||
|
||
export default Vote; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useMemo } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { useAccount } from "wagmi"; | ||
|
||
import { useDrawQuery } from "hooks/queries/useDrawQuery"; | ||
import { useVotingContext } from "hooks/useVotingContext"; | ||
import { useDisputeDetailsQuery } from "queries/useDisputeDetailsQuery"; | ||
|
||
import ShutterCommit from "./Commit"; | ||
|
||
interface IShutter { | ||
arbitrable: `0x${string}`; | ||
setIsOpen: (val: boolean) => void; | ||
} | ||
|
||
const Shutter: React.FC<IShutter> = ({ arbitrable, setIsOpen }) => { | ||
const { id } = useParams(); | ||
const { address } = useAccount(); | ||
const { data: disputeData } = useDisputeDetailsQuery(id); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { data: drawData, refetch } = useDrawQuery(address?.toLowerCase(), id, disputeData?.dispute?.currentRound.id); | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { isCommitPeriod, commited } = useVotingContext(); | ||
const voteIDs = useMemo(() => drawData?.draws?.map((draw) => draw.voteIDNum) as string[], [drawData]); | ||
|
||
return id && isCommitPeriod && !commited ? <ShutterCommit {...{ arbitrable, setIsOpen, voteIDs, refetch }} /> : null; | ||
kemuru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export default Shutter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.