mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-06 18:56:43 +01:00
pedersen2 adapted
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
const bigInt = require("big-integer");
|
||||
const tester = require("circom").tester;
|
||||
|
||||
|
||||
14291
test/circuits/pedersen2_test.cpp
Normal file
14291
test/circuits/pedersen2_test.cpp
Normal file
File diff suppressed because it is too large
Load Diff
8127
test/circuits/pedersen2_test.sym
Normal file
8127
test/circuits/pedersen2_test.sym
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,7 @@
|
||||
const chai = require("chai");
|
||||
const path = require("path");
|
||||
const snarkjs = require("snarkjs");
|
||||
const compiler = require("circom");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
const bigInt = snarkjs.bigInt;
|
||||
const bigInt = require("big-integer");
|
||||
const tester = require("circom").tester;
|
||||
|
||||
const babyJub = require("../src/babyjub.js");
|
||||
const pedersen = require("../src/pedersenHash.js");
|
||||
@@ -15,60 +11,39 @@ describe("Pedersen test", function() {
|
||||
let circuit;
|
||||
this.timeout(100000);
|
||||
before( async() => {
|
||||
const cirDef = await compiler(path.join(__dirname, "circuits", "pedersen2_test.circom"));
|
||||
|
||||
circuit = new snarkjs.Circuit(cirDef);
|
||||
|
||||
console.log("NConstrains Pedersen2: " + circuit.nConstraints);
|
||||
circuit = await tester(path.join(__dirname, "circuits", "pedersen2_test.circom"));
|
||||
});
|
||||
it("Should pedersen at zero", async () => {
|
||||
|
||||
let w, xout, yout;
|
||||
let w;
|
||||
|
||||
w = circuit.calculateWitness({ in: 0});
|
||||
|
||||
xout = w[circuit.getSignalIdx("main.out[0]")];
|
||||
yout = w[circuit.getSignalIdx("main.out[1]")];
|
||||
w = await circuit.calculateWitness({ in: 0});
|
||||
|
||||
const b = Buffer.alloc(32);
|
||||
|
||||
const h = pedersen.hash(b);
|
||||
const hP = babyJub.unpackPoint(h);
|
||||
|
||||
/*
|
||||
console.log(`[${xout.toString()}, ${yout.toString()}]`);
|
||||
console.log(`[${hP[0].toString()}, ${hP[1].toString()}]`);
|
||||
*/
|
||||
await circuit.assertOut(w, {out: hP});
|
||||
|
||||
assert(xout.equals(hP[0]));
|
||||
assert(yout.equals(hP[1]));
|
||||
});
|
||||
it("Should pedersen with 253 ones", async () => {
|
||||
|
||||
let w, xout, yout;
|
||||
let w;
|
||||
|
||||
const n = bigInt.one.shl(253).sub(bigInt.one);
|
||||
console.log(n.toString(16));
|
||||
const n = bigInt.one.shiftLeft(253).minus(bigInt.one);
|
||||
|
||||
w = circuit.calculateWitness({ in: n});
|
||||
|
||||
xout = w[circuit.getSignalIdx("main.out[0]")];
|
||||
yout = w[circuit.getSignalIdx("main.out[1]")];
|
||||
w = await circuit.calculateWitness({ in: n});
|
||||
|
||||
const b = Buffer.alloc(32);
|
||||
for (let i=0; i<31; i++) b[i] = 0xFF;
|
||||
b[31] = 0x1F;
|
||||
|
||||
|
||||
const h = pedersen.hash(b);
|
||||
const hP = babyJub.unpackPoint(h);
|
||||
|
||||
/*
|
||||
console.log(`[${xout.toString()}, ${yout.toString()}]`);
|
||||
console.log(`[${hP[0].toString()}, ${hP[1].toString()}]`);
|
||||
*/
|
||||
await circuit.assertOut(w, {out: hP});
|
||||
|
||||
assert(xout.equals(hP[0]));
|
||||
assert(yout.equals(hP[1]));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user