5 Commits

Author SHA1 Message Date
Jordi Baylina
2d852d7a8f 0.0.3 2021-10-06 13:18:14 +02:00
alrubio
30f12bf326 Merge branch 'main' of https://github.com/iden3/circom_tester into main 2021-10-06 13:17:53 +02:00
alrubio
a7db09fba9 version added 2021-10-06 13:16:25 +02:00
Jordi Baylina
e615bc3280 0.0.2 2021-10-06 12:52:07 +02:00
alrubio
3942e16d84 test added 2021-10-06 12:49:54 +02:00
7 changed files with 50 additions and 13 deletions

View File

@@ -1,2 +1,2 @@
exports.wasm = import("./wasm/tester"); exports.wasm = require("./wasm/tester");
exports.c = import("./c/tester"); //exports.c = require("./c/tester");

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "circom_tester", "name": "circom_tester",
"version": "0.0.1", "version": "0.0.3",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "circom_tester", "name": "circom_tester",
"version": "0.0.1", "version": "0.0.3",
"license": "GPL-3.0", "license": "GPL-3.0",
"dependencies": { "dependencies": {
"chai": "^4.3.4", "chai": "^4.3.4",

View File

@@ -1,6 +1,6 @@
{ {
"name": "circom_tester", "name": "circom_tester",
"version": "0.0.1", "version": "0.0.3",
"description": "Tools for testing circom circuits.", "description": "Tools for testing circom circuits.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

11
test/Multiplier2.circom Normal file
View File

@@ -0,0 +1,11 @@
pragma circom 2.0.0;
template Multiplier2() {
signal input a;
signal input b;
signal output c;
c <== a*b;
}
component main = Multiplier2();

24
test/multiplier2.js Normal file
View File

@@ -0,0 +1,24 @@
const chai = require("chai");
const path = require("path");
const wasm_tester = require("./../index").wasm;
const F1Field = require("ffjavascript").F1Field;
const Scalar = require("ffjavascript").Scalar;
exports.p = Scalar.fromString("21888242871839275222246405745257275088548364400416034343698204186575808495617");
const Fr = new F1Field(exports.p);
const assert = chai.assert;
describe("Exponentioation test", function () {
this.timeout(100000);
it("Should generate the Exponentiation table in k=0", async () => {
const circuit = await wasm_tester(path.join(__dirname, "Multiplier2.circom"));
const w = await circuit.calculateWitness({a: 2, b: 4});
await circuit.checkConstraints(w);
});
});

View File

@@ -51,7 +51,6 @@ async function compile (fileName, options) {
if (options.r1cs) flags += "--r1cs "; if (options.r1cs) flags += "--r1cs ";
if (options.json) flags += "--json "; if (options.json) flags += "--json ";
if (options.output) flags += "--output " + options.output + " "; if (options.output) flags += "--output " + options.output + " ";
console.log(circom + flags + fileName);
await exec("circom " + flags + fileName); await exec("circom " + flags + fileName);
} }

View File

@@ -80,19 +80,22 @@ class WitnessCalculator {
this.version = this.instance.exports.getVersion(); this.version = this.instance.exports.getVersion();
this.n32 = this.instance.exports.getFieldNumLen32(); this.n32 = this.instance.exports.getFieldNumLen32();
// Not needed this.instance.exports.getRawPrime();
// this.instance.exports.getRawPrime(); const arr = new Array(this.n32);
// const arr = new Array(this.n32); for (let i=0; i<this.n32; i++) {
// for (let i=0; i<this.n32; i++) { arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i);
// arr[this.n32-1-i] = this.instance.exports.readSharedRWMemory(i); }
// } this.prime = utils.fromArray32(arr);
// this.prime = utils.fromArray32(arr);
this.witnessSize = this.instance.exports.getWitnessSize(); this.witnessSize = this.instance.exports.getWitnessSize();
this.sanityCheck = sanityCheck; this.sanityCheck = sanityCheck;
} }
circom_version() {
return this.instance.exports.getVersion();
}
async _doCalculateWitness(input, sanityCheck) { async _doCalculateWitness(input, sanityCheck) {
//input is assumed to be a map from signals to arrays of bigints //input is assumed to be a map from signals to arrays of bigints
this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0); this.instance.exports.init((this.sanityCheck || sanityCheck) ? 1 : 0);