2022-11-22 07:44:34 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
2022-11-07 16:50:32 +00:00
|
|
|
namespace Ckzg.Test;
|
2022-11-03 13:08:17 +00:00
|
|
|
|
2022-11-07 16:50:32 +00:00
|
|
|
[TestFixture]
|
2022-11-22 07:44:34 +00:00
|
|
|
public class BasicKzgTests
|
2022-11-03 13:08:17 +00:00
|
|
|
{
|
2022-11-22 07:44:34 +00:00
|
|
|
[TestCase]
|
|
|
|
public unsafe void Test_Computes_And_Verifies()
|
2022-11-03 13:08:17 +00:00
|
|
|
{
|
2022-11-22 07:44:34 +00:00
|
|
|
IntPtr ts = Ckzg.LoadTrustedSetup("trusted_setup.txt");
|
2022-11-07 16:50:32 +00:00
|
|
|
Assert.That((ulong)ts, Is.Not.EqualTo((ulong)0));
|
2022-11-09 19:16:00 +00:00
|
|
|
byte[] blob = Enumerable.Range(0, 4096 * 32).Select(x => (byte)(x % 256)).ToArray();
|
2022-11-03 13:08:17 +00:00
|
|
|
|
2022-11-07 16:50:32 +00:00
|
|
|
byte[] proof = new byte[48];
|
|
|
|
byte[] commitment = new byte[48];
|
2022-11-09 19:16:00 +00:00
|
|
|
fixed (byte* commitmentPtr = commitment, blobPtr = blob, proofPtr = proof)
|
|
|
|
{
|
2022-11-22 07:44:34 +00:00
|
|
|
Ckzg.ComputeAggregatedKzgProof(proofPtr, blobPtr, 1, ts);
|
2022-11-09 19:16:00 +00:00
|
|
|
Ckzg.BlobToKzgCommitment(commitmentPtr, blobPtr, ts);
|
2022-11-22 07:44:34 +00:00
|
|
|
int result = Ckzg.VerifyAggregatedKzgProof(blobPtr, commitmentPtr, 1, proofPtr, ts);
|
2022-11-09 19:16:00 +00:00
|
|
|
Assert.That(result, Is.EqualTo(0));
|
|
|
|
Ckzg.FreeTrustedSetup(ts);
|
|
|
|
}
|
2022-11-07 16:50:32 +00:00
|
|
|
}
|
2022-11-03 13:08:17 +00:00
|
|
|
|
2022-11-22 07:44:34 +00:00
|
|
|
[TestCase]
|
|
|
|
public unsafe void Test_PointEvaluationPrecompile_Verifies()
|
2022-11-07 16:50:32 +00:00
|
|
|
{
|
2022-11-22 07:44:34 +00:00
|
|
|
IntPtr ts = Ckzg.LoadTrustedSetup("trusted_setup.txt");
|
2022-11-09 19:16:00 +00:00
|
|
|
Assert.That((ulong)ts, Is.Not.EqualTo((ulong)0));
|
|
|
|
byte[] commitment = new byte[48];
|
|
|
|
commitment[0] = 0xc0;
|
|
|
|
byte[] x = new byte[32];
|
|
|
|
byte[] y = new byte[32];
|
|
|
|
byte[] proof = new byte[48];
|
|
|
|
proof[0] = 0xc0;
|
|
|
|
|
|
|
|
fixed (byte* commitmentPtr = commitment, xPtr = x, yPtr = y, proofPtr = proof)
|
|
|
|
{
|
|
|
|
int result = Ckzg.VerifyKzgProof(commitmentPtr, xPtr, yPtr, proofPtr, ts);
|
|
|
|
Ckzg.FreeTrustedSetup(ts);
|
|
|
|
Assert.That(result, Is.EqualTo(0));
|
|
|
|
}
|
2022-11-03 13:08:17 +00:00
|
|
|
}
|
|
|
|
}
|