Skip to content

Commit 8e46e05

Browse files
committed
feat: fully fletched DisputeKitShutter
1 parent cd016b3 commit 8e46e05

File tree

4 files changed

+93
-344
lines changed

4 files changed

+93
-344
lines changed

contracts/deploy/09-shutter.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

contracts/scripts/shutterAutoVote.ts

Lines changed: 0 additions & 207 deletions
This file was deleted.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity 0.8.24;
4+
5+
import {DisputeKitClassicBase, KlerosCore} from "./DisputeKitClassicBase.sol";
6+
7+
/// @title DisputeKitShutter
8+
/// Dispute kit implementation of the Kleros v1 features including:
9+
/// - a drawing system: proportional to staked PNK,
10+
/// - a vote aggregation system: plurality,
11+
/// - an incentive system: equal split between coherent votes,
12+
/// - an appeal system: fund 2 choices only, vote on any choice.
13+
/// Added functionality: an Shutter-specific event emitted when a vote is cast.
14+
contract DisputeKitShutter is DisputeKitClassicBase {
15+
string public constant override version = "0.9.0";
16+
17+
// ************************************* //
18+
// * Events * //
19+
// ************************************* //
20+
21+
/// @dev Emitted when a vote is cast.
22+
/// @param _commit The commitment hash.
23+
/// @param _identity The Shutter identity used for encryption.
24+
event CommitCastShutter(bytes32 indexed _commit, bytes32 _identity);
25+
26+
// ************************************* //
27+
// * Constructor * //
28+
// ************************************* //
29+
30+
/// @custom:oz-upgrades-unsafe-allow constructor
31+
constructor() {
32+
_disableInitializers();
33+
}
34+
35+
/// @dev Initializer.
36+
/// @param _governor The governor's address.
37+
/// @param _core The KlerosCore arbitrator.
38+
function initialize(address _governor, KlerosCore _core) external reinitializer(1) {
39+
__DisputeKitClassicBase_initialize(_governor, _core);
40+
}
41+
42+
// ************************ //
43+
// * Governance * //
44+
// ************************ //
45+
46+
/// @dev Access Control to perform implementation upgrades (UUPS Proxiable)
47+
/// Only the governor can perform upgrades (`onlyByGovernor`)
48+
function _authorizeUpgrade(address) internal view override onlyByGovernor {
49+
// NOP
50+
}
51+
52+
// ************************************* //
53+
// * State Modifiers * //
54+
// ************************************* //
55+
56+
/// @dev Sets the caller's commit for the specified votes. It can be called multiple times during the
57+
/// commit period, each call overrides the commits of the previous one.
58+
/// `O(n)` where
59+
/// `n` is the number of votes.
60+
/// @param _coreDisputeID The ID of the dispute in Kleros Core.
61+
/// @param _voteIDs The IDs of the votes.
62+
/// @param _commit The commitment hash including the justification.
63+
/// @param _identity The Shutter identity used for encryption.
64+
function castCommitShutter(
65+
uint256 _coreDisputeID,
66+
uint256[] calldata _voteIDs,
67+
bytes32 _commit,
68+
bytes32 _identity
69+
) external notJumped(_coreDisputeID) {
70+
this.castCommit(_coreDisputeID, _voteIDs, _commit);
71+
emit CommitCastShutter(_commit, _identity);
72+
}
73+
74+
// ************************************* //
75+
// * Public Views * //
76+
// ************************************* //
77+
78+
/**
79+
* @dev Computes the hash of a vote using ABI encoding
80+
* @param _choice The choice being voted for
81+
* @param _justification The justification for the vote
82+
* @param _salt A random salt for commitment
83+
* @return bytes32 The hash of the encoded vote parameters
84+
*/
85+
function hashVote(
86+
uint256 _choice,
87+
uint256 _salt,
88+
string memory _justification
89+
) public pure override returns (bytes32) {
90+
bytes32 justificationHash = keccak256(bytes(_justification));
91+
return keccak256(abi.encode(_choice, _salt, justificationHash));
92+
}
93+
}

0 commit comments

Comments
 (0)