Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Sep 28, 2023
1 parent b5d5c2b commit 76a5008
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
10 changes: 4 additions & 6 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,22 @@ func TestInvalidCliqueConfig(t *testing.T) {
}
}

func newUint64(val uint64) *uint64 { return &val }

func TestSetupGenesis(t *testing.T) {
var (
customghash = common.HexToHash("0x89c99d90b79719238d2645c7642f2c9295246e80775b38cfd162b696817fbd50")
customg = Genesis{
Config: &params.ChainConfig{HomesteadBlock: big.NewInt(3), ArbitrumChainParams: params.ArbitrumChainParams{
MaxCodeSize: newUint64(params.MaxCodeSize),
MaxInitCodeSize: newUint64(params.MaxInitCodeSize)}},
MaxCodeSize: params.MaxCodeSize,
MaxInitCodeSize: params.MaxInitCodeSize}},
Alloc: GenesisAlloc{
{1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
},
}
oldcustomg = customg
)
oldcustomg.Config = &params.ChainConfig{HomesteadBlock: big.NewInt(2), ArbitrumChainParams: params.ArbitrumChainParams{
MaxCodeSize: newUint64(params.MaxCodeSize),
MaxInitCodeSize: newUint64(params.MaxInitCodeSize)}}
MaxCodeSize: params.MaxCodeSize,
MaxInitCodeSize: params.MaxInitCodeSize}}
tests := []struct {
name string
fn func(ethdb.Database) (*params.ChainConfig, common.Hash, error)
Expand Down
12 changes: 6 additions & 6 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestStateProcessorErrors(t *testing.T) {
LondonBlock: big.NewInt(0),
Ethash: new(params.EthashConfig),
ArbitrumChainParams: params.ArbitrumChainParams{
MaxCodeSize: newUint64(params.MaxCodeSize),
MaxInitCodeSize: newUint64(params.MaxInitCodeSize),
MaxCodeSize: params.MaxCodeSize,
MaxInitCodeSize: params.MaxInitCodeSize,
},
}
signer = types.LatestSigner(config)
Expand Down Expand Up @@ -242,8 +242,8 @@ func TestStateProcessorErrors(t *testing.T) {
IstanbulBlock: big.NewInt(0),
MuirGlacierBlock: big.NewInt(0),
ArbitrumChainParams: params.ArbitrumChainParams{
MaxCodeSize: newUint64(params.MaxCodeSize),
MaxInitCodeSize: newUint64(params.MaxInitCodeSize),
MaxCodeSize: params.MaxCodeSize,
MaxInitCodeSize: params.MaxInitCodeSize,
},
},
Alloc: GenesisAlloc{
Expand Down Expand Up @@ -342,8 +342,8 @@ func TestStateProcessorErrors(t *testing.T) {
TerminalTotalDifficultyPassed: true,
ShanghaiTime: u64(0),
ArbitrumChainParams: params.ArbitrumChainParams{
MaxCodeSize: newUint64(params.MaxCodeSize),
MaxInitCodeSize: newUint64(params.MaxInitCodeSize),
MaxCodeSize: params.MaxCodeSize,
MaxInitCodeSize: params.MaxInitCodeSize,
},
},
Alloc: GenesisAlloc{
Expand Down
4 changes: 2 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}

// Check whether the init code size has been exceeded.
if rules.IsShanghai && contractCreation && len(msg.Data) > int(*st.evm.ChainConfig().ArbitrumChainParams.MaxInitCodeSize) {
return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), int(*st.evm.ChainConfig().ArbitrumChainParams.MaxInitCodeSize))
if rules.IsShanghai && contractCreation && len(msg.Data) > int(st.evm.ChainConfig().ArbitrumChainParams.MaxInitCodeSize) {
return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), int(st.evm.ChainConfig().ArbitrumChainParams.MaxInitCodeSize))
}

