Skip to content

Commit

Permalink
tx: ensure eip3860 txs can have more than max_initcode_size data if t…
Browse files Browse the repository at this point in the history
…o field is non-empty (#2575)
  • Loading branch information
jochem-brouwer authored Mar 9, 2023
1 parent 1d65ea0 commit 26a8dcd
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/tx/src/eip1559Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ export class FeeMarketEIP1559Transaction extends BaseTransaction<FeeMarketEIP155
this._validateYParity()
this._validateHighS()

if (this.common.isActivatedEIP(3860)) {
const createContract = txData.to === undefined || txData.to === null
if (createContract && this.common.isActivatedEIP(3860)) {
checkMaxInitCodeSize(this.common, this.data.length)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/tx/src/eip2930Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ export class AccessListEIP2930Transaction extends BaseTransaction<AccessListEIP2
this._validateYParity()
this._validateHighS()

if (this.common.isActivatedEIP(3860)) {
const createContract = txData.to === undefined || txData.to === null
if (createContract && this.common.isActivatedEIP(3860)) {
checkMaxInitCodeSize(this.common, this.data.length)
}
const freeze = opts?.freeze ?? true
Expand Down
3 changes: 2 additions & 1 deletion packages/tx/src/eip4844Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export class BlobEIP4844Transaction extends BaseTransaction<BlobEIP4844Transacti
this._validateYParity()
this._validateHighS()

if (this.common.isActivatedEIP(3860)) {
const createContract = txData.to === undefined || txData.to === null
if (createContract && this.common.isActivatedEIP(3860)) {
checkMaxInitCodeSize(this.common, this.data.length)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/tx/src/legacyTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export class Transaction extends BaseTransaction<Transaction> {
}
}

if (this.common.isActivatedEIP(3860)) {
const createContract = txData.to === undefined || txData.to === null
if (createContract && this.common.isActivatedEIP(3860)) {
checkMaxInitCodeSize(this.common, this.data.length)
}

Expand Down
69 changes: 69 additions & 0 deletions packages/tx/test/eip3860.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { Address } from '@ethereumjs/util'
import * as tape from 'tape'

import { TransactionFactory } from '../src'

const common = new Common({
chain: Chain.Mainnet,
hardfork: Hardfork.Merge,
eips: [3860, 4844, 4895],
})

const maxInitCodeSize = common.param('vm', 'maxInitCodeSize')
const txTypes = [0, 1, 2, 5]
const addressZero = Address.zero()

tape('[EIP3860 tests]', function (t) {
t.test('Should instantiate create txs with MAX_INITCODE_SIZE', (st) => {
const data = Buffer.alloc(Number(maxInitCodeSize))
for (const txType of txTypes) {
try {
TransactionFactory.fromTxData({ data, type: txType }, { common })
st.ok('Instantiated create tx with MAX_INITCODE_SIZE data')
} catch (e) {
st.fail('Did not instantiate create tx with MAX_INITCODE_SIZE')
}
}
st.end()
})

t.test('Should instantiate txs with MAX_INITCODE_SIZE data', (st) => {
const data = Buffer.alloc(Number(maxInitCodeSize))
for (const txType of txTypes) {
try {
TransactionFactory.fromTxData({ data, type: txType, to: addressZero }, { common })
st.ok('Instantiated tx with MAX_INITCODE_SIZE')
} catch (e) {
st.fail('Did not instantiated tx with MAX_INITCODE_SIZE')
}
}
st.end()
})

t.test('Should not instantiate create txs with MAX_INITCODE_SIZE+1 data', (st) => {
const data = Buffer.alloc(Number(maxInitCodeSize) + 1)
for (const txType of txTypes) {
try {
TransactionFactory.fromTxData({ data, type: txType }, { common })
st.fail('Instantiated create tx with MAX_INITCODE_SIZE+1')
} catch (e) {
st.ok('Did not instantiate create tx with MAX_INITCODE_SIZE+1')
}
}
st.end()
})

t.test('Should instantiate txs with MAX_INITCODE_SIZE+1 data', (st) => {
const data = Buffer.alloc(Number(maxInitCodeSize) + 1)
for (const txType of txTypes) {
try {
TransactionFactory.fromTxData({ data, type: txType, to: addressZero }, { common })
st.ok('Instantiated tx with MAX_INITCODE_SIZE+1')
} catch (e) {
st.fail('Did not instantiate tx with MAX_INITCODE_SIZE+1')
}
}
st.end()
})
})

1 comment on commit 26a8dcd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 26a8dcd Previous: 1d65ea0 Ratio
Block 9422907 7727 ops/sec (±4.48%) 15876 ops/sec (±1.64%) 2.05

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.