Skip to content

Commit

Permalink
PIP-30: increased max code size limit to 32KB (#1310)
Browse files Browse the repository at this point in the history
* PIP-30: increased max code size limit to 32KB

* fixed tests
  • Loading branch information
pratikspatil024 authored Aug 20, 2024
1 parent 5009267 commit 635dacc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,14 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
ret, err := evm.interpreter.PreRun(contract, nil, false, nil)

// Check whether the max code size has been exceeded, assign err if the case.
if err == nil && evm.chainRules.IsEIP158 && len(ret) > params.MaxCodeSize {
err = ErrMaxCodeSizeExceeded
if err == nil && evm.chainRules.IsEIP158 {
if evm.chainConfig.Bor != nil && evm.chainConfig.Bor.IsAhmedabad(evm.Context.BlockNumber) {
if len(ret) > params.MaxCodeSizePostAhmedabad {
err = ErrMaxCodeSizeExceeded
}
} else if len(ret) > params.MaxCodeSize {
err = ErrMaxCodeSizeExceeded
}
}

// Reject code starting with 0xEF if EIP-3541 is enabled.
Expand Down
5 changes: 5 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ type BorConfig struct {
DelhiBlock *big.Int `json:"delhiBlock"` // Delhi switch block (nil = no fork, 0 = already on delhi)
IndoreBlock *big.Int `json:"indoreBlock"` // Indore switch block (nil = no fork, 0 = already on indore)
StateSyncConfirmationDelay map[string]uint64 `json:"stateSyncConfirmationDelay"` // StateSync Confirmation Delay, in seconds, to calculate `to`
AhmedabadBlock *big.Int `json:"ahmedabadBlock"` // Ahmedabad switch block (nil = no fork, 0 = already on ahmedabad)
}

// String implements the stringer interface, returning the consensus engine details.
Expand Down Expand Up @@ -657,6 +658,10 @@ func (c *BorConfig) CalculateStateSyncDelay(number uint64) uint64 {
return borKeyValueConfigHelper(c.StateSyncConfirmationDelay, number)
}

func (c *BorConfig) IsAhmedabad(number *big.Int) bool {
return isBlockForked(c.AhmedabadBlock, number)
}

// // TODO: modify this function once the block number is finalized
// func (c *BorConfig) IsNapoli(number *big.Int) bool {
// if c.NapoliBlock != nil {
Expand Down
5 changes: 3 additions & 2 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ const (
DefaultBaseFeeChangeDenominator = 8 // Bounds the amount the base fee can change between blocks.
DefaultElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.

MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions
MaxCodeSize = 24576 // Maximum bytecode to permit for a contract
MaxCodeSizePostAhmedabad = 32768 // Maximum bytecode to permit for a contract post Ahmedabad hard fork (bor / polygon pos) (32KB)
MaxInitCodeSize = 2 * MaxCodeSize // Maximum initcode to permit in a creation transaction and create instructions

// Precompiled contract gas prices

Expand Down

0 comments on commit 635dacc

Please sign in to comment.