diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 1bf48cf949..db965bc71a 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1030,6 +1030,21 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error { // TODO: seems like an easy optimization here would be getting the serialized tx // from limbo instead of re-serializing it here. + // Converts reorged-out legacy blob transactions to the new format to prevent + // them from becoming stuck in the pool until eviction. + // + // Performance note: Conversion takes ~140ms (Mac M1 Pro). Since a maximum of + // 9 legacy blob transactions are allowed in a block pre-Osaka, an adversary + // could theoretically halt a Geth node for ~1.2s by reorging per block. However, + // this attack is financially inefficient to execute. + head := p.head.Load() + if p.chain.Config().IsOsaka(head.Number, head.Time) && tx.BlobTxSidecar().Version == types.BlobSidecarVersion0 { + if err := tx.BlobTxSidecar().ToV1(); err != nil { + log.Error("Failed to convert the legacy sidecar", "err", err) + return err + } + log.Info("Legacy blob transaction is reorged", "hash", tx.Hash()) + } // Serialize the transaction back into the primary datastore. blob, err := rlp.EncodeToBytes(tx) if err != nil { diff --git a/crypto/kzg4844/kzg4844_test.go b/crypto/kzg4844/kzg4844_test.go index d398a0f48b..743a277199 100644 --- a/crypto/kzg4844/kzg4844_test.go +++ b/crypto/kzg4844/kzg4844_test.go @@ -225,3 +225,31 @@ func testKZGCells(t *testing.T, ckzg bool) { t.Fatalf("failed to verify KZG proof at point: %v", err) } } + +// goos: darwin +// goarch: arm64 +// pkg: github.com/ethereum/go-ethereum/crypto/kzg4844 +// cpu: Apple M1 Pro +// BenchmarkGOKZGComputeCellProofs +// BenchmarkGOKZGComputeCellProofs-8 8 139012286 ns/op +func BenchmarkGOKZGComputeCellProofs(b *testing.B) { benchmarkComputeCellProofs(b, false) } +func BenchmarkCKZGComputeCellProofs(b *testing.B) { benchmarkComputeCellProofs(b, true) } + +func benchmarkComputeCellProofs(b *testing.B, ckzg bool) { + if ckzg && !ckzgAvailable { + b.Skip("CKZG unavailable in this test build") + } + defer func(old bool) { useCKZG.Store(old) }(useCKZG.Load()) + useCKZG.Store(ckzg) + + blob := randBlob() + _, _ = ComputeCellProofs(blob) // for kzg initialization + b.ResetTimer() + + for b.Loop() { + _, err := ComputeCellProofs(blob) + if err != nil { + b.Fatalf("failed to create KZG proof at point: %v", err) + } + } +}