Commit 1e62a0b7 authored by Inphi's avatar Inphi Committed by GitHub

fault-proofs: non-zero bond requirement (#9409)

* fault-proofs: non-zero bond requirement

* rebase

rebase

* permissioned game fix

* safe transactOpts w/ bonds

---------
Co-authored-by: default avatarclabby <ben@clab.by>
parent b89c9c6e
This diff is collapsed.
...@@ -451,6 +451,12 @@ func (g *OutputGameHelper) waitForNewClaim(ctx context.Context, checkPoint int64 ...@@ -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) { 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) 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) tx, err := g.game.Attack(opts, big.NewInt(claimIdx), claim)
if err != nil { if err != nil {
g.require.NoErrorf(err, "Attack transaction did not send. Game state: \n%v", g.gameData(ctx)) g.require.NoErrorf(err, "Attack transaction did not send. Game state: \n%v", g.gameData(ctx))
...@@ -467,7 +473,13 @@ func (g *OutputGameHelper) Attack(ctx context.Context, claimIdx int64, claim com ...@@ -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) { 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) 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 { if err != nil {
g.require.NoErrorf(err, "Defend transaction did not send. Game state: \n%v", g.gameData(ctx)) g.require.NoErrorf(err, "Defend transaction did not send. Game state: \n%v", g.gameData(ctx))
} }
...@@ -481,6 +493,14 @@ func (g *OutputGameHelper) Defend(ctx context.Context, claimIdx int64, claim com ...@@ -481,6 +493,14 @@ func (g *OutputGameHelper) Defend(ctx context.Context, claimIdx int64, claim com
g.DefendWithTransactOpts(ctx, claimIdx, claim, g.opts) 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 { type ErrWithData interface {
ErrorData() interface{} ErrorData() interface{}
} }
......
...@@ -96,8 +96,8 @@ ...@@ -96,8 +96,8 @@
"sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984" "sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984"
}, },
"src/dispute/FaultDisputeGame.sol": { "src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0x206faab5d19598def839adac4f85427b945b222adc8401626fd1d7a58ec52262", "initCodeHash": "0x44969c83852ed72e3152bcd98533fefa7b88116a939bf7ee4ad0f87dc9091ea2",
"sourceCodeHash": "0xfafd5423f3ffb2101cba4feb023127a887838423146f1838a9d8c6e9853c73c7" "sourceCodeHash": "0x47a93c22df3b8481be0a553ba0ecccfc63cccf1ce7a5d908f11c940f4924b09a"
}, },
"src/legacy/DeployerWhitelist.sol": { "src/legacy/DeployerWhitelist.sol": {
"initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d", "initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d",
......
...@@ -81,8 +81,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -81,8 +81,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
bool internal initialized; bool internal initialized;
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 0.4.0 /// @custom:semver 0.5.0
string public constant version = "0.4.0"; string public constant version = "0.5.0";
/// @param _gameType The type ID of the game. /// @param _gameType The type ID of the game.
/// @param _absolutePrestate The absolute prestate of the instruction trace. /// @param _absolutePrestate The absolute prestate of the instruction trace.
...@@ -535,9 +535,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver { ...@@ -535,9 +535,9 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @param _position The position of the bonded interaction. /// @param _position The position of the bonded interaction.
/// @return requiredBond_ The required ETH bond for the given move, in wei. /// @return requiredBond_ The required ETH bond for the given move, in wei.
function getRequiredBond(Position _position) public pure returns (uint256 requiredBond_) { 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; _position;
requiredBond_ = 0; requiredBond_ = 0.01 ether;
} }
/// @notice Claim the credit belonging to the recipient address. /// @notice Claim the credit belonging to the recipient address.
......
...@@ -96,6 +96,8 @@ contract PermissionedDisputeGame_Init is DisputeGameFactory_Init { ...@@ -96,6 +96,8 @@ contract PermissionedDisputeGame_Init is DisputeGameFactory_Init {
contract PermissionedDisputeGame_Test is PermissionedDisputeGame_Init { contract PermissionedDisputeGame_Test is PermissionedDisputeGame_Init {
/// @dev The root claim of the game. /// @dev The root claim of the game.
Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32((uint256(1) << 248) | uint256(10))); Claim internal constant ROOT_CLAIM = Claim.wrap(bytes32((uint256(1) << 248) | uint256(10)));
/// @dev Minimum bond value that covers all possible moves.
uint256 internal constant MIN_BOND = 0.01 ether;
/// @dev The preimage of the absolute prestate claim /// @dev The preimage of the absolute prestate claim
bytes internal absolutePrestateData; bytes internal absolutePrestateData;
...@@ -134,18 +136,20 @@ contract PermissionedDisputeGame_Test is PermissionedDisputeGame_Init { ...@@ -134,18 +136,20 @@ contract PermissionedDisputeGame_Test is PermissionedDisputeGame_Init {
/// @dev Tests that the challenger can participate in a permissioned dispute game. /// @dev Tests that the challenger can participate in a permissioned dispute game.
function test_participateInGame_challenger_succeeds() public { function test_participateInGame_challenger_succeeds() public {
vm.startPrank(CHALLENGER, CHALLENGER); vm.startPrank(CHALLENGER, CHALLENGER);
gameProxy.attack(0, Claim.wrap(0)); vm.deal(CHALLENGER, MIN_BOND * 3);
gameProxy.defend(1, Claim.wrap(0)); gameProxy.attack{ value: MIN_BOND }(0, Claim.wrap(0));
gameProxy.move(2, Claim.wrap(0), true); gameProxy.defend{ value: MIN_BOND }(1, Claim.wrap(0));
gameProxy.move{ value: MIN_BOND }(2, Claim.wrap(0), true);
vm.stopPrank(); vm.stopPrank();
} }
/// @dev Tests that the proposer can participate in a permissioned dispute game. /// @dev Tests that the proposer can participate in a permissioned dispute game.
function test_participateInGame_proposer_succeeds() public { function test_participateInGame_proposer_succeeds() public {
vm.startPrank(PROPOSER, PROPOSER); vm.startPrank(PROPOSER, PROPOSER);
gameProxy.attack(0, Claim.wrap(0)); vm.deal(PROPOSER, MIN_BOND * 3);
gameProxy.defend(1, Claim.wrap(0)); gameProxy.attack{ value: MIN_BOND }(0, Claim.wrap(0));
gameProxy.move(2, Claim.wrap(0), true); gameProxy.defend{ value: MIN_BOND }(1, Claim.wrap(0));
gameProxy.move{ value: MIN_BOND }(2, Claim.wrap(0), true);
vm.stopPrank(); vm.stopPrank();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment