mirror of
https://github.com/arnaucube/miksi-core.git
synced 2026-02-06 19:16:40 +01:00
Add very initial version of circuom circuit
This commit is contained in:
3
circuits/.gitignore
vendored
Normal file
3
circuits/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
.github
|
||||
6
circuits/README.md
Normal file
6
circuits/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# circuits [](https://github.com/miksi/miksi/circuits/actions?query=workflow%3ATests)
|
||||
|
||||
Circuits used by miksi.
|
||||
|
||||
**Warning:** This repository is in a very early stage.
|
||||
|
||||
42
circuits/circuits/withdraw.circom
Normal file
42
circuits/circuits/withdraw.circom
Normal file
@@ -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
circuits/package-lock.json
generated
Normal file
3751
circuits/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
circuits/package.json
Normal file
29
circuits/package.json
Normal file
@@ -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
circuits/test/withdraw.test.ts
Normal file
36
circuits/test/withdraw.test.ts
Normal file
@@ -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
circuits/tsconfig.json
Normal file
19
circuits/tsconfig.json
Normal file
@@ -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
circuits/tslint.json
Normal file
17
circuits/tslint.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"defaultSeverity": "error",
|
||||
"extends": [
|
||||
"tslint:recommended"
|
||||
],
|
||||
"jsRules": {},
|
||||
"rules": {
|
||||
"indent": [true, "spaces", 4],
|
||||
"semicolon": [false, "always"]
|
||||
},
|
||||
"rulesDirectory": [],
|
||||
"linterOptions": {
|
||||
"exclude": [
|
||||
"node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user