Skip to content

Commit

Permalink
[Polygon] Bor: PIP-30: increased max code size limit to 32KB [For Eri…
Browse files Browse the repository at this point in the history
…gon-2] (#11811)

[Polygon] Bor: [PIP-30: increased max code size limit to
32KB](https://github.com/maticnetwork/Polygon-Improvement-Proposals/blob/main/PIPs/PIP-30.md)
  • Loading branch information
pratikspatil024 authored Aug 30, 2024
1 parent fec000b commit e62c2fd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gasRemainin
ret, err = run(evm, contract, nil, false)

// EIP-170: Contract code size limit
if err == nil && evm.chainRules.IsSpuriousDragon && len(ret) > params.MaxCodeSize {
if err == nil && evm.chainRules.IsSpuriousDragon && len(ret) > evm.maxCodeSize() {
// Gnosis Chain prior to Shanghai didn't have EIP-170 enabled,
// but EIP-3860 (part of Shanghai) requires EIP-170.
if !evm.chainRules.IsAura || evm.config.HasEip3860(evm.chainRules) {
Expand Down Expand Up @@ -462,6 +462,13 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gasRemainin
return ret, address, contract.Gas, err
}

func (evm *EVM) maxCodeSize() int {
if evm.chainConfig.Bor != nil && evm.chainConfig.Bor.IsAhmedabad(evm.Context.BlockNumber) {
return params.MaxCodeSizePostAhmedabad
}
return params.MaxCodeSize
}

// Create creates a new contract using code as deployment code.
// DESCRIBED: docs/programmers_guide/guide.md#nonce
func (evm *EVM) Create(caller ContractRef, code []byte, gasRemaining uint64, endowment *uint256.Int, bailout bool) (ret []byte, contractAddr libcommon.Address, leftOverGas uint64, err error) {
Expand Down
1 change: 1 addition & 0 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type BorConfig interface {
GetAgraBlock() *big.Int
IsNapoli(num uint64) bool
GetNapoliBlock() *big.Int
IsAhmedabad(number uint64) bool
}

func (c *Config) String() string {
Expand Down
5 changes: 3 additions & 2 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ const (
ElasticityMultiplier = 2 // Bounds the maximum gas limit an EIP-1559 block may have.
InitialBaseFee = 1000000000 // Initial base fee for EIP-1559 blocks.

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
5 changes: 5 additions & 0 deletions polygon/bor/borcfg/bor_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BorConfig struct {
IndoreBlock *big.Int `json:"indoreBlock"` // Indore switch block (nil = no fork, 0 = already on Indore)
AgraBlock *big.Int `json:"agraBlock"` // Agra switch block (nil = no fork, 0 = already on Agra)
NapoliBlock *big.Int `json:"napoliBlock"` // Napoli switch block (nil = no fork, 0 = already on Napoli)
AhmedabadBlock *big.Int `json:"ahmedabadBlock"` // Ahmedabad switch block (nil = no fork, 0 = already on Ahmedabad)
StateSyncConfirmationDelay map[string]uint64 `json:"stateSyncConfirmationDelay"` // StateSync Confirmation Delay, in seconds, to calculate `to`

sprints sprints
Expand Down Expand Up @@ -130,6 +131,10 @@ func (c *BorConfig) IsNapoli(num uint64) bool {
return isForked(c.NapoliBlock, num)
}

func (c *BorConfig) IsAhmedabad(number uint64) bool {
return isForked(c.AhmedabadBlock, number)
}

func (c *BorConfig) GetNapoliBlock() *big.Int {
return c.NapoliBlock
}
Expand Down

0 comments on commit e62c2fd

Please sign in to comment.