You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

5 years ago
5 years ago
  1. #!/usr/bin/env node
  2. /*
  3. Copyright 2018 0KIMS association.
  4. This file is part of circom (Zero Knowledge Circuit Compiler).
  5. circom is a free software: you can redistribute it and/or modify it
  6. under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. circom is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with circom. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. /* eslint-disable no-console */
  17. const fs = require("fs");
  18. const path = require("path");
  19. const compiler = require("./src/compiler");
  20. const version = require("./package").version;
  21. const argv = require("yargs")
  22. .version(version)
  23. .usage("circom [input source circuit file] -o [output definition circuit file]")
  24. .alias("o", "output")
  25. .help("h")
  26. .alias("h", "help")
  27. .alias("v", "verbose")
  28. .alias("f", "fast")
  29. .epilogue(`Copyright (C) 2018 0kims association
  30. This program comes with ABSOLUTELY NO WARRANTY;
  31. This is free software, and you are welcome to redistribute it
  32. under certain conditions; see the COPYING file in the official
  33. repo directory at https://github.com/iden3/circom `)
  34. .argv;
  35. let inputFile;
  36. if (argv._.length == 0) {
  37. inputFile = "circuit.circom";
  38. } else if (argv._.length == 1) {
  39. inputFile = argv._[0];
  40. } else {
  41. console.log("Only one circuit at a time is permited");
  42. process.exit(1);
  43. }
  44. const fullFileName = path.resolve(process.cwd(), inputFile);
  45. const outName = argv.output ? argv.output : "circuit.json";
  46. compiler(fullFileName, {reduceConstraints: !argv.fast}).then( (cir) => {
  47. fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8");
  48. process.exit(0);
  49. }, (err) => {
  50. // console.log(err);
  51. console.log(err.stack);
  52. if (err.pos) {
  53. console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`);
  54. } else {
  55. console.log(err.message);
  56. if (argv.verbose) console.log(err.stack);
  57. }
  58. if (err.ast) {
  59. console.error(JSON.stringify(err.ast, null, 1));
  60. }
  61. process.exit(1);
  62. });