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

Bugfix: Added _attackbranch logic to the _findStartingAndDisputedOutp… #14

Open
wants to merge 1 commit into
base: develop_1.20_nary4_fix_step
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions packages/contracts-bedrock/src/dispute/FaultDisputeGameN.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1005,27 +1005,30 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
// above. This is important because it determines which claim is the starting output root and which
// is the disputed output root.
(Position execRootPos, Position outputPos) = (execRootClaim.position, claim.position);
bool wasAttack = execRootPos.parent().raw() == outputPos.raw();
uint64 attackBranch = uint64(execRootPos.raw() % outputPos.raw() / (1 << N_BITS));

// Determine the starting and disputed output root indices.
// 1. If it was an attack, the disputed output root is `claim`, and the starting output root is
// elsewhere in the DAG (it must commit to the block # index at depth of `outputPos - 1`).
// 2. If it was a defense, the starting output root is `claim`, and the disputed output root is
// elsewhere in the DAG (it must commit to the block # index at depth of `outputPos + 1`).
if (wasAttack) {
if (attackBranch != MAX_ATTACK_BRANCH) {
// If this is an attack on the first output root (the block directly after the starting
// block number), the starting claim nor position exists in the tree. We leave these as
// 0, which can be easily identified due to 0 being an invalid Gindex.
if (outputPos.indexAtDepth() > 0) {
(startingClaim_, startingPos_) =
_findTraceAncestorV2(Position.wrap(outputPos.raw() - 1), claimIdx, true);
_findTraceAncestorV2(Position.wrap(outputPos.raw() - 1 + attackBranch), claimIdx, true);
} else {
startingClaim_ = Claim.wrap(startingOutputRoot.root.raw());
}
(disputedClaim_, disputedPos_) = (claim.claim, claim.position);
disputedPos_ = Position.wrap(claim.position.raw() + attackBranch);
disputedClaim_ = getClaim(claim, disputedPos_);
} else {
(startingClaim_, startingPos_) = (claim.claim, claim.position);
(disputedClaim_, disputedPos_) = _findTraceAncestorV2(Position.wrap(outputPos.raw() + 1), claimIdx, true);
startingPos_ = Position.wrap(claim.position.raw() + attackBranch);
startingClaim_ = getClaim(claim, startingPos_);
(disputedClaim_, disputedPos_) =
_findTraceAncestorV2(Position.wrap(outputPos.raw() + 1 + attackBranch), claimIdx, true);
}
}

Expand Down