diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/BlobsBundleV1.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/BlobsBundleV1.cs index 7cfb6a4f1793..68593565d61e 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/BlobsBundleV1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/BlobsBundleV1.cs @@ -22,9 +22,17 @@ public BlobsBundleV1() public BlobsBundleV1(Block block) { - List> commitments = new(); - List> blobs = new(); - List> proofs = new(); + int blobsCount = 0; + foreach (Transaction? tx in block.Transactions) + { + blobsCount += tx?.BlobVersionedHashes?.Length ?? 0; + } + + Commitments = new Memory[blobsCount]; + Blobs = new Memory[blobsCount]; + Proofs = new Memory[blobsCount]; + int i = 0; + foreach (Transaction? tx in block.Transactions) { if (tx.Type is not TxType.Blob || tx.BlobKzgs is null || tx.Blobs is null) @@ -34,19 +42,16 @@ public BlobsBundleV1(Block block) for (int cc = 0, bc = 0, pc = 0; cc < tx.BlobKzgs.Length; + i++, cc += Ckzg.Ckzg.BytesPerCommitment, bc += Ckzg.Ckzg.BytesPerBlob, - pc += Ckzg.Ckzg.BytesPerCommitment) + pc += Ckzg.Ckzg.BytesPerProof) { - commitments.Add(tx.BlobKzgs.AsMemory(cc, cc + Ckzg.Ckzg.BytesPerCommitment)); - blobs.Add(tx.Blobs.AsMemory(bc, bc + Ckzg.Ckzg.BytesPerBlob)); - proofs.Add(tx.BlobProofs.AsMemory(pc, pc + Ckzg.Ckzg.BytesPerProof)); + Commitments[i] = tx.BlobKzgs.AsMemory(cc, cc + Ckzg.Ckzg.BytesPerCommitment); + Blobs[i] = tx.Blobs.AsMemory(bc, bc + Ckzg.Ckzg.BytesPerBlob); + Proofs[i] = tx.BlobProofs.AsMemory(pc, pc + Ckzg.Ckzg.BytesPerProof); } } - - Commitments = commitments.ToArray(); - Blobs = blobs.ToArray(); - Proofs = proofs.ToArray(); } public Memory[]? Commitments { get; set; }