-
Notifications
You must be signed in to change notification settings - Fork 45
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
Adapt Court to MultiSortition #41
Conversation
Add baches.
- Remove queues. - Make activations and deactivations immediate, instead of scheduled (on next term). - Allow jurors to re-activate, simpliflying this logic. There's no `PastJuror` state anymore.
If a juror was selected more than once in a round, the voting contract and the rewarding system would only count it once.
Shrink jurors array in round struct too in case of repeated jurors.
Add tests for batches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some initial comments focused on drafting, will continue reviewing later
@@ -254,9 +231,11 @@ contract Court is ERC900, ApproveAndCallFallBack { | |||
) public { | |||
termDuration = _termDuration; | |||
jurorToken = _jurorToken; | |||
voting = _voting; | |||
sumTree = _sumTree; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go the owner
route for voting
and sumTree
we should check that the Court is the owner and that they are in the initial state
if (round.nextJurorIndex > 0 && round.jurors[round.nextJurorIndex - 1] == juror) { | ||
round.jurors.length--; | ||
} else { | ||
round.jurors[round.nextJurorIndex] = juror; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to update round.nextJurorIndex
only after adding all the jurors which would save a lot of gas in extra SSTORE
and SLOAD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above, actually, see here: https://github.com/aragon/aragon-court/blob/split_sumtree/contracts/Court.sol#L472
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a new issue: #43
Simplify activation/deactivation logic. Address PR #41 comments.
and that it does from the very beginning. Address PR #41 comments.
Needed for settleAppealDeposit in PR #40.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still in the process of review this PR, but some more comments:
contracts/Court.sol
Outdated
round.jurorNumber, | ||
sortitionIteration | ||
); | ||
require(jurorKeys.length == stakes.length, ERROR_SORTITION_LENGTHS_MIMATCH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we can use the same error for these two
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would definitely save some bytecode. My idea was to make it easier to spot the mismatch, but happy to join them.
contracts/CRVoting.sol
Outdated
_; | ||
} | ||
|
||
constructor(address _preOwner) public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of the preOwner
doesn't really solve the frontrunning problem for initialization (as the initcode
could be fetched from a pending transaction) and adds some complexity that feels hacky.
I think we can just not set an owner in the constructor and allow the Court contract to 'claim ownership' which will revert if the ownership has already been claimed. This can be frontrun as well, but the frontrunning can be detected as the Court constructor will revert.
We should acknowledge that this is vulnerable to frontrunning at deployment time but in a way that is easily detectable.
function init(address _owner, bytes32 _initCode) external { | ||
require(address(owner) == address(keccak256(abi.encodePacked(_initCode))), ERROR_WRONG_INIT_CODE); | ||
owner = _owner; | ||
tree.init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before initialization we could check that tree.rootDepth == 0
to ensure that the tree cannot be reinitialized for whatever reason.
contracts/HexSumTreeWrapper.sol
Outdated
_; | ||
} | ||
|
||
constructor(address _preOwner) public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about preOwner
as in CRVoting
contracts/Court.sol
Outdated
mapping (address => Account) public accounts; | ||
mapping (uint256 => address) public jurorsByTreeId; | ||
mapping (uint64 => Term) public terms; | ||
HexSumTree.Tree internal sumTree; | ||
ISumTree internal sumTree; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved up next to voting
as it is not strictly court state anymore.
contracts/Court.sol
Outdated
} | ||
|
||
function _canPerformVotingAction(uint256 _voteId, address _voter, AdjudicationState _state) internal returns (uint256) { | ||
require(_voteId <= MAX_UINT32, ERROR_OVERFLOW); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that canCommit
and canReveal
aren't view
functions, we should ensure that only voting
can call these two functions for extra security
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, but the only thing that will modify state after this commit will be ensureTerm
, that doesn't seem harmful. Do you think we can then keep it as is, or do you still want to add that check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd still add the check
contracts/Court.sol
Outdated
@@ -847,56 +777,42 @@ contract Court is ERC900, ApproveAndCallFallBack { | |||
nC = pA == pC ? nC : -nC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes we can now remove the _signedSum
function which is no longer used
contracts/Court.sol
Outdated
|
||
uint256 rulingVotes = round.rulingVotes[_ruling] + 1; | ||
round.rulingVotes[_ruling] = rulingVotes; | ||
votes[voteId] = Vote(uint128(_disputeId), uint128(roundId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nice optimization could be that the Court sets the id for votes (rather than being consecutive), so the vote ids could be _disputeId << 128 + roundId
in a way that we wouldn't need a mapping between vote ids and the specific round, as it could be derived directly.
It would save a bunch of storage writes and reads. We don't necessarily need to implement it right away, but we can consider it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
With batching, it doesn't make sense, as it could run out of gas. It must be done manually before.
Court: allow to continue draft at a later term
Court: remove dismiss dispute
Drafting will have to wait for a later term where randomness seed is available. Closes #15.
Address PR #41 comments.
Address PR #58 comments.
Court: prevents drafting without randomness seed
Plus make _getVoteId and _decodeVoteId pure. Missing changes in commit d4234fc: "Court: build voteId from disputeId and roundId".
Closing this PR since |
* Add confirmation date to Appeal entity * Update confirm date only when opposed ruling is not zero Address PR #41. * Update schema.graphql Co-Authored-By: Fabrizio Vigevani <fabriziovigevani@gmail.com> * Change BigInt constructor Address PR #41 comments. Co-authored-by: Fabrizio Vigevani <fabriziovigevani@gmail.com>
Pull requests:
Replaces #37, #38 and #39
Closes: #27
Issues:
Fixes: #8, #12, #23
Closes: #17, #26