Skip to content

Commit f96f82b

Browse files
authored
core, params: add limit for max blobs in blob transaction (#32246)
[EIP-7594](https://eips.ethereum.org/EIPS/eip-7594) defines a limit of max 6 blobs per transaction. We need to enforce this limit during block processing. > Additionally, a limit of 6 blobs per transaction is introduced. Clients MUST enforce this limit when validating blob transactions at submission time, when received from the network, and during block production and processing.
1 parent d80094f commit f96f82b

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

core/error.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ var (
118118
// ErrMissingBlobHashes is returned if a blob transaction has no blob hashes.
119119
ErrMissingBlobHashes = errors.New("blob transaction missing blob hashes")
120120

121+
// ErrTooManyBlobs is returned if a blob transaction exceeds the maximum number of blobs.
122+
ErrTooManyBlobs = errors.New("blob transaction has too many blobs")
123+
121124
// ErrBlobTxCreate is returned if a blob transaction has no explicit to field.
122125
ErrBlobTxCreate = errors.New("blob transaction of type create")
123126

core/state_transition.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ func (st *stateTransition) preCheck() error {
354354
}
355355
}
356356
// Check the blob version validity
357+
isOsaka := st.evm.ChainConfig().IsOsaka(st.evm.Context.BlockNumber, st.evm.Context.Time)
357358
if msg.BlobHashes != nil {
358359
// The to field of a blob tx type is mandatory, and a `BlobTx` transaction internally
359360
// has it as a non-nillable value, so any msg derived from blob transaction has it non-nil.
@@ -364,6 +365,9 @@ func (st *stateTransition) preCheck() error {
364365
if len(msg.BlobHashes) == 0 {
365366
return ErrMissingBlobHashes
366367
}
368+
if isOsaka && len(msg.BlobHashes) > params.BlobTxMaxBlobs {
369+
return ErrTooManyBlobs
370+
}
367371
for i, hash := range msg.BlobHashes {
368372
if !kzg4844.IsValidVersionedHash(hash[:]) {
369373
return fmt.Errorf("blob %d has invalid hash version", i)
@@ -395,7 +399,7 @@ func (st *stateTransition) preCheck() error {
395399
}
396400
}
397401
// Verify tx gas limit does not exceed EIP-7825 cap.
398-
if st.evm.ChainConfig().IsOsaka(st.evm.Context.BlockNumber, st.evm.Context.Time) && msg.GasLimit > params.MaxTxGas {
402+
if isOsaka && msg.GasLimit > params.MaxTxGas {
399403
return fmt.Errorf("%w (cap: %d, tx: %d)", ErrGasLimitTooHigh, params.MaxTxGas, msg.GasLimit)
400404
}
401405
return st.buyGas()

core/txpool/blobpool/blobpool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const (
6565
// carry. We choose a smaller limit than the protocol-permitted MaxBlobsPerBlock
6666
// in order to ensure network and txpool stability.
6767
// Note: if you increase this, validation will fail on txMaxSize.
68-
maxBlobsPerTx = 7
68+
maxBlobsPerTx = params.BlobTxMaxBlobs
6969

7070
// maxTxsPerAccount is the maximum number of blob transactions admitted from
7171
// a single account. The limit is enforced to minimize the DoS potential of

core/txpool/blobpool/blobpool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,8 @@ func TestBlobCountLimit(t *testing.T) {
11911191

11921192
// Attempt to add transactions.
11931193
var (
1194-
tx1 = makeMultiBlobTx(0, 1, 1000, 100, 7, key1)
1195-
tx2 = makeMultiBlobTx(0, 1, 800, 70, 8, key2)
1194+
tx1 = makeMultiBlobTx(0, 1, 1000, 100, 6, key1)
1195+
tx2 = makeMultiBlobTx(0, 1, 800, 70, 7, key2)
11961196
)
11971197
errs := pool.Add([]*types.Transaction{tx1, tx2}, true)
11981198

params/protocol_params.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const (
177177
BlobTxBlobGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size)
178178
BlobTxMinBlobGasprice = 1 // Minimum gas price for data blobs
179179
BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile.
180+
BlobTxMaxBlobs = 6
180181
BlobBaseCost = 1 << 13 // Base execution gas cost for a blob.
181182

182183
HistoryServeWindow = 8192 // Number of blocks to serve historical block hashes for, EIP-2935.

0 commit comments

Comments
 (0)