Skip to content

Commit

Permalink
Merge pull request #53 from ethstorage/bill/unittest_test_da
Browse files Browse the repository at this point in the history
Added an attack test with the da type as calldata.
  • Loading branch information
JustXxx authored Aug 23, 2024
2 parents f87be16 + c1d29c5 commit be6b55b
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/contracts-bedrock/test/dispute/FaultDisputeGameN.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,60 @@ contract FaultDisputeGameN_Test is FaultDisputeGame_Init {
bytes32 h = keccak256(abi.encode(_ident | (1 << 248), address(gameProxy), _localContext));
return bytes32((uint256(h) & ~uint256(0xFF << 248)) | (1 << 248));
}

function test_stepAttackDummyClaim_attackDACalldata_succeeds() public {
// Give the test contract some ether
vm.deal(address(this), 1000 ether);

bytes memory claimData1 = abi.encode(1, 1);
bytes memory claimData2 = abi.encode(2, 2);
bytes memory claimData3 = abi.encode(3, 3);
Claim claim1 = Claim.wrap(keccak256(claimData1));
Claim claim2 = Claim.wrap(keccak256(claimData2));
Claim claim3 = Claim.wrap(keccak256(claimData3));

bytes memory claims = abi.encodePacked(claim1, claim2, claim3);

// Make claims all the way down the tree.
(,,,, Claim disputed,,) = gameProxy.claimData(0);
gameProxy.attackV2{ value: _getRequiredBondV2(0, 0) }(disputed, 0, _dummyClaim(), 0);

(,,,, disputed,,) = gameProxy.claimData(1);
gameProxy.attackV2{ value: _getRequiredBondV2(1, 0) }(disputed, 1, _dummyClaim(), 0);

(,,,, disputed,,) = gameProxy.claimData(2);
gameProxy.attackV2{ value: _getRequiredBondV2(2, 0) }(disputed, 2, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC), 0);

(,,,, disputed,,) = gameProxy.claimData(3);
uint256 bond = _getRequiredBondV2(3, 0);
gameProxy.attackV2{ value: bond }(disputed, 3, 0, LibDA.DA_TYPE_CALLDATA, claims);
vm.expectRevert(ClaimAlreadyExists.selector);
gameProxy.attackV2{ value: bond }(disputed, 3, Claim.wrap(LibDA.getClaimsHash(LibDA.DA_TYPE_CALLDATA, 3, claims)), 0);

LibDA.DAItem memory dummyDataItem = LibDA.DAItem({
daType: LibDA.DA_TYPE_CALLDATA,
dataHash: _dummyClaim().raw(),
proof: hex""
});
gameProxy.addLocalData(LocalPreimageKey.DISPUTED_L2_BLOCK_NUMBER, 4, 2, dummyDataItem);

LibDA.DAItem memory preStateItem = LibDA.DAItem({
daType: LibDA.DA_TYPE_CALLDATA,
dataHash: claim2.raw(),
proof: abi.encodePacked(claim1, claim3)
});
LibDA.DAItem memory postStateItem = LibDA.DAItem({
daType: LibDA.DA_TYPE_CALLDATA,
dataHash: claim3.raw(),
proof: bytes.concat(keccak256(abi.encode(claim1.raw(), claim2.raw())))
});
FaultDisputeGame.StepProof memory stepProof = FaultDisputeGame.StepProof({
preStateItem: preStateItem,
postStateItem: postStateItem,
vmProof: hex""
});
gameProxy.stepV2({_claimIndex: 4, _attackBranch: 2, _stateData: claimData2, _proof: stepProof});
}
}

contract FaultDisputeGameN_LessSplitDepth_Test is FaultDisputeGame_Init {
Expand Down

0 comments on commit be6b55b

Please sign in to comment.