Commit b37df3e9 authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: implement bigbond version of getRequiredBond (#9580)

Implements the Big Bonds v1.5 (tm) version of getRequiredBond.
This is a relatively simple bond model designed to carry the
contracts through the next 6-12 months until a fully dynamic bond
model is implemented.
parent 5b23c3d1
This diff is collapsed.
......@@ -100,8 +100,8 @@
"sourceCodeHash": "0x1e5a6deded88804971fc1847c9eac65921771bff353437c0b29ed2f55513b984"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0xe78a025dc7e95b4767ec683b0f188565c45cc5f0236e8706fd86d2fddcee59d5",
"sourceCodeHash": "0xb70cd464f9b6f444b489b2cdd6a2d69fd7f14db8eba535b2289974f51061b3c2"
"initCodeHash": "0x9f8e47a4073639af201991a075c7eb03a73055750b3808281e7615b46d47a104",
"sourceCodeHash": "0xef3dee1a6dd89270b67c7e6a54862de9d11b9059cf053127bd26704e7e6b1fbf"
},
"src/dispute/weth/DelayedWETH.sol": {
"initCodeHash": "0x41e274b12dc48658d073dfea67ef694c5cce3963757911ee4cecc9f4c312e4bb",
......
......@@ -359,7 +359,7 @@
"type": "uint256"
}
],
"stateMutability": "pure",
"stateMutability": "view",
"type": "function"
},
{
......
......@@ -369,7 +369,7 @@
"type": "uint256"
}
],
"stateMutability": "pure",
"stateMutability": "view",
"type": "function"
},
{
......
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
import { IDelayedWETH } from "src/dispute/interfaces/IDelayedWETH.sol";
import { IDisputeGame } from "src/dispute/interfaces/IDisputeGame.sol";
import { IFaultDisputeGame } from "src/dispute/interfaces/IFaultDisputeGame.sol";
......@@ -88,8 +90,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
bool internal initialized;
/// @notice Semantic version.
/// @custom:semver 0.7.0
string public constant version = "0.7.0";
/// @custom:semver 0.7.1
string public constant version = "0.7.1";
/// @param _gameType The type ID of the game.
/// @param _absolutePrestate The absolute prestate of the instruction trace.
......@@ -558,10 +560,47 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
/// @notice Returns the required bond for a given move kind.
/// @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(client-pod#551): For now use a non-zero bond amount to unblock functional tests.
_position;
requiredBond_ = 0.01 ether;
function getRequiredBond(Position _position) public view returns (uint256 requiredBond_) {
uint256 depth = uint256(_position.depth());
if (depth > MAX_GAME_DEPTH) revert GameDepthExceeded();
// Values taken from Big Bonds v1.5 (TM) spec.
uint256 assumedBaseFee = 200 gwei;
uint256 baseGasCharged = 400_000;
uint256 highGasCharged = 200_000_000;
// Goal here is to compute the fixed multiplier that will be applied to the base gas
// charged to get the required gas amount for the given depth. We apply this multiplier
// some `n` times where `n` is the depth of the position. We are looking for some number
// that, when multiplied by itself `MAX_GAME_DEPTH` times and then multiplied by the base
// gas charged, will give us the maximum gas that we want to charge.
// We want to solve for (highGasCharged/baseGasCharged) ** (1/MAX_GAME_DEPTH).
// We know that a ** (b/c) is equal to e ** (ln(a) * (b/c)).
// We can compute e ** (ln(a) * (b/c)) quite easily with FixedPointMathLib.
// Set up a, b, and c.
uint256 a = highGasCharged / baseGasCharged;
uint256 b = FixedPointMathLib.WAD;
uint256 c = MAX_GAME_DEPTH * FixedPointMathLib.WAD;
// Compute ln(a).
// slither-disable-next-line divide-before-multiply
uint256 lnA = uint256(FixedPointMathLib.lnWad(int256(a * FixedPointMathLib.WAD)));
// Computes (b / c) with full precision using WAD = 1e18.
uint256 bOverC = FixedPointMathLib.divWad(b, c);
// Compute e ** (ln(a) * (b/c))
// sMulWad can be used here since WAD = 1e18 maintains the same precision.
uint256 numerator = FixedPointMathLib.mulWad(lnA, bOverC);
int256 base = FixedPointMathLib.expWad(int256(numerator));
// Compute the required gas amount.
int256 rawGas = FixedPointMathLib.powWad(base, int256(depth * FixedPointMathLib.WAD));
uint256 requiredGas = FixedPointMathLib.mulWad(baseGasCharged, uint256(rawGas));
// Compute the required bond.
requiredBond_ = assumedBaseFee * requiredGas;
}
/// @notice Claim the credit belonging to the recipient address.
......
......@@ -104,7 +104,7 @@ contract PermissionedDisputeGame_Test is PermissionedDisputeGame_Init {
/// @dev The root claim of the game.
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;
uint256 internal constant MIN_BOND = 50 ether;
/// @dev The preimage of the absolute prestate claim
bytes internal absolutePrestateData;
......
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