Commit 0839333d authored by clabby's avatar clabby Committed by GitHub

chore: adhere to style guide in `OutputBisectionGame` for immutables (#8656)

* chore: adhere to style guide in `OutputBisectionGame` for immutables

* Patch `OutputBisectionGame` selectors in `op-challenger`

* :broom:

* fix getters tests in `op-challenger`
parent 8a23b65e
This diff is collapsed.
...@@ -13,25 +13,33 @@ import ( ...@@ -13,25 +13,33 @@ import (
) )
const ( const (
methodGameDuration = "GAME_DURATION" methodGameDurationV0 = "GAME_DURATION"
methodMaxGameDepth = "MAX_GAME_DEPTH" methodMaxGameDepthV0 = "MAX_GAME_DEPTH"
methodAbsolutePrestate = "ABSOLUTE_PRESTATE" methodAbsolutePrestateV0 = "ABSOLUTE_PRESTATE"
methodStatus = "status" methodGameDurationV1 = "gameDuration"
methodClaimCount = "claimDataLen" methodMaxGameDepthV1 = "maxGameDepth"
methodClaim = "claimData" methodAbsolutePrestateV1 = "absolutePrestate"
methodL1Head = "l1Head" methodStatus = "status"
methodResolve = "resolve" methodClaimCount = "claimDataLen"
methodResolveClaim = "resolveClaim" methodClaim = "claimData"
methodAttack = "attack" methodL1Head = "l1Head"
methodDefend = "defend" methodResolve = "resolve"
methodStep = "step" methodResolveClaim = "resolveClaim"
methodAddLocalData = "addLocalData" methodAttack = "attack"
methodVM = "VM" methodDefend = "defend"
methodStep = "step"
methodAddLocalData = "addLocalData"
methodVMV0 = "VM"
methodVMV1 = "vm"
) )
type disputeGameContract struct { type disputeGameContract struct {
multiCaller *batching.MultiCaller multiCaller *batching.MultiCaller
contract *batching.BoundContract contract *batching.BoundContract
// The version byte signifies the version of the dispute game contract due to mismatching function selectors.
// 0 = `FaultDisputeGame`
// 1 = `OutputBisectionGame`
version uint8
} }
// contractProposal matches the structure for output root proposals used by the contracts. // contractProposal matches the structure for output root proposals used by the contracts.
...@@ -56,6 +64,13 @@ func asProposal(p contractProposal) Proposal { ...@@ -56,6 +64,13 @@ func asProposal(p contractProposal) Proposal {
} }
func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) { func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, error) {
var methodGameDuration string
if f.version == 1 {
methodGameDuration = methodGameDurationV1
} else {
methodGameDuration = methodGameDurationV0
}
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameDuration))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch game duration: %w", err) return 0, fmt.Errorf("failed to fetch game duration: %w", err)
...@@ -64,6 +79,13 @@ func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, erro ...@@ -64,6 +79,13 @@ func (f *disputeGameContract) GetGameDuration(ctx context.Context) (uint64, erro
} }
func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) { func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, error) {
var methodMaxGameDepth string
if f.version == 1 {
methodMaxGameDepth = methodMaxGameDepthV1
} else {
methodMaxGameDepth = methodMaxGameDepthV0
}
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodMaxGameDepth))
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to fetch max game depth: %w", err) return 0, fmt.Errorf("failed to fetch max game depth: %w", err)
...@@ -72,6 +94,13 @@ func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, erro ...@@ -72,6 +94,13 @@ func (f *disputeGameContract) GetMaxGameDepth(ctx context.Context) (uint64, erro
} }
func (f *disputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) { func (f *disputeGameContract) GetAbsolutePrestateHash(ctx context.Context) (common.Hash, error) {
var methodAbsolutePrestate string
if f.version == 1 {
methodAbsolutePrestate = methodAbsolutePrestateV1
} else {
methodAbsolutePrestate = methodAbsolutePrestateV0
}
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodAbsolutePrestate))
if err != nil { if err != nil {
return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err) return common.Hash{}, fmt.Errorf("failed to fetch absolute prestate hash: %w", err)
...@@ -135,6 +164,13 @@ func (f *disputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim, ...@@ -135,6 +164,13 @@ func (f *disputeGameContract) GetAllClaims(ctx context.Context) ([]types.Claim,
} }
func (f *disputeGameContract) vm(ctx context.Context) (*VMContract, error) { func (f *disputeGameContract) vm(ctx context.Context) (*VMContract, error) {
var methodVM string
if f.version == 1 {
methodVM = methodVMV1
} else {
methodVM = methodVMV0
}
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM)) result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodVM))
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to fetch VM addr: %w", err) return nil, fmt.Errorf("failed to fetch VM addr: %w", err)
......
...@@ -48,28 +48,44 @@ func runCommonDisputeGameTests(t *testing.T, setup disputeGameSetupFunc) { ...@@ -48,28 +48,44 @@ func runCommonDisputeGameTests(t *testing.T, setup disputeGameSetupFunc) {
func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
tests := []struct { tests := []struct {
method string methodAlias string
args []interface{} method func(game *disputeGameContract) string
result interface{} args []interface{}
expected interface{} // Defaults to expecting the same as result result interface{}
call func(game *disputeGameContract) (any, error) expected interface{} // Defaults to expecting the same as result
call func(game *disputeGameContract) (any, error)
}{ }{
{ {
method: methodStatus, methodAlias: "status",
result: types.GameStatusChallengerWon, method: func(game *disputeGameContract) string { return methodStatus },
result: types.GameStatusChallengerWon,
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetStatus(context.Background()) return game.GetStatus(context.Background())
}, },
}, },
{ {
method: methodGameDuration, methodAlias: "gameDuration",
method: func(game *disputeGameContract) string {
if game.version == 1 {
return methodGameDurationV1
} else {
return methodGameDurationV0
}
},
result: uint64(5566), result: uint64(5566),
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetGameDuration(context.Background()) return game.GetGameDuration(context.Background())
}, },
}, },
{ {
method: methodMaxGameDepth, methodAlias: "maxGameDepth",
method: func(game *disputeGameContract) string {
if game.version == 1 {
return methodMaxGameDepthV1
} else {
return methodMaxGameDepthV0
}
},
result: big.NewInt(128), result: big.NewInt(128),
expected: uint64(128), expected: uint64(128),
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
...@@ -77,30 +93,40 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { ...@@ -77,30 +93,40 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
}, },
}, },
{ {
method: methodAbsolutePrestate, methodAlias: "absolutePrestate",
method: func(game *disputeGameContract) string {
if game.version == 1 {
return methodAbsolutePrestateV1
} else {
return methodAbsolutePrestateV0
}
},
result: common.Hash{0xab}, result: common.Hash{0xab},
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetAbsolutePrestateHash(context.Background()) return game.GetAbsolutePrestateHash(context.Background())
}, },
}, },
{ {
method: methodClaimCount, methodAlias: "claimCount",
result: big.NewInt(9876), method: func(game *disputeGameContract) string { return methodClaimCount },
expected: uint64(9876), result: big.NewInt(9876),
expected: uint64(9876),
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetClaimCount(context.Background()) return game.GetClaimCount(context.Background())
}, },
}, },
{ {
method: methodL1Head, methodAlias: "l1Head",
result: common.Hash{0xdd, 0xbb}, method: func(game *disputeGameContract) string { return methodL1Head },
result: common.Hash{0xdd, 0xbb},
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.GetL1Head(context.Background()) return game.GetL1Head(context.Background())
}, },
}, },
{ {
method: methodResolve, methodAlias: "resolve",
result: types.GameStatusInProgress, method: func(game *disputeGameContract) string { return methodResolve },
result: types.GameStatusInProgress,
call: func(game *disputeGameContract) (any, error) { call: func(game *disputeGameContract) (any, error) {
return game.CallResolve(context.Background()) return game.CallResolve(context.Background())
}, },
...@@ -108,9 +134,9 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) { ...@@ -108,9 +134,9 @@ func runSimpleGettersTest(t *testing.T, setup disputeGameSetupFunc) {
} }
for _, test := range tests { for _, test := range tests {
test := test test := test
t.Run(test.method, func(t *testing.T) { t.Run(test.methodAlias, func(t *testing.T) {
stubRpc, game := setup(t) stubRpc, game := setup(t)
stubRpc.SetResponse(fdgAddr, test.method, batching.BlockLatest, nil, []interface{}{test.result}) stubRpc.SetResponse(fdgAddr, test.method(game), batching.BlockLatest, nil, []interface{}{test.result})
status, err := test.call(game) status, err := test.call(game)
require.NoError(t, err) require.NoError(t, err)
expected := test.expected expected := test.expected
......
...@@ -30,6 +30,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall ...@@ -30,6 +30,7 @@ func NewFaultDisputeGameContract(addr common.Address, caller *batching.MultiCall
disputeGameContract: disputeGameContract{ disputeGameContract: disputeGameContract{
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(fdgAbi, addr), contract: batching.NewBoundContract(fdgAbi, addr),
version: 0,
}, },
}, nil }, nil
} }
......
...@@ -84,7 +84,7 @@ func TestFaultDisputeGame_UpdateOracleTx(t *testing.T) { ...@@ -84,7 +84,7 @@ func TestFaultDisputeGame_UpdateOracleTx(t *testing.T) {
OracleOffset: 16, OracleOffset: 16,
} }
claimIdx := uint64(6) claimIdx := uint64(6)
stubRpc.SetResponse(fdgAddr, methodVM, batching.BlockLatest, nil, []interface{}{vmAddr}) stubRpc.SetResponse(fdgAddr, methodVMV0, batching.BlockLatest, nil, []interface{}{vmAddr})
stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr}) stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr})
stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{ stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{
new(big.Int).SetUint64(uint64(data.OracleOffset)), new(big.Int).SetUint64(uint64(data.OracleOffset)),
......
...@@ -13,9 +13,9 @@ import ( ...@@ -13,9 +13,9 @@ import (
) )
var ( var (
methodGenesisBlockNumber = "GENESIS_BLOCK_NUMBER" methodGenesisBlockNumber = "genesisBlockNumber"
methodGenesisOutputRoot = "GENESIS_OUTPUT_ROOT" methodGenesisOutputRoot = "genesisOutputRoot"
methodSplitDepth = "SPLIT_DEPTH" methodSplitDepth = "splitDepth"
methodL2BlockNumber = "l2BlockNumber" methodL2BlockNumber = "l2BlockNumber"
) )
...@@ -33,6 +33,7 @@ func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiC ...@@ -33,6 +33,7 @@ func NewOutputBisectionGameContract(addr common.Address, caller *batching.MultiC
disputeGameContract: disputeGameContract{ disputeGameContract: disputeGameContract{
multiCaller: caller, multiCaller: caller,
contract: batching.NewBoundContract(contractAbi, addr), contract: batching.NewBoundContract(contractAbi, addr),
version: 1,
}, },
}, nil }, nil
} }
......
...@@ -79,7 +79,7 @@ func TestOutputBisectionGame_UpdateOracleTx(t *testing.T) { ...@@ -79,7 +79,7 @@ func TestOutputBisectionGame_UpdateOracleTx(t *testing.T) {
OracleOffset: 16, OracleOffset: 16,
} }
claimIdx := uint64(6) claimIdx := uint64(6)
stubRpc.SetResponse(fdgAddr, methodVM, batching.BlockLatest, nil, []interface{}{vmAddr}) stubRpc.SetResponse(fdgAddr, methodVMV1, batching.BlockLatest, nil, []interface{}{vmAddr})
stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr}) stubRpc.SetResponse(vmAddr, methodOracle, batching.BlockLatest, nil, []interface{}{oracleAddr})
stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{ stubRpc.SetResponse(oracleAddr, methodLoadKeccak256PreimagePart, batching.BlockLatest, []interface{}{
new(big.Int).SetUint64(uint64(data.OracleOffset)), new(big.Int).SetUint64(uint64(data.OracleOffset)),
......
...@@ -34,11 +34,13 @@ import ( ...@@ -34,11 +34,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
const alphabetGameType uint8 = 255 const (
const cannonGameType uint8 = 0 alphabetGameType uint8 = 255
const outputCannonGameType uint8 = 1 cannonGameType uint8 = 0
const outputAlphabetGameType uint8 = 254 outputCannonGameType uint8 = 1
const alphabetGameDepth = 4 outputAlphabetGameType uint8 = 254
alphabetGameDepth = 4
)
var lastAlphabetTraceIndex = big.NewInt(1<<alphabetGameDepth - 1) var lastAlphabetTraceIndex = big.NewInt(1<<alphabetGameDepth - 1)
...@@ -185,11 +187,11 @@ func (h *FactoryHelper) StartOutputCannonGame(ctx context.Context, l2Node string ...@@ -185,11 +187,11 @@ func (h *FactoryHelper) StartOutputCannonGame(ctx context.Context, l2Node string
game, err := bindings.NewOutputBisectionGame(createdEvent.DisputeProxy, h.client) game, err := bindings.NewOutputBisectionGame(createdEvent.DisputeProxy, h.client)
h.require.NoError(err) h.require.NoError(err)
prestateBlock, err := game.GENESISBLOCKNUMBER(&bind.CallOpts{Context: ctx}) prestateBlock, err := game.GenesisBlockNumber(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load genesis block number") h.require.NoError(err, "Failed to load genesis block number")
poststateBlock, err := game.L2BlockNumber(&bind.CallOpts{Context: ctx}) poststateBlock, err := game.L2BlockNumber(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load l2 block number") h.require.NoError(err, "Failed to load l2 block number")
splitDepth, err := game.SPLITDEPTH(&bind.CallOpts{Context: ctx}) splitDepth, err := game.SplitDepth(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load split depth") h.require.NoError(err, "Failed to load split depth")
prestateProvider := outputs.NewPrestateProvider(ctx, logger, rollupClient, prestateBlock.Uint64()) prestateProvider := outputs.NewPrestateProvider(ctx, logger, rollupClient, prestateBlock.Uint64())
provider := outputs.NewTraceProviderFromInputs(logger, prestateProvider, rollupClient, splitDepth.Uint64(), prestateBlock.Uint64(), poststateBlock.Uint64()) provider := outputs.NewTraceProviderFromInputs(logger, prestateProvider, rollupClient, splitDepth.Uint64(), prestateBlock.Uint64(), poststateBlock.Uint64())
...@@ -234,11 +236,11 @@ func (h *FactoryHelper) StartOutputAlphabetGame(ctx context.Context, l2Node stri ...@@ -234,11 +236,11 @@ func (h *FactoryHelper) StartOutputAlphabetGame(ctx context.Context, l2Node stri
game, err := bindings.NewOutputBisectionGame(createdEvent.DisputeProxy, h.client) game, err := bindings.NewOutputBisectionGame(createdEvent.DisputeProxy, h.client)
h.require.NoError(err) h.require.NoError(err)
prestateBlock, err := game.GENESISBLOCKNUMBER(&bind.CallOpts{Context: ctx}) prestateBlock, err := game.GenesisBlockNumber(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load genesis block number") h.require.NoError(err, "Failed to load genesis block number")
poststateBlock, err := game.L2BlockNumber(&bind.CallOpts{Context: ctx}) poststateBlock, err := game.L2BlockNumber(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load l2 block number") h.require.NoError(err, "Failed to load l2 block number")
splitDepth, err := game.SPLITDEPTH(&bind.CallOpts{Context: ctx}) splitDepth, err := game.SplitDepth(&bind.CallOpts{Context: ctx})
h.require.NoError(err, "Failed to load split depth") h.require.NoError(err, "Failed to load split depth")
prestateProvider := outputs.NewPrestateProvider(ctx, logger, rollupClient, prestateBlock.Uint64()) prestateProvider := outputs.NewPrestateProvider(ctx, logger, rollupClient, prestateBlock.Uint64())
provider := outputs.NewTraceProviderFromInputs(logger, prestateProvider, rollupClient, splitDepth.Uint64(), prestateBlock.Uint64(), poststateBlock.Uint64()) provider := outputs.NewTraceProviderFromInputs(logger, prestateProvider, rollupClient, splitDepth.Uint64(), prestateBlock.Uint64(), poststateBlock.Uint64())
......
...@@ -37,7 +37,7 @@ func (g *OutputGameHelper) Addr() common.Address { ...@@ -37,7 +37,7 @@ func (g *OutputGameHelper) Addr() common.Address {
} }
func (g *OutputGameHelper) SplitDepth(ctx context.Context) int64 { func (g *OutputGameHelper) SplitDepth(ctx context.Context) int64 {
splitDepth, err := g.game.SPLITDEPTH(&bind.CallOpts{Context: ctx}) splitDepth, err := g.game.SplitDepth(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "failed to load split depth") g.require.NoError(err, "failed to load split depth")
return splitDepth.Int64() return splitDepth.Int64()
} }
...@@ -49,7 +49,7 @@ func (g *OutputGameHelper) L2BlockNum(ctx context.Context) uint64 { ...@@ -49,7 +49,7 @@ func (g *OutputGameHelper) L2BlockNum(ctx context.Context) uint64 {
} }
func (g *OutputGameHelper) GenesisBlockNum(ctx context.Context) uint64 { func (g *OutputGameHelper) GenesisBlockNum(ctx context.Context) uint64 {
blockNum, err := g.game.GENESISBLOCKNUMBER(&bind.CallOpts{Context: ctx}) blockNum, err := g.game.GenesisBlockNumber(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "failed to load genesis block number") g.require.NoError(err, "failed to load genesis block number")
return blockNum.Uint64() return blockNum.Uint64()
} }
...@@ -99,7 +99,7 @@ func (g *OutputGameHelper) correctOutputRoot(ctx context.Context, pos types.Posi ...@@ -99,7 +99,7 @@ func (g *OutputGameHelper) correctOutputRoot(ctx context.Context, pos types.Posi
} }
func (g *OutputGameHelper) GameDuration(ctx context.Context) time.Duration { func (g *OutputGameHelper) GameDuration(ctx context.Context) time.Duration {
duration, err := g.game.GAMEDURATION(&bind.CallOpts{Context: ctx}) duration, err := g.game.GameDuration(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "failed to get game duration") g.require.NoError(err, "failed to get game duration")
return time.Duration(duration) * time.Second return time.Duration(duration) * time.Second
} }
...@@ -133,7 +133,7 @@ type ContractClaim struct { ...@@ -133,7 +133,7 @@ type ContractClaim struct {
} }
func (g *OutputGameHelper) MaxDepth(ctx context.Context) int64 { func (g *OutputGameHelper) MaxDepth(ctx context.Context) int64 {
depth, err := g.game.MAXGAMEDEPTH(&bind.CallOpts{Context: ctx}) depth, err := g.game.MaxGameDepth(&bind.CallOpts{Context: ctx})
g.require.NoError(err, "Failed to load game depth") g.require.NoError(err, "Failed to load game depth")
return depth.Int64() return depth.Int64()
} }
...@@ -376,6 +376,7 @@ func (g *OutputGameHelper) getClaimCount(ctx context.Context) int64 { ...@@ -376,6 +376,7 @@ func (g *OutputGameHelper) getClaimCount(ctx context.Context) int64 {
func (g *OutputGameHelper) WaitForNewClaim(ctx context.Context, checkPoint int64) (int64, error) { func (g *OutputGameHelper) WaitForNewClaim(ctx context.Context, checkPoint int64) (int64, error) {
return g.waitForNewClaim(ctx, checkPoint, defaultTimeout) return g.waitForNewClaim(ctx, checkPoint, defaultTimeout)
} }
func (g *OutputGameHelper) waitForNewClaim(ctx context.Context, checkPoint int64, timeout time.Duration) (int64, error) { func (g *OutputGameHelper) waitForNewClaim(ctx context.Context, checkPoint int64, timeout time.Duration) (int64, error) {
timedCtx, cancel := context.WithTimeout(ctx, timeout) timedCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel() defer cancel()
......
...@@ -100,8 +100,8 @@ ...@@ -100,8 +100,8 @@
"sourceCodeHash": "0xa995b54dce03ddf5c9c47451bd7181996b91398ad66b54ab0b8cbf582863a33e" "sourceCodeHash": "0xa995b54dce03ddf5c9c47451bd7181996b91398ad66b54ab0b8cbf582863a33e"
}, },
"src/dispute/OutputBisectionGame.sol": { "src/dispute/OutputBisectionGame.sol": {
"initCodeHash": "0xe5799a4c06cf02fa1fba61129bd32d1a4b07df737a1f2b429b1acd7160093f0a", "initCodeHash": "0xcf6ab94ff4048485d9d13753bb2c49e0af716a50c3d853ad187517a6bdb77070",
"sourceCodeHash": "0xf95c7b1575988853b10d4ad2219a6031be27278add5073f3e96854f41f75ba62" "sourceCodeHash": "0x2963a04d32929665d1ca31d79b840068de0541d2e6f5e48e5655041b7e406d65"
}, },
"src/legacy/DeployerWhitelist.sol": { "src/legacy/DeployerWhitelist.sol": {
"initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d", "initCodeHash": "0x8de80fb23b26dd9d849f6328e56ea7c173cd9e9ce1f05c9beea559d1720deb3d",
......
...@@ -47,95 +47,17 @@ ...@@ -47,95 +47,17 @@
}, },
{ {
"inputs": [], "inputs": [],
"name": "ABSOLUTE_PRESTATE", "name": "absolutePrestate",
"outputs": [ "outputs": [
{ {
"internalType": "Claim", "internalType": "Claim",
"name": "", "name": "absolutePrestate_",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "GAME_DURATION",
"outputs": [
{
"internalType": "Duration",
"name": "",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "GENESIS_BLOCK_NUMBER",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "GENESIS_OUTPUT_ROOT",
"outputs": [
{
"internalType": "Hash",
"name": "",
"type": "bytes32" "type": "bytes32"
} }
], ],
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "MAX_GAME_DEPTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "SPLIT_DEPTH",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "VM",
"outputs": [
{
"internalType": "contract IBigStepper",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
...@@ -309,6 +231,19 @@ ...@@ -309,6 +231,19 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "gameDuration",
"outputs": [
{
"internalType": "Duration",
"name": "gameDuration_",
"type": "uint64"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [], "inputs": [],
"name": "gameType", "name": "gameType",
...@@ -322,6 +257,32 @@ ...@@ -322,6 +257,32 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "genesisBlockNumber",
"outputs": [
{
"internalType": "uint256",
"name": "genesisBlockNumber_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "genesisOutputRoot",
"outputs": [
{
"internalType": "Hash",
"name": "genesisOutputRoot_",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [], "inputs": [],
"name": "initialize", "name": "initialize",
...@@ -355,6 +316,19 @@ ...@@ -355,6 +316,19 @@
"stateMutability": "pure", "stateMutability": "pure",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "maxGameDepth",
"outputs": [
{
"internalType": "uint256",
"name": "maxGameDepth_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
...@@ -430,6 +404,19 @@ ...@@ -430,6 +404,19 @@
"stateMutability": "pure", "stateMutability": "pure",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "splitDepth",
"outputs": [
{
"internalType": "uint256",
"name": "splitDepth_",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [], "inputs": [],
"name": "status", "name": "status",
...@@ -484,6 +471,19 @@ ...@@ -484,6 +471,19 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "vm",
"outputs": [
{
"internalType": "contract IBigStepper",
"name": "vm_",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"anonymous": false, "anonymous": false,
"inputs": [ "inputs": [
......
...@@ -26,26 +26,26 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver { ...@@ -26,26 +26,26 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver {
/// @notice The absolute prestate of the instruction trace. This is a constant that is defined /// @notice The absolute prestate of the instruction trace. This is a constant that is defined
/// by the program that is being used to execute the trace. /// by the program that is being used to execute the trace.
Claim public immutable ABSOLUTE_PRESTATE; Claim internal immutable ABSOLUTE_PRESTATE;
/// @notice The max depth of the game. /// @notice The max depth of the game.
uint256 public immutable MAX_GAME_DEPTH; uint256 internal immutable MAX_GAME_DEPTH;
/// @notice The max depth of the output bisection portion of the position tree. Immediately beneath /// @notice The max depth of the output bisection portion of the position tree. Immediately beneath
/// this depth, execution trace bisection begins. /// this depth, execution trace bisection begins.
uint256 public immutable SPLIT_DEPTH; uint256 internal immutable SPLIT_DEPTH;
/// @notice The duration of the game. /// @notice The duration of the game.
Duration public immutable GAME_DURATION; Duration internal immutable GAME_DURATION;
/// @notice An onchain VM that performs single instruction steps on a fault proof program trace. /// @notice An onchain VM that performs single instruction steps on a fault proof program trace.
IBigStepper public immutable VM; IBigStepper internal immutable VM;
/// @notice The genesis block number /// @notice The genesis block number
uint256 public immutable GENESIS_BLOCK_NUMBER; uint256 internal immutable GENESIS_BLOCK_NUMBER;
/// @notice The genesis output root /// @notice The genesis output root
Hash public immutable GENESIS_OUTPUT_ROOT; Hash internal immutable GENESIS_OUTPUT_ROOT;
/// @notice The game type ID /// @notice The game type ID
GameType internal immutable GAME_TYPE; GameType internal immutable GAME_TYPE;
...@@ -81,8 +81,8 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver { ...@@ -81,8 +81,8 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver {
bool internal subgameAtRootResolved; bool internal subgameAtRootResolved;
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 0.0.16 /// @custom:semver 0.0.17
string public constant version = "0.0.16"; string public constant version = "0.0.17";
/// @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.
...@@ -474,6 +474,45 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver { ...@@ -474,6 +474,45 @@ contract OutputBisectionGame is IOutputBisectionGame, Clone, ISemver {
len_ = claimData.length; len_ = claimData.length;
} }
////////////////////////////////////////////////////////////////
// IMMUTABLE GETTERS //
////////////////////////////////////////////////////////////////
/// @notice Returns the absolute prestate of the instruction trace.
function absolutePrestate() external view returns (Claim absolutePrestate_) {
absolutePrestate_ = ABSOLUTE_PRESTATE;
}
/// @notice Returns the max game depth.
function maxGameDepth() external view returns (uint256 maxGameDepth_) {
maxGameDepth_ = MAX_GAME_DEPTH;
}
/// @notice Returns the split depth.
function splitDepth() external view returns (uint256 splitDepth_) {
splitDepth_ = SPLIT_DEPTH;
}
/// @notice Returns the game duration.
function gameDuration() external view returns (Duration gameDuration_) {
gameDuration_ = GAME_DURATION;
}
/// @notice Returns the address of the VM.
function vm() external view returns (IBigStepper vm_) {
vm_ = VM;
}
/// @notice Returns the genesis block number.
function genesisBlockNumber() external view returns (uint256 genesisBlockNumber_) {
genesisBlockNumber_ = GENESIS_BLOCK_NUMBER;
}
/// @notice Returns the genesis output root.
function genesisOutputRoot() external view returns (Hash genesisOutputRoot_) {
genesisOutputRoot_ = GENESIS_OUTPUT_ROOT;
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// HELPERS // // HELPERS //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
......
...@@ -60,8 +60,8 @@ abstract contract GameSolver is CommonBase { ...@@ -60,8 +60,8 @@ abstract contract GameSolver is CommonBase {
bytes memory _preStateData bytes memory _preStateData
) { ) {
GAME = _gameProxy; GAME = _gameProxy;
SPLIT_DEPTH = GAME.SPLIT_DEPTH(); SPLIT_DEPTH = GAME.splitDepth();
MAX_DEPTH = GAME.MAX_GAME_DEPTH(); MAX_DEPTH = GAME.maxGameDepth();
MAX_L2_BLOCK_NUMBER = 2 ** (MAX_DEPTH - SPLIT_DEPTH); MAX_L2_BLOCK_NUMBER = 2 ** (MAX_DEPTH - SPLIT_DEPTH);
l2Outputs = _l2Outputs; l2Outputs = _l2Outputs;
......
...@@ -70,13 +70,13 @@ contract OutputBisectionGame_Init is DisputeGameFactory_Init { ...@@ -70,13 +70,13 @@ contract OutputBisectionGame_Init is DisputeGameFactory_Init {
// Check immutables // Check immutables
assertEq(GameType.unwrap(gameProxy.gameType()), GameType.unwrap(GAME_TYPE)); assertEq(GameType.unwrap(gameProxy.gameType()), GameType.unwrap(GAME_TYPE));
assertEq(Claim.unwrap(gameProxy.ABSOLUTE_PRESTATE()), Claim.unwrap(absolutePrestate)); assertEq(Claim.unwrap(gameProxy.absolutePrestate()), Claim.unwrap(absolutePrestate));
assertEq(gameProxy.GENESIS_BLOCK_NUMBER(), genesisBlockNumber); assertEq(gameProxy.genesisBlockNumber(), genesisBlockNumber);
assertEq(Hash.unwrap(gameProxy.GENESIS_OUTPUT_ROOT()), Hash.unwrap(genesisOutputRoot)); assertEq(Hash.unwrap(gameProxy.genesisOutputRoot()), Hash.unwrap(genesisOutputRoot));
assertEq(gameProxy.MAX_GAME_DEPTH(), 2 ** 3); assertEq(gameProxy.maxGameDepth(), 2 ** 3);
assertEq(gameProxy.SPLIT_DEPTH(), 2 ** 2); assertEq(gameProxy.splitDepth(), 2 ** 2);
assertEq(Duration.unwrap(gameProxy.GAME_DURATION()), 7 days); assertEq(Duration.unwrap(gameProxy.gameDuration()), 7 days);
assertEq(address(gameProxy.VM()), address(_vm)); assertEq(address(gameProxy.vm()), address(_vm));
// Label the proxy // Label the proxy
vm.label(address(gameProxy), "OutputBisectionGame_Clone"); vm.label(address(gameProxy), "OutputBisectionGame_Clone");
...@@ -161,7 +161,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -161,7 +161,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
/// @dev Tests that the game cannot be initialized with an output root that commits to <= the configured genesis /// @dev Tests that the game cannot be initialized with an output root that commits to <= the configured genesis
/// block number /// block number
function testFuzz_initialize_cannotProposeGenesis_reverts(uint256 _blockNumber) public { function testFuzz_initialize_cannotProposeGenesis_reverts(uint256 _blockNumber) public {
_blockNumber = bound(_blockNumber, 0, gameProxy.GENESIS_BLOCK_NUMBER()); _blockNumber = bound(_blockNumber, 0, gameProxy.genesisBlockNumber());
Claim claim = _dummyClaim(); Claim claim = _dummyClaim();
vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, claim)); vm.expectRevert(abi.encodeWithSelector(UnexpectedRootClaim.selector, claim));
...@@ -234,7 +234,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -234,7 +234,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
function test_move_gameDepthExceeded_reverts() public { function test_move_gameDepthExceeded_reverts() public {
Claim claim = _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC); Claim claim = _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC);
uint256 maxDepth = gameProxy.MAX_GAME_DEPTH(); uint256 maxDepth = gameProxy.maxGameDepth();
for (uint256 i = 0; i <= maxDepth; i++) { for (uint256 i = 0; i <= maxDepth; i++) {
// At the max game depth, the `_move` function should revert with // At the max game depth, the `_move` function should revert with
...@@ -461,12 +461,12 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -461,12 +461,12 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
/// @dev Static unit test for the correctness of resolving a game that reaches max game depth. /// @dev Static unit test for the correctness of resolving a game that reaches max game depth.
function test_resolve_stepReached_succeeds() public { function test_resolve_stepReached_succeeds() public {
Claim claim = _dummyClaim(); Claim claim = _dummyClaim();
for (uint256 i; i < gameProxy.SPLIT_DEPTH(); i++) { for (uint256 i; i < gameProxy.splitDepth(); i++) {
gameProxy.attack(i, claim); gameProxy.attack(i, claim);
} }
claim = _changeClaimStatus(claim, VMStatuses.PANIC); claim = _changeClaimStatus(claim, VMStatuses.PANIC);
for (uint256 i = gameProxy.claimDataLen() - 1; i < gameProxy.MAX_GAME_DEPTH(); i++) { for (uint256 i = gameProxy.claimDataLen() - 1; i < gameProxy.maxGameDepth(); i++) {
gameProxy.attack(i, claim); gameProxy.attack(i, claim);
} }
...@@ -495,12 +495,12 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -495,12 +495,12 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
/// @dev Static unit test asserting that resolve reverts when attempting to resolve a subgame at max depth /// @dev Static unit test asserting that resolve reverts when attempting to resolve a subgame at max depth
function test_resolve_claimAtMaxDepthAlreadyResolved_reverts() public { function test_resolve_claimAtMaxDepthAlreadyResolved_reverts() public {
Claim claim = _dummyClaim(); Claim claim = _dummyClaim();
for (uint256 i; i < gameProxy.SPLIT_DEPTH(); i++) { for (uint256 i; i < gameProxy.splitDepth(); i++) {
gameProxy.attack(i, claim); gameProxy.attack(i, claim);
} }
claim = _changeClaimStatus(claim, VMStatuses.PANIC); claim = _changeClaimStatus(claim, VMStatuses.PANIC);
for (uint256 i = gameProxy.claimDataLen() - 1; i < gameProxy.MAX_GAME_DEPTH(); i++) { for (uint256 i = gameProxy.claimDataLen() - 1; i < gameProxy.maxGameDepth(); i++) {
gameProxy.attack(i, claim); gameProxy.attack(i, claim);
} }
...@@ -539,7 +539,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -539,7 +539,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
/// @dev Tests that local data is loaded into the preimage oracle correctly in the subgame /// @dev Tests that local data is loaded into the preimage oracle correctly in the subgame
/// that is disputing the transition from `GENESIS -> GENESIS + 1` /// that is disputing the transition from `GENESIS -> GENESIS + 1`
function test_addLocalDataGenesisTransition_static_succeeds() public { function test_addLocalDataGenesisTransition_static_succeeds() public {
IPreimageOracle oracle = IPreimageOracle(address(gameProxy.VM().oracle())); IPreimageOracle oracle = IPreimageOracle(address(gameProxy.vm().oracle()));
// Get a claim below the split depth so that we can add local data for an execution trace subgame. // Get a claim below the split depth so that we can add local data for an execution trace subgame.
for (uint256 i; i < 4; i++) { for (uint256 i; i < 4; i++) {
...@@ -548,7 +548,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -548,7 +548,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
gameProxy.attack(4, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC)); gameProxy.attack(4, _changeClaimStatus(_dummyClaim(), VMStatuses.PANIC));
// Expected start/disputed claims // Expected start/disputed claims
bytes32 startingClaim = Hash.unwrap(gameProxy.GENESIS_OUTPUT_ROOT()); bytes32 startingClaim = Hash.unwrap(gameProxy.genesisOutputRoot());
bytes32 disputedClaim = bytes32(uint256(3)); bytes32 disputedClaim = bytes32(uint256(3));
Position disputedPos = LibPosition.wrap(4, 0); Position disputedPos = LibPosition.wrap(4, 0);
...@@ -579,7 +579,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init { ...@@ -579,7 +579,7 @@ contract OutputBisectionGame_Test is OutputBisectionGame_Init {
/// @dev Tests that local data is loaded into the preimage oracle correctly. /// @dev Tests that local data is loaded into the preimage oracle correctly.
function test_addLocalDataMiddle_static_succeeds() public { function test_addLocalDataMiddle_static_succeeds() public {
IPreimageOracle oracle = IPreimageOracle(address(gameProxy.VM().oracle())); IPreimageOracle oracle = IPreimageOracle(address(gameProxy.vm().oracle()));
// Get a claim below the split depth so that we can add local data for an execution trace subgame. // Get a claim below the split depth so that we can add local data for an execution trace subgame.
for (uint256 i; i < 4; i++) { for (uint256 i; i < 4; i++) {
......
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