@@ -138,35 +138,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
138
138
return fmt .Errorf ("%w: gas tip cap %v, minimum needed %v" , ErrTxGasPriceTooLow , tx .GasTipCap (), opts .MinTip )
139
139
}
140
140
if tx .Type () == types .BlobTxType {
141
- // Ensure the blob fee cap satisfies the minimum blob gas price
142
- if tx .BlobGasFeeCapIntCmp (blobTxMinBlobGasPrice ) < 0 {
143
- return fmt .Errorf ("%w: blob fee cap %v, minimum needed %v" , ErrTxGasPriceTooLow , tx .BlobGasFeeCap (), blobTxMinBlobGasPrice )
144
- }
145
- sidecar := tx .BlobTxSidecar ()
146
- if sidecar == nil {
147
- return errors .New ("missing sidecar in blob transaction" )
148
- }
149
- // Ensure the number of items in the blob transaction and various side
150
- // data match up before doing any expensive validations
151
- hashes := tx .BlobHashes ()
152
- if len (hashes ) == 0 {
153
- return errors .New ("blobless blob transaction" )
154
- }
155
- maxBlobs := eip4844 .MaxBlobsPerBlock (opts .Config , head .Time )
156
- if len (hashes ) > maxBlobs {
157
- return fmt .Errorf ("too many blobs in transaction: have %d, permitted %d" , len (hashes ), maxBlobs )
158
- }
159
- if opts .Config .IsOsaka (head .Number , head .Time ) {
160
- // Ensure commitments, cell proofs and hashes are valid
161
- if err := validateBlobSidecarOsaka (hashes , sidecar ); err != nil {
162
- return err
163
- }
164
- } else {
165
- // Ensure commitments, proofs and hashes are valid
166
- if err := validateBlobSidecar (hashes , sidecar ); err != nil {
167
- return err
168
- }
169
- }
141
+ return validateBlobTx (tx , head , opts )
170
142
}
171
143
if tx .Type () == types .SetCodeTxType {
172
144
if len (tx .SetCodeAuthorizations ()) == 0 {
@@ -176,21 +148,46 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
176
148
return nil
177
149
}
178
150
179
- func validateBlobSidecar (hashes []common.Hash , sidecar * types.BlobTxSidecar ) error {
180
- if sidecar .Version != 0 {
181
- return fmt .Errorf ("invalid sidecar version pre-osaka: %v" , sidecar .Version )
151
+ // validateBlobTx implements the blob-transaction specific validations.
152
+ func validateBlobTx (tx * types.Transaction , head * types.Header , opts * ValidationOptions ) error {
153
+ sidecar := tx .BlobTxSidecar ()
154
+ if sidecar == nil {
155
+ return errors .New ("missing sidecar in blob transaction" )
156
+ }
157
+ // Ensure the blob fee cap satisfies the minimum blob gas price
158
+ if tx .BlobGasFeeCapIntCmp (blobTxMinBlobGasPrice ) < 0 {
159
+ return fmt .Errorf ("%w: blob fee cap %v, minimum needed %v" , ErrTxGasPriceTooLow , tx .BlobGasFeeCap (), blobTxMinBlobGasPrice )
160
+ }
161
+ // Ensure the number of items in the blob transaction and various side
162
+ // data match up before doing any expensive validations
163
+ hashes := tx .BlobHashes ()
164
+ if len (hashes ) == 0 {
165
+ return errors .New ("blobless blob transaction" )
166
+ }
167
+ maxBlobs := eip4844 .MaxBlobsPerBlock (opts .Config , head .Time )
168
+ if len (hashes ) > maxBlobs {
169
+ return fmt .Errorf ("too many blobs in transaction: have %d, permitted %d" , len (hashes ), maxBlobs )
182
170
}
183
171
if len (sidecar .Blobs ) != len (hashes ) {
184
172
return fmt .Errorf ("invalid number of %d blobs compared to %d blob hashes" , len (sidecar .Blobs ), len (hashes ))
185
173
}
174
+ // Fork-specific sidecar checks, including proof verification.
175
+ if opts .Config .IsOsaka (head .Number , head .Time ) {
176
+ return validateBlobSidecarOsaka (sidecar , hashes )
177
+ }
178
+ return validateBlobSidecarLegacy (sidecar , hashes )
179
+ }
180
+
181
+ func validateBlobSidecarLegacy (sidecar * types.BlobTxSidecar , hashes []common.Hash ) error {
182
+ if sidecar .Version != 0 {
183
+ return fmt .Errorf ("invalid sidecar version pre-osaka: %v" , sidecar .Version )
184
+ }
186
185
if len (sidecar .Proofs ) != len (hashes ) {
187
- return fmt .Errorf ("invalid number of %d blob proofs compared to %d blob hashes " , len (sidecar .Proofs ), len (hashes ))
186
+ return fmt .Errorf ("invalid number of %d blob proofs expected %d " , len (sidecar .Proofs ), len (hashes ))
188
187
}
189
188
if err := sidecar .ValidateBlobCommitmentHashes (hashes ); err != nil {
190
189
return err
191
190
}
192
- // Blob commitments match with the hashes in the transaction, verify the
193
- // blobs themselves via KZG
194
191
for i := range sidecar .Blobs {
195
192
if err := kzg4844 .VerifyBlobProof (& sidecar .Blobs [i ], sidecar .Commitments [i ], sidecar .Proofs [i ]); err != nil {
196
193
return fmt .Errorf ("invalid blob %d: %v" , i , err )
@@ -199,29 +196,20 @@ func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobTxSidecar) err
199
196
return nil
200
197
}
201
198
202
- func validateBlobSidecarOsaka (hashes []common.Hash , sidecar * types. BlobTxSidecar ) error {
199
+ func validateBlobSidecarOsaka (sidecar * types. BlobTxSidecar , hashes []common.Hash ) error {
203
200
if sidecar .Version != 1 {
204
201
return fmt .Errorf ("invalid sidecar version post-osaka: %v" , sidecar .Version )
205
202
}
206
- if len (sidecar .Blobs ) != len (hashes ) {
207
- return fmt .Errorf ("invalid number of %d blobs compared to %d blob hashes" , len (sidecar .Blobs ), len (hashes ))
208
- }
209
- if len (sidecar .Commitments ) != len (hashes ) {
210
- return fmt .Errorf ("invalid number of %d commitments compared to %d blob hashes" , len (sidecar .Commitments ), len (hashes ))
211
- }
212
203
if len (sidecar .Proofs ) != len (hashes )* kzg4844 .CellProofsPerBlob {
213
204
return fmt .Errorf ("invalid number of %d blob proofs expected %d" , len (sidecar .Proofs ), len (hashes )* kzg4844 .CellProofsPerBlob )
214
205
}
215
206
if err := sidecar .ValidateBlobCommitmentHashes (hashes ); err != nil {
216
207
return err
217
208
}
218
- // Blob commitments match with the hashes in the transaction, verify the
219
- // blobs themselves via KZG
220
209
var blobs []* kzg4844.Blob
221
210
for _ , blob := range sidecar .Blobs {
222
211
blobs = append (blobs , & blob )
223
212
}
224
-
225
213
if err := kzg4844 .VerifyCellProofs (blobs , sidecar .Commitments , sidecar .Proofs ); err != nil {
226
214
return err
227
215
}
0 commit comments