Skip to content

Commit 6b68eb5

Browse files
authored
Add EIP-7594 PeerDAS Max Blob Limit for Txs (#4138)
* Add EIP-7594 PeerDAS tx max blob limit + test case * Fix spelling error * Remove side-effect causing geth genesis test data addition (new fork times) * Another side effect removal
1 parent 28a7455 commit 6b68eb5

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

packages/tx/src/4844/tx.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,26 @@ export class Blob4844Tx implements TransactionInterface<typeof TransactionType.B
187187
}
188188
}
189189

190+
// EIP-7594 PeerDAS: Limit of 6 blobs per transaction
191+
if (this.common.isActivatedEIP(7594)) {
192+
const maxBlobsPerTx = this.common.param('maxBlobsPerTx')
193+
if (this.blobVersionedHashes.length > maxBlobsPerTx) {
194+
const msg = Legacy.errorMsg(
195+
this,
196+
`tx can contain at most ${maxBlobsPerTx} blobs (EIP-7594)`,
197+
)
198+
throw EthereumJSErrorWithoutCode(msg)
199+
}
200+
}
201+
202+
// "Old" limit (superseded by EIP-7594 starting with Osaka)
190203
const limitBlobsPerTx =
191204
this.common.param('maxBlobGasPerBlock') / this.common.param('blobGasPerBlob')
192205
if (this.blobVersionedHashes.length > limitBlobsPerTx) {
193-
const msg = Legacy.errorMsg(this, `tx can contain at most ${limitBlobsPerTx} blobs`)
206+
const msg = Legacy.errorMsg(
207+
this,
208+
`tx can contain at most ${limitBlobsPerTx} blobs (maxBlobGasPerBlock/blobGasPerBlob)`,
209+
)
194210
throw EthereumJSErrorWithoutCode(msg)
195211
} else if (this.blobVersionedHashes.length === 0) {
196212
const msg = Legacy.errorMsg(this, `tx should contain at least one blob`)

packages/tx/src/params.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export const paramsTx: ParamsDict = {
4545
blobGasPerBlob: 131072, // The base fee for blob gas per blob
4646
maxBlobGasPerBlock: 786432, // The max blob gas allowable per block
4747
},
48+
/**
49+
* PeerDAS - Peer Data Availability Sampling
50+
*/
51+
7594: {
52+
maxBlobsPerTx: 6, // Max number of blobs per tx
53+
},
4854
/**
4955
* Increase calldata cost to reduce maximum block size
5056
*/

packages/tx/test/eip4844.spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('fromTxData using from a json', () => {
214214
})
215215

216216
describe('EIP4844 constructor tests - invalid scenarios', () => {
217-
const common = createCommonFromGethGenesis(eip4844GethGenesis, {
217+
let common = createCommonFromGethGenesis(eip4844GethGenesis, {
218218
chain: 'customChain',
219219
hardfork: Hardfork.Cancun,
220220
customCrypto: { kzg },
@@ -232,11 +232,15 @@ describe('EIP4844 constructor tests - invalid scenarios', () => {
232232
const invalidVersionHash = {
233233
blobVersionedHashes: [concatBytes(new Uint8Array([3]), randomBytes(31))],
234234
}
235-
const tooManyBlobs = {
235+
const tooManyBlobs7 = {
236236
blobVersionedHashes: [
237237
concatBytes(new Uint8Array([1]), randomBytes(31)),
238238
concatBytes(new Uint8Array([1]), randomBytes(31)),
239239
concatBytes(new Uint8Array([1]), randomBytes(31)),
240+
concatBytes(new Uint8Array([1]), randomBytes(31)),
241+
concatBytes(new Uint8Array([1]), randomBytes(31)),
242+
concatBytes(new Uint8Array([1]), randomBytes(31)),
243+
concatBytes(new Uint8Array([1]), randomBytes(31)),
240244
],
241245
}
242246
try {
@@ -256,10 +260,25 @@ describe('EIP4844 constructor tests - invalid scenarios', () => {
256260
)
257261
}
258262
try {
259-
createBlob4844Tx({ ...baseTxData, ...tooManyBlobs }, { common })
263+
createBlob4844Tx({ ...baseTxData, ...tooManyBlobs7 }, { common })
264+
} catch (err: any) {
265+
assert.isTrue(
266+
err.message.includes('tx can contain at most 6 blobs (maxBlobGasPerBlock/blobGasPerBlob)'),
267+
'throws on too many versioned hashes',
268+
)
269+
}
270+
271+
common = createCommonFromGethGenesis(eip4844GethGenesis, {
272+
chain: 'customChain',
273+
hardfork: Hardfork.Cancun,
274+
eips: [7594],
275+
customCrypto: { kzg },
276+
})
277+
try {
278+
createBlob4844Tx({ ...baseTxData, ...tooManyBlobs7 }, { common })
260279
} catch (err: any) {
261280
assert.isTrue(
262-
err.message.includes('tx can contain at most'),
281+
err.message.includes('tx can contain at most 6 blobs (EIP-7594)'),
263282
'throws on too many versioned hashes',
264283
)
265284
}

0 commit comments

Comments
 (0)