Update references to Poseidon hash in the project
This commit is contained in:
parent
82c2f606cc
commit
528b292da5
@ -780,7 +780,7 @@ Implementation of Poseidon hash function (LINK)
|
|||||||
- BENCHMARKS
|
- BENCHMARKS
|
||||||
- EXAMPLE
|
- EXAMPLE
|
||||||
|
|
||||||
- `Ark(t, C)`
|
- `Ark(t, C, r)`
|
||||||
|
|
||||||
- DESCRIPTION
|
- DESCRIPTION
|
||||||
- SCHEMA
|
- SCHEMA
|
||||||
@ -798,7 +798,7 @@ Implementation of Poseidon hash function (LINK)
|
|||||||
- BENCHMARKS
|
- BENCHMARKS
|
||||||
- EXAMPLE
|
- EXAMPLE
|
||||||
|
|
||||||
- `Poseidon(nInputs, t, nRoundsF, nRoundsP)`
|
- `Poseidon(nInputs)`
|
||||||
|
|
||||||
- DESCRIPTION
|
- DESCRIPTION
|
||||||
- SCHEMA
|
- SCHEMA
|
||||||
|
@ -50,7 +50,7 @@ template EdDSAPoseidonVerifier() {
|
|||||||
|
|
||||||
// Calculate the h = H(R,A, msg)
|
// Calculate the h = H(R,A, msg)
|
||||||
|
|
||||||
component hash = Poseidon(5, 6, 8, 57);
|
component hash = Poseidon(5);
|
||||||
|
|
||||||
hash.inputs[0] <== R8x;
|
hash.inputs[0] <== R8x;
|
||||||
hash.inputs[1] <== R8y;
|
hash.inputs[1] <== R8y;
|
||||||
|
@ -29,7 +29,7 @@ template SMTHash1() {
|
|||||||
signal input value;
|
signal input value;
|
||||||
signal output out;
|
signal output out;
|
||||||
|
|
||||||
component h = Poseidon(3, 6, 8, 57); // Constant
|
component h = Poseidon(3); // Constant
|
||||||
h.inputs[0] <== key;
|
h.inputs[0] <== key;
|
||||||
h.inputs[1] <== value;
|
h.inputs[1] <== value;
|
||||||
h.inputs[2] <== 1;
|
h.inputs[2] <== 1;
|
||||||
@ -48,7 +48,7 @@ template SMTHash2() {
|
|||||||
signal input R;
|
signal input R;
|
||||||
signal output out;
|
signal output out;
|
||||||
|
|
||||||
component h = Poseidon(2, 6, 8, 57); // Constant
|
component h = Poseidon(2); // Constant
|
||||||
h.inputs[0] <== L;
|
h.inputs[0] <== L;
|
||||||
h.inputs[1] <== R;
|
h.inputs[1] <== R;
|
||||||
|
|
||||||
|
@ -105,8 +105,7 @@ function signPoseidon(prv, msg) {
|
|||||||
let r = bigInt.leBuff2int(rBuff);
|
let r = bigInt.leBuff2int(rBuff);
|
||||||
r = r.mod(babyJub.subOrder);
|
r = r.mod(babyJub.subOrder);
|
||||||
const R8 = babyJub.mulPointEscalar(babyJub.Base8, r);
|
const R8 = babyJub.mulPointEscalar(babyJub.Base8, r);
|
||||||
const hash = poseidon.createHash(6, 8, 57);
|
const hm = poseidon([R8[0], R8[1], A[0], A[1], msg]);
|
||||||
const hm = hash([R8[0], R8[1], A[0], A[1], msg]);
|
|
||||||
const S = r.add(hm.mul(s)).mod(babyJub.subOrder);
|
const S = r.add(hm.mul(s)).mod(babyJub.subOrder);
|
||||||
return {
|
return {
|
||||||
R8: R8,
|
R8: R8,
|
||||||
@ -173,8 +172,7 @@ function verifyPoseidon(msg, sig, A) {
|
|||||||
if (!babyJub.inCurve(A)) return false;
|
if (!babyJub.inCurve(A)) return false;
|
||||||
if (sig.S>= babyJub.subOrder) return false;
|
if (sig.S>= babyJub.subOrder) return false;
|
||||||
|
|
||||||
const hash = poseidon.createHash(6, 8, 57);
|
const hm = poseidon([sig.R8[0], sig.R8[1], A[0], A[1], msg]);
|
||||||
const hm = hash([sig.R8[0], sig.R8[1], A[0], A[1], msg]);
|
|
||||||
|
|
||||||
const Pleft = babyJub.mulPointEscalar(babyJub.Base8, sig.S);
|
const Pleft = babyJub.mulPointEscalar(babyJub.Base8, sig.S);
|
||||||
let Pright = babyJub.mulPointEscalar(A, hm.mul(bigInt("8")));
|
let Pright = babyJub.mulPointEscalar(A, hm.mul(bigInt("8")));
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
const Poseidon = require("./poseidon");
|
const poseidon = require("./poseidon");
|
||||||
const bigInt = require("snarkjs").bigInt;
|
const bigInt = require("snarkjs").bigInt;
|
||||||
|
|
||||||
const hash = Poseidon.createHash(6, 8, 57);
|
|
||||||
|
|
||||||
exports.hash0 = function (left, right) {
|
exports.hash0 = function (left, right) {
|
||||||
return hash([left, right]);
|
return poseidon([left, right]);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.hash1 = function(key, value) {
|
exports.hash1 = function(key, value) {
|
||||||
return hash([key, value, bigInt.one]);
|
return poseidon([key, value, bigInt.one]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.F = poseidon.F;
|
||||||
|
@ -2,19 +2,18 @@ const ganache = require("ganache-cli");
|
|||||||
const Web3 = require("web3");
|
const Web3 = require("web3");
|
||||||
const chai = require("chai");
|
const chai = require("chai");
|
||||||
const poseidonGenContract = require("../src/poseidon_gencontract.js");
|
const poseidonGenContract = require("../src/poseidon_gencontract.js");
|
||||||
const Poseidon = require("../src/poseidon.js");
|
const poseidon = require("../src/poseidon.js");
|
||||||
const bigInt = require("snarkjs").bigInt;
|
|
||||||
|
|
||||||
const assert = chai.assert;
|
const assert = chai.assert;
|
||||||
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
|
const log = (msg) => { if (process.env.MOCHA_VERBOSE) console.log(msg); };
|
||||||
|
|
||||||
const SEED = "mimc";
|
describe("Poseidon Smart contract test", function () {
|
||||||
|
|
||||||
describe("Poseidon Smart contract test", () => {
|
|
||||||
let testrpc;
|
let testrpc;
|
||||||
let web3;
|
let web3;
|
||||||
let mimc;
|
let poseidon2;
|
||||||
|
let poseidon4;
|
||||||
let accounts;
|
let accounts;
|
||||||
|
this.timeout(100000);
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
|
web3 = new Web3(ganache.provider(), null, { transactionConfirmationBlocks: 1 });
|
||||||
@ -24,26 +23,42 @@ describe("Poseidon Smart contract test", () => {
|
|||||||
it("Should deploy the contract", async () => {
|
it("Should deploy the contract", async () => {
|
||||||
const C = new web3.eth.Contract(poseidonGenContract.abi);
|
const C = new web3.eth.Contract(poseidonGenContract.abi);
|
||||||
|
|
||||||
mimc = await C.deploy({
|
poseidon2 = await C.deploy({
|
||||||
data: poseidonGenContract.createCode()
|
data: poseidonGenContract.createCode(2)
|
||||||
|
}).send({
|
||||||
|
gas: 2500000,
|
||||||
|
from: accounts[0]
|
||||||
|
});
|
||||||
|
poseidon4 = await C.deploy({
|
||||||
|
data: poseidonGenContract.createCode(4)
|
||||||
}).send({
|
}).send({
|
||||||
gas: 2500000,
|
gas: 2500000,
|
||||||
from: accounts[0]
|
from: accounts[0]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Shold calculate the mimic correctly", async () => {
|
it("Shold calculate the poseidon correctly for 2 inputs", async () => {
|
||||||
|
|
||||||
const res = await mimc.methods.poseidon([1,2]).call();
|
const res = await poseidon2.methods.poseidon([1, 2]).call();
|
||||||
|
|
||||||
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
|
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
|
||||||
|
|
||||||
const hash = Poseidon.createHash(6, 8, 57);
|
const res2 = poseidon([1, 2]);
|
||||||
|
|
||||||
const res2 = hash([1,2]);
|
|
||||||
// console.log("Ref: " + bigInt(res2).toString(16));
|
// console.log("Ref: " + bigInt(res2).toString(16));
|
||||||
|
|
||||||
assert.equal(res.toString(), res2.toString());
|
assert.equal(res.toString(), res2.toString());
|
||||||
});
|
});
|
||||||
|
it("Shold calculate the poseidon correctly for 4 inputs", async () => {
|
||||||
|
|
||||||
|
const res = await poseidon4.methods.poseidon([1, 2, 3, 4]).call();
|
||||||
|
|
||||||
|
// console.log("Cir: " + bigInt(res.toString(16)).toString(16));
|
||||||
|
|
||||||
|
const res2 = poseidon([1, 2, 3, 4]);
|
||||||
|
// console.log("Ref: " + bigInt(res2).toString(16));
|
||||||
|
|
||||||
|
assert.equal(res.toString(), res2.toString());
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user