mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-07 11:16:42 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c03ae4033 | ||
|
|
5e58584a01 | ||
|
|
cb9a5b536e | ||
|
|
70c88be334 | ||
|
|
25759e53cd | ||
|
|
4fa0c79e26 | ||
|
|
e685392523 | ||
|
|
e81c4f1331 | ||
|
|
483c9c0c26 | ||
|
|
eb1834833d | ||
|
|
49a6120eeb |
@@ -1,4 +1,4 @@
|
|||||||
# Circon
|
# Circom
|
||||||
|
|
||||||
Circon is a language designed to write arithmetic circuits that can be used in zero knowledge proofs.
|
Circon is a language designed to write arithmetic circuits that can be used in zero knowledge proofs.
|
||||||
|
|
||||||
|
|||||||
31
cli.js
31
cli.js
@@ -30,12 +30,11 @@ const version = require("./package").version;
|
|||||||
|
|
||||||
const argv = require("yargs")
|
const argv = require("yargs")
|
||||||
.version(version)
|
.version(version)
|
||||||
.usage("circom -s [input source circuit file] -o [output definition circuit file]")
|
.usage("circom [input source circuit file] -o [output definition circuit file]")
|
||||||
.alias("s", "source")
|
|
||||||
.alias("o", "output")
|
.alias("o", "output")
|
||||||
.require(["s","o"])
|
|
||||||
.help("h")
|
.help("h")
|
||||||
.alias("h", "help")
|
.alias("h", "help")
|
||||||
|
.alias("v", "verbose")
|
||||||
.epilogue(`Copyright (C) 2018 0kims association
|
.epilogue(`Copyright (C) 2018 0kims association
|
||||||
This program comes with ABSOLUTELY NO WARRANTY;
|
This program comes with ABSOLUTELY NO WARRANTY;
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
@@ -43,14 +42,34 @@ const argv = require("yargs")
|
|||||||
repo directory at https://github.com/iden3/circom `)
|
repo directory at https://github.com/iden3/circom `)
|
||||||
.argv;
|
.argv;
|
||||||
|
|
||||||
const fullFileName = path.resolve(process.cwd(), argv.source);
|
|
||||||
|
let inputFile;
|
||||||
|
if (argv._.length == 0) {
|
||||||
|
inputFile = "circuit.circom";
|
||||||
|
} else if (argv._.length == 1) {
|
||||||
|
inputFile = argv._[0];
|
||||||
|
} else {
|
||||||
|
console.log("Only one circuit at a time is permited");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullFileName = path.resolve(process.cwd(), inputFile);
|
||||||
|
const outName = argv.output ? argv.output : "circuit.json";
|
||||||
|
|
||||||
compiler(fullFileName).then( (cir) => {
|
compiler(fullFileName).then( (cir) => {
|
||||||
fs.writeFileSync(argv.output, JSON.stringify(cir, null, 1), "utf8");
|
fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8");
|
||||||
|
process.exit(0);
|
||||||
}, (err) => {
|
}, (err) => {
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
|
if (err.pos) {
|
||||||
console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`);
|
console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`);
|
||||||
|
} else {
|
||||||
|
console.log(err.message);
|
||||||
|
if (argv.verbose) console.log(err.stack);
|
||||||
|
}
|
||||||
|
if (err.ast) {
|
||||||
console.error(JSON.stringify(err.ast, null, 1));
|
console.error(JSON.stringify(err.ast, null, 1));
|
||||||
|
}
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "circom",
|
"name": "circom",
|
||||||
"version": "0.0.10",
|
"version": "0.0.15",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -1469,14 +1469,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"snarkjs": {
|
"snarkjs": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.3.tgz",
|
||||||
"integrity": "sha512-i+OOKwATef3/oUleae9FHt/qACPYH1M5gjQkdYYkyRYqScIuZHCmNSf6Q5RWJT5hmOkTEor+T2C5qwKSrzzGSg==",
|
"integrity": "sha512-z5HhuNt019ZzNzUztETK31rpjRRSz3Uzy8TjGgSROf+9ZT9i6dbdWkjTC3fh5o9H+R/2+hcR+7IKAmpIR56V+A==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"big-integer": "^1.6.35",
|
"big-integer": "^1.6.35",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.1.2",
|
||||||
"eslint": "^5.3.0"
|
"eslint": "^5.3.0",
|
||||||
|
"yargs": "^12.0.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ajv": {
|
"ajv": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "circom",
|
"name": "circom",
|
||||||
"version": "0.0.10",
|
"version": "0.0.15",
|
||||||
"description": "Language to generate logic circuits",
|
"description": "Language to generate logic circuits",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
@@ -38,6 +38,6 @@
|
|||||||
"eslint": "^5.0.1",
|
"eslint": "^5.0.1",
|
||||||
"eslint-plugin-mocha": "^5.0.0",
|
"eslint-plugin-mocha": "^5.0.0",
|
||||||
"jison": "^0.4.18",
|
"jison": "^0.4.18",
|
||||||
"snarkjs": "0.1.3"
|
"snarkjs": "0.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ module.exports = compile;
|
|||||||
|
|
||||||
const parser = require("../parser/jaz.js").parser;
|
const parser = require("../parser/jaz.js").parser;
|
||||||
|
|
||||||
const timeout = ms => new Promise(res => setTimeout(res, ms))
|
const timeout = ms => new Promise(res => setTimeout(res, ms));
|
||||||
|
|
||||||
async function compile(srcFile) {
|
async function compile(srcFile) {
|
||||||
const fullFileName = srcFile;
|
const fullFileName = srcFile;
|
||||||
@@ -62,8 +62,13 @@ async function compile(srcFile) {
|
|||||||
fileName: fullFileName
|
fileName: fullFileName
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
exec(ctx, ast);
|
exec(ctx, ast);
|
||||||
|
|
||||||
|
if (!ctx.components["main"]) {
|
||||||
|
throw new Error("A main component must be defined");
|
||||||
|
}
|
||||||
|
|
||||||
classifySignals(ctx);
|
classifySignals(ctx);
|
||||||
reduceConstants(ctx);
|
reduceConstants(ctx);
|
||||||
|
|
||||||
|
|||||||
@@ -578,9 +578,11 @@ function execIf(ctx, ast) {
|
|||||||
exec(ctx, ast.then);
|
exec(ctx, ast.then);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
} else {
|
} else {
|
||||||
|
if (ast.else) {
|
||||||
exec(ctx, ast.else);
|
exec(ctx, ast.else);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -246,9 +246,13 @@ function genIf(ctx, ast) {
|
|||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
const thenBody = gen(ctx, ast.then);
|
const thenBody = gen(ctx, ast.then);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
|
if (ast.else) {
|
||||||
const elseBody = gen(ctx, ast.else);
|
const elseBody = gen(ctx, ast.else);
|
||||||
if (ctx.error) return;
|
if (ctx.error) return;
|
||||||
return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`;
|
return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`;
|
||||||
|
} else {
|
||||||
|
return `if (${condition}) {\n${thenBody}\n}\n`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user