Browse Source

Add very initial version of circuom circuit

pull/1/head
arnaucube 4 years ago
parent
commit
6b947cb838
8 changed files with 3903 additions and 0 deletions
  1. +3
    -0
      circuits/.gitignore
  2. +6
    -0
      circuits/README.md
  3. +42
    -0
      circuits/circuits/withdraw.circom
  4. +3751
    -0
      circuits/package-lock.json
  5. +29
    -0
      circuits/package.json
  6. +36
    -0
      circuits/test/withdraw.test.ts
  7. +19
    -0
      circuits/tsconfig.json
  8. +17
    -0
      circuits/tslint.json

+ 3
- 0
circuits/.gitignore

@ -0,0 +1,3 @@
node_modules
build
.github

+ 6
- 0
circuits/README.md

@ -0,0 +1,6 @@
# circuits [![Tests](https://github.com/miksi/miksi/circuits/workflows/Tests/badge.svg)](https://github.com/miksi/miksi/circuits/actions?query=workflow%3ATests)
Circuits used by miksi.
**Warning:** This repository is in a very early stage.

+ 42
- 0
circuits/circuits/withdraw.circom

@ -0,0 +1,42 @@
/*
# withdraw.circom
WARNING: WIP, very initial version of the miksi circuit
+--------+
PUB_coinCode+------->+ |
| | +----+
PUB_amount+--------->+Poseidon+------->+ == +<-----+PUB_commitment
| | +----+
PRI_secret+--------->+ |
+--------+
*/
include "../node_modules/circomlib/circuits/babyjub.circom";
include "../node_modules/circomlib/circuits/comparators.circom";
include "../node_modules/circomlib/circuits/poseidon.circom";
include "../node_modules/circomlib/circuits/bitify.circom";
include "../node_modules/circomlib/circuits/smt/smtverifier.circom";
include "../node_modules/circomlib/circuits/smt/smtprocessor.circom";
template Withdraw() {
signal input coinCode;
signal input amount;
signal input commitment;
signal private input secret;
component hash = Poseidon(3, 6, 8, 57);
hash.inputs[0] <== coinCode;
hash.inputs[1] <== amount;
hash.inputs[2] <== secret;
component eq = IsEqual();
eq.in[0] <== hash.out;
eq.in[1] <== commitment;
eq.out === 1;
}
component main = Withdraw();

+ 3751
- 0
circuits/package-lock.json
File diff suppressed because it is too large
View File


+ 29
- 0
circuits/package.json

@ -0,0 +1,29 @@
{
"name": "circuits",
"version": "0.0.1",
"description": "miksilo circuits",
"main": "index.js",
"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/node": "^12.12.0",
"circom": "0.5.10",
"eslint-plugin-mocha": "^6.1.0",
"snarkjs": "^0.1.31",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.6",
"chai": "^4.2.0",
"mocha": "^5.2.0",
"mocha-steps": "^1.3.0",
"ts-node": "^7.0.1",
"tslint": "^5.18.0",
"typescript": "^3.5.3"
}
}

+ 36
- 0
circuits/test/withdraw.test.ts

@ -0,0 +1,36 @@
const path = require("path");
const tester = require("circom").tester;
const chai = require("chai");
const assert = chai.assert;
const circomlib = require("circomlib");
export {};
describe("withdraw test", function () {
this.timeout(200000);
it("Test Withdraw", async () => {
const circuit = await tester(
path.join(__dirname, "../circuits", "withdraw.circom"),
{reduceConstraints: false}
);
// const secret = Math.floor(Math.random()*1000).toString();
const secret = "123456789";
const coinCode = "1";
const amount = "100";
const poseidon = circomlib.poseidon.createHash(6, 8, 57);
const commitment = poseidon([coinCode, amount, secret]).toString();
const witness = await circuit.calculateWitness({
"coinCode": coinCode,
"amount": amount,
"commitment": commitment,
"secret": secret
});
await circuit.checkConstraints(witness);
});
});

+ 19
- 0
circuits/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
circuits/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