// Execute the preparatory steps for state transition which includes:
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ func (pool *TxPool) validateTxBasics(tx *types.Transaction, local bool) error {
return ErrOversizedData
}
// Check whether the init code size has been exceeded.
if pool.shanghai.Load() && tx.To() == nil && len(tx.Data()) > int(*pool.chainconfig.ArbitrumChainParams.MaxInitCodeSize) {
return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), int(*pool.chainconfig.ArbitrumChainParams.MaxInitCodeSize))
if pool.shanghai.Load() && tx.To() == nil && len(tx.Data()) > int(pool.chainconfig.ArbitrumChainParams.MaxInitCodeSize) {
return fmt.Errorf("%w: code size %v limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), int(pool.chainconfig.ArbitrumChainParams.MaxInitCodeSize))
}
// Transactions can't be negative. This may never happen using RLP decoded
// transactions but may occur if you create a transaction using the RPC.
Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
ret, err := evm.interpreter.Run(contract, nil, false)

// Check whether the max code size has been exceeded, assign err if the case.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > int(*evm.chainConfig.ArbitrumChainParams.MaxCodeSize) {
if err == nil && evm.chainRules.IsEIP158 && len(ret) > int(evm.chainConfig.ArbitrumChainParams.MaxCodeSize) {
err = ErrMaxCodeSizeExceeded
}

Expand Down
4 changes: 2 additions & 2 deletions core/vm/gas_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
return 0, err
}
size, overflow := stack.Back(2).Uint64WithOverflow()
if overflow || size > *evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize {
if overflow || size > evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize {
return 0, ErrGasUintOverflow
}
// Since size <= *evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize, these multiplication cannot overflow
Expand All @@ -324,7 +324,7 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
return 0, err
}
size, overflow := stack.Back(2).Uint64WithOverflow()
if overflow || size > *evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize {
if overflow || size > evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize {
return 0, ErrGasUintOverflow
}
// Since size <= *evm.chainConfig.ArbitrumChainParams.MaxInitCodeSize, these multiplication cannot overflow
Expand Down
8 changes: 4 additions & 4 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,11 @@ func (c *ChainConfig) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &cfgJSON); err != nil {
return err
}
if cfgJSON.ArbitrumChainParams.MaxCodeSize == nil {
cfgJSON.ArbitrumChainParams.MaxCodeSize = newUint64(MaxCodeSize)
if cfgJSON.ArbitrumChainParams.MaxCodeSize == 0 {
cfgJSON.ArbitrumChainParams.MaxCodeSize = MaxCodeSize
}
if cfgJSON.ArbitrumChainParams.MaxInitCodeSize == nil {
cfgJSON.ArbitrumChainParams.MaxInitCodeSize = newUint64(MaxInitCodeSize)
if cfgJSON.ArbitrumChainParams.MaxInitCodeSize == 0 {
cfgJSON.ArbitrumChainParams.MaxInitCodeSize = MaxInitCodeSize
}
*c = ChainConfig(cfgJSON)
return nil
Expand Down
8 changes: 4 additions & 4 deletions params/config_arbitrum.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type ArbitrumChainParams struct {
InitialArbOSVersion uint64
InitialChainOwner common.Address
GenesisBlockNum uint64
MaxCodeSize *uint64 `json:"maxCodeSize,omitempty,"` // Maximum bytecode to permit for a contract
MaxInitCodeSize *uint64 `json:"maxInitCodeSize,omitempty"` // Maximum initcode to permit in a creation transaction and create instructions
MaxCodeSize uint64 `json:"maxCodeSize,omitempty,"` // Maximum bytecode to permit for a contract. 0 value implies params.MaxCodeSize
MaxInitCodeSize uint64 `json:"maxInitCodeSize,omitempty"` // Maximum initcode to permit in a creation transaction and create instructions. o vale implies params.MaxInitCodeSize
}

func (c *ChainConfig) IsArbitrum() bool {
Expand Down Expand Up @@ -138,8 +138,8 @@ func DisableArbitrumParams() ArbitrumChainParams {
DataAvailabilityCommittee: false,
InitialArbOSVersion: 0,
InitialChainOwner: common.Address{},
MaxCodeSize: newUint64(MaxCodeSize),
MaxInitCodeSize: newUint64(MaxInitCodeSize),
MaxCodeSize: MaxCodeSize,
MaxInitCodeSize: MaxInitCodeSize,
}
}

Expand Down
6 changes: 4 additions & 2 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ var unmarshalChainConfigTests = []marshalUnMarshalTest{
want: [2]uint64{MaxCodeSize, 10}},
{input: `{"arbitrum": {} }`,
want: [2]uint64{MaxCodeSize, MaxInitCodeSize}},
{input: `{"arbitrum": {"maxCodeSize": 0, "maxInitCodeSize": 0} }`,
want: [2]uint64{MaxCodeSize, MaxInitCodeSize}},
}

func TestUnmarshalChainConfig(t *testing.T) {
Expand All @@ -165,9 +167,9 @@ func TestUnmarshalChainConfig(t *testing.T) {
t.Errorf("failed to unmarshal. Error: %q", err)
}
expected := test.want.([2]uint64)
if *c.ArbitrumChainParams.MaxCodeSize != expected[0] || *c.ArbitrumChainParams.MaxInitCodeSize != expected[1] {
if c.ArbitrumChainParams.MaxCodeSize != expected[0] || c.ArbitrumChainParams.MaxInitCodeSize != expected[1] {
t.Errorf("failed to unmarshal MaxCodeSize and MaxInitCodeSize correctly. unmarshalled as (%d %d) want (%d %d))",
*c.ArbitrumChainParams.MaxCodeSize, *c.ArbitrumChainParams.MaxInitCodeSize, expected[0], expected[1])
c.ArbitrumChainParams.MaxCodeSize, c.ArbitrumChainParams.MaxInitCodeSize, expected[0], expected[1])
}
}
}

0 comments on commit 76a5008

Please sign in to comment.