Skip to content

Commit

Permalink
fault-proofs: non-zero bond requirement (ethereum-optimism#9409)
Browse files Browse the repository at this point in the history
* fault-proofs: non-zero bond requirement

* rebase

rebase

* permissioned game fix

* safe transactOpts w/ bonds

---------

Co-authored-by: clabby <[email protected]>
  • Loading branch information
Inphi and clabby authored Feb 15, 2024
1 parent b89c9c6 commit 1e62a0b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 68 deletions.
2 changes: 1 addition & 1 deletion op-bindings/bindings/faultdisputegame.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion op-bindings/bindings/faultdisputegame_more.go

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion op-e2e/e2eutils/disputegame/output_game_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ func (g *OutputGameHelper) waitForNewClaim(ctx context.Context, checkPoint int64

func (g *OutputGameHelper) AttackWithTransactOpts(ctx context.Context, claimIdx int64, claim common.Hash, opts *bind.TransactOpts) {
g.t.Logf("Attacking claim %v with value %v", claimIdx, claim)

claimData, err := g.game.ClaimData(&bind.CallOpts{Context: ctx}, big.NewInt(claimIdx))
g.require.NoError(err, "Failed to get claim data")
pos := types.NewPositionFromGIndex(claimData.Position)
opts = g.makeBondedTransactOpts(ctx, pos.Attack().ToGIndex(), opts)

tx, err := g.game.Attack(opts, big.NewInt(claimIdx), claim)
if err != nil {
g.require.NoErrorf(err, "Attack transaction did not send. Game state: \n%v", g.gameData(ctx))
Expand All @@ -467,7 +473,13 @@ func (g *OutputGameHelper) Attack(ctx context.Context, claimIdx int64, claim com

func (g *OutputGameHelper) DefendWithTransactOpts(ctx context.Context, claimIdx int64, claim common.Hash, opts *bind.TransactOpts) {
g.t.Logf("Defending claim %v with value %v", claimIdx, claim)
tx, err := g.game.Defend(g.opts, big.NewInt(claimIdx), claim)

claimData, err := g.game.ClaimData(&bind.CallOpts{Context: ctx}, big.NewInt(claimIdx))
g.require.NoError(err, "Failed to get claim data")
pos := types.NewPositionFromGIndex(claimData.Position)
opts = g.makeBondedTransactOpts(ctx, pos.Defend().ToGIndex(), opts)

tx, err := g.game.Defend(opts, big.NewInt(claimIdx), claim)
if err != nil {
g.require.NoErrorf(err, "Defend transaction did not send. Game state: \n%v", g.gameData(ctx))
}
Expand All @@ -481,6 +493,14 @@ func (g *OutputGameHelper) Defend(ctx context.Context, claimIdx int64, claim com
g.DefendWithTransactOpts(ctx, claimIdx, claim, g.opts)
}

func (g *OutputGameHelper) makeBondedTransactOpts(ctx context.Context, pos *big.Int, opts *bind.TransactOpts) *bind.TransactOpts {
bopts := *opts
bond, err := g.game.GetRequiredBond(&bind.CallOpts{Context: ctx}, pos)
g.require.NoError(err, "Failed to get required bond")
bopts.Value = bond
return &bopts
}

type ErrWithData interface {
ErrorData() interface{}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0x206faab5d19598def839adac4f85427b945b222adc8401626fd1d7a58ec52262",
"sourceCodeHash": "0xfafd5423f3ffb2101cba4feb023127a887838423146f1838a9d8c6e9853c73c7"
"initCodeHash": "0x44969c83852ed72e3152bcd98533fefa7b88116a939bf7ee4ad0f87dc9091ea2",
"sourceCodeHash": "0x47a93c22df3b8481be0a553ba0ecccfc63cccf1ce7a5d908f11c940f4924b09a"
},
"src/legacy/DeployerWhitelist.sol": {
"initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d",
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
bool internal initialized;

/// @notice Semantic version.
/// @custom:semver 0.4.0
string public constant version = "0.4.0";
/// @custom:semver 0.5.0
string public constant version = "0.5.0";

/// @param _gameType The type ID of the game.
/// @param _absolutePrestate The absolute prestate of the instruction trace.
Expand Down Expand Up @@ -535,9 +535,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @param _position The position of the bonded interaction.
/// @return requiredBond_ The required ETH bond for the given move, in wei.
function getRequiredBond(Position _position) public pure returns (uint256 requiredBond_) {
// TODO
// TODO(client-pod#551): For now use a non-zero bond amount to unblock functional tests.
_position;
requiredBond_ = 0;
requiredBond_ = 0.01 ether;
}

/// @notice Claim the credit belonging to the recipient address.
Expand Down
Loading

0 comments on commit 1e62a0b

Please sign in to comment.