Browse Source

Add circom-examples/equation.circom

pull/1/head
arnaucube 3 years ago
parent
commit
f7de1bb933
8 changed files with 3661 additions and 0 deletions
  1. +2
    -0
      circom-examples/.gitignore
  2. +11
    -0
      circom-examples/README.md
  3. +35
    -0
      circom-examples/circuits/equation.circom
  4. +3525
    -0
      circom-examples/package-lock.json
  5. +28
    -0
      circom-examples/package.json
  6. +24
    -0
      circom-examples/test/equation.test.ts
  7. +19
    -0
      circom-examples/tsconfig.json
  8. +17
    -0
      circom-examples/tslint.json

+ 2
- 0
circom-examples/.gitignore

@ -0,0 +1,2 @@
node_modules
build

+ 11
- 0
circom-examples/README.md

@ -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
```

+ 35
- 0
circom-examples/circuits/equation.circom

@ -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);

+ 3525
- 0
circom-examples/package-lock.json
File diff suppressed because it is too large
View File


+ 28
- 0
circom-examples/package.json

@ -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"
}
}

+ 24
- 0
circom-examples/test/equation.test.ts

@ -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);
});
});

+ 19
- 0
circom-examples/tsconfig.json

@ -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"
]
}

+ 17
- 0
circom-examples/tslint.json

@ -0,0 +1,17 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"indent": [true, "spaces", 4],
"semicolon": [false, "always"]
},
"rulesDirectory": [],
"linterOptions": {
"exclude": [
"node_modules/**"
]
}
}

Loading…
Cancel
Save