Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tests
on:
push:
branches:
- main
pull_request:

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
timeout-minutes: 30

strategy:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
node-version: ["lts/*", "lts/-1"]

steps:
- name: Checkout project
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: "npm"

- name: Setup Circom
run: wget https://github.com/iden3/circom/releases/latest/download/circom-linux-amd64 && sudo mv ./circom-linux-amd64 /usr/bin/circom && sudo chmod +x /usr/bin/circom

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
89 changes: 48 additions & 41 deletions build/main.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var ffjavascript = require('ffjavascript');
var blake2b = require('blake2b');
var createBlakeHash = require('blake-hash');
var ethers = require('ethers');
var assert = require('assert');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var blake2b__default = /*#__PURE__*/_interopDefaultLegacy(blake2b);
var createBlakeHash__default = /*#__PURE__*/_interopDefaultLegacy(createBlakeHash);
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);

async function buildBabyJub() {
const bn128 = await ffjavascript.getCurveFromName("bn128", true);
return new BabyJub(bn128.Fr);
Expand Down Expand Up @@ -170,9 +162,9 @@ class PedersenHash {

baseHash(type, S) {
if (type == "blake") {
return createBlakeHash__default["default"]("blake256").update(S).digest();
return createBlakeHash("blake256").update(S).digest();
} else if (type == "blake2b") {
return Buffer.from(blake2b__default["default"](32).update(Buffer.from(S)).digest());
return Buffer.from(blake2b(32).update(Buffer.from(S)).digest());
}
}

Expand Down Expand Up @@ -293,7 +285,7 @@ class Mimc7 {
getIV(seed) {
const F = this.F;
if (typeof seed === "undefined") seed = SEED$1;
const c = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(seed+"_iv"));
const c = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(seed+"_iv"));
const cn = ffjavascript.Scalar.e(c);
const iv = ffjavascript.Scalar.mod(cn, F.p);
return iv;
Expand All @@ -303,9 +295,9 @@ class Mimc7 {
const F = this.F;
if (typeof nRounds === "undefined") nRounds = NROUNDS$1;
const cts = new Array(nRounds);
let c = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(SEED$1));
let c = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(SEED$1));
for (let i=1; i<nRounds; i++) {
c = ethers.ethers.utils.keccak256(c);
c = ethers.ethers.keccak256(c);

cts[i] = F.e(c);
}
Expand Down Expand Up @@ -25602,7 +25594,7 @@ class MimcSponge {
getIV (seed) {
const F = this.F;
if (typeof seed === "undefined") seed = SEED;
const c = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(seed+"_iv"));
const c = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(seed+"_iv"));
const cn = ffjavascript.Scalar.e(c);
const iv = cn.mod(F.p);
return iv;
Expand All @@ -25612,8 +25604,8 @@ class MimcSponge {
const F = this.F;
if (typeof nRounds === "undefined") nRounds = NROUNDS;
const cts = new Array(nRounds);
let c = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(SEED)); for (let i=1; i<nRounds; i++) {
c = ethers.ethers.utils.keccak256(c);
let c = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(SEED)); for (let i=1; i<nRounds; i++) {
c = ethers.ethers.keccak256(c);

cts[i] = F.e(c);
}
Expand Down Expand Up @@ -25710,22 +25702,22 @@ class Eddsa {

prv2pub(prv) {
this.babyJub.F;
const sBuff = this.pruneBuffer(createBlakeHash__default["default"]("blake512").update(Buffer.from(prv)).digest());
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
let s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32);
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, ffjavascript.Scalar.shr(s,3));
return A;
}

signPedersen(prv, msg) {
this.babyJub.F;
const sBuff = this.pruneBuffer(createBlakeHash__default["default"]("blake512").update(Buffer.from(prv)).digest());
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32);
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, ffjavascript.Scalar.shr(s, 3));

const composeBuff = new Uint8Array(32 + msg.length);
composeBuff.set(sBuff.slice(32), 0);
composeBuff.set(msg, 32);
const rBuff = createBlakeHash__default["default"]("blake512").update(Buffer.from(composeBuff)).digest();
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
let r = ffjavascript.Scalar.mod(ffjavascript.Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);
const R8p = this.babyJub.packPoint(R8);
Expand Down Expand Up @@ -25754,15 +25746,15 @@ class Eddsa {

signMiMC(prv, msg) {
const F = this.babyJub.F;
const sBuff = this.pruneBuffer(createBlakeHash__default["default"]("blake512").update(Buffer.from(prv)).digest());
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32);
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, ffjavascript.Scalar.shr(s, 3));


const composeBuff = new Uint8Array(32 + msg.length);
composeBuff.set(sBuff.slice(32), 0);
F.toRprLE(composeBuff, 32, msg);
const rBuff = createBlakeHash__default["default"]("blake512").update(Buffer.from(composeBuff)).digest();
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
let r = ffjavascript.Scalar.mod(ffjavascript.Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);

Expand All @@ -25783,14 +25775,14 @@ class Eddsa {

signMiMCSponge(prv, msg) {
const F = this.babyJub.F;
const sBuff = this.pruneBuffer(createBlakeHash__default["default"]("blake512").update(Buffer.from(prv)).digest());
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32);
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, ffjavascript.Scalar.shr(s, 3));

const composeBuff = new Uint8Array(32 + msg.length);
composeBuff.set(sBuff.slice(32), 0);
F.toRprLE(composeBuff, 32, msg);
const rBuff = createBlakeHash__default["default"]("blake512").update(Buffer.from(composeBuff)).digest();
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
let r = ffjavascript.Scalar.mod(ffjavascript.Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);

Expand All @@ -25811,14 +25803,14 @@ class Eddsa {

signPoseidon(prv, msg) {
const F = this.babyJub.F;
const sBuff = this.pruneBuffer(createBlakeHash__default["default"]("blake512").update(Buffer.from(prv)).digest());
const sBuff = this.pruneBuffer(createBlakeHash("blake512").update(Buffer.from(prv)).digest());
const s = ffjavascript.Scalar.fromRprLE(sBuff, 0, 32);
const A = this.babyJub.mulPointEscalar(this.babyJub.Base8, ffjavascript.Scalar.shr(s, 3));

const composeBuff = new Uint8Array(32 + msg.length);
composeBuff.set(sBuff.slice(32), 0);
F.toRprLE(composeBuff, 32, msg);
const rBuff = createBlakeHash__default["default"]("blake512").update(Buffer.from(composeBuff)).digest();
const rBuff = createBlakeHash("blake512").update(Buffer.from(composeBuff)).digest();
let r = ffjavascript.Scalar.mod(ffjavascript.Scalar.fromRprLE(rBuff, 0, 64), this.babyJub.subOrder);
const R8 = this.babyJub.mulPointEscalar(this.babyJub.Base8, r);

Expand Down Expand Up @@ -25958,6 +25950,9 @@ class Eddsa {
}

// Copyright (c) 2018 Jordi Baylina
// License: LGPL-3.0+
//


class Contract {
constructor() {
Expand Down Expand Up @@ -25992,7 +25987,7 @@ class Contract {
genLoadedLength = C.code.length;
}

return ethers.ethers.utils.hexlify(C.code.concat(this.code));
return ethers.ethers.hexlify(new Uint8Array(C.code.concat(this.code)));
}

stop() { this.code.push(0x00); }
Expand Down Expand Up @@ -26118,7 +26113,7 @@ class Contract {
S = "0x" +S;
data = S;
}
const d = ethers.ethers.utils.arrayify(data);
const d = ethers.ethers.getBytes(data);
if (d.length == 0 || d.length > 32) {
throw new Error("Assertion failed");
}
Expand Down Expand Up @@ -26161,10 +26156,14 @@ class Contract {
}

// Copyright (c) 2018 Jordi Baylina
// License: LGPL-3.0+
//


function createCode$2(seed, n) {

let ci = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(seed));
let ci = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(seed));

const C = new Contract();

C.push(0x44);
Expand Down Expand Up @@ -26206,7 +26205,7 @@ function createCode$2(seed, n) {
C.mulmod(); // r=t^7 k q

for (let i=0; i<n-1; i++) {
ci = ethers.ethers.utils.keccak256(ci);
ci = ethers.ethers.keccak256(ci);
C.dup(2); // q r k q
C.dup(0); // q q r k q
C.dup(0); // q q q r k q
Expand Down Expand Up @@ -26266,15 +26265,18 @@ const abi$1 = [

var _mimc7Contract = /*#__PURE__*/Object.freeze({
__proto__: null,
createCode: createCode$2,
abi: abi$1
abi: abi$1,
createCode: createCode$2
});

// Copyright (c) 2018 Jordi Baylina
// License: LGPL-3.0+
//


function createCode$1(seed, n) {

let ci = ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(seed));
let ci = ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(seed));

const C = new Contract();

Expand Down Expand Up @@ -26317,7 +26319,7 @@ function createCode$1(seed, n) {

for (let i=0; i<n-1; i++) {
if (i < n-2) {
ci = ethers.ethers.utils.keccak256(ci);
ci = ethers.ethers.keccak256(ci);
} else {
ci = "0x00";
}
Expand Down Expand Up @@ -26391,8 +26393,8 @@ const abi = [

var _mimcSpongeContract = /*#__PURE__*/Object.freeze({
__proto__: null,
createCode: createCode$1,
abi: abi
abi: abi,
createCode: createCode$1
});

var poseidonConstants = {
Expand Down Expand Up @@ -26603,6 +26605,9 @@ var poseidonConstants = {
};

// Copyright (c) 2018 Jordi Baylina
// License: LGPL-3.0+
//

const { unstringifyBigInts } = ffjavascript.utils;

const { C:K, M } = unstringifyBigInts(poseidonConstants);
Expand Down Expand Up @@ -26700,10 +26705,10 @@ function createCode(nInputs) {
C.calldataload();
C.div();
C.dup(0);
C.push(ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(`poseidon(uint256[${nInputs}])`)).slice(0, 10)); // poseidon(uint256[n])
C.push(ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(`poseidon(uint256[${nInputs}])`)).slice(0, 10)); // poseidon(uint256[n])
C.eq();
C.swap(1);
C.push(ethers.ethers.utils.keccak256(ethers.ethers.utils.toUtf8Bytes(`poseidon(bytes32[${nInputs}])`)).slice(0, 10)); // poseidon(bytes32[n])
C.push(ethers.ethers.keccak256(ethers.ethers.toUtf8Bytes(`poseidon(bytes32[${nInputs}])`)).slice(0, 10)); // poseidon(bytes32[n])
C.eq();
C.or();
C.jmpi("start");
Expand Down Expand Up @@ -26845,8 +26850,8 @@ async function buildPoseidon$1() {
const pow5 = a => F.mul(a, F.square(F.square(a, a)));

function poseidon(inputs, initState, nOut) {
assert__default["default"](inputs.length > 0);
assert__default["default"](inputs.length <= N_ROUNDS_P.length);
assert(inputs.length > 0);
assert(inputs.length <= N_ROUNDS_P.length);

const t = inputs.length + 1;
const nRoundsF = N_ROUNDS_F;
Expand Down Expand Up @@ -26885,6 +26890,8 @@ async function buildPoseidon$1() {
}

// Parameters are generated by a reference script https://extgit.iaik.tugraz.at/krypto/hadeshash/-/blob/master/code/generate_parameters_grain.sage
// Used like so: sage generate_parameters_grain.sage 1 0 254 2 8 56 0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001


function unsringifyConstants(Fr, o) {
if ((typeof(o) == "string") && (/^[0-9]+$/.test(o) )) {
Expand Down Expand Up @@ -26919,8 +26926,8 @@ async function buildPoseidon() {
const pow5 = a => F.mul(a, F.square(F.square(a, a)));

function poseidon(inputs, initState, nOut) {
assert__default["default"](inputs.length > 0);
assert__default["default"](inputs.length <= N_ROUNDS_P.length);
assert(inputs.length > 0);
assert(inputs.length <= N_ROUNDS_P.length);

if (initState) {
initState = F.e(initState);
Expand Down
3 changes: 2 additions & 1 deletion hardhat.config.js → hardhat.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require("@nomicfoundation/hardhat-ethers");
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.7.3",
solidity: "0.7.3"
};
Loading