@ -0,0 +1,2 @@ |
|||||
|
node_modules |
||||
|
build |
@ -0,0 +1,11 @@ |
|||||
|
# circom-examples |
||||
|
|
||||
|
- `equation.circom`: Circuit to check that prover knows a private inputs `x` & `y`, such as `x**a - y**b = 0`, where `a` & `b` are known parameters. |
||||
|
|
||||
|
|
||||
|
## Run |
||||
|
``` |
||||
|
npm install |
||||
|
|
||||
|
npm run test |
||||
|
``` |
@ -0,0 +1,35 @@ |
|||||
|
include "../node_modules/circomlib/circuits/comparators.circom"; |
||||
|
|
||||
|
/* |
||||
|
Circuit to check that prover knows a private inputs x & y, |
||||
|
such as x**a - y**b = 0, where a & b are known parameters. |
||||
|
*/ |
||||
|
template Equation(a, b) { |
||||
|
signal private input x; |
||||
|
signal private input y; |
||||
|
|
||||
|
|
||||
|
signal aArray[a]; |
||||
|
signal bArray[b]; |
||||
|
for (var i=0; i<a; i++) { |
||||
|
if (i==0) { |
||||
|
aArray[0] <== x; |
||||
|
} else { |
||||
|
aArray[i] <== x * aArray[i-1]; |
||||
|
} |
||||
|
} |
||||
|
for(var i=0; i<b; i++) { |
||||
|
if (i==0) { |
||||
|
bArray[0] <== y; |
||||
|
} else { |
||||
|
bArray[i] <== y * bArray[i-1]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
component checkEq = IsEqual(); |
||||
|
checkEq.in[0] <== aArray[a-1]; |
||||
|
checkEq.in[1] <== bArray[b-1]; |
||||
|
checkEq.out === 1; |
||||
|
} |
||||
|
|
||||
|
component main = Equation(4, 8); |
@ -0,0 +1,28 @@ |
|||||
|
{ |
||||
|
"name": "kesto", |
||||
|
"version": "0.0.1", |
||||
|
"description": "kesto", |
||||
|
"main": "src/index.ts", |
||||
|
"scripts": { |
||||
|
"clean": "rm -fR dist", |
||||
|
"build": "npm run clean && ./node_modules/.bin/tsc --strictNullChecks", |
||||
|
"test": "./node_modules/.bin/mocha -r ts-node/register test/*.ts" |
||||
|
}, |
||||
|
"license": "GPL-3.0", |
||||
|
"dependencies": { |
||||
|
"circomlib": "0.2.2" |
||||
|
}, |
||||
|
"devDependencies": { |
||||
|
"@types/chai": "^4.1.7", |
||||
|
"@types/mocha": "^5.2.6", |
||||
|
"@types/node": "^12.12.0", |
||||
|
"chai": "^4.2.0", |
||||
|
"circom": "0.5.10", |
||||
|
"eslint-plugin-mocha": "^6.1.0", |
||||
|
"mocha": "^5.2.0", |
||||
|
"mocha-steps": "^1.3.0", |
||||
|
"ts-node": "^7.0.1", |
||||
|
"tslint": "^5.18.0", |
||||
|
"typescript": "^3.5.3" |
||||
|
} |
||||
|
} |
@ -0,0 +1,24 @@ |
|||||
|
const path = require("path"); |
||||
|
const tester = require("circom").tester; |
||||
|
const chai = require("chai"); |
||||
|
const assert = chai.assert; |
||||
|
|
||||
|
export {}; |
||||
|
|
||||
|
describe("equation test", function () { |
||||
|
this.timeout(200000); |
||||
|
|
||||
|
|
||||
|
it("Test equation", async () => { |
||||
|
const circuit = await tester( |
||||
|
path.join(__dirname, "../circuits", "equation.circom"), |
||||
|
{reduceConstraints: false} |
||||
|
); |
||||
|
|
||||
|
const witness = await circuit.calculateWitness({ |
||||
|
"x": 4, |
||||
|
"y": 2 |
||||
|
}); |
||||
|
await circuit.checkConstraints(witness); |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,19 @@ |
|||||
|
{ |
||||
|
"compilerOptions": { |
||||
|
"module": "commonjs", |
||||
|
"moduleResolution": "node", |
||||
|
"resolveJsonModule": true, |
||||
|
"pretty": true, |
||||
|
"declaration": true, |
||||
|
"sourceMap": true, |
||||
|
"target": "es6", |
||||
|
"outDir": "dist", |
||||
|
"baseUrl": "src" |
||||
|
}, |
||||
|
"include": [ |
||||
|
"src/**/*.ts" |
||||
|
], |
||||
|
"exclude": [ |
||||
|
"node_modules" |
||||
|
] |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
{ |
||||
|
"defaultSeverity": "error", |
||||
|
"extends": [ |
||||
|
"tslint:recommended" |
||||
|
], |
||||
|
"jsRules": {}, |
||||
|
"rules": { |
||||
|
"indent": [true, "spaces", 4], |
||||
|
"semicolon": [false, "always"] |
||||
|
}, |
||||
|
"rulesDirectory": [], |
||||
|
"linterOptions": { |
||||
|
"exclude": [ |
||||
|
"node_modules/**" |
||||
|
] |
||||
|
} |
||||
|
} |