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

Fix bugs of addLocalData() and add tests for edge cases #41

Merged
merged 2 commits into from
Jul 20, 2024

Conversation

dajuguan
Copy link

  • Add tests for attacking the mid-right and right most branch and fix related bug

@dajuguan dajuguan requested review from qizhou and JustXxx July 19, 2024 03:36
@@ -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) {
Copy link

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

Copy link
Author

Choose a reason for hiding this comment

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

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

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_?

Copy link
Author

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) {
Copy link

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?

Copy link
Author

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) {
Copy link
Author

@dajuguan dajuguan Jul 19, 2024

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) {
Copy link
Author

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.

@@ -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
Copy link

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.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

@JustXxx JustXxx merged commit a9b33dd into develop-find-outputs Jul 20, 2024
2 checks passed
@JustXxx JustXxx deleted the po/develop-find-outputs branch July 20, 2024 09:30
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