diff --git a/core/state/access_list.go b/core/state/access_list.go index 9d929e2d6d..16a1524991 100644 --- a/core/state/access_list.go +++ b/core/state/access_list.go @@ -62,7 +62,8 @@ func (al *accessList) Contains(address common.Address, slot common.Hash) (addres // newAccessList creates a new accessList. func newAccessList() *accessList { return &accessList{ - addresses: make(map[common.Address]int), + addresses: make(map[common.Address]int), + addressCodes: make(map[common.Address]struct{}), } } diff --git a/core/state_transition.go b/core/state_transition.go index 3ec718c52c..ec7c333753 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -471,8 +471,11 @@ func (st *stateTransition) execute() (*ExecutionResult, error) { } // Check whether the init code size has been exceeded. - if rules.IsShanghai && contractCreation && len(msg.Data) > params.MaxInitCodeSize { - return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSize) + if rules.IsOsaka && contractCreation && len(msg.Data) > params.MaxInitCodeSizeEIP7907 { + return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSizeEIP7907) + } + if !rules.IsOsaka && rules.IsShanghai && contractCreation && len(msg.Data) > params.MaxInitCodeSizeEIP3860 { + return nil, fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(msg.Data), params.MaxInitCodeSizeEIP3860) } // Execute the preparatory steps for state transition which includes: diff --git a/core/vm/eips.go b/core/vm/eips.go index 9dea2fff94..76c5d47211 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -547,4 +547,6 @@ func enable7907(jt *JumpTable) { jt[STATICCALL].dynamicGas = gasStaticCallEIP7907 jt[DELEGATECALL].dynamicGas = gasDelegateCallEIP7907 jt[EXTCODECOPY].dynamicGas = gasExtCodeCopyEIP7907 + jt[CREATE].dynamicGas = gasCreateEip7907 + jt[CREATE2].dynamicGas = gasCreate2Eip7907 } diff --git a/core/vm/evm.go b/core/vm/evm.go index a1fe1293c5..e25df1b9b5 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -530,10 +530,10 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address) ([]b } // Check whether the max code size has been exceeded, assign err if the case. - if evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSizeEIP170 { + if evm.chainRules.IsOsaka && len(ret) > params.MaxCodeSizeEIP7907 { return ret, ErrMaxCodeSizeExceeded } - if evm.chainRules.IsOsaka && len(ret) > params.MaxCodeSizeEIP7907 { + if !evm.chainRules.IsOsaka && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSizeEIP170 { return ret, ErrMaxCodeSizeExceeded } diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index 2d2314d880..ca3a1a595e 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -344,6 +344,45 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, return gas, nil } +func gasCreateEip7907(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { + gas, err := memoryGasCost(mem, memorySize) + if err != nil { + return 0, err + } + size, overflow := stack.Back(2).Uint64WithOverflow() + if overflow { + return 0, ErrGasUintOverflow + } + if size > params.MaxInitCodeSizeEIP7907 { + return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size) + } + // Since size <= params.MaxInitCodeSize, these multiplication cannot overflow + moreGas := params.InitCodeWordGas * ((size + 31) / 32) + if gas, overflow = math.SafeAdd(gas, moreGas); overflow { + return 0, ErrGasUintOverflow + } + return gas, nil +} +func gasCreate2Eip7907(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { + gas, err := memoryGasCost(mem, memorySize) + if err != nil { + return 0, err + } + size, overflow := stack.Back(2).Uint64WithOverflow() + if overflow { + return 0, ErrGasUintOverflow + } + if size > params.MaxInitCodeSizeEIP7907 { + return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size) + } + // Since size <= params.MaxInitCodeSize, these multiplication cannot overflow + moreGas := (params.InitCodeWordGas + params.Keccak256WordGas) * ((size + 31) / 32) + if gas, overflow = math.SafeAdd(gas, moreGas); overflow { + return 0, ErrGasUintOverflow + } + return gas, nil +} + func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) { expByteLen := uint64((stack.data[stack.len()-2].BitLen() + 7) / 8) diff --git a/params/protocol_params.go b/params/protocol_params.go index d0a99c9eee..6b376d4072 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -132,10 +132,10 @@ const ( DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have. InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks. - MaxCodeSizeEIP170 = 24576 // Maximum bytecode to permit for a contract - MaxCodeSizeEIP7907 = 268435456 // Maximum bytecode permitted per contract after EIP-7907 - MaxInitCodeSizeEIP3860 = 2 * MaxCodeSizeEIP170 // Maximum initcode to permit in a creation transaction and create instructions - MaxInitCodeSizeEIP7903 = 2 * MaxCodeSizeEIP170 // Maximum initcode to permit in a creation transaction and create instructions + MaxCodeSizeEIP170 = 24576 // Maximum bytecode to permit for a contract + MaxCodeSizeEIP7907 = 268435456 // Maximum bytecode permitted per contract after EIP-7907 + MaxInitCodeSizeEIP3860 = 2 * MaxCodeSizeEIP170 // Maximum initcode to permit in a creation transaction and create instructions + MaxInitCodeSizeEIP7907 = 2 * MaxCodeSizeEIP7907 // Maximum initcode to permit in a creation transaction and create instructions // Precompiled contract gas prices