Skip to content

Commit

Permalink
bn254: add simple test
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign committed Aug 26, 2023
1 parent 850241c commit 9cbc850
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/bn254/tests.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const std = @import("std");
const Fr = @import("fr.zig");
const parameters = @import("../parameters.zig");
const poseidon = @import("../poseidon.zig");

test "babyjubjub" {
var allocator = std.testing.allocator;
var babyjubjub_parameters = try parameters.get_babyjubjub_parameters(allocator);
defer babyjubjub_parameters.deinit();

var instance = poseidon.Poseidon(Fr, 2).init(babyjubjub_parameters);

var one: u256 = 1;
var buf: [32]u8 = undefined;
std.mem.writeIntLittle(u256, &buf, one);
var nonMontB1: Fr.NonMontgomeryDomainFieldElement = undefined;
Fr.fromBytes(&nonMontB1, buf);
var b1: Fr.MontgomeryDomainFieldElement = undefined;
Fr.toMontgomery(&b1, nonMontB1);

var res = instance.hash(.{b1});

Fr.toBytes(&buf, res);
const A = std.mem.readInt(u256, &buf, std.builtin.Endian.Little);

try std.testing.expect(18586133768512220936620570745912940619677854269274689475585506675881198879027 == A);
}

0 comments on commit 9cbc850

Please sign in to comment.