-
Notifications
You must be signed in to change notification settings - Fork 49
Drawing bug: test coverage + contract fix #1148
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
Merged
Conversation
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
✅ Deploy Preview for kleros-v2-contracts ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2 canceled.
|
jaybuidl
added a commit
that referenced
this pull request
Aug 12, 2023
3d94c75
to
d9adb8f
Compare
Code Climate has analyzed commit 5704cdc and detected 11 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Kudos, SonarCloud Quality Gate passed!
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Thanks to @unknownunknown1 @shotaronowhere @alcercu for helping with the investigation.
Summary
The arbitrator cannot draw any juror anymore when calling
KlerosCore.draw(disputeId, iterations)
, regardless of the number of iterations. The transaction does not revert.Interestingly it was working fine up to disputeId 6 round 0, and started failing from round 1 onwards and disputeId 7.
Once in a while a juror still manages to get drawn successfully (example tx)
Analysis
Transaction traces
Looking at the draw transaction traces, KlerosCore goes through the max number of iterations because (almost) every drawn juror fails the
DisputeKitClassic._postDrawCheck()
. It turns out that this logic fails to take into account the juror's stake in the parent courts.Why is suddenly starting to fail?
Because of a large increase of the stakes in the two subcourts (courtIds 2 and 3), relative to the stakes in the general court (courtId 1), cf. timeline below.
In particular a farmer collected 170K PNK at address
0xFD4bA0A1C08E0aF938A2B1AC06E8937c8535eC93
, then transferred it to address0x36b6c8fe413ba60c0db27b2a67a3a0e4cd97b651
and proceeded to stake. We'll call it juror X.Timeline
Aug-09-2023 10:01:05 PM +UTC: Juror X stakes 100K in subcourt 2
Aug-10-2023 01:25:52 AM +UTC: Drawing of voteId 0 and 1 for dispute 6 round 0
Aug-10-2023 03:07:52 AM +UTC: Juror X stakes 20K in subcourt 3
Aug-10-2023 10:37:45 AM +UTC: Drawing of voteId 2 for dispute 6 round 0, it should not have taken so long (9 hours) , there were many unsuccessful draw() attempts.
Aug-10-2023 04:33:52 PM +UTC: First successful draw of voteId 0 for dispute 6 round 1.
Until now, dispute 6 round 1 and dispute 7 round 0 could never complet their draw of 7 and 3 jurors respectively.
Reproduction
The minimal scenario to reproduce this bug is to stake in a subcourt, create a dispute in the parent court. The draw will never succeed.
kleros-v2/contracts/test/arbitration/draw.ts
Lines 188 to 203 in 7eb8634
Solution
Code
It consists in disabling the _postDrawCheck() for now, until the check on locked stakes can be implemented correctly.
The impact of this fix is that only the juror's overall locked PNK (total for all the courts) is checked, instead of checking also at the court level.
Additional logic has been added to gracefully handle drawing in a court where no juror has staked.
Deployment
The new DisputeKitClassic contract can be deployed, but not the new SortitionModule which is not required to fix the issue. The goal is to avoid a total redeploy which would require the jurors to stake again in the new deployment. If the SortitionModule or KlerosCore is redeployed, it is equivalent to a total redeploy.
kleros-v2/contracts/deploy/fix1148.ts
Lines 25 to 50 in ce24e73
Then...