-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix bugs of addLocalData() and add tests for edge cases #41
Conversation
dajuguan
commented
Jul 19, 2024
- Add tests for attacking the mid-right and right most branch and fix related bug
@@ -517,7 +517,12 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
value_ = starting.raw(); | |||
} else if (_ident == LocalPreimageKey.DISPUTED_OUTPUT_ROOT) { | |||
// Load the disputed proposal's output root | |||
Claim disputed = getClaim(disputedRoot.raw(), disputedPos, _daItem); | |||
Claim disputed; | |||
if (disputedPos.raw() == 1) { |
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 would suggest adding a comment here
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.
Fixed in 74242dc#r1683759252
@@ -1115,7 +1120,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
if (ancestorPos_.depth() == SPLIT_DEPTH + N_BITS) { | |||
ancestorClaim_ = ancestorClaimRoot; | |||
} else { | |||
ancestorClaim_ = getClaim(ancestorClaimRoot.raw(), _pos, _daItem); | |||
ancestorClaim_ = getClaim(ancestorClaimRoot.raw(), Position.wrap(_pos.raw() - 1), _daItem); |
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 _pos
be replaced by ancestorPos_
?
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.
Actually, ancestorPos_
should be the right context, but the ancestorPos_
value is not right. Maybe we should rename _pos
to ancestorPos_
?
@@ -1156,10 +1161,14 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
// Walk up the DAG to find a claim that commits to the same trace index as `_pos`. It is | |||
// guaranteed that such a claim exists. | |||
ClaimData storage ancestor_ = claimData[_start]; | |||
while (ancestor_.position.raw() != traceAncestorPosValue) { | |||
ancestor_ = claimData[ancestor_.parentIndex]; | |||
if (traceAncestorPosValue == 0) { |
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 traceAncestorPosValue
should the claim be starting
one? Or in what situation that traceAncestorPosValue
is zero?
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.
Because we offset it by 1, so it's 0 here. For consistency, I've made changes to the offset logic and let the traceAncestorPosValue be 1. 74242dc#r1683762415
@@ -518,8 +518,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
} else if (_ident == LocalPreimageKey.DISPUTED_OUTPUT_ROOT) { | |||
// Load the disputed proposal's output root | |||
Claim disputed; | |||
// If the pos is 1, then the rootclaim itself is the output hash. | |||
if (disputedPos.raw() == 1) { |
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.
@@ -1154,14 +1155,15 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
: _firstValidRightIndex(_pos.traceAncestorBounded(SPLIT_DEPTH), N_BITS); | |||
|
|||
uint256 offset = ancestorPos_.raw() % (1 << N_BITS); | |||
if (MAX_ATTACK_BRANCH == offset) { | |||
// If ancestorPos_.raw() == 1 (rootclaim), we don't offset it | |||
if (MAX_ATTACK_BRANCH == offset || ancestorPos_.raw() == 1) { |
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.
Let offset be 0 when its rootClaim, so the meaning of traceAncestorPosValue
will be consistent.
74242dc
to
4a98049
Compare
@@ -1149,8 +1155,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { | |||
: _firstValidRightIndex(_pos.traceAncestorBounded(SPLIT_DEPTH), N_BITS); | |||
|
|||
uint256 offset = ancestorPos_.raw() % (1 << N_BITS); | |||
if (MAX_ATTACK_BRANCH == offset) { | |||
offset = 0; | |||
// If ancestorPos_.raw() == 1 (rootclaim), we don't offset it |
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.
Comment should be updated accordingly.
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.
Fixed
4a98049
to
adc68c0
Compare