mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
core/vm, params: raise codesize limit and initcode limit
This commit is contained in:
parent
0983cd789e
commit
b2e78c4861
8 changed files with 41 additions and 13 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/tests"
|
||||
|
|
@ -180,8 +181,10 @@ func Transaction(ctx *cli.Context) error {
|
|||
r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits")
|
||||
}
|
||||
// Check whether the init code size has been exceeded.
|
||||
if chainConfig.IsShanghai(new(big.Int), 0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
|
||||
r.Error = errors.New("max initcode size exceeded")
|
||||
if tx.To() == nil {
|
||||
if err := vm.CheckInitCodeSize(&rules, uint64(len(tx.Data()))); err != nil {
|
||||
r.Error = err
|
||||
}
|
||||
}
|
||||
results = append(results, r)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -60,7 +61,7 @@ var (
|
|||
|
||||
// ErrMaxInitCodeSizeExceeded is returned if creation transaction provides the init code bigger
|
||||
// than init code size limit.
|
||||
ErrMaxInitCodeSizeExceeded = errors.New("max initcode size exceeded")
|
||||
ErrMaxInitCodeSizeExceeded = vm.ErrMaxInitCodeSizeExceeded
|
||||
|
||||
// ErrInsufficientBalanceWitness is returned if the transaction sender has enough
|
||||
// funds to cover the transfer, but not enough to pay for witness access/modification
|
||||
|
|
|
|||
|
|
@ -471,8 +471,10 @@ 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 contractCreation {
|
||||
if err := vm.CheckInitCodeSize(&rules, uint64(len(msg.Data))); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the preparatory steps for state transition which includes:
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
|
@ -87,8 +88,10 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
|
|||
return fmt.Errorf("%w: type %d rejected, pool not yet in Prague", core.ErrTxTypeNotSupported, tx.Type())
|
||||
}
|
||||
// Check whether the init code size has been exceeded
|
||||
if rules.IsShanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
|
||||
return fmt.Errorf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
|
||||
if tx.To() == nil {
|
||||
if err := vm.CheckInitCodeSize(&rules, uint64(len(tx.Data()))); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Transactions can't be negative. This may never happen using RLP decoded
|
||||
// transactions but may occur for transactions created using the RPC.
|
||||
|
|
|
|||
|
|
@ -17,12 +17,26 @@
|
|||
package vm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
// CheckInitCodeSize checks the size of contract initcode against the protocol-defined limit.
|
||||
func CheckInitCodeSize(rules *params.Rules, size uint64) error {
|
||||
switch {
|
||||
case rules.IsOsaka && size > params.MaxInitCodeSizeOsaka:
|
||||
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, size, params.MaxInitCodeSizeOsaka)
|
||||
case rules.IsShanghai && size > params.MaxInitCodeSize:
|
||||
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, size, params.MaxInitCodeSize)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// calcMemSize64 calculates the required memory size, and returns
|
||||
// the size and whether the result overflowed uint64
|
||||
func calcMemSize64(off, l *uint256.Int) (uint64, bool) {
|
||||
|
|
|
|||
|
|
@ -526,7 +526,9 @@ 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.MaxCodeSize {
|
||||
if evm.chainRules.IsOsaka && len(ret) > params.MaxCodeSizeOsaka {
|
||||
return ret, ErrMaxCodeSizeExceeded
|
||||
} else if evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
|
||||
return ret, ErrMaxCodeSizeExceeded
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package vm
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
|
|
@ -314,8 +313,8 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
|
|||
if overflow {
|
||||
return 0, ErrGasUintOverflow
|
||||
}
|
||||
if size > params.MaxInitCodeSize {
|
||||
return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size)
|
||||
if err := CheckInitCodeSize(&evm.chainRules, size); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
||||
moreGas := params.InitCodeWordGas * ((size + 31) / 32)
|
||||
|
|
@ -324,6 +323,7 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
|
|||
}
|
||||
return gas, nil
|
||||
}
|
||||
|
||||
func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||
gas, err := memoryGasCost(mem, memorySize)
|
||||
if err != nil {
|
||||
|
|
@ -333,8 +333,8 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
|
|||
if overflow {
|
||||
return 0, ErrGasUintOverflow
|
||||
}
|
||||
if size > params.MaxInitCodeSize {
|
||||
return 0, fmt.Errorf("%w: size %d", ErrMaxInitCodeSizeExceeded, size)
|
||||
if err := CheckInitCodeSize(&evm.chainRules, size); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
|
||||
moreGas := (params.InitCodeWordGas + params.Keccak256WordGas) * ((size + 31) / 32)
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ const (
|
|||
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
|
||||
MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions
|
||||
|
||||
MaxCodeSizeOsaka = 0xC000 // Maximum bytecode to permit for a contract
|
||||
MaxInitCodeSizeOsaka = 0x12000 // Maximum initcode to permit in a creation transaction and create instructions
|
||||
|
||||
// Precompiled contract gas prices
|
||||
|
||||
EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price
|
||||
|
|
|
|||
Loading…
Reference in a new issue