diff --git a/circuits/common/joinCommitments.zok b/circuits/common/joinCommitments.zok index 555079f73..d421d8b38 100644 --- a/circuits/common/joinCommitments.zok +++ b/circuits/common/joinCommitments.zok @@ -10,8 +10,7 @@ from "./common/hashes/poseidon/poseidon.zok" import main as poseidon from "./common/casts/u32_array_to_field.zok" import main as u32_array_to_field from "utils/pack/bool/pack256.zok" import main as bool_256_to_field from "./common/merkle-tree/mimc/altbn254/verify-membership/height32.zok" import main as checkRoot -from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import checkUpdatedPath as checkUpdatedPath -from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as checkproof +from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as updateNullifierRoot def main(\ private field fromId,\ @@ -20,13 +19,10 @@ def main(\ private field oldCommitment_0_owner_secretKey_field,\ private field oldCommitment_1_owner_secretKey_field,\ public field nullifierRoot,\ - public field newNullifierRoot,\ public field oldCommitment_0_nullifier,\ - public field[32] oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\ - private field[32] oldCommitment_0_nullifier_nonmembershipWitness_newsiblingPath,\ + private field[32] oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\ public field oldCommitment_1_nullifier,\ private field[32] oldCommitment_1_nullifier_nonmembershipWitness_siblingPath,\ - private field[32] oldCommitment_1_nullifier_nonmembershipWitness_newsiblingPath,\ private field oldCommitment_0_value,\ private field oldCommitment_0_salt_field,\ private field oldCommitment_1_value,\ @@ -39,7 +35,7 @@ def main(\ private field newCommitment_owner_publicKey_field,\ private field newCommitment_salt_field,\ public field newCommitment_commitment\ -) -> (bool) : +) -> (field) : // check if state is mapping or not @@ -94,18 +90,14 @@ def main(\ field_to_bool_256(oldCommitment_0_nullifier)[8..256] == field_to_bool_256(oldCommitment_0_nullifier_check_field)[8..256]\ ) - assert(\ - nullifierRoot == checkproof(\ - oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\ - oldCommitment_0_nullifier\ - ) ) - - assert( newNullifierRoot == checkUpdatedPath(oldCommitment_0_nullifier_nonmembershipWitness_newsiblingPath,\ - oldCommitment_0_nullifier) ) - - + nullifierRoot = updateNullifierRoot(\ + oldCommitment_0_nullifier_nonmembershipWitness_siblingPath,\ + oldCommitment_0_nullifier,\ + nullifierRoot\ + ) + // Nullify oldCommitment_1: field oldCommitment_1_nullifier_check_field = poseidon([\ @@ -118,15 +110,14 @@ def main(\ field_to_bool_256(oldCommitment_1_nullifier)[8..256] == field_to_bool_256(oldCommitment_1_nullifier_check_field)[8..256]\ ) - assert(\ - nullifierRoot == checkproof(\ + + nullifierRoot = updateNullifierRoot(\ oldCommitment_1_nullifier_nonmembershipWitness_siblingPath,\ - oldCommitment_1_nullifier\ - ) ) + oldCommitment_1_nullifier,\ + nullifierRoot\ + ) + - assert( newNullifierRoot == checkUpdatedPath(oldCommitment_1_nullifier_nonmembershipWitness_newsiblingPath,\ - oldCommitment_1_nullifier) ) - // oldCommitment_0_commitment: preimage check field oldCommitment_0_commitment_field = poseidon([\ @@ -190,4 +181,4 @@ def main(\ field_to_bool_256(newCommitment_commitment)[8..256] == field_to_bool_256(newCommitment_commitment_check_field)[8..256]\ ) - return true + return nullifierRoot diff --git a/circuits/common/merkle-tree/sparse-merkle-tree/checkproof.zok b/circuits/common/merkle-tree/sparse-merkle-tree/checkproof.zok index 73989f1a4..42170ee6f 100644 --- a/circuits/common/merkle-tree/sparse-merkle-tree/checkproof.zok +++ b/circuits/common/merkle-tree/sparse-merkle-tree/checkproof.zok @@ -2,8 +2,7 @@ from "hashes/poseidon/poseidon.zok" import main as poseidon from "../../concatenate/order-left-right-1x1.zok" import main as orderLeftRight from "utils/pack/bool/nonStrictUnpack256.zok" import main as field_to_bool_256 -def main(field[32] siblingPath, field value) -> (field): - +def checkRoot(field[32] siblingPath, field value, field root) -> (field): field accValue = 0 // checking against zero element field[2] preimage = [0, 0] @@ -20,17 +19,22 @@ for u32 i in 0..32 do ]) endfor +assert(root == accValue) + return accValue -def checkUpdatedPath(field[32] siblingPath, field value) -> (field): +def main(field[32] siblingPath, field value, field root) -> (field): + +assert(root == checkRoot(siblingPath, value, root)) -field accValue = value // checking against zero element +// Calculate the new Root + +field accValue = value // Inserting the element field[2] preimage = [0, 0] bool[32] valueIndex = field_to_bool_256(value)[2..34] - for u32 i in 0..32 do u32 j = i // iterator for the siblingPath u32 k = 31 - i // iterator for the leafIndexBits @@ -41,5 +45,4 @@ for u32 i in 0..32 do ]) endfor - return accValue \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c64eb62b5..5c0ac0f4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "prettier": "^2.2.1", "shelljs": "^0.8.5", "solc": "^0.8.0", - "typescript": "4.9.5", + "typescript": "^4.9.5", "winston": "^3.3.3", "yargs": "^15.4.1", "zkp-utils": "^1.0.8" @@ -58,7 +58,6 @@ }, "node_modules/@babel/code-frame": { "version": "7.12.11", - "dev": true, "license": "MIT", "dependencies": { "@babel/highlight": "^7.10.4" @@ -1886,7 +1885,6 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.1.tgz", "integrity": "sha512-5v7TDE9plVhvxQeWLXDTvFvJBdH6pEsdnl2g/dAptmuFEPedQ4Erq5rsDsX+mvAM610IhNaO2W5V1dOOnDKxkQ==", - "dev": true, "dependencies": { "ajv": "^6.12.4", "debug": "^4.1.1", @@ -1906,7 +1904,6 @@ "version": "12.4.0", "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", - "dev": true, "dependencies": { "type-fest": "^0.8.1" }, @@ -2656,7 +2653,6 @@ "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", - "dev": true, "bin": { "acorn": "bin/acorn" }, @@ -2668,14 +2664,12 @@ "version": "5.3.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", - "dev": true, "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "node_modules/ajv": { "version": "6.12.6", - "dev": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", @@ -2698,7 +2692,6 @@ }, "node_modules/ansi-colors": { "version": "4.1.1", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -2724,7 +2717,6 @@ }, "node_modules/argparse": { "version": "1.0.10", - "dev": true, "license": "MIT", "dependencies": { "sprintf-js": "~1.0.2" @@ -2871,7 +2863,6 @@ }, "node_modules/astral-regex": { "version": "2.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -3250,7 +3241,6 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true, "engines": { "node": ">=6" } @@ -3688,7 +3678,6 @@ }, "node_modules/cross-spawn": { "version": "7.0.3", - "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -3773,7 +3762,6 @@ }, "node_modules/deep-is": { "version": "0.1.3", - "dev": true, "license": "MIT" }, "node_modules/define-properties": { @@ -3869,7 +3857,6 @@ }, "node_modules/doctrine": { "version": "3.0.0", - "dev": true, "license": "Apache-2.0", "dependencies": { "esutils": "^2.0.2" @@ -3963,7 +3950,6 @@ }, "node_modules/enquirer": { "version": "2.3.6", - "dev": true, "license": "MIT", "dependencies": { "ansi-colors": "^4.1.1" @@ -4094,7 +4080,6 @@ "version": "7.26.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.26.0.tgz", "integrity": "sha512-4R1ieRf52/izcZE7AlLy56uIHHDLT74Yzz2Iv2l6kDaYvEu9x+wMB5dZArVL8SYGXSYV2YAg70FcW5Y5nGGNIg==", - "dev": true, "dependencies": { "@babel/code-frame": "7.12.11", "@eslint/eslintrc": "^0.4.1", @@ -4779,7 +4764,6 @@ }, "node_modules/eslint-scope": { "version": "5.1.1", - "dev": true, "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", @@ -4791,7 +4775,6 @@ }, "node_modules/eslint-utils": { "version": "2.1.0", - "dev": true, "license": "MIT", "dependencies": { "eslint-visitor-keys": "^1.1.0" @@ -4805,7 +4788,6 @@ }, "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { "version": "1.3.0", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=4" @@ -4813,7 +4795,6 @@ }, "node_modules/eslint-visitor-keys": { "version": "2.0.0", - "dev": true, "license": "Apache-2.0", "engines": { "node": ">=10" @@ -4821,7 +4802,6 @@ }, "node_modules/eslint/node_modules/ansi-regex": { "version": "5.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4829,7 +4809,6 @@ }, "node_modules/eslint/node_modules/ansi-styles": { "version": "4.3.0", - "dev": true, "license": "MIT", "dependencies": { "color-convert": "^2.0.1" @@ -4843,7 +4822,6 @@ }, "node_modules/eslint/node_modules/chalk": { "version": "4.1.0", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", @@ -4858,7 +4836,6 @@ }, "node_modules/eslint/node_modules/color-convert": { "version": "2.0.1", - "dev": true, "license": "MIT", "dependencies": { "color-name": "~1.1.4" @@ -4869,12 +4846,10 @@ }, "node_modules/eslint/node_modules/color-name": { "version": "1.1.4", - "dev": true, "license": "MIT" }, "node_modules/eslint/node_modules/globals": { "version": "13.7.0", - "dev": true, "license": "MIT", "dependencies": { "type-fest": "^0.20.2" @@ -4888,7 +4863,6 @@ }, "node_modules/eslint/node_modules/has-flag": { "version": "4.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -4896,7 +4870,6 @@ }, "node_modules/eslint/node_modules/semver": { "version": "7.3.4", - "dev": true, "license": "ISC", "dependencies": { "lru-cache": "^6.0.0" @@ -4910,7 +4883,6 @@ }, "node_modules/eslint/node_modules/strip-ansi": { "version": "6.0.0", - "dev": true, "license": "MIT", "dependencies": { "ansi-regex": "^5.0.0" @@ -4921,7 +4893,6 @@ }, "node_modules/eslint/node_modules/supports-color": { "version": "7.2.0", - "dev": true, "license": "MIT", "dependencies": { "has-flag": "^4.0.0" @@ -4932,7 +4903,6 @@ }, "node_modules/eslint/node_modules/type-fest": { "version": "0.20.2", - "dev": true, "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=10" @@ -4945,7 +4915,6 @@ "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", - "dev": true, "dependencies": { "acorn": "^7.4.0", "acorn-jsx": "^5.3.1", @@ -4959,14 +4928,12 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", - "dev": true, "engines": { "node": ">=4" } }, "node_modules/esprima": { "version": "4.0.1", - "dev": true, "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", @@ -4978,7 +4945,6 @@ }, "node_modules/esquery": { "version": "1.4.0", - "dev": true, "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" @@ -4989,7 +4955,6 @@ }, "node_modules/esquery/node_modules/estraverse": { "version": "5.2.0", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=4.0" @@ -4997,7 +4962,6 @@ }, "node_modules/esrecurse": { "version": "4.3.0", - "dev": true, "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" @@ -5008,7 +4972,6 @@ }, "node_modules/esrecurse/node_modules/estraverse": { "version": "5.2.0", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=4.0" @@ -5016,7 +4979,6 @@ }, "node_modules/estraverse": { "version": "4.3.0", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=4.0" @@ -5024,7 +4986,6 @@ }, "node_modules/esutils": { "version": "2.0.3", - "dev": true, "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" @@ -5158,7 +5119,6 @@ }, "node_modules/fast-deep-equal": { "version": "3.1.3", - "dev": true, "license": "MIT" }, "node_modules/fast-diff": { @@ -5184,12 +5144,10 @@ }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", - "dev": true, "license": "MIT" }, "node_modules/fast-levenshtein": { "version": "2.0.6", - "dev": true, "license": "MIT" }, "node_modules/fastq": { @@ -5214,7 +5172,6 @@ }, "node_modules/file-entry-cache": { "version": "6.0.1", - "dev": true, "license": "MIT", "dependencies": { "flat-cache": "^3.0.4" @@ -5368,7 +5325,6 @@ }, "node_modules/flat-cache": { "version": "3.0.4", - "dev": true, "license": "MIT", "dependencies": { "flatted": "^3.1.0", @@ -5380,7 +5336,6 @@ }, "node_modules/flatted": { "version": "3.1.1", - "dev": true, "license": "ISC" }, "node_modules/fn.name": { @@ -5468,7 +5423,6 @@ }, "node_modules/functional-red-black-tree": { "version": "1.0.1", - "dev": true, "license": "MIT" }, "node_modules/general-number": { @@ -5533,7 +5487,6 @@ }, "node_modules/glob-parent": { "version": "5.1.2", - "dev": true, "license": "ISC", "dependencies": { "is-glob": "^4.0.1" @@ -5766,7 +5719,6 @@ "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", - "dev": true, "engines": { "node": ">= 4" } @@ -5775,7 +5727,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", - "dev": true, "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -5789,7 +5740,6 @@ }, "node_modules/imurmurhash": { "version": "0.1.4", - "dev": true, "license": "MIT", "engines": { "node": ">=0.8.19" @@ -5905,7 +5855,6 @@ }, "node_modules/is-extglob": { "version": "2.1.1", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -5920,7 +5869,6 @@ }, "node_modules/is-glob": { "version": "4.0.1", - "dev": true, "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" @@ -6041,7 +5989,6 @@ }, "node_modules/isexe": { "version": "2.0.0", - "dev": true, "license": "ISC" }, "node_modules/isobject": { @@ -6092,7 +6039,6 @@ "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", - "dev": true, "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -6147,12 +6093,10 @@ }, "node_modules/json-schema-traverse": { "version": "0.4.1", - "dev": true, "license": "MIT" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", - "dev": true, "license": "MIT" }, "node_modules/json5": { @@ -6252,7 +6196,6 @@ }, "node_modules/levn": { "version": "0.4.1", - "dev": true, "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1", @@ -6450,7 +6393,6 @@ }, "node_modules/lru-cache": { "version": "6.0.0", - "dev": true, "license": "ISC", "dependencies": { "yallist": "^4.0.0" @@ -6987,7 +6929,6 @@ }, "node_modules/natural-compare": { "version": "1.4.0", - "dev": true, "license": "MIT" }, "node_modules/negotiator": { @@ -7157,7 +7098,156 @@ "treeverse", "validate-npm-package-name", "which", - "write-file-atomic" + "write-file-atomic", + "@colors/colors", + "@gar/promisify", + "@isaacs/cliui", + "@npmcli/disparity-colors", + "@npmcli/fs", + "@npmcli/git", + "@npmcli/installed-package-contents", + "@npmcli/metavuln-calculator", + "@npmcli/move-file", + "@npmcli/name-from-folder", + "@npmcli/node-gyp", + "@npmcli/promise-spawn", + "@npmcli/query", + "@pkgjs/parseargs", + "@sigstore/protobuf-specs", + "@tootallnate/once", + "@tufjs/canonical-json", + "@tufjs/models", + "abort-controller", + "agent-base", + "agentkeepalive", + "aggregate-error", + "ansi-regex", + "ansi-styles", + "aproba", + "are-we-there-yet", + "balanced-match", + "base64-js", + "bin-links", + "binary-extensions", + "brace-expansion", + "buffer", + "builtins", + "chownr", + "cidr-regex", + "clean-stack", + "clone", + "cmd-shim", + "color-convert", + "color-name", + "color-support", + "common-ancestor-path", + "concat-map", + "console-control-strings", + "cross-spawn", + "cssesc", + "debug", + "defaults", + "delegates", + "depd", + "diff", + "eastasianwidth", + "emoji-regex", + "encoding", + "env-paths", + "err-code", + "event-target-shim", + "events", + "foreground-child", + "fs.realpath", + "function-bind", + "gauge", + "has", + "has-flag", + "has-unicode", + "http-cache-semantics", + "http-proxy-agent", + "https-proxy-agent", + "humanize-ms", + "iconv-lite", + "ieee754", + "ignore-walk", + "imurmurhash", + "indent-string", + "infer-owner", + "inflight", + "inherits", + "ip", + "ip-regex", + "is-core-module", + "is-fullwidth-code-point", + "is-lambda", + "isexe", + "jackspeak", + "json-stringify-nice", + "jsonparse", + "just-diff", + "just-diff-apply", + "lru-cache", + "minipass-collect", + "minipass-fetch", + "minipass-flush", + "minipass-json-stream", + "minipass-sized", + "minizlib", + "mkdirp", + "mute-stream", + "negotiator", + "normalize-package-data", + "npm-bundled", + "npm-normalize-package-bin", + "npm-packlist", + "once", + "path-is-absolute", + "path-key", + "path-scurry", + "postcss-selector-parser", + "process", + "promise-all-reject-late", + "promise-call-limit", + "promise-inflight", + "promise-retry", + "promzard", + "read-cmd-shim", + "readable-stream", + "retry", + "rimraf", + "safe-buffer", + "safer-buffer", + "set-blocking", + "shebang-command", + "shebang-regex", + "signal-exit", + "sigstore", + "smart-buffer", + "socks", + "socks-proxy-agent", + "spdx-correct", + "spdx-exceptions", + "spdx-expression-parse", + "spdx-license-ids", + "string_decoder", + "string-width", + "string-width-cjs", + "strip-ansi", + "strip-ansi-cjs", + "supports-color", + "tuf-js", + "unique-filename", + "unique-slug", + "util-deprecate", + "validate-npm-package-license", + "walk-up-path", + "wcwidth", + "wide-align", + "wrap-ansi", + "wrap-ansi-cjs", + "wrappy", + "yallist" ], "dependencies": { "@isaacs/string-locale-compare": "^1.1.0", @@ -10241,7 +10331,6 @@ }, "node_modules/optionator": { "version": "0.9.1", - "dev": true, "license": "MIT", "dependencies": { "deep-is": "^0.1.3", @@ -10311,7 +10400,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, "dependencies": { "callsites": "^3.0.0" }, @@ -10377,7 +10465,6 @@ }, "node_modules/path-key": { "version": "3.1.1", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -10522,7 +10609,6 @@ }, "node_modules/prelude-ls": { "version": "1.2.1", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.8.0" @@ -10616,7 +10702,6 @@ }, "node_modules/progress": { "version": "2.0.3", - "dev": true, "license": "MIT", "engines": { "node": ">=0.4.0" @@ -10669,7 +10754,6 @@ }, "node_modules/punycode": { "version": "2.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">=6" @@ -10941,7 +11025,6 @@ }, "node_modules/regexpp": { "version": "3.1.0", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -11029,7 +11112,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true, "engines": { "node": ">=4" } @@ -11045,7 +11127,6 @@ }, "node_modules/rimraf": { "version": "3.0.2", - "dev": true, "license": "ISC", "dependencies": { "glob": "^7.1.3" @@ -11230,7 +11311,6 @@ }, "node_modules/shebang-command": { "version": "2.0.0", - "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" @@ -11241,7 +11321,6 @@ }, "node_modules/shebang-regex": { "version": "3.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -11409,7 +11488,6 @@ }, "node_modules/sprintf-js": { "version": "1.0.3", - "dev": true, "license": "BSD-3-Clause" }, "node_modules/stack-trace": { @@ -11568,7 +11646,6 @@ }, "node_modules/strip-json-comments": { "version": "3.1.1", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -11620,7 +11697,6 @@ }, "node_modules/table": { "version": "6.0.7", - "dev": true, "license": "BSD-3-Clause", "dependencies": { "ajv": "^7.0.2", @@ -11634,7 +11710,6 @@ }, "node_modules/table/node_modules/ajv": { "version": "7.0.4", - "dev": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", @@ -11649,7 +11724,6 @@ }, "node_modules/table/node_modules/ansi-styles": { "version": "4.3.0", - "dev": true, "license": "MIT", "dependencies": { "color-convert": "^2.0.1" @@ -11663,7 +11737,6 @@ }, "node_modules/table/node_modules/color-convert": { "version": "2.0.1", - "dev": true, "license": "MIT", "dependencies": { "color-name": "~1.1.4" @@ -11674,17 +11747,14 @@ }, "node_modules/table/node_modules/color-name": { "version": "1.1.4", - "dev": true, "license": "MIT" }, "node_modules/table/node_modules/json-schema-traverse": { "version": "1.0.0", - "dev": true, "license": "MIT" }, "node_modules/table/node_modules/slice-ansi": { "version": "4.0.0", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", @@ -11772,7 +11842,6 @@ }, "node_modules/text-table": { "version": "0.2.0", - "dev": true, "license": "MIT" }, "node_modules/timers-browserify": { @@ -11894,7 +11963,6 @@ }, "node_modules/type-check": { "version": "0.4.0", - "dev": true, "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1" @@ -11912,7 +11980,6 @@ }, "node_modules/type-fest": { "version": "0.8.1", - "dev": true, "license": "(MIT OR CC0-1.0)", "engines": { "node": ">=8" @@ -12036,7 +12103,6 @@ }, "node_modules/uri-js": { "version": "4.4.1", - "dev": true, "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" @@ -12083,7 +12149,6 @@ }, "node_modules/v8-compile-cache": { "version": "2.2.0", - "dev": true, "license": "MIT" }, "node_modules/validate-npm-package-license": { @@ -12218,7 +12283,6 @@ }, "node_modules/which": { "version": "2.0.2", - "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" @@ -12338,7 +12402,6 @@ }, "node_modules/word-wrap": { "version": "1.2.3", - "dev": true, "license": "MIT", "engines": { "node": ">=0.10.0" @@ -12372,7 +12435,6 @@ }, "node_modules/yallist": { "version": "4.0.0", - "dev": true, "license": "ISC" }, "node_modules/yargs": { @@ -12532,7 +12594,6 @@ "dependencies": { "@babel/code-frame": { "version": "7.12.11", - "dev": true, "requires": { "@babel/highlight": "^7.10.4" } @@ -13803,7 +13864,6 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.1.tgz", "integrity": "sha512-5v7TDE9plVhvxQeWLXDTvFvJBdH6pEsdnl2g/dAptmuFEPedQ4Erq5rsDsX+mvAM610IhNaO2W5V1dOOnDKxkQ==", - "dev": true, "requires": { "ajv": "^6.12.4", "debug": "^4.1.1", @@ -13820,7 +13880,6 @@ "version": "12.4.0", "resolved": "https://registry.npmjs.org/globals/-/globals-12.4.0.tgz", "integrity": "sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg==", - "dev": true, "requires": { "type-fest": "^0.8.1" } @@ -14362,19 +14421,16 @@ "acorn": { "version": "7.4.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", - "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", - "dev": true + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==" }, "acorn-jsx": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.1.tgz", "integrity": "sha512-K0Ptm/47OKfQRpNQ2J/oIN/3QYiK6FwW+eJbILhsdxh2WTLdl+30o8aGdTbm5JbffpFFAg/g+zi1E+jvJha5ng==", - "dev": true, "requires": {} }, "ajv": { "version": "6.12.6", - "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -14388,8 +14444,7 @@ "requires": {} }, "ansi-colors": { - "version": "4.1.1", - "dev": true + "version": "4.1.1" }, "ansi-regex": { "version": "3.0.0", @@ -14403,7 +14458,6 @@ }, "argparse": { "version": "1.0.10", - "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -14508,8 +14562,7 @@ "dev": true }, "astral-regex": { - "version": "2.0.0", - "dev": true + "version": "2.0.0" }, "async": { "version": "3.2.4", @@ -14780,8 +14833,7 @@ "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", - "dev": true + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==" }, "caniuse-lite": { "version": "1.0.30001451", @@ -15096,7 +15148,6 @@ }, "cross-spawn": { "version": "7.0.3", - "dev": true, "requires": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -15154,8 +15205,7 @@ } }, "deep-is": { - "version": "0.1.3", - "dev": true + "version": "0.1.3" }, "define-properties": { "version": "1.1.3", @@ -15224,7 +15274,6 @@ }, "doctrine": { "version": "3.0.0", - "dev": true, "requires": { "esutils": "^2.0.2" } @@ -15297,7 +15346,6 @@ }, "enquirer": { "version": "2.3.6", - "dev": true, "requires": { "ansi-colors": "^4.1.1" } @@ -15401,7 +15449,6 @@ "version": "7.26.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-7.26.0.tgz", "integrity": "sha512-4R1ieRf52/izcZE7AlLy56uIHHDLT74Yzz2Iv2l6kDaYvEu9x+wMB5dZArVL8SYGXSYV2YAg70FcW5Y5nGGNIg==", - "dev": true, "requires": { "@babel/code-frame": "7.12.11", "@eslint/eslintrc": "^0.4.1", @@ -15443,19 +15490,16 @@ }, "dependencies": { "ansi-regex": { - "version": "5.0.0", - "dev": true + "version": "5.0.0" }, "ansi-styles": { "version": "4.3.0", - "dev": true, "requires": { "color-convert": "^2.0.1" } }, "chalk": { "version": "4.1.0", - "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -15463,50 +15507,42 @@ }, "color-convert": { "version": "2.0.1", - "dev": true, "requires": { "color-name": "~1.1.4" } }, "color-name": { - "version": "1.1.4", - "dev": true + "version": "1.1.4" }, "globals": { "version": "13.7.0", - "dev": true, "requires": { "type-fest": "^0.20.2" } }, "has-flag": { - "version": "4.0.0", - "dev": true + "version": "4.0.0" }, "semver": { "version": "7.3.4", - "dev": true, "requires": { "lru-cache": "^6.0.0" } }, "strip-ansi": { "version": "6.0.0", - "dev": true, "requires": { "ansi-regex": "^5.0.0" } }, "supports-color": { "version": "7.2.0", - "dev": true, "requires": { "has-flag": "^4.0.0" } }, "type-fest": { - "version": "0.20.2", - "dev": true + "version": "0.20.2" } } }, @@ -15904,7 +15940,6 @@ }, "eslint-scope": { "version": "5.1.1", - "dev": true, "requires": { "esrecurse": "^4.3.0", "estraverse": "^4.1.1" @@ -15912,26 +15947,22 @@ }, "eslint-utils": { "version": "2.1.0", - "dev": true, "requires": { "eslint-visitor-keys": "^1.1.0" }, "dependencies": { "eslint-visitor-keys": { - "version": "1.3.0", - "dev": true + "version": "1.3.0" } } }, "eslint-visitor-keys": { - "version": "2.0.0", - "dev": true + "version": "2.0.0" }, "espree": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", "integrity": "sha512-v3JCNCE64umkFpmkFGqzVKsOT0tN1Zr+ueqLZfpV1Ob8e+CEgPWa+OxCoGH3tnhimMKIaBm4m/vaRpJ/krRz2g==", - "dev": true, "requires": { "acorn": "^7.4.0", "acorn-jsx": "^5.3.1", @@ -15941,48 +15972,40 @@ "eslint-visitor-keys": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", - "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", - "dev": true + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==" } } }, "esprima": { - "version": "4.0.1", - "dev": true + "version": "4.0.1" }, "esquery": { "version": "1.4.0", - "dev": true, "requires": { "estraverse": "^5.1.0" }, "dependencies": { "estraverse": { - "version": "5.2.0", - "dev": true + "version": "5.2.0" } } }, "esrecurse": { "version": "4.3.0", - "dev": true, "requires": { "estraverse": "^5.2.0" }, "dependencies": { "estraverse": { - "version": "5.2.0", - "dev": true + "version": "5.2.0" } } }, "estraverse": { - "version": "4.3.0", - "dev": true + "version": "4.3.0" }, "esutils": { - "version": "2.0.3", - "dev": true + "version": "2.0.3" }, "etag": { "version": "1.8.1", @@ -16090,8 +16113,7 @@ "dev": true }, "fast-deep-equal": { - "version": "3.1.3", - "dev": true + "version": "3.1.3" }, "fast-diff": { "version": "1.2.0", @@ -16110,12 +16132,10 @@ } }, "fast-json-stable-stringify": { - "version": "2.1.0", - "dev": true + "version": "2.1.0" }, "fast-levenshtein": { - "version": "2.0.6", - "dev": true + "version": "2.0.6" }, "fastq": { "version": "1.11.0", @@ -16134,7 +16154,6 @@ }, "file-entry-cache": { "version": "6.0.1", - "dev": true, "requires": { "flat-cache": "^3.0.4" } @@ -16240,15 +16259,13 @@ }, "flat-cache": { "version": "3.0.4", - "dev": true, "requires": { "flatted": "^3.1.0", "rimraf": "^3.0.2" } }, "flatted": { - "version": "3.1.1", - "dev": true + "version": "3.1.1" }, "fn.name": { "version": "1.1.0" @@ -16300,8 +16317,7 @@ "version": "1.1.1" }, "functional-red-black-tree": { - "version": "1.0.1", - "dev": true + "version": "1.0.1" }, "general-number": { "version": "1.0.1", @@ -16341,7 +16357,6 @@ }, "glob-parent": { "version": "5.1.2", - "dev": true, "requires": { "is-glob": "^4.0.1" } @@ -16483,22 +16498,19 @@ "ignore": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", - "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", - "dev": true + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==" }, "import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", - "dev": true, "requires": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" } }, "imurmurhash": { - "version": "0.1.4", - "dev": true + "version": "0.1.4" }, "inflight": { "version": "1.0.6", @@ -16563,15 +16575,13 @@ "dev": true }, "is-extglob": { - "version": "2.1.1", - "dev": true + "version": "2.1.1" }, "is-fullwidth-code-point": { "version": "3.0.0" }, "is-glob": { "version": "4.0.1", - "dev": true, "requires": { "is-extglob": "^2.1.1" } @@ -16637,8 +16647,7 @@ "dev": true }, "isexe": { - "version": "2.0.0", - "dev": true + "version": "2.0.0" }, "isobject": { "version": "3.0.1", @@ -16674,7 +16683,6 @@ "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", - "dev": true, "requires": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -16708,12 +16716,10 @@ "dev": true }, "json-schema-traverse": { - "version": "0.4.1", - "dev": true + "version": "0.4.1" }, "json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "dev": true + "version": "1.0.1" }, "json5": { "version": "2.2.0", @@ -16787,7 +16793,6 @@ }, "levn": { "version": "0.4.1", - "dev": true, "requires": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -16923,7 +16928,6 @@ }, "lru-cache": { "version": "6.0.0", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -17288,8 +17292,7 @@ "dev": true }, "natural-compare": { - "version": "1.4.0", - "dev": true + "version": "1.4.0" }, "negotiator": { "version": "0.6.3", @@ -19406,7 +19409,6 @@ }, "optionator": { "version": "0.9.1", - "dev": true, "requires": { "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", @@ -19448,7 +19450,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, "requires": { "callsites": "^3.0.0" } @@ -19490,8 +19491,7 @@ "version": "1.0.1" }, "path-key": { - "version": "3.1.1", - "dev": true + "version": "3.1.1" }, "path-parse": { "version": "1.0.6" @@ -19582,8 +19582,7 @@ } }, "prelude-ls": { - "version": "1.2.1", - "dev": true + "version": "1.2.1" }, "prettier": { "version": "2.2.1" @@ -19638,8 +19637,7 @@ "dev": true }, "progress": { - "version": "2.0.3", - "dev": true + "version": "2.0.3" }, "prop-types": { "version": "15.7.2", @@ -19684,8 +19682,7 @@ } }, "punycode": { - "version": "2.1.0", - "dev": true + "version": "2.1.0" }, "qs": { "version": "6.11.0", @@ -19868,8 +19865,7 @@ } }, "regexpp": { - "version": "3.1.0", - "dev": true + "version": "3.1.0" }, "regexpu-core": { "version": "5.3.0", @@ -19925,8 +19921,7 @@ "resolve-from": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", - "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", - "dev": true + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==" }, "reusify": { "version": "1.0.4", @@ -19934,7 +19929,6 @@ }, "rimraf": { "version": "3.0.2", - "dev": true, "requires": { "glob": "^7.1.3" } @@ -20067,14 +20061,12 @@ }, "shebang-command": { "version": "2.0.0", - "dev": true, "requires": { "shebang-regex": "^3.0.0" } }, "shebang-regex": { - "version": "3.0.0", - "dev": true + "version": "3.0.0" }, "shelljs": { "version": "0.8.5", @@ -20198,8 +20190,7 @@ "dev": true }, "sprintf-js": { - "version": "1.0.3", - "dev": true + "version": "1.0.3" }, "stack-trace": { "version": "0.0.10" @@ -20302,8 +20293,7 @@ "dev": true }, "strip-json-comments": { - "version": "3.1.1", - "dev": true + "version": "3.1.1" }, "superagent": { "version": "3.8.3", @@ -20342,7 +20332,6 @@ }, "table": { "version": "6.0.7", - "dev": true, "requires": { "ajv": "^7.0.2", "lodash": "^4.17.20", @@ -20352,7 +20341,6 @@ "dependencies": { "ajv": { "version": "7.0.4", - "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -20362,29 +20350,24 @@ }, "ansi-styles": { "version": "4.3.0", - "dev": true, "requires": { "color-convert": "^2.0.1" } }, "color-convert": { "version": "2.0.1", - "dev": true, "requires": { "color-name": "~1.1.4" } }, "color-name": { - "version": "1.1.4", - "dev": true + "version": "1.1.4" }, "json-schema-traverse": { - "version": "1.0.0", - "dev": true + "version": "1.0.0" }, "slice-ansi": { "version": "4.0.0", - "dev": true, "requires": { "ansi-styles": "^4.0.0", "astral-regex": "^2.0.0", @@ -20438,8 +20421,7 @@ "version": "1.0.0" }, "text-table": { - "version": "0.2.0", - "dev": true + "version": "0.2.0" }, "timers-browserify": { "version": "2.0.12", @@ -20528,7 +20510,6 @@ }, "type-check": { "version": "0.4.0", - "dev": true, "requires": { "prelude-ls": "^1.2.1" } @@ -20537,8 +20518,7 @@ "version": "4.0.8" }, "type-fest": { - "version": "0.8.1", - "dev": true + "version": "0.8.1" }, "type-is": { "version": "1.6.18", @@ -20613,7 +20593,6 @@ }, "uri-js": { "version": "4.4.1", - "dev": true, "requires": { "punycode": "^2.1.0" } @@ -20654,8 +20633,7 @@ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==" }, "v8-compile-cache": { - "version": "2.2.0", - "dev": true + "version": "2.2.0" }, "validate-npm-package-license": { "version": "3.0.4", @@ -20745,7 +20723,6 @@ }, "which": { "version": "2.0.2", - "dev": true, "requires": { "isexe": "^2.0.0" } @@ -20836,8 +20813,7 @@ } }, "word-wrap": { - "version": "1.2.3", - "dev": true + "version": "1.2.3" }, "wordwrap": { "version": "1.0.0", @@ -20859,8 +20835,7 @@ "version": "4.0.1" }, "yallist": { - "version": "4.0.0", - "dev": true + "version": "4.0.0" }, "yargs": { "version": "15.4.1", diff --git a/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts b/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts index 40f5d02ed..b4c769a6c 100644 --- a/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts +++ b/src/boilerplate/circuit/zokrates/raw/BoilerplateGenerator.ts @@ -48,12 +48,18 @@ class BoilerplateGenerator { }; nullification = { - importStatements(): string[] { + importStatements({ isAccessed, isNullified }): string[] { + if(isAccessed && !isNullified) + return [ + `from "utils/pack/bool/nonStrictUnpack256.zok" import main as field_to_bool_256`, + `from "./common/hashes/poseidon/poseidon.zok" import main as poseidon`, + `from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import checkRoot as checkNullifierRoot`, + ]; + return [ `from "utils/pack/bool/nonStrictUnpack256.zok" import main as field_to_bool_256`, `from "./common/hashes/poseidon/poseidon.zok" import main as poseidon`, - `from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as checkproof`, - `from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import checkUpdatedPath as checkUpdatedPath`, + `from "./common/merkle-tree/sparse-merkle-tree/checkproof.zok" import main as updateNullifierRoot`, ]; }, @@ -61,10 +67,8 @@ class BoilerplateGenerator { let para = [ `private field ${x}_oldCommitment_owner_secretKey`, `public field nullifierRoot`, - `public field newNullifierRoot`, `public field ${x}_oldCommitment_nullifier`, `private field[32] ${x}_nullifier_nonmembershipWitness_siblingPath`, - `private field[32] ${x}_nullifier_nonmembershipWitness_newsiblingPath`, ] if(isAccessed && !isNullified) @@ -104,27 +108,13 @@ class BoilerplateGenerator { ) // ${x}_oldCommitment_nullifier : non-existence check - assert(\\ - nullifierRoot == checkproof(\\ - ${x}_nullifier_nonmembershipWitness_siblingPath,\\ - ${x}_oldCommitment_nullifier\\ - )\ - ) - - assert(\\ - newNullifierRoot == checkUpdatedPath(\\ - ${x}_nullifier_nonmembershipWitness_newsiblingPath,\\ - ${x}_oldCommitment_nullifier\\ - )\ - ) - `, ]; - if(isAccessed && !isNullified) + (isAccessed && !isNullified) ? lines = [ ` - // Create the Nullifier for ${x} and no need to nnullify it as its accessed only: + // Create the Nullifier for ${x} and no need to nullify it as its accessed only: field ${x}_oldCommitment_nullifier = poseidon([\\ ${x}_stateVarId_field,\\ @@ -133,15 +123,24 @@ class BoilerplateGenerator { ]) // ${x}_oldCommitment_nullifier : non-existence check - - assert(\\ - nullifierRoot == checkproof(\\ - ${x}_nullifier_nonmembershipWitness_siblingPath,\\ - ${x}_oldCommitment_nullifier\\ - )\ - ) + + + nullifierRoot = checkNullifierRoot(\\ + ${x}_nullifier_nonmembershipWitness_siblingPath,\\ + ${x}_oldCommitment_nullifier,\\ + nullifierRoot\\ + )\ `, - ]; + ] : lines.push( + ` + + nullifierRoot = updateNullifierRoot(\\ + ${x}_nullifier_nonmembershipWitness_siblingPath,\\ + ${x}_oldCommitment_nullifier,\\ + nullifierRoot\\ + )\ + ` + ); if (this.initialisationRequired && this.isWhole) { diff --git a/src/boilerplate/common/commitment-storage.mjs b/src/boilerplate/common/commitment-storage.mjs index a51db2048..613ece8e3 100644 --- a/src/boilerplate/common/commitment-storage.mjs +++ b/src/boilerplate/common/commitment-storage.mjs @@ -185,7 +185,7 @@ export async function markNullified(commitmentHash, secretKey = null) { }, }; // updating the original tree - smt_tree = temp_smt_tree; + await updateNullifierTree(); return db.collection(COMMITMENTS_COLLECTION).updateOne(query, update); } @@ -340,36 +340,19 @@ export async function joinCommitments( const oldCommitment_0_nullifier_NonMembership_witness = getnullifierMembershipWitness( oldCommitment_0_nullifier ); - const oldCommitment_1_nullifier_NonMembership_witness = getnullifierMembershipWitness( - oldCommitment_1_nullifier - ); - const oldCommitment_nullifierRoot = generalise(oldCommitment_0_nullifier_NonMembership_witness.root); const oldCommitment_0_nullifier_path = generalise( oldCommitment_0_nullifier_NonMembership_witness.path ).all; - const oldCommitment_1_nullifier_path = generalise( - oldCommitment_1_nullifier_NonMembership_witness.path - ).all; - - - await temporaryUpdateNullifier(a_0_nullifier); - await temporaryUpdateNullifier(a_1_nullifier); - const oldCommitment_0_updated_nullifier_NonMembership_witness = getupdatedNullifierPaths( - oldCommitment_0_nullifier - ); - const oldCommitment_1_updated_nullifier_NonMembership_witness = getupdatedNullifierPaths( + await temporaryUpdateNullifier(oldCommitment_0_nullifier); + const oldCommitment_1_nullifier_NonMembership_witness = getnullifierMembershipWitness( oldCommitment_1_nullifier ); - - const oldCommitment_0_nullifier_newpath = generalise( - oldCommitment_0_updated_nullifier_NonMembership_witness.path - ).all; - const oldCommitment_1_nullifier_newpath = generalise( - oldCommitment_1_updated_nullifier_NonMembership_witness.path + const oldCommitment_1_nullifier_path = generalise( + oldCommitment_1_nullifier_NonMembership_witness.path ).all; - const oldCommitment_newNullifierRoot = generalise(oldCommitment_0_updated_nullifier_NonMembership_witness.root); + await temporaryUpdateNullifier(oldCommitment_1_nullifier); // Calculate commitment(s): const newCommitment_newSalt = generalise(utils.randomHex(31)); @@ -407,13 +390,10 @@ export async function joinCommitments( secretKey.integer, oldCommitment_nullifierRoot.integer, - oldCommitment_newNullifierRoot.integer, oldCommitment_0_nullifier.integer, oldCommitment_0_nullifier_path.integer, - oldCommitment_0_nullifier_newpath.integer, oldCommitment_1_nullifier.integer, oldCommitment_1_nullifier_path.integer, - oldCommitment_1_nullifier_newpath.integer, oldCommitment_0_prev.integer, oldCommitment_0_prevSalt.integer, oldCommitment_1_prev.integer, @@ -432,12 +412,15 @@ export async function joinCommitments( const proof = generalise(Object.values(res.proof).flat(Infinity)) .map((coeff) => coeff.integer) .flat(Infinity); + const oldCommitment_newNullifierRoot = res.inputs + .slice(-1) + .map((e) => generalise(e).integer)[0]; // Send transaction to the blockchain: const txData = await instance.methods .joinCommitments( oldCommitment_nullifierRoot.integer, - oldCommitment_newNullifierRoot.integer, + oldCommitment_newNullifierRoot, [oldCommitment_0_nullifier.integer, oldCommitment_1_nullifier.integer], oldCommitment_root.integer, [newCommitment.integer], @@ -521,7 +504,11 @@ const _getnullifierMembershipWitness = (binArr, element, tree, acc) => { }; export async function updateNullifierTree() { - smt_tree = temp_smt_tree; + smt_tree = temp_smt_tree; +} + +export async function resetTemporaryNullifierTree() { + temp_smt_tree = smt_tree; } @@ -531,8 +518,8 @@ export function getnullifierMembershipWitness(nullifier) { const padBinArr = Array(254 - binArr.length) .fill("0") .concat(...binArr).slice(0, TRUNC_LENGTH); - const membershipPath = _getnullifierMembershipWitness(padBinArr, nullifier, smt_tree, []); - const root = getHash(smt_tree); + const membershipPath = _getnullifierMembershipWitness(padBinArr, nullifier, temp_smt_tree, []); + const root = getHash(temp_smt_tree); const witness = {path : membershipPath.path, root: root} return witness; @@ -566,20 +553,4 @@ export async function reinstateNullifiers() { temp_smt_tree = smt_tree; } -export function getupdatedNullifierPaths(nullifier){ - const binArr = toBinArray(generalise(nullifier)); - const padBinArr = Array(254 - binArr.length) - .fill("0") - .concat(...binArr) - .slice(0, TRUNC_LENGTH); - const membershipPath = _getnullifierMembershipWitness( - padBinArr, - nullifier, - temp_smt_tree, - [] - ); - const root = getHash(temp_smt_tree); - const witness = { path: membershipPath.path, root: root }; - return witness; -} diff --git a/src/boilerplate/common/generic-test.mjs b/src/boilerplate/common/generic-test.mjs index 57bd6875c..46609309a 100644 --- a/src/boilerplate/common/generic-test.mjs +++ b/src/boilerplate/common/generic-test.mjs @@ -4,6 +4,7 @@ import logger from './common/logger.mjs'; import web3 from './common/web3.mjs'; + // 'sleep' just creates a delay, ensuring the tests don't overlap const sleep = ms => new Promise(r => setTimeout(r, ms)); // initialises leafIndex so we can use it to test the merkle tree is working across tests @@ -46,7 +47,7 @@ describe('FUNCTION_NAME', async function () { console.log(`Merkle tree event returnValues:`); console.log(tx.returnValues[0]); } - if (encEvent[0].event) { + if (encEvent && encEvent[0]?.event) { encryption.msgs = encEvent[0].returnValues[0]; encryption.key = encEvent[0].returnValues[1]; console.log("EncryptedMsgs:"); @@ -54,6 +55,7 @@ describe('FUNCTION_NAME', async function () { } await sleep(10); } catch (err) { + await resetTemporaryNullifierTree(); logger.error(err); process.exit(1); } @@ -82,6 +84,7 @@ describe('FUNCTION_NAME', async function () { console.log(tx.returnValues[0]); } } catch (err) { + await resetTemporaryNullifierTree(); logger.error(err); process.exit(1); } diff --git a/src/boilerplate/common/services/generic-api_services.mjs b/src/boilerplate/common/services/generic-api_services.mjs index 6dba0b2a6..48f0cf10e 100644 --- a/src/boilerplate/common/services/generic-api_services.mjs +++ b/src/boilerplate/common/services/generic-api_services.mjs @@ -6,7 +6,7 @@ import { startEventFilter, getSiblingPath } from "./common/timber.mjs"; import fs from "fs"; import logger from "./common/logger.mjs"; import { decrypt } from "./common/number-theory.mjs"; -import { getAllCommitments, getCommitmentsByState } from "./common/commitment-storage.mjs"; +import { getAllCommitments, getCommitmentsByState} from "./common/commitment-storage.mjs"; import web3 from "./common/web3.mjs"; /** @@ -44,7 +44,7 @@ export async function service_FUNCTION_NAME (req, res, next){ console.log(`Merkle tree event returnValues:`); console.log(tx.returnValues); } - if (encEvent.event) { + if (encEvent && encEvent[0]?.event) { encryption.msgs = encEvent[0].returnValues[0]; encryption.key = encEvent[0].returnValues[1]; console.log("EncryptedMsgs:"); @@ -52,6 +52,7 @@ export async function service_FUNCTION_NAME (req, res, next){ } await sleep(10); } catch (err) { + await resetTemporaryNullifierTree(); logger.error(err); res.send({ errors: [err.message] }); } diff --git a/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts index ecb949926..0a30cf9ef 100644 --- a/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/nodes/FunctionBoilerplateGenerator.ts @@ -71,7 +71,7 @@ class FunctionBoilerplateGenerator { }, getIndicators() { - const { indicators, msgSigRequired } = this.scope; + const { indicators } = this.scope; const isConstructor = this.scope.path.node.kind === 'constructor' ? true : false; const { nullifiersRequired, oldCommitmentAccessRequired, msgSenderParam, msgValueParam, containsAccessedOnlyState, encryptionRequired } = indicators; @@ -119,13 +119,10 @@ class FunctionBoilerplateGenerator { if(node.expression?.nodeType === 'InternalFunctionCall'){ if(node.expression.parameters.includes('cipherText') ) internalFunctionEncryptionRequired = true - - } - + } }) - - if(path.node.returnParameters.parameters.length === 0 && !indicators.encryptionRequired && !internalFunctionEncryptionRequired) { + if(path.node.returnParameters.parameters.length === 0 && !indicators.encryptionRequired && !internalFunctionEncryptionRequired ) { publicParams?.push({ name: 1, type: 'uint256', dummy: true , inCircuit: true }); } diff --git a/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts index 5ba86aea0..2a6623794 100644 --- a/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/raw/ContractBoilerplateGenerator.ts @@ -127,8 +127,6 @@ class ContractBoilerplateGenerator { case 'nullifierRoot': verifyInput.push( ` inputs[k++] = _inputs.nullifierRoot;`); - verifyInput.push( ` - inputs[k++] = _inputs.latestNullifierRoot;`); break; case 'nullifier': verifyInput.push( ` @@ -221,13 +219,15 @@ class ContractBoilerplateGenerator { }; _inputs.map(i => verifyInputsMap(type, i, counter)); - - - + } - - if(_params && !(Object.keys(_params).includes('returnParameters'))) verifyInput.push(` + + if(_params && (Object.values(_params)[0].includes('nullifierRoot'))) verifyInput.push(` + inputs[k++] = _inputs.latestNullifierRoot;`) + + if(_params && !(Object.values(_params)[0].includes('nullifierRoot')) && !(Object.keys(_params).includes('returnParameters'))) verifyInput.push(` inputs[k++] = 1;`) + verifyInputs.push(` if (functionId == uint(FunctionNames.${name})) { @@ -270,9 +270,6 @@ class ContractBoilerplateGenerator { Inputs memory inputs; - inputs.customInputs = new uint[](1); - inputs.customInputs[0] = 1; - inputs.nullifierRoot = nullifierRoot; inputs.latestNullifierRoot = latestNullifierRoot; @@ -295,12 +292,11 @@ class ContractBoilerplateGenerator { uint k = 0; inputs[k++] = _inputs.nullifierRoot; - inputs[k++] = _inputs.latestNullifierRoot; inputs[k++] = newNullifiers[0]; inputs[k++] = newNullifiers[1]; inputs[k++] = _inputs.commitmentRoot; inputs[k++] = newCommitments[0]; - inputs[k++] = 1; + inputs[k++] = _inputs.latestNullifierRoot; }`) diff --git a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts index fe357fde8..270f1b540 100644 --- a/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts +++ b/src/boilerplate/contract/solidity/raw/FunctionBoilerplateGenerator.ts @@ -36,7 +36,6 @@ class FunctionBoilerplateGenerator { nullifiersRequired: newNullifiers, oldCommitmentAccessRequired: commitmentRoot, newCommitmentsRequired: newCommitments, - containsAccessedOnlyState: checkNullifiers, encryptionRequired, isConstructor }): string[] { @@ -63,7 +62,6 @@ class FunctionBoilerplateGenerator { encryptionRequired }): string[] { // prettier-ignore - let parameter = [ ...(customInputs ? customInputs.filter(input => !input.dummy && input.isParam) .map(input => input.structName ? `(${input.properties.map(p => p.type)})` : input.isConstantArray ? `${input.type}[${input.isConstantArray}]` : input.type) : []), // TODO arrays of structs/ structs of arrays @@ -98,6 +96,11 @@ class FunctionBoilerplateGenerator { let msgSigCheck = ([...(isConstructor ? [] : [`bytes4 sig = bytes4(keccak256("${functionName}(${parameter})")) ; \n \t \t \t if (sig == msg.sig)`])]); customInputs = customInputs?.flat(Infinity).filter(p => p.inCircuit); + + customInputs?.forEach((input, i) => { + if(input.name === 1 && input.type === 'uint256' && newNullifiers) customInputs.splice(i,1); + }); + return [ ` diff --git a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts index a5bef90b0..111da83cd 100644 --- a/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts +++ b/src/boilerplate/orchestration/javascript/raw/boilerplate-generator.ts @@ -270,12 +270,15 @@ class BoilerplateGenerator { ${stateName}_0_nullifier = generalise(${stateName}_0_nullifier.hex(32)); // truncate ${stateName}_1_nullifier = generalise(${stateName}_1_nullifier.hex(32)); // truncate // Non-membership witness for Nullifier + const ${stateName}_0_nullifier_NonMembership_witness = getnullifierMembershipWitness(${stateName}_0_nullifier); - const ${stateName}_1_nullifier_NonMembership_witness = getnullifierMembershipWitness(${stateName}_1_nullifier); - const ${stateName}_nullifierRoot = generalise(${stateName}_0_nullifier_NonMembership_witness.root); const ${stateName}_0_nullifier_path = generalise(${stateName}_0_nullifier_NonMembership_witness.path).all; + + await temporaryUpdateNullifier(${stateName}_0_nullifier); + const ${stateName}_1_nullifier_NonMembership_witness = getnullifierMembershipWitness(${stateName}_1_nullifier); const ${stateName}_1_nullifier_path = generalise(${stateName}_1_nullifier_NonMembership_witness.path).all; + await temporaryUpdateNullifier(${stateName}_1_nullifier); `]; case 'whole': if(accessedOnly) @@ -284,6 +287,7 @@ class BoilerplateGenerator { \n${stateName}_nullifier = generalise(${stateName}_nullifier.hex(32)); // truncate // Non-membership witness for Nullifier + const ${stateName}_nullifier_NonMembership_witness = getnullifierMembershipWitness(${stateName}_nullifier); const ${stateName}_nullifierRoot = generalise(${stateName}_nullifier_NonMembership_witness.root); @@ -294,71 +298,20 @@ class BoilerplateGenerator { \n${stateName}_nullifier = generalise(${stateName}_nullifier.hex(32)); // truncate // Non-membership witness for Nullifier + const ${stateName}_nullifier_NonMembership_witness = getnullifierMembershipWitness(${stateName}_nullifier); const ${stateName}_nullifierRoot = generalise(${stateName}_nullifier_NonMembership_witness.root); const ${stateName}_nullifier_path = generalise(${stateName}_nullifier_NonMembership_witness.path).all; - `]; - default: - throw new TypeError(stateType); - } - }, - }; - - temporaryUpdatedNullifier = { - postStatements({ stateName, accessedOnly, stateType }): string[] { - // if (!isWhole && !newCommitmentValue) throw new Error('PATH'); - switch (stateType) { - - case 'partitioned': - return [` - - - await temporaryUpdateNullifier(${stateName}_0_nullifier); - await temporaryUpdateNullifier(${stateName}_1_nullifier); - `]; - case 'whole': - if(!accessedOnly) - return [` await temporaryUpdateNullifier(${stateName}_nullifier); `]; - return [` `]; default: throw new TypeError(stateType); } }, - }; - calculateUpdateNullifierPath = { - postStatements({ stateName, accessedOnly, stateType }): string[] { - // if (!isWhole && !newCommitmentValue) throw new Error('PATH'); - switch (stateType) { - - case 'partitioned': - return [` - // Get the new updated nullifier Paths - const ${stateName}_0_updated_nullifier_NonMembership_witness = getupdatedNullifierPaths(${stateName}_0_nullifier); - const ${stateName}_1_updated_nullifier_NonMembership_witness = getupdatedNullifierPaths(${stateName}_1_nullifier); - - const ${stateName}_newNullifierRoot = generalise(${stateName}_0_updated_nullifier_NonMembership_witness.root); - const ${stateName}_0_nullifier_updatedpath = generalise(${stateName}_0_updated_nullifier_NonMembership_witness.path).all; - const ${stateName}_1_nullifier_updatedpath = generalise(${stateName}_1_updated_nullifier_NonMembership_witness.path).all; - `]; - case 'whole': - if(!accessedOnly) - return [` - // Get the new updated nullifier Paths - const ${stateName}_updated_nullifier_NonMembership_witness = getupdatedNullifierPaths(${stateName}_nullifier); - const ${stateName}_nullifier_updatedpath = generalise(${stateName}_updated_nullifier_NonMembership_witness.path).all; - const ${stateName}_newNullifierRoot = generalise(${stateName}_updated_nullifier_NonMembership_witness.root); - `]; - return [` `]; - default: - throw new TypeError(stateType); - } - }, - }; + calculateCommitment = { @@ -405,7 +358,7 @@ class BoilerplateGenerator { `\nimport fs from 'fs'; \n`, `\nimport { getContractInstance, getContractAddress, registerKey } from './common/contract.mjs';`, - `\nimport { storeCommitment, getCurrentWholeCommitment, getCommitmentsById, getAllCommitments, getInputCommitments, joinCommitments, markNullified,getnullifierMembershipWitness,getupdatedNullifierPaths,temporaryUpdateNullifier,updateNullifierTree } from './common/commitment-storage.mjs';`, + `\nimport { storeCommitment, getCurrentWholeCommitment, getCommitmentsById, getAllCommitments, getInputCommitments, joinCommitments, markNullified,getnullifierMembershipWitness,temporaryUpdateNullifier,updateNullifierTree} from './common/commitment-storage.mjs';`, `\nimport { generateProof } from './common/zokrates.mjs';`, `\nimport { getMembershipWitness, getRoot } from './common/timber.mjs';`, `\nimport Web3 from './common/web3.mjs';`, @@ -454,13 +407,10 @@ class BoilerplateGenerator { \tsecretKey.integer, \tsecretKey.integer, ${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``} - ${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``} \t${stateName}_0_nullifier.integer, \t${stateName}_0_nullifier_path.integer, - \t${stateName}_0_nullifier_updatedpath.integer, \t${stateName}_1_nullifier.integer, \t${stateName}_1_nullifier_path.integer, - \t${stateName}_1_nullifier_updatedpath.integer, ${prev(0)}, \t${stateName}_0_prevSalt.integer, ${prev(1)}, @@ -489,10 +439,8 @@ class BoilerplateGenerator { ${parameters.join('\n')}${stateVarIds.join('\n')} \tsecretKey.integer, ${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``} - ${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``} \t${stateName}_nullifier.integer, \t${stateName}_nullifier_path.integer, - \t${stateName}_nullifier_updatedpath.integer, ${prev}, \t${stateName}_prevSalt.integer, ${initialisationRequired ? `\t${stateName}_commitmentExists ? 0 : 1,` : ``} @@ -517,10 +465,8 @@ class BoilerplateGenerator { ${parameters.join('\n')}${stateVarIds.join('\n')} \t${stateName}_commitmentExists ? secretKey.integer: generalise(0).integer, ${nullifierRootRequired ? `\t${stateName}_nullifierRoot.integer,` : ``} - ${nullifierRootRequired ? `\t${stateName}_newNullifierRoot.integer,` : ``} \t${stateName}_nullifier.integer, \t${stateName}_nullifier_path.integer, - \t${stateName}_nullifier_updatedpath.integer, ${prev}, \t${stateName}_prevSalt.integer, ${initialisationRequired ? `\t${stateName}_commitmentExists ? 0 : 1,` : ``} @@ -654,7 +600,7 @@ integrationTestBoilerplate = { ` }, preStatements(): string{ - return ` import { startEventFilter, getSiblingPath } from './common/timber.mjs';\nimport fs from "fs";\n import GN from "general-number";\nimport {getAllCommitments} from "./common/commitment-storage.mjs";\nimport logger from './common/logger.mjs';\nimport { decrypt } from "./common/number-theory.mjs";\nimport web3 from './common/web3.mjs';\n\n + return ` import { startEventFilter, getSiblingPath } from './common/timber.mjs';\nimport fs from "fs";\n import GN from "general-number";\nimport {getAllCommitments, resetTemporaryNullifierTree} from "./common/commitment-storage.mjs";\nimport logger from './common/logger.mjs';\nimport { decrypt } from "./common/number-theory.mjs";\nimport web3 from './common/web3.mjs';\n\n /** Welcome to your zApp's integration test! Depending on how your functions interact and the range of inputs they expect, the below may need to be changed. @@ -693,7 +639,7 @@ integrationApiServicesBoilerplate = { ` }, preStatements(): string{ - return ` import { startEventFilter, getSiblingPath } from './common/timber.mjs';\nimport fs from "fs";\nimport logger from './common/logger.mjs';\nimport { decrypt } from "./common/number-theory.mjs";\nimport { getAllCommitments, getCommitmentsByState, reinstateNullifiers } from "./common/commitment-storage.mjs";\nimport web3 from './common/web3.mjs';\n\n + return ` import { startEventFilter, getSiblingPath } from './common/timber.mjs';\nimport fs from "fs";\nimport logger from './common/logger.mjs';\nimport { decrypt } from "./common/number-theory.mjs";\nimport { getAllCommitments, getCommitmentsByState, resetTemporaryNullifierTree, reinstateNullifiers } from "./common/commitment-storage.mjs";\nimport web3 from './common/web3.mjs';\n\n /** NOTE: this is the api service file, if you need to call any function use the correct url and if Your input contract has two functions, add() and minus(). minus() cannot be called before an initial add(). */ diff --git a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts index 528eb4ee4..6f7e66e75 100644 --- a/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts +++ b/src/boilerplate/orchestration/javascript/raw/toOrchestration.ts @@ -72,7 +72,7 @@ export const sendTransactionBoilerplate = (node: any) => { case true: // decrement output[2].push(`${privateStateName}_root.integer`); - output[0].push(`${privateStateName}_nullifierRoot.integer`, `${privateStateName}_newNullifierRoot.integer`); + output[0].push(`${privateStateName}_nullifierRoot.integer`, `newNullifierRoot`); output[1].push( `${privateStateName}_0_nullifier.integer, ${privateStateName}_1_nullifier.integer`, ); @@ -96,7 +96,7 @@ export const sendTransactionBoilerplate = (node: any) => { output[2].push(`${privateStateName}_root.integer`); if (!stateNode.accessedOnly && !stateNode.reinitialisedOnly) { output[1].push(`${privateStateName}_nullifier.integer`); - output[0].push(`${privateStateName}_nullifierRoot.integer`,`${privateStateName}_newNullifierRoot.integer`); + output[0].push(`${privateStateName}_nullifierRoot.integer`,`newNullifierRoot`); } if (!stateNode.accessedOnly && !stateNode.burnedOnly) output[3].push(`${privateStateName}_newCommitment.integer`); @@ -114,6 +114,7 @@ export const sendTransactionBoilerplate = (node: any) => { export const generateProofBoilerplate = (node: any) => { const output: (string[] | string)[] = []; const enc: any[][] = []; + const latestNullifierRoot: any[] = []; const cipherTextLength: number[] = []; let containsRoot = false; let containsNullifierRoot = false; @@ -129,6 +130,13 @@ export const generateProofBoilerplate = (node: any) => { enc[1] ??= []; enc[1].push(`const ${stateName}_encKey = res.inputs.slice(START_SLICE END_SLICE).map(e => generalise(e).integer);`); } + // We read the latestNullifierRoot + + if(stateNode.nullifierRequired && latestNullifierRoot.length === 0) { + latestNullifierRoot.push(`const newNullifierRoot = res.inputs.slice(-1).map(e => generalise(e).integer)[0];`) + + } + const parameters: string[] = []; // we include the state variable key (mapping key) if its not a param (we include params separately) const msgSenderParamAndMappingKey = stateNode.isMapping && (node.parameters.includes('msgSender') || output.join().includes('_msg_stateVarId_key.integer')) && stateNode.stateVarId[1] === 'msg'; @@ -263,7 +271,7 @@ export const generateProofBoilerplate = (node: any) => { // extract the nullifier Root output.push(`\n].flat(Infinity);`); - return [output, [enc]]; + return [output, [enc], latestNullifierRoot]; }; export const preimageBoilerPlate = (node: any) => { @@ -417,6 +425,7 @@ export const preimageBoilerPlate = (node: any) => { export const OrchestrationCodeBoilerPlate: any = (node: any) => { const lines: any[] = []; const params:any[] = []; + const latestNullifierRoot:any[] = []; const states: string[] = []; const rtnparams: string[] = []; let stateName: string; @@ -686,43 +695,6 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { } } - for ([stateName, stateNode] of Object.entries(node.privateStates)) { - if (stateNode.isPartitioned) { - lines.push( - Orchestrationbp.temporaryUpdatedNullifier.postStatements({ - stateName, - accessedOnly: stateNode.accessedOnly, - stateType: 'partitioned', - })); - - } else { - lines.push( - Orchestrationbp.temporaryUpdatedNullifier.postStatements({ - stateName, - accessedOnly: stateNode.accessedOnly, - stateType: 'whole', - })); - } - } - - for ([stateName, stateNode] of Object.entries(node.privateStates)) { - if (stateNode.isPartitioned) { - lines.push( - Orchestrationbp.calculateUpdateNullifierPath.postStatements({ - stateName, - accessedOnly: stateNode.accessedOnly, - stateType: 'partitioned', - })); - - } else { - lines.push( - Orchestrationbp.calculateUpdateNullifierPath.postStatements({ - stateName, - accessedOnly: stateNode.accessedOnly, - stateType: 'whole', - })); - } - } return { statements: [`\n// Calculate nullifier(s): \n`, ...lines], @@ -772,16 +744,18 @@ export const OrchestrationCodeBoilerPlate: any = (node: any) => { }; case 'GenerateProof': - [ lines[0], params[0] ] = generateProofBoilerplate(node); + [ lines[0], params[0], latestNullifierRoot[0] ] = generateProofBoilerplate(node); + return { statements: [ `\n\n// Call Zokrates to generate the proof: - \nconst allInputs = [`, + \nconst allInputs = [`, `${lines[0]}`, `\nconst res = await generateProof('${node.circuitName}', allInputs);`, `\nconst proof = generalise(Object.values(res.proof).flat(Infinity)) .map(coeff => coeff.integer) .flat(Infinity);`, + `${latestNullifierRoot[0]}`, `${params[0].flat(Infinity).join('\n')}` ], }; diff --git a/src/codeGenerators/circuit/zokrates/toCircuit.ts b/src/codeGenerators/circuit/zokrates/toCircuit.ts index a31c55d8f..a8024a66f 100644 --- a/src/codeGenerators/circuit/zokrates/toCircuit.ts +++ b/src/codeGenerators/circuit/zokrates/toCircuit.ts @@ -95,11 +95,18 @@ function codeGenerator(node: any) { returnType.push(node.typeName.name); }); + if(codeGenerator(node.parameters).includes('nullifierRoot')){ + returnStatement.push('nullifierRoot'); + returnType.push('field') ; + } + if(returnStatement.length === 0){ returnStatement.push('true'); returnType.push('bool') ; } + + return `${functionSignature}(${returnType}): ${body} @@ -189,8 +196,10 @@ function codeGenerator(node: any) { }) return `${returnPara} ${node.name}(${(node.CircuitArguments).join(',\\\n \t')})` } - else if(node.CircuitArguments.length) - return `assert(${node.name}(${(node.CircuitArguments).join(',\\\n \t')})) ` ; + else if(node.CircuitArguments.length && node.CircuitArguments.includes('nullifierRoot')) + return ` nullifierRoot = ${node.name} (${(node.CircuitArguments).join(',\\\n \t')}) ` ; + else if(node.CircuitArguments.length && !node.CircuitArguments.includes('nullifierRoot')) + return ` assert( ${node.name} (${(node.CircuitArguments).join(',\\\n \t')}) )` ; else return ``; } diff --git a/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts b/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts index 24ea2f537..367fe561a 100644 --- a/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts +++ b/src/transformers/visitors/circuitInternalFunctionCallVisitor.ts @@ -57,6 +57,7 @@ const internalCallVisitor = { } }) + // Collect the internal call ParameterList let internalFncParameters: string[] = []; state.newParameterList.forEach(node => { @@ -71,10 +72,8 @@ const internalCallVisitor = { case 'nullification' : { internalFncParameters.push(`${node.name}_oldCommitment_owner_secretKey`) ; internalFncParameters.push(`nullifierRoot`); - internalFncParameters.push(`newNullifierRoot`); internalFncParameters.push(`${node.name}_oldCommitment_nullifier`); internalFncParameters.push(`${node.name}_nullifier_nonmembershipWitness_siblingPath`); - internalFncParameters.push(`${node.name}_nullifier_nonmembershipWitness_newsiblingPath`); break; }; case 'oldCommitmentPreimage' : { diff --git a/src/transformers/visitors/toContractVisitor.ts b/src/transformers/visitors/toContractVisitor.ts index 9e5c6618f..abedaf84b 100644 --- a/src/transformers/visitors/toContractVisitor.ts +++ b/src/transformers/visitors/toContractVisitor.ts @@ -29,13 +29,13 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { item.expression.components.forEach(element => { if(element.kind === 'bool'){ thisState.customInputs ??= []; - thisState.customInputs.push({name: '1', typeName: {name: 'bool'}}); + thisState.customInputs.push({name: '1', typeName: {name: 'bool'}, inCircuit: true}); } }); } else { if(item.expression.kind === 'bool'){ thisState.customInputs ??= []; - thisState.customInputs.push({name: '1', typeName: {name: 'bool'}}); + thisState.customInputs.push({name: '1', typeName: {name: 'bool'}, inCircuit: true}); } } } @@ -44,7 +44,7 @@ const findCustomInputsVisitor = (thisPath: NodePath, thisState: any) => { if(thisPath.getAncestorOfType('Return') && binding instanceof VariableBinding && binding.isSecret){ thisState.customInputs ??= []; if(thisState.variableName.includes(indicator.node.name)) - thisState.customInputs.push({name: 'newCommitments['+(thisState.variableName.indexOf(indicator.node.name))+']', typeName: {name: 'uint256'}}); + thisState.customInputs.push({name: 'newCommitments['+(thisState.variableName.indexOf(indicator.node.name))+']', typeName: {name: 'uint256'},inCircuit: true}); } // for some reason, node.interactsWithSecret has disappeared here but not in toCircuit diff --git a/test/contracts/Assign-Return.zol b/test/contracts/Assign-Return.zol index 812ecdcd5..515bd29d5 100644 --- a/test/contracts/Assign-Return.zol +++ b/test/contracts/Assign-Return.zol @@ -5,11 +5,12 @@ pragma solidity ^0.8.0; contract Assign { secret uint256 private a; - uint256 private b; + secret uint256 private b; - function add( uint256 value) public returns (bool, uint256) { + function add( uint256 value) public { unknown a += value; - return (true, 5); + unknown b += value; + } function remove(secret uint256 value, uint256 value1) public returns (uint256, uint256) {