Skip to content
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

Closed
wants to merge 50 commits into from
Closed

Adapt Court to MultiSortition #41

wants to merge 50 commits into from

Conversation

bingen
Copy link
Contributor

@bingen bingen commented May 16, 2019

  • Add batches
  • Remove queues
  • Split voting
  • Split Sum Tree

Pull requests:
Replaces #37, #38 and #39
Closes: #27

Issues:
Fixes: #8, #12, #23
Closes: #17, #26

ßingen added 19 commits May 2, 2019 22:16
- 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.
@bingen bingen requested a review from izqui May 16, 2019 22:06
@bingen bingen self-assigned this May 16, 2019
Copy link
Contributor

@izqui izqui left a 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;
Copy link
Contributor

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

contracts/Court.sol Outdated Show resolved Hide resolved
contracts/Court.sol Show resolved Hide resolved
contracts/Court.sol Show resolved Hide resolved
contracts/Court.sol Show resolved Hide resolved
if (round.nextJurorIndex > 0 && round.jurors[round.nextJurorIndex - 1] == juror) {
round.jurors.length--;
} else {
round.jurors[round.nextJurorIndex] = juror;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

contracts/Court.sol Outdated Show resolved Hide resolved
contracts/Court.sol Show resolved Hide resolved
contracts/Court.sol Outdated Show resolved Hide resolved
contracts/Court.sol Outdated Show resolved Hide resolved
Simplify activation/deactivation logic.
Address PR #41 comments.
and that it does from the very beginning.

Address PR #41 comments.
Copy link
Contributor

@izqui izqui left a 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:

round.jurorNumber,
sortitionIteration
);
require(jurorKeys.length == stakes.length, ERROR_SORTITION_LENGTHS_MIMATCH);
Copy link
Contributor

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

Copy link
Contributor Author

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.

_;
}

constructor(address _preOwner) public {
Copy link
Contributor

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();
Copy link
Contributor

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.

_;
}

constructor(address _preOwner) public {
Copy link
Contributor

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

mapping (address => Account) public accounts;
mapping (uint256 => address) public jurorsByTreeId;
mapping (uint64 => Term) public terms;
HexSumTree.Tree internal sumTree;
ISumTree internal sumTree;
Copy link
Contributor

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.

}

function _canPerformVotingAction(uint256 _voteId, address _voter, AdjudicationState _state) internal returns (uint256) {
require(_voteId <= MAX_UINT32, ERROR_OVERFLOW);
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

@@ -847,56 +777,42 @@ contract Court is ERC900, ApproveAndCallFallBack {
nC = pA == pC ? nC : -nC;
Copy link
Contributor

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


uint256 rulingVotes = round.rulingVotes[_ruling] + 1;
round.rulingVotes[_ruling] = rulingVotes;
votes[voteId] = Vote(uint128(_disputeId), uint128(roundId));
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

ßingen added 12 commits June 3, 2019 23:21
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
Drafting will have to wait for a later term where randomness seed is
available.

Closes #15.
Court: prevents drafting without randomness seed
Plus make _getVoteId and _decodeVoteId pure.

Missing changes in commit d4234fc: "Court: build voteId from disputeId
and roundId".
@facuspagnuolo
Copy link
Contributor

Closing this PR since development branch was already updated with these commits manually

@facuspagnuolo facuspagnuolo deleted the split_sumtree branch August 1, 2019 20:36
@izqui izqui added this to the Freeze #1 milestone Oct 15, 2019
facuspagnuolo pushed a commit that referenced this pull request Oct 12, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants