core/types, internal/ethapi, signer/core/apitypes: avoid copying 128KB blobs in range loops (#33717)
Some checks are pending
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Linux Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

kzg4844.Blob is 131072 bytes. Using `for _, blob := range` copies the
entire blob on each iteration. With up to 6 blobs per transaction, this
wastes ~768KB of memory copies.

Switch to index-based iteration and pass pointers directly.
This commit is contained in:
Lessa 2026-02-03 08:36:59 -05:00 committed by GitHub
parent b9288765a3
commit 54a91b3ad8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 16 deletions

View file

@ -118,8 +118,8 @@ func (sc *BlobTxSidecar) ToV1() error {
} }
if sc.Version == BlobSidecarVersion0 { if sc.Version == BlobSidecarVersion0 {
proofs := make([]kzg4844.Proof, 0, len(sc.Blobs)*kzg4844.CellProofsPerBlob) proofs := make([]kzg4844.Proof, 0, len(sc.Blobs)*kzg4844.CellProofsPerBlob)
for _, blob := range sc.Blobs { for i := range sc.Blobs {
cellProofs, err := kzg4844.ComputeCellProofs(&blob) cellProofs, err := kzg4844.ComputeCellProofs(&sc.Blobs[i])
if err != nil { if err != nil {
return err return err
} }

View file

@ -329,8 +329,8 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
commitments = make([]kzg4844.Commitment, n) commitments = make([]kzg4844.Commitment, n)
proofs = make([]kzg4844.Proof, 0, proofLen) proofs = make([]kzg4844.Proof, 0, proofLen)
) )
for i, b := range args.Blobs { for i := range args.Blobs {
c, err := kzg4844.BlobToCommitment(&b) c, err := kzg4844.BlobToCommitment(&args.Blobs[i])
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err) return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
} }
@ -338,13 +338,13 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
switch config.blobSidecarVersion { switch config.blobSidecarVersion {
case types.BlobSidecarVersion0: case types.BlobSidecarVersion0:
p, err := kzg4844.ComputeBlobProof(&b, c) p, err := kzg4844.ComputeBlobProof(&args.Blobs[i], c)
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err) return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
} }
proofs = append(proofs, p) proofs = append(proofs, p)
case types.BlobSidecarVersion1: case types.BlobSidecarVersion1:
ps, err := kzg4844.ComputeCellProofs(&b) ps, err := kzg4844.ComputeCellProofs(&args.Blobs[i])
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err) return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
} }
@ -356,8 +356,8 @@ func (args *TransactionArgs) setBlobTxSidecar(ctx context.Context, config sideca
} else { } else {
switch config.blobSidecarVersion { switch config.blobSidecarVersion {
case types.BlobSidecarVersion0: case types.BlobSidecarVersion0:
for i, b := range args.Blobs { for i := range args.Blobs {
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil { if err := kzg4844.VerifyBlobProof(&args.Blobs[i], args.Commitments[i], args.Proofs[i]); err != nil {
return fmt.Errorf("failed to verify blob proof: %v", err) return fmt.Errorf("failed to verify blob proof: %v", err)
} }
} }

View file

@ -242,8 +242,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
if args.Proofs != nil { if args.Proofs != nil {
if len(args.Proofs) == n { if len(args.Proofs) == n {
// v1 transaction // v1 transaction
for i, b := range args.Blobs { for i := range args.Blobs {
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil { if err := kzg4844.VerifyBlobProof(&args.Blobs[i], args.Commitments[i], args.Proofs[i]); err != nil {
return fmt.Errorf("failed to verify blob proof: %v", err) return fmt.Errorf("failed to verify blob proof: %v", err)
} }
} }
@ -259,8 +259,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
if args.Commitments == nil { if args.Commitments == nil {
// Generate commitment and proof. // Generate commitment and proof.
commitments := make([]kzg4844.Commitment, n) commitments := make([]kzg4844.Commitment, n)
for i, b := range args.Blobs { for i := range args.Blobs {
c, err := kzg4844.BlobToCommitment(&b) c, err := kzg4844.BlobToCommitment(&args.Blobs[i])
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err) return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
} }
@ -269,8 +269,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
var proofs []kzg4844.Proof var proofs []kzg4844.Proof
if args.BlobVersion == types.BlobSidecarVersion1 { if args.BlobVersion == types.BlobSidecarVersion1 {
proofs = make([]kzg4844.Proof, 0, n*kzg4844.CellProofsPerBlob) proofs = make([]kzg4844.Proof, 0, n*kzg4844.CellProofsPerBlob)
for i, b := range args.Blobs { for i := range args.Blobs {
p, err := kzg4844.ComputeCellProofs(&b) p, err := kzg4844.ComputeCellProofs(&args.Blobs[i])
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing cell proof: %v", i, err) return fmt.Errorf("blobs[%d]: error computing cell proof: %v", i, err)
} }
@ -278,8 +278,8 @@ func (args *SendTxArgs) validateTxSidecar() error {
} }
} else { } else {
proofs = make([]kzg4844.Proof, 0, n) proofs = make([]kzg4844.Proof, 0, n)
for i, b := range args.Blobs { for i := range args.Blobs {
p, err := kzg4844.ComputeBlobProof(&b, commitments[i]) p, err := kzg4844.ComputeBlobProof(&args.Blobs[i], commitments[i])
if err != nil { if err != nil {
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err) return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
} }