Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No batch processing needed in case of single blob #7159

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Nethermind/Nethermind.Crypto/KzgPolynomialCommitments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,29 @@ public static bool VerifyProof(ReadOnlySpan<byte> commitment, ReadOnlySpan<byte>

public static bool AreProofsValid(byte[][] blobs, byte[][] commitments, byte[][] proofs)
{
var length = blobs.Length * Ckzg.Ckzg.BytesPerBlob;
if (blobs.Length is 1 && commitments.Length is 1 && proofs.Length is 1)
{
try
{
return Ckzg.Ckzg.VerifyBlobKzgProof(blobs[0], commitments[0], proofs[0], _ckzgSetup);
}
catch (Exception e) when (e is ArgumentException or ApplicationException or InsufficientMemoryException)
{
return false;
}
}

int length = blobs.Length * Ckzg.Ckzg.BytesPerBlob;
byte[] flatBlobsArray = ArrayPool<byte>.Shared.Rent(length);
var flatBlobs = new Span<byte>(flatBlobsArray, 0, length);
Span<byte> flatBlobs = new(flatBlobsArray, 0, length);

length = blobs.Length * Ckzg.Ckzg.BytesPerCommitment;
byte[] flatCommitmentsArray = ArrayPool<byte>.Shared.Rent(length);
var flatCommitments = new Span<byte>(flatCommitmentsArray, 0, length);
Span<byte> flatCommitments = new(flatCommitmentsArray, 0, length);

length = blobs.Length * Ckzg.Ckzg.BytesPerProof;
byte[] flatProofsArray = ArrayPool<byte>.Shared.Rent(length);
var flatProofs = new Span<byte>(flatProofsArray, 0, length);
Span<byte> flatProofs = new(flatProofsArray, 0, length);

for (int i = 0; i < blobs.Length; i++)
{
Expand Down