Skip to content

Commit

Permalink
Fix the limit for TX pool contract creation size (#1345)
Browse files Browse the repository at this point in the history
* Fix the limit for TX pool contract creation size

The limit should be double the size of contract code size.
  • Loading branch information
vcastellm committed Mar 30, 2023
1 parent ecadb95 commit 879cdf5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

const (
SpuriousDragonMaxCodeSize = 24576
TxPoolMaxInitCodeSize = 2 * SpuriousDragonMaxCodeSize

TxGas uint64 = 21000 // Per transaction not creating a contract
TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract
Expand Down
2 changes: 1 addition & 1 deletion txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ func (p *TxPool) validateTx(tx *types.Transaction) error {
return ErrSmartContractRestricted
}

if p.forks.EIP158 && len(tx.Input) > state.SpuriousDragonMaxCodeSize {
if p.forks.EIP158 && len(tx.Input) > state.TxPoolMaxInitCodeSize {
return runtime.ErrMaxCodeSizeExceeded
}
}
Expand Down
8 changes: 4 additions & 4 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1750,12 +1750,12 @@ func TestPermissionSmartContractDeployment(t *testing.T) {
)
})

t.Run("Input larger then the MaxInitCodeSize", func(t *testing.T) {
t.Run("Input larger than the TxPoolMaxInitCodeSize", func(t *testing.T) {
t.Parallel()
pool := setupPool()
pool.forks.EIP158 = true

input := make([]byte, state.SpuriousDragonMaxCodeSize+1)
input := make([]byte, state.TxPoolMaxInitCodeSize+1)
_, err := rand.Read(input)
require.NoError(t, err)

Expand All @@ -1769,12 +1769,12 @@ func TestPermissionSmartContractDeployment(t *testing.T) {
)
})

t.Run("Input the same as MaxInitCodeSize", func(t *testing.T) {
t.Run("Input the same as TxPoolMaxInitCodeSize", func(t *testing.T) {
t.Parallel()
pool := setupPool()
pool.forks.EIP158 = true

input := make([]byte, state.SpuriousDragonMaxCodeSize)
input := make([]byte, state.TxPoolMaxInitCodeSize)
_, err := rand.Read(input)
require.NoError(t, err)

Expand Down

0 comments on commit 879cdf5

Please sign in to comment.