Commit e34b518b authored by clabby's avatar clabby Committed by GitHub

feat(ctb): Bump `GameType` size to 32 bits (#9220)

* `GameType` u8 -> u32

* go lint
parent 64723888
This diff is collapsed.
This diff is collapsed.
......@@ -49,7 +49,7 @@ func (f *DisputeGameFactoryContract) GetGame(ctx context.Context, idx uint64, bl
return f.decodeGame(result), nil
}
func (f *DisputeGameFactoryContract) GetGameImpl(ctx context.Context, gameType uint8) (common.Address, error) {
func (f *DisputeGameFactoryContract) GetGameImpl(ctx context.Context, gameType uint32) (common.Address, error) {
result, err := f.multiCaller.SingleCall(ctx, batching.BlockLatest, f.contract.Call(methodGameImpls, gameType))
if err != nil {
return common.Address{}, fmt.Errorf("failed to load game impl for type %v: %w", gameType, err)
......@@ -81,7 +81,7 @@ func (f *DisputeGameFactoryContract) GetAllGames(ctx context.Context, blockHash
}
func (f *DisputeGameFactoryContract) decodeGame(result *batching.CallResult) types.GameMetadata {
gameType := result.GetUint8(0)
gameType := result.GetUint32(0)
timestamp := result.GetUint64(1)
proxy := result.GetAddress(2)
return types.GameMetadata{
......
......@@ -13,9 +13,7 @@ import (
"github.com/stretchr/testify/require"
)
var (
factoryAddr = common.HexToAddress("0x24112842371dFC380576ebb09Ae16Cb6B6caD7CB")
)
var factoryAddr = common.HexToAddress("0x24112842371dFC380576ebb09Ae16Cb6B6caD7CB")
func TestDisputeGameFactorySimpleGetters(t *testing.T) {
blockHash := common.Hash{0xbb, 0xcd}
......@@ -109,7 +107,7 @@ func TestGetAllGames(t *testing.T) {
func TestGetGameImpl(t *testing.T) {
stubRpc, factory := setupDisputeGameFactoryTest(t)
gameType := uint8(3)
gameType := uint32(3)
gameImplAddr := common.Address{0xaa}
stubRpc.SetResponse(
factoryAddr,
......
......@@ -20,14 +20,14 @@ import (
)
var (
cannonGameType = uint8(0)
alphabetGameType = uint8(255)
cannonGameType = uint32(0)
alphabetGameType = uint32(255)
)
type CloseFunc func()
type Registry interface {
RegisterGameType(gameType uint8, creator scheduler.PlayerCreator, oracle keccakTypes.LargePreimageOracle)
RegisterGameType(gameType uint32, creator scheduler.PlayerCreator, oracle keccakTypes.LargePreimageOracle)
}
func RegisterGameTypes(
......@@ -107,7 +107,7 @@ func registerAlphabet(
return nil
}
func createOracle(ctx context.Context, gameFactory *contracts.DisputeGameFactoryContract, caller *batching.MultiCaller, gameType uint8) (*contracts.PreimageOracleContract, error) {
func createOracle(ctx context.Context, gameFactory *contracts.DisputeGameFactoryContract, caller *batching.MultiCaller, gameType uint32) (*contracts.PreimageOracleContract, error) {
implAddr, err := gameFactory.GetGameImpl(ctx, gameType)
if err != nil {
return nil, fmt.Errorf("failed to load implementation for game type %v: %w", gameType, err)
......
......@@ -149,7 +149,7 @@ func (m *mockMinimalDisputeGameFactoryCaller) GetGameCount(_ context.Context, _
func (m *mockMinimalDisputeGameFactoryCaller) GetGame(_ context.Context, index uint64, _ common.Hash) (types.GameMetadata, error) {
if m.indexErrors[index] {
return struct {
GameType uint8
GameType uint32
Timestamp uint64
Proxy common.Address
}{}, gameIndexErr
......
......@@ -11,25 +11,23 @@ import (
"golang.org/x/exp/maps"
)
var (
ErrUnsupportedGameType = errors.New("unsupported game type")
)
var ErrUnsupportedGameType = errors.New("unsupported game type")
type GameTypeRegistry struct {
types map[uint8]scheduler.PlayerCreator
types map[uint32]scheduler.PlayerCreator
oracles map[common.Address]keccakTypes.LargePreimageOracle
}
func NewGameTypeRegistry() *GameTypeRegistry {
return &GameTypeRegistry{
types: make(map[uint8]scheduler.PlayerCreator),
types: make(map[uint32]scheduler.PlayerCreator),
oracles: make(map[common.Address]keccakTypes.LargePreimageOracle),
}
}
// RegisterGameType registers a scheduler.PlayerCreator to use for a specific game type.
// Panics if the same game type is registered multiple times, since this indicates a significant programmer error.
func (r *GameTypeRegistry) RegisterGameType(gameType uint8, creator scheduler.PlayerCreator, oracle keccakTypes.LargePreimageOracle) {
func (r *GameTypeRegistry) RegisterGameType(gameType uint32, creator scheduler.PlayerCreator, oracle keccakTypes.LargePreimageOracle) {
if _, ok := r.types[gameType]; ok {
panic(fmt.Errorf("duplicate creator registered for game type: %v", gameType))
}
......
......@@ -37,7 +37,7 @@ func GameStatusFromUint8(i uint8) (GameStatus, error) {
}
type GameMetadata struct {
GameType uint8
GameType uint32
Timestamp uint64
Proxy common.Address
}
......@@ -29,7 +29,7 @@ type ProposerCfg struct {
OutputOracleAddr *common.Address
DisputeGameFactoryAddr *common.Address
ProposalInterval time.Duration
DisputeGameType uint8
DisputeGameType uint32
ProposerKey *ecdsa.PrivateKey
AllowNonFinalized bool
}
......
......@@ -31,9 +31,9 @@ import (
)
const (
cannonGameType uint8 = 0
alphabetGameType uint8 = 255
alphabetGameDepth = 4
cannonGameType uint32 = 0
alphabetGameType uint32 = 255
alphabetGameDepth = 4
)
type Status uint8
......
......@@ -103,13 +103,13 @@ func TestManualABIPacking(t *testing.T) {
output = testutils.RandomOutputResponse(rng)
txData, err = proposeL2OutputDGFTxData(dgfAbi, uint8(0), output)
txData, err = proposeL2OutputDGFTxData(dgfAbi, uint32(0), output)
require.NoError(t, err)
opts.GasLimit = 100_000
dgfTx, err := dgf.Create(
opts,
uint8(0),
uint32(0),
output.OutputRoot,
math.U256Bytes(new(big.Int).SetUint64(output.BlockRef.Number)),
)
......
......@@ -54,7 +54,7 @@ type CLIConfig struct {
ProposalInterval time.Duration
// DisputeGameType is the type of dispute game to create when submitting an output proposal.
DisputeGameType uint8
DisputeGameType uint32
// ActiveSequencerCheckDuration is the duration between checks to determine the active sequencer endpoint.
ActiveSequencerCheckDuration time.Duration
......@@ -104,7 +104,7 @@ func NewConfig(ctx *cli.Context) *CLIConfig {
PprofConfig: oppprof.ReadCLIConfig(ctx),
DGFAddress: ctx.String(flags.DisputeGameFactoryAddressFlag.Name),
ProposalInterval: ctx.Duration(flags.ProposalIntervalFlag.Name),
DisputeGameType: uint8(ctx.Uint(flags.DisputeGameTypeFlag.Name)),
DisputeGameType: uint32(ctx.Uint(flags.DisputeGameTypeFlag.Name)),
ActiveSequencerCheckDuration: ctx.Duration(flags.ActiveSequencerCheckDurationFlag.Name),
}
}
......@@ -330,7 +330,7 @@ func (l *L2OutputSubmitter) ProposeL2OutputDGFTxData(output *eth.OutputResponse)
}
// proposeL2OutputDGFTxData creates the transaction data for the DisputeGameFactory's `create` function
func proposeL2OutputDGFTxData(abi *abi.ABI, gameType uint8, output *eth.OutputResponse) ([]byte, error) {
func proposeL2OutputDGFTxData(abi *abi.ABI, gameType uint32, output *eth.OutputResponse) ([]byte, error) {
return abi.Pack("create", gameType, output.OutputRoot, math.U256Bytes(new(big.Int).SetUint64(output.BlockRef.Number)))
}
......
......@@ -36,7 +36,7 @@ type ProposerConfig struct {
L2OutputOracleAddr *common.Address
DisputeGameFactoryAddr *common.Address
DisputeGameType uint8
DisputeGameType uint32
// AllowNonFinalized enables the proposal of safe, but non-finalized L2 blocks.
// The L1 block-hash embedded in the proposal TX is checked and should ensure the proposal
......
......@@ -1115,7 +1115,7 @@ contract Deploy is Deployer {
})
);
uint8 rawGameType = GameType.unwrap(_gameType);
uint32 rawGameType = GameType.unwrap(_gameType);
string memory gameTypeString;
if (rawGameType == GameType.unwrap(GameTypes.CANNON)) {
gameTypeString = "Cannon";
......
......@@ -88,11 +88,11 @@
"sourceCodeHash": "0x1afb1d392e8f6a58ff86ea7f648e0d1756d4ba8d0d964279d58a390deaa53b7e"
},
"src/dispute/DisputeGameFactory.sol": {
"initCodeHash": "0xf6ab546550f8d3d85e9bde748eeea21f7fb16db3d63b8312c04598ca64c1be16",
"initCodeHash": "0x56a9edbde3365f51454f6e0f12e136f4f19c0cdb10e89467be00129bb72f139e",
"sourceCodeHash": "0x01c757935c87dcf2faa7f16bcf29cfb29b90c671a874f983067614670147b11d"
},
"src/dispute/FaultDisputeGame.sol": {
"initCodeHash": "0x2f30aa96d5c4d126d93dfe15bbfc90e1bbd6bc6208bcc4a49e250790c2a0918d",
"initCodeHash": "0xe410bdcc3f0e8e71ddb609d1a0c21a40e1b06debeb55de6aff1452c8dda4af0b",
"sourceCodeHash": "0x315508f5b100dcb6b81077fb8d6999de425b47f0dfd0330ac1973ee4df166f4a"
},
"src/legacy/DeployerWhitelist.sol": {
......
......@@ -9,7 +9,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Claim",
......@@ -46,7 +46,7 @@
{
"internalType": "GameType",
"name": "gameType_",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Timestamp",
......@@ -80,7 +80,7 @@
{
"internalType": "GameType",
"name": "",
"type": "uint8"
"type": "uint32"
}
],
"name": "gameImpls",
......@@ -99,7 +99,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Claim",
......@@ -133,7 +133,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Claim",
......@@ -162,7 +162,7 @@
{
"internalType": "GameType",
"name": "",
"type": "uint8"
"type": "uint32"
}
],
"name": "initBonds",
......@@ -214,7 +214,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "contract IDisputeGame",
......@@ -232,7 +232,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "uint256",
......@@ -284,7 +284,7 @@
"indexed": true,
"internalType": "GameType",
"name": "gameType",
"type": "uint8"
"type": "uint32"
},
{
"indexed": true,
......@@ -309,7 +309,7 @@
"indexed": true,
"internalType": "GameType",
"name": "gameType",
"type": "uint8"
"type": "uint32"
}
],
"name": "ImplementationSet",
......@@ -322,7 +322,7 @@
"indexed": true,
"internalType": "GameType",
"name": "gameType",
"type": "uint8"
"type": "uint32"
},
{
"indexed": true,
......@@ -387,7 +387,7 @@
{
"internalType": "GameType",
"name": "gameType",
"type": "uint8"
"type": "uint32"
}
],
"name": "NoImplementation",
......
......@@ -4,7 +4,7 @@
{
"internalType": "GameType",
"name": "_gameType",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Claim",
......@@ -244,7 +244,7 @@
{
"internalType": "GameType",
"name": "gameType_",
"type": "uint8"
"type": "uint32"
},
{
"internalType": "Claim",
......@@ -280,7 +280,7 @@
{
"internalType": "GameType",
"name": "gameType_",
"type": "uint8"
"type": "uint32"
}
],
"stateMutability": "view",
......
......@@ -22,7 +22,7 @@ library LibGameId {
returns (GameId gameId_)
{
assembly {
gameId_ := or(or(shl(248, _gameType), shl(184, _timestamp)), _gameProxy)
gameId_ := or(or(shl(224, _gameType), shl(160, _timestamp)), _gameProxy)
}
}
......@@ -37,9 +37,9 @@ library LibGameId {
returns (GameType gameType_, Timestamp timestamp_, IDisputeGame gameProxy_)
{
assembly {
gameType_ := shr(248, _gameId)
timestamp_ := shr(184, and(_gameId, not(shl(248, 0xff))))
gameProxy_ := and(_gameId, 0xffffffffffffffffffffffffffffffffffffffff)
gameType_ := shr(224, _gameId)
timestamp_ := and(shr(160, _gameId), 0xFFFFFFFFFFFFFFFF)
gameProxy_ := and(_gameId, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
}
}
}
......@@ -74,7 +74,7 @@ type Clock is uint128;
type Position is uint128;
/// @notice A `GameType` represents the type of game being played.
type GameType is uint8;
type GameType is uint32;
/// @notice A `VMStatus` represents the status of a VM execution.
type VMStatus is uint8;
......
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