Merge pull request #26 from flcl42/check_encodings

Align C# tests with the modulus check
This commit is contained in:
Ramana Kumar 2022-12-11 21:10:14 +00:00 committed by GitHub
commit 382cd2d6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 14 deletions

View File

@ -5,30 +5,41 @@ namespace Ckzg.Test;
[TestFixture]
public class BasicKzgTests
{
[TestCase]
public unsafe void Test_Computes_And_Verifies()
private IntPtr _ts;
[SetUp]
public void Setup()
{
IntPtr ts = Ckzg.LoadTrustedSetup("trusted_setup.txt");
Assert.That((ulong)ts, Is.Not.EqualTo((ulong)0));
byte[] blob = Enumerable.Range(0, 4096 * 32).Select(x => (byte)(x % 256)).ToArray();
_ts = Ckzg.LoadTrustedSetup("trusted_setup.txt");
Assert.That(_ts, Is.Not.EqualTo(IntPtr.Zero));
}
[TestCase(0xff, -1, -1)]
[TestCase(0x73, -1, -1)]
[TestCase(0x72, 0, 0)]
[TestCase(0x00, 0, 0)]
public unsafe void Test_Computes_And_Verifies(byte highByteValue, int expectedProofComputed, int expectedProofVerified)
{
byte[] blob = Enumerable.Range(0, 4096 * 32).Select(x => x % 32 == 31 ? highByteValue : (byte)(x % 256)).ToArray();
byte[] proof = new byte[48];
byte[] commitment = new byte[48];
fixed (byte* commitmentPtr = commitment, blobPtr = blob, proofPtr = proof)
{
Ckzg.ComputeAggregatedKzgProof(proofPtr, blobPtr, 1, ts);
Ckzg.BlobToKzgCommitment(commitmentPtr, blobPtr, ts);
int result = Ckzg.VerifyAggregatedKzgProof(blobPtr, commitmentPtr, 1, proofPtr, ts);
Assert.That(result, Is.EqualTo(0));
Ckzg.FreeTrustedSetup(ts);
int proofComputed = Ckzg.ComputeAggregatedKzgProof(proofPtr, blobPtr, 1, _ts);
Assert.That(proofComputed, Is.EqualTo(expectedProofComputed));
Ckzg.BlobToKzgCommitment(commitmentPtr, blobPtr, _ts);
int proofVerified = Ckzg.VerifyAggregatedKzgProof(blobPtr, commitmentPtr, 1, proofPtr, _ts);
Assert.That(proofVerified, Is.EqualTo(expectedProofVerified));
Ckzg.FreeTrustedSetup(_ts);
}
}
[TestCase]
public unsafe void Test_PointEvaluationPrecompile_Verifies()
{
IntPtr ts = Ckzg.LoadTrustedSetup("trusted_setup.txt");
Assert.That((ulong)ts, Is.Not.EqualTo((ulong)0));
byte[] commitment = new byte[48];
commitment[0] = 0xc0;
byte[] x = new byte[32];
@ -38,8 +49,8 @@ public class BasicKzgTests
fixed (byte* commitmentPtr = commitment, xPtr = x, yPtr = y, proofPtr = proof)
{
int result = Ckzg.VerifyKzgProof(commitmentPtr, xPtr, yPtr, proofPtr, ts);
Ckzg.FreeTrustedSetup(ts);
int result = Ckzg.VerifyKzgProof(commitmentPtr, xPtr, yPtr, proofPtr, _ts);
Ckzg.FreeTrustedSetup(_ts);
Assert.That(result, Is.EqualTo(0));
}
}