Skip to content

Commit 93b7de9

Browse files
Merge remote-tracking branch 'origin/master' into merge-v1.12.1
Conflicts: core/txpool/txpool.go We added max code size to ChainConfig on master (ethereum#255) and this conflicted with upstream changes to refactoring txpool. Resolved by putting the check in ValidateTransaction in the file it was moved to.
2 parents 627e5f3 + 859182f commit 93b7de9

File tree

8 files changed

+34
-11
lines changed

8 files changed

+34
-11
lines changed

arbitrum/apibackend.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,13 @@ func (a *APIBackend) GetEVM(ctx context.Context, msg *core.Message, state *state
504504
vmConfig = a.BlockChain().GetVMConfig()
505505
}
506506
txContext := core.NewEVMTxContext(msg)
507-
return vm.NewEVM(*blockCtx, txContext, state, a.BlockChain().Config(), *vmConfig), vmError
507+
var context vm.BlockContext
508+
if blockCtx != nil {
509+
context = *blockCtx
510+
} else {
511+
context = core.NewEVMBlockContext(header, a.BlockChain(), nil)
512+
}
513+
return vm.NewEVM(context, txContext, state, a.BlockChain().Config(), *vmConfig), vmError
508514
}
509515

510516
func (a *APIBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription {

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func Transaction(ctx *cli.Context) error {
172172
r.Error = errors.New("gas * maxFeePerGas exceeds 256 bits")
173173
}
174174
// Check whether the init code size has been exceeded.
175-
if chainConfig.IsShanghai(new(big.Int), 0, 0) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
175+
if chainConfig.IsShanghai(new(big.Int), 0, 0) && tx.To() == nil && len(tx.Data()) > int(chainConfig.MaxInitCodeSize()) {
176176
r.Error = errors.New("max initcode size exceeded")
177177
}
178178
results = append(results, r)

core/state_transition.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
449449
}
450450

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

456456
// Execute the preparatory steps for state transition which includes:

core/txpool/validation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func ValidateTransaction(tx *types.Transaction, blobs []kzg4844.Blob, commits []
6767
return fmt.Errorf("%w: type %d rejected, pool not yet in Cancun", core.ErrTxTypeNotSupported, tx.Type())
6868
}
6969
// Check whether the init code size has been exceeded
70-
if opts.Config.IsShanghai(head.Number, head.Time, types.DeserializeHeaderExtraInformation(head).ArbOSFormatVersion) && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
71-
return fmt.Errorf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
70+
if opts.Config.IsShanghai(head.Number, head.Time, types.DeserializeHeaderExtraInformation(head).ArbOSFormatVersion) && tx.To() == nil && len(tx.Data()) > int(opts.Config.MaxInitCodeSize()) {
71+
return fmt.Errorf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(tx.Data()), int(opts.Config.MaxInitCodeSize()))
7272
}
7373
// Transactions can't be negative. This may never happen using RLP decoded
7474
// transactions but may occur for transactions created using the RPC.

core/vm/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
505505
ret, err := evm.interpreter.Run(contract, nil, false)
506506

507507
// Check whether the max code size has been exceeded, assign err if the case.
508-
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
508+
if err == nil && evm.chainRules.IsEIP158 && len(ret) > int(evm.chainConfig.MaxCodeSize()) {
509509
err = ErrMaxCodeSizeExceeded
510510
}
511511

core/vm/gas_table.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ func gasCreateEip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory, m
310310
return 0, err
311311
}
312312
size, overflow := stack.Back(2).Uint64WithOverflow()
313-
if overflow || size > params.MaxInitCodeSize {
313+
if overflow || size > evm.chainConfig.MaxInitCodeSize() {
314314
return 0, ErrGasUintOverflow
315315
}
316-
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
316+
// Since size <= evm.chainConfig.MaxInitCodeSize(), these multiplication cannot overflow
317317
moreGas := params.InitCodeWordGas * ((size + 31) / 32)
318318
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
319319
return 0, ErrGasUintOverflow
@@ -326,10 +326,10 @@ func gasCreate2Eip3860(evm *EVM, contract *Contract, stack *Stack, mem *Memory,
326326
return 0, err
327327
}
328328
size, overflow := stack.Back(2).Uint64WithOverflow()
329-
if overflow || size > params.MaxInitCodeSize {
329+
if overflow || size > evm.chainConfig.MaxInitCodeSize() {
330330
return 0, ErrGasUintOverflow
331331
}
332-
// Since size <= params.MaxInitCodeSize, these multiplication cannot overflow
332+
// Since size <= evm.chainConfig.MaxInitCodeSize(), these multiplication cannot overflow
333333
moreGas := (params.InitCodeWordGas + params.Keccak256WordGas) * ((size + 31) / 32)
334334
if gas, overflow = math.SafeAdd(gas, moreGas); overflow {
335335
return 0, ErrGasUintOverflow

internal/ethapi/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ func doCall(ctx context.Context, b Backend, args TransactionArgs, state *state.S
10981098
if err != nil {
10991099
return nil, err
11001100
}
1101+
msg.TxRunMode = runMode
11011102
// make a new EVM for the scheduled Tx (an EVM must never be reused)
11021103
evm, vmError := b.GetEVM(ctx, msg, state, header, &vm.Config{NoBaseFee: true}, &blockCtx)
11031104
go func() {

params/config_arbitrum.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type ArbitrumChainParams struct {
2929
InitialArbOSVersion uint64
3030
InitialChainOwner common.Address
3131
GenesisBlockNum uint64
32+
MaxCodeSize uint64 `json:"MaxCodeSize,omitempty"` // Maximum bytecode to permit for a contract. 0 value implies params.MaxCodeSize
33+
MaxInitCodeSize uint64 `json:"MaxInitCodeSize,omitempty"` // Maximum initcode to permit in a creation transaction and create instructions. 0 value implies params.MaxInitCodeSize
3234
}
3335

3436
func (c *ChainConfig) IsArbitrum() bool {
@@ -39,6 +41,20 @@ func (c *ChainConfig) IsArbitrumNitro(num *big.Int) bool {
3941
return c.IsArbitrum() && isBlockForked(new(big.Int).SetUint64(c.ArbitrumChainParams.GenesisBlockNum), num)
4042
}
4143

44+
func (c *ChainConfig) MaxCodeSize() uint64 {
45+
if c.ArbitrumChainParams.MaxCodeSize == 0 {
46+
return MaxCodeSize
47+
}
48+
return c.ArbitrumChainParams.MaxCodeSize
49+
}
50+
51+
func (c *ChainConfig) MaxInitCodeSize() uint64 {
52+
if c.ArbitrumChainParams.MaxInitCodeSize == 0 {
53+
return c.MaxCodeSize() * 2
54+
}
55+
return c.ArbitrumChainParams.MaxInitCodeSize
56+
}
57+
4258
func (c *ChainConfig) DebugMode() bool {
4359
return c.ArbitrumChainParams.AllowDebugPrecompiles
4460
}

0 commit comments

Comments
 (0)