diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ea90840c048..05448211414 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -12,7 +12,7 @@ env: jobs: check_n_test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: @@ -49,7 +49,7 @@ jobs: clippy: name: cargo clippy - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 @@ -61,6 +61,9 @@ jobs: toolchain: stable override: true components: rustfmt, clippy + + - name: Install dependencies + run: sudo apt update && sudo apt install libomp-dev - name: Run cargo clippy uses: actions-rs/cargo@v1 @@ -71,7 +74,7 @@ jobs: format: name: cargo fmt - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 @@ -83,7 +86,10 @@ jobs: toolchain: stable override: true components: rustfmt, clippy - + + - name: Install dependencies + run: sudo apt update && sudo apt install libomp-dev + - name: Run cargo fmt uses: actions-rs/cargo@v1 with: diff --git a/Cargo.lock b/Cargo.lock index 9a7d8052128..cc76290d5b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,28 +8,112 @@ version = "0.1.0" dependencies = [ "flate2", "indexmap", - "noir_field", + "noir_field 0.1.0", "rmp-serde", "serde", "serde_json", ] +[[package]] +name = "acir" +version = "0.1.0" +source = "git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f#cc5ee63072e09779bebd7e7dd054ae16be307d7f" +dependencies = [ + "indexmap", + "noir_field 0.1.0 (git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f)", + "serde", +] + +[[package]] +name = "acir" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aad7977c11d19ae0dd983b50dc5fd9eb96c002072f75643e45daa6dc0c23fba5" +dependencies = [ + "acir_field", + "flate2", + "rmp-serde", + "serde", +] + +[[package]] +name = "acir_field" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "687506e635efa7ce15d6b93ceae14dec1519ed2e54c24298fc8c40e86edbce24" +dependencies = [ + "ark-bn254", + "ark-ff", + "blake2", + "cfg-if 1.0.0", + "hex", + "num-bigint", + "num-traits", + "serde", +] + [[package]] name = "acvm" version = "0.1.0" dependencies = [ - "acir", + "acir 0.1.0", "blake2", "hex", "indexmap", "k256", - "noir_field", + "noir_field 0.1.0", "num-bigint", "num-traits", "sha2", "tempfile", ] +[[package]] +name = "acvm" +version = "0.1.0" +source = "git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f#cc5ee63072e09779bebd7e7dd054ae16be307d7f" +dependencies = [ + "acir 0.1.0 (git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f)", + "blake2", + "hex", + "indexmap", + "k256", + "noir_field 0.1.0 (git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f)", + "num-bigint", + "num-traits", + "sha2", + "sled", +] + +[[package]] +name = "acvm" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99007127e84602134226eefc2245c59b7fe55853bfeba572714b04c5b3fefdea" +dependencies = [ + "acir 0.3.1", + "acir_field", + "acvm_stdlib", + "blake2", + "hex", + "indexmap", + "k256", + "num-bigint", + "num-traits", + "sha2", + "thiserror", +] + +[[package]] +name = "acvm_stdlib" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f5ef183f4a10b4a257d25c3a37fd090b9e8fbb7dff0902329fb6606b524114" +dependencies = [ + "acir 0.3.1", + "acir_field", +] + [[package]] name = "adler" version = "1.0.2" @@ -242,7 +326,7 @@ name = "arkworks_backend" version = "0.1.0" source = "git+https://github.com/noir-lang/arkworks_backend?rev=ee6d468f5cc635dc2589965b6bf16cd2a839d7d3#ee6d468f5cc635dc2589965b6bf16cd2a839d7d3" dependencies = [ - "acvm", + "acvm 0.1.0 (git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f)", "ark-bls12-381", "ark-bn254", "ark-ff", @@ -264,7 +348,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -278,12 +362,11 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "barretenberg_static_lib" version = "0.1.0" -source = "git+https://github.com/noir-lang/aztec_backend?rev=8c8ec2dd9c376bef598d17f023fac172e5e47860#8c8ec2dd9c376bef598d17f023fac172e5e47860" +source = "git+https://github.com/noir-lang/aztec_backend?rev=441de9d897683f770f8cd09c34ddca69fe41f3f2#441de9d897683f770f8cd09c34ddca69fe41f3f2" dependencies = [ "barretenberg_wrapper", "blake2", "common", - "console_error_panic_hook", "dirs 3.0.2", "downloader", "hex", @@ -299,7 +382,7 @@ dependencies = [ [[package]] name = "barretenberg_wrapper" version = "0.1.0" -source = "git+https://github.com/noir-lang/aztec-connect?rev=2c961d511c245d7debef04d99b42c3de4268cad8#2c961d511c245d7debef04d99b42c3de4268cad8" +source = "git+https://github.com/noir-lang/aztec-connect?branch=kw/noir-dsl#2ef8be41993ead9993c09b1d99fef6dc68e231a6" dependencies = [ "bindgen", "cmake", @@ -375,9 +458,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" @@ -393,9 +476,9 @@ checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" [[package]] name = "cc" -version = "1.0.77" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" +checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" [[package]] name = "cexpr" @@ -508,9 +591,9 @@ dependencies = [ [[package]] name = "common" version = "0.1.0" -source = "git+https://github.com/noir-lang/aztec_backend?rev=8c8ec2dd9c376bef598d17f023fac172e5e47860#8c8ec2dd9c376bef598d17f023fac172e5e47860" +source = "git+https://github.com/noir-lang/aztec_backend?rev=441de9d897683f770f8cd09c34ddca69fe41f3f2#441de9d897683f770f8cd09c34ddca69fe41f3f2" dependencies = [ - "acvm", + "acvm 0.3.1", "blake2", "dirs 3.0.2", "downloader", @@ -521,16 +604,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.2" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" +checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" dependencies = [ "encode_unicode", "lazy_static", "libc", - "terminal_size", "unicode-width", - "winapi", + "windows-sys", ] [[package]] @@ -685,9 +767,9 @@ dependencies = [ [[package]] name = "downloader" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074093edfa907e8203c17c5111b04e114e03bde5ccdfa21a388fa4f34dabad96" +checksum = "d05213e96f184578b5f70105d4d0a644a168e99e12d7bea0b200c15d67b5c182" dependencies = [ "futures", "rand 0.8.5", @@ -983,9 +1065,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gloo-utils" @@ -1054,6 +1136,15 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + [[package]] name = "hex" version = "0.4.3" @@ -1190,9 +1281,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.6.0" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec947b7a4ce12e3b87e353abae7ce124d025b6c7d6c5aea5cc0bcf92e9510ded" +checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" [[package]] name = "iter-extended" @@ -1200,9 +1291,9 @@ version = "0.1.0" [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" @@ -1239,9 +1330,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.138" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libloading" @@ -1277,7 +1368,7 @@ name = "marlin_arkworks_backend" version = "0.1.0" source = "git+https://github.com/noir-lang/marlin_arkworks_backend?rev=601e24dcb5dcbe72e3de7a33879aaf84e171d541#601e24dcb5dcbe72e3de7a33879aaf84e171d541" dependencies = [ - "acvm", + "acvm 0.1.0 (git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f)", "arkworks_backend", "blake2", "dirs 3.0.2", @@ -1336,18 +1427,17 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] name = "nargo" version = "0.1.0" dependencies = [ - "acvm", + "acvm 0.3.1", "barretenberg_static_lib", "cfg-if 1.0.0", "clap 2.34.0", - "dirs 3.0.2", "dirs 4.0.0", "fm", "hex", @@ -1396,11 +1486,26 @@ dependencies = [ "serde", ] +[[package]] +name = "noir_field" +version = "0.1.0" +source = "git+https://github.com/noir-lang/noir?rev=cc5ee63072e09779bebd7e7dd054ae16be307d7f#cc5ee63072e09779bebd7e7dd054ae16be307d7f" +dependencies = [ + "ark-bls12-381", + "ark-ff", + "blake2", + "cfg-if 1.0.0", + "hex", + "num-bigint", + "num-traits", + "serde", +] + [[package]] name = "noir_wasm" version = "0.1.0" dependencies = [ - "acvm", + "acvm 0.3.1", "console_error_panic_hook", "getrandom", "gloo-utils", @@ -1414,7 +1519,7 @@ dependencies = [ name = "noirc_abi" version = "0.1.0" dependencies = [ - "acvm", + "acvm 0.3.1", "blake2", "serde", "serde_derive", @@ -1426,8 +1531,8 @@ dependencies = [ name = "noirc_driver" version = "0.1.0" dependencies = [ - "acvm", - "dirs 3.0.2", + "acvm 0.3.1", + "dirs 4.0.0", "fm", "noirc_abi", "noirc_errors", @@ -1451,7 +1556,7 @@ dependencies = [ name = "noirc_evaluator" version = "0.1.0" dependencies = [ - "acvm", + "acvm 0.3.1", "arena", "fm", "iter-extended", @@ -1468,7 +1573,7 @@ dependencies = [ name = "noirc_frontend" version = "0.1.0" dependencies = [ - "acvm", + "acvm 0.3.1", "arena", "chumsky", "fm", @@ -1483,9 +1588,9 @@ dependencies = [ [[package]] name = "nom" -version = "7.1.1" +version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ "memchr", "minimal-lexical", @@ -1532,11 +1637,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] @@ -1548,9 +1653,9 @@ checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" [[package]] name = "once_cell" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "opaque-debug" @@ -1560,9 +1665,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.44" +version = "0.10.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d971fd5722fec23977260f6e81aa67d2f22cadbdc2aa049f1022d9a3be1566" +checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -1592,9 +1697,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.79" +version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5454462c0eced1e97f2ec09036abc8da362e66802f66fd20f86854d9d8cbcbc4" +checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ "autocfg", "cc", @@ -1622,9 +1727,9 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76e8e1493bcac0d2766c42737f34458f1c8c50c0d23bcb24ea953affb273216" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" dependencies = [ "cfg-if 1.0.0", "instant", @@ -1636,9 +1741,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "pathdiff" @@ -1660,9 +1765,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.1" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc8bed3549e0f9b0a2a78bf7c0018237a2cdf085eecbbc048e52612438e4e9d0" +checksum = "4257b4a04d91f7e9e6290be5d3da4804dd5784fafde3a497d73eb2b4a158c30a" dependencies = [ "thiserror", "ucd-trie", @@ -1703,9 +1808,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" dependencies = [ "unicode-ident", ] @@ -1721,9 +1826,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -1829,9 +1934,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" dependencies = [ "aho-corasick", "memchr", @@ -1929,18 +2034,17 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "schannel" -version = "0.1.20" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "lazy_static", - "windows-sys 0.36.1", + "windows-sys", ] [[package]] @@ -1998,18 +2102,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.149" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256b9932320c590e707b94576e3cc1f7c9024d0ee6612dfbcf1cb106cbe8e055" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.149" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4eae9b04cbffdfd550eb462ed33bc6a1b68c935127d008b27444d08380f94e4" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -2018,9 +2122,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "itoa", "ryu", @@ -2151,9 +2255,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.105" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -2198,23 +2302,13 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "textwrap" version = "0.11.0" @@ -2232,18 +2326,18 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", @@ -2267,19 +2361,19 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.23.0" +version = "1.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" +checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", - "num_cpus 1.14.0", + "num_cpus 1.15.0", "pin-project-lite", "socket2", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -2308,9 +2402,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.9" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f" dependencies = [ "serde", ] @@ -2355,9 +2449,9 @@ dependencies = [ [[package]] name = "try-lock" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "typenum" @@ -2379,9 +2473,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "unicode-normalization" @@ -2593,19 +2687,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" -dependencies = [ - "windows_aarch64_msvc 0.36.1", - "windows_i686_gnu 0.36.1", - "windows_i686_msvc 0.36.1", - "windows_x86_64_gnu 0.36.1", - "windows_x86_64_msvc 0.36.1", -] - [[package]] name = "windows-sys" version = "0.42.0" @@ -2613,85 +2694,55 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.0", - "windows_i686_gnu 0.42.0", - "windows_i686_msvc 0.42.0", - "windows_x86_64_gnu 0.42.0", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.0", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" [[package]] name = "winreg" diff --git a/Cargo.toml b/Cargo.toml index 8e963b352d5..f92d5589ad2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ rust-version = "1.64" [workspace.dependencies] acir = { path = "crates/acir" } -acvm = { path = "crates/acvm" } +acvm = "0.3.1" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } @@ -88,8 +88,3 @@ toml = "0.5.8" url = "2.2.0" wasm-bindgen = { version = "*", features = ["serde-serialize"] } wasm-bindgen-test = "*" - - -# Patch github versions of acvm with local copy -[patch.'https://github.com/noir-lang/noir'] -acvm = { path = "crates/acvm" } diff --git a/crates/nargo/Cargo.toml b/crates/nargo/Cargo.toml index cb953e36e01..9e2edf3ad1b 100644 --- a/crates/nargo/Cargo.toml +++ b/crates/nargo/Cargo.toml @@ -17,7 +17,7 @@ noirc_driver.workspace = true noirc_frontend.workspace = true noirc_abi.workspace = true fm.workspace = true -acvm = { git = "https://github.com/noir-lang/noir" } +acvm.workspace = true cfg-if.workspace = true toml.workspace = true @@ -29,7 +29,7 @@ hex.workspace = true tempdir.workspace = true # Backends -aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "8c8ec2dd9c376bef598d17f023fac172e5e47860" } +aztec_backend = { optional = true, package = "barretenberg_static_lib", git = "https://github.com/noir-lang/aztec_backend", rev = "441de9d897683f770f8cd09c34ddca69fe41f3f2" } marlin_arkworks_backend = { optional = true, git = "https://github.com/noir-lang/marlin_arkworks_backend", rev = "601e24dcb5dcbe72e3de7a33879aaf84e171d541" } [features] diff --git a/crates/nargo/src/cli/build_cmd.rs b/crates/nargo/src/cli/build_cmd.rs index f23c4e1d520..aaefdec30d3 100644 --- a/crates/nargo/src/cli/build_cmd.rs +++ b/crates/nargo/src/cli/build_cmd.rs @@ -22,6 +22,7 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> { // This is exposed so that we can run the examples and verify that they pass pub fn build_from_path>(p: P, allow_warnings: bool) -> Result<(), CliError> { let backend = crate::backends::ConcreteBackend; + let mut driver = Resolver::resolve_root_config(p.as_ref(), backend.np_language())?; add_std_lib(&mut driver); driver.build(allow_warnings); diff --git a/crates/nargo/src/cli/compile_cmd.rs b/crates/nargo/src/cli/compile_cmd.rs index 02f99fa654c..8bad76d90a8 100644 --- a/crates/nargo/src/cli/compile_cmd.rs +++ b/crates/nargo/src/cli/compile_cmd.rs @@ -34,6 +34,7 @@ pub(crate) fn run(args: ArgMatches) -> Result<(), CliError> { } } +#[allow(deprecated)] pub fn generate_circuit_and_witness_to_disk>( circuit_name: &str, program_dir: P, diff --git a/crates/nargo/src/cli/gates_cmd.rs b/crates/nargo/src/cli/gates_cmd.rs index 35672a0fe89..46d3d7ef8ed 100644 --- a/crates/nargo/src/cli/gates_cmd.rs +++ b/crates/nargo/src/cli/gates_cmd.rs @@ -23,10 +23,14 @@ pub fn count_gates_with_path>( allow_warnings: bool, ) -> Result<(), CliError> { let compiled_program = compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?; - let gates = compiled_program.circuit.gates.clone(); + let num_opcodes = compiled_program.circuit.opcodes.len(); let backend = crate::backends::ConcreteBackend; - println!("Total gates generated for language {:?}: {}\n", backend.np_language(), gates.len()); + println!( + "Total ACIR opcodes generated for language {:?}: {}\n", + backend.np_language(), + num_opcodes + ); let exact_circuit_size = backend.get_exact_circuit_size(compiled_program.circuit); println!("\nBackend circuit size: {exact_circuit_size}\n"); diff --git a/crates/nargo/src/cli/prove_cmd.rs b/crates/nargo/src/cli/prove_cmd.rs index 5cc5a3d9605..ce02d92a1da 100644 --- a/crates/nargo/src/cli/prove_cmd.rs +++ b/crates/nargo/src/cli/prove_cmd.rs @@ -2,8 +2,8 @@ use std::{collections::BTreeMap, path::PathBuf}; use acvm::acir::native_types::Witness; use acvm::FieldElement; +use acvm::PartialWitnessGenerator; use acvm::ProofSystemCompiler; -use acvm::{GateResolution, PartialWitnessGenerator}; use clap::ArgMatches; use noirc_abi::errors::AbiError; use noirc_abi::input_parser::{Format, InputValue}; @@ -104,18 +104,9 @@ fn solve_witness( .collect(); let backend = crate::backends::ConcreteBackend; - let solver_res = backend.solve(&mut solved_witness, compiled_program.circuit.gates.clone()); - - match solver_res { - GateResolution::UnsupportedOpcode(opcode) => return Err(CliError::Generic(format!( - "backend does not currently support the {opcode} opcode. ACVM does not currently fall back to arithmetic gates.", - ))), - GateResolution::UnsatisfiedConstrain => return Err(CliError::Generic( - "could not satisfy all constraints".to_string() - )), - GateResolution::Resolved => (), - _ => unreachable!(), - } + let solver_res = backend.solve(&mut solved_witness, compiled_program.circuit.opcodes.clone()); + + solver_res.map_err(CliError::from)?; Ok(solved_witness) } diff --git a/crates/nargo/src/errors.rs b/crates/nargo/src/errors.rs index 04c0036e4d2..6a8c50b1ca1 100644 --- a/crates/nargo/src/errors.rs +++ b/crates/nargo/src/errors.rs @@ -1,3 +1,4 @@ +use acvm::OpcodeResolutionError; use hex::FromHexError; use noirc_abi::errors::{AbiError, InputParserError}; use std::{fmt::Display, io::Write, path::PathBuf}; @@ -12,6 +13,12 @@ pub enum CliError { MissingTomlFile(PathBuf), } +impl From for CliError { + fn from(value: OpcodeResolutionError) -> Self { + CliError::Generic(value.to_string()) + } +} + impl CliError { pub(crate) fn write(&self) -> ! { let mut stderr = StandardStream::stderr(ColorChoice::Always); diff --git a/crates/noirc_abi/Cargo.toml b/crates/noirc_abi/Cargo.toml index 4206142ab5a..7f77d897087 100644 --- a/crates/noirc_abi/Cargo.toml +++ b/crates/noirc_abi/Cargo.toml @@ -7,7 +7,7 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -acvm = { git = "https://github.com/noir-lang/noir" } +acvm.workspace = true toml.workspace = true serde.workspace = true serde_derive.workspace = true diff --git a/crates/noirc_driver/Cargo.toml b/crates/noirc_driver/Cargo.toml index 7bc712e231f..b53e3ab5e0a 100644 --- a/crates/noirc_driver/Cargo.toml +++ b/crates/noirc_driver/Cargo.toml @@ -11,7 +11,7 @@ noirc_errors.workspace = true noirc_frontend.workspace = true noirc_evaluator.workspace = true noirc_abi.workspace = true -acvm = { git = "https://github.com/noir-lang/noir", rev = "cc5ee63072e09779bebd7e7dd054ae16be307d7f" } +acvm.workspace = true fm.workspace = true serde.workspace = true dirs.workspace = true diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index ca5a0886caf..9edbaf1037e 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -1,4 +1,5 @@ use acvm::acir::circuit::Circuit; + use acvm::Language; use fm::FileType; use noirc_abi::Abi; @@ -159,6 +160,7 @@ impl Driver { Some(abi) } + #[allow(deprecated)] pub fn into_compiled_program( mut self, np_language: acvm::Language, @@ -189,7 +191,12 @@ impl Driver { let program = monomorphise(main_function, self.context.def_interner); // Compile Program - let circuit = match create_circuit(program, np_language, show_ssa) { + let circuit = match create_circuit( + program, + np_language.clone(), + acvm::default_is_blackbox_supported(np_language), + show_ssa, + ) { Ok(circuit) => circuit, Err(err) => { // The FileId here will be the file id of the file with the main file diff --git a/crates/noirc_evaluator/Cargo.toml b/crates/noirc_evaluator/Cargo.toml index f9f99c94429..4f1e10ea60b 100644 --- a/crates/noirc_evaluator/Cargo.toml +++ b/crates/noirc_evaluator/Cargo.toml @@ -10,7 +10,7 @@ edition.workspace = true noirc_frontend.workspace = true noirc_errors.workspace = true noirc_abi.workspace = true -acvm = { git = "https://github.com/noir-lang/noir" } +acvm.workspace = true arena.workspace = true fm.workspace = true iter-extended.workspace = true diff --git a/crates/noirc_evaluator/src/lib.rs b/crates/noirc_evaluator/src/lib.rs index b46baa476eb..24f27ab8780 100644 --- a/crates/noirc_evaluator/src/lib.rs +++ b/crates/noirc_evaluator/src/lib.rs @@ -1,8 +1,9 @@ mod errors; mod ssa; -use acvm::acir::circuit::{gate::Gate, Circuit, PublicInputs}; +use acvm::acir::circuit::{opcodes::Opcode as AcirOpcode, Circuit, PublicInputs}; use acvm::acir::native_types::{Expression, Witness}; +use acvm::compiler::fallback::IsBlackBoxSupported; use acvm::Language; use errors::{RuntimeError, RuntimeErrorKind}; use iter_extended::btree_map; @@ -20,7 +21,7 @@ pub struct Evaluator { // to compile wasm64. current_witness_index: u32, public_inputs: Vec, - gates: Vec, + opcodes: Vec, } /// Compiles the Program into ACIR and applies optimisations to the arithmetic gates @@ -31,6 +32,7 @@ pub struct Evaluator { pub fn create_circuit( program: Program, np_language: Language, + is_blackbox_supported: IsBlackBoxSupported, enable_logging: bool, ) -> Result { let mut evaluator = Evaluator::new(); @@ -43,11 +45,13 @@ pub fn create_circuit( let optimised_circuit = acvm::compiler::compile( Circuit { current_witness_index: witness_index, - gates: evaluator.gates, + opcodes: evaluator.opcodes, public_inputs: PublicInputs(evaluator.public_inputs), }, np_language, - ); + is_blackbox_supported, + ) + .map_err(|_| RuntimeErrorKind::Spanless(String::from("produced an acvm compile error")))?; Ok(optimised_circuit) } @@ -65,7 +69,7 @@ impl Evaluator { // following transformation to the witness index : f(i) = i + 1 // current_witness_index: 0, - gates: Vec::new(), + opcodes: Vec::new(), } } @@ -105,7 +109,7 @@ impl Evaluator { // Link that witness to the arithmetic gate let constraint = &arithmetic_gate - &inter_var_witness; - self.gates.push(Gate::Arithmetic(constraint)); + self.opcodes.push(AcirOpcode::Arithmetic(constraint)); inter_var_witness } diff --git a/crates/noirc_evaluator/src/ssa/acir_gen.rs b/crates/noirc_evaluator/src/ssa/acir_gen.rs index 718497863bd..257ef8f6fa5 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen.rs @@ -14,9 +14,11 @@ use crate::ssa::context::SsaContext; use crate::ssa::node::Node; use crate::ssa::{mem, node}; use crate::Evaluator; -use crate::Gate; use crate::RuntimeErrorKind; -use acvm::acir::circuit::gate::{Directive, GadgetCall, GadgetInput}; +use acvm::acir::circuit::directives::Directive; +use acvm::acir::circuit::opcodes::{BlackBoxFuncCall, FunctionInput}; + +use acvm::acir::circuit::Opcode as AcirOpcode; use acvm::acir::native_types::{Expression, Linear, Witness}; use num_bigint::BigUint; @@ -143,7 +145,7 @@ impl Acir { Operation::Constrain(value, ..) => { let value = self.substitute(*value, evaluator, ctx); let subtract = subtract(&Expression::one(), FieldElement::one(), &value.expression); - evaluator.gates.push(Gate::Arithmetic(subtract)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract)); value } Operation::Not(value) => { @@ -290,7 +292,7 @@ impl Acir { let mut sub_var = sub_expr.into(); //TODO: uses interval analysis for more precise check if let Some(lhs_const) = l_c.to_const() { - if max_rhs_value <= &BigUint::from_bytes_be(&lhs_const.to_bytes()) { + if max_rhs_value <= &BigUint::from_bytes_be(&lhs_const.to_be_bytes()) { sub_var = InternalVar::from(subtract( &l_c.expression, FieldElement::one(), @@ -359,9 +361,9 @@ impl Acir { } } - pub fn print_circuit(gates: &[Gate]) { - for gate in gates { - println!("{gate:?}"); + pub fn print_circuit(opcodes: &[AcirOpcode]) { + for opcode in opcodes { + println!("{opcode:?}"); } } @@ -476,7 +478,7 @@ impl Acir { witness: Some(diff_witness), id: None, }; - evaluator.gates.push(Gate::Arithmetic(subtract( + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract( &diff_expr, FieldElement::one(), &from_witness(diff_witness), @@ -497,8 +499,8 @@ impl Acir { args: &[NodeId], cfg: &SsaContext, evaluator: &mut Evaluator, - ) -> Vec { - let mut inputs: Vec = Vec::new(); + ) -> Vec { + let mut inputs: Vec = Vec::new(); for a in args { let l_obj = cfg.try_get_node(*a).unwrap(); @@ -512,17 +514,17 @@ impl Acir { let address = array.adr + i; if self.memory_map.contains_key(&address) { if let Some(wit) = self.memory_map[&address].witness { - inputs.push(GadgetInput { witness: wit, num_bits }); + inputs.push(FunctionInput { witness: wit, num_bits }); } else { //TODO we should store the witnesses somewhere, else if the inputs are re-used //we will duplicate the witnesses. let w = evaluator.create_intermediate_variable( self.memory_map[&address].expression.clone(), ); - inputs.push(GadgetInput { witness: w, num_bits }); + inputs.push(FunctionInput { witness: w, num_bits }); } } else { - inputs.push(GadgetInput { + inputs.push(FunctionInput { witness: array.values[i as usize].witness.unwrap(), num_bits, }); @@ -531,7 +533,8 @@ impl Acir { } _ => { if let Some(w) = v.witness { - inputs.push(GadgetInput { witness: w, num_bits: v.size_in_bits() }); + inputs + .push(FunctionInput { witness: w, num_bits: v.size_in_bits() }); } else { todo!("generate a witness"); } @@ -543,7 +546,7 @@ impl Acir { let mut var = self.arith_cache[a].clone(); let witness = var.witness.unwrap_or_else(|| var.generate_witness(evaluator)); - inputs.push(GadgetInput { witness, num_bits: l_obj.size_in_bits() }); + inputs.push(FunctionInput { witness, num_bits: l_obj.size_in_bits() }); } else { unreachable!("invalid input: {:?}", l_obj) } @@ -586,12 +589,12 @@ impl Acir { let output_count = op.definition().output_size.0 as u32; outputs = self.prepare_outputs(instruction_id, output_count, ctx, evaluator); - let call_gate = GadgetCall { + let call_gate = BlackBoxFuncCall { name: op, inputs, //witness + bit size outputs: outputs.clone(), //witness }; - evaluator.gates.push(Gate::GadgetCall(call_gate)); + evaluator.opcodes.push(AcirOpcode::BlackBoxFuncCall(call_gate)); } } @@ -716,13 +719,17 @@ pub fn to_radix_base( assert!(max < FieldElement::modulus()); let (result, bytes) = to_radix(radix, limb_size, evaluator); - evaluator.gates.push(Gate::Directive(Directive::ToRadix { + evaluator.opcodes.push(AcirOpcode::Directive(Directive::ToRadix { a: lhs.expression.clone(), b: result.clone(), radix, })); - evaluator.gates.push(Gate::Arithmetic(subtract(&lhs.expression, FieldElement::one(), &bytes))); + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract( + &lhs.expression, + FieldElement::one(), + &bytes, + ))); result } @@ -824,12 +831,17 @@ pub fn evaluate_and( let result = evaluator.add_witness_to_cs(); let bsize = if bit_size % 2 == 1 { bit_size + 1 } else { bit_size }; assert!(bsize < FieldElement::max_num_bits() - 1); - evaluator.gates.push(Gate::And(acvm::acir::circuit::gate::AndGate { - a: a_witness, - b: b_witness, - result, - num_bits: bsize, - })); + + let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall { + name: acvm::acir::BlackBoxFunc::AND, + inputs: vec![ + FunctionInput { witness: a_witness, num_bits: bsize }, + FunctionInput { witness: b_witness, num_bits: bsize }, + ], + outputs: vec![result], + }); + evaluator.opcodes.push(gate); + Expression::from(Linear::from_witness(result)) } @@ -857,12 +869,17 @@ pub fn evaluate_xor( let b_witness = rhs.generate_witness(evaluator); let bsize = if bit_size % 2 == 1 { bit_size + 1 } else { bit_size }; assert!(bsize < FieldElement::max_num_bits() - 1); - evaluator.gates.push(Gate::Xor(acvm::acir::circuit::gate::XorGate { - a: a_witness, - b: b_witness, - result, - num_bits: bsize, - })); + + let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall { + name: acvm::acir::BlackBoxFunc::XOR, + inputs: vec![ + FunctionInput { witness: a_witness, num_bits: bsize }, + FunctionInput { witness: b_witness, num_bits: bsize }, + ], + outputs: vec![result], + }); + evaluator.opcodes.push(gate); + from_witness(result) } @@ -909,7 +926,7 @@ pub fn evaluate_truncate( //0. Check for constant expression. This can happen through arithmetic simplifications if let Some(a_c) = lhs.to_const() { - let mut a_big = BigUint::from_bytes_be(&a_c.to_bytes()); + let mut a_big = BigUint::from_bytes_be(&a_c.to_be_bytes()); let two = BigUint::from(2_u32); a_big %= two.pow(rhs); return InternalVar::from(FieldElement::from_be_bytes_reduce(&a_big.to_bytes_be())); @@ -928,13 +945,13 @@ pub fn evaluate_truncate( let c_arith = from_witness(c_witness); let res = add(&b_arith, f, &c_arith); //b+2^Nc let my_constraint = add(&res, -FieldElement::one(), &lhs.expression); - evaluator.gates.push(Gate::Directive(Directive::Truncate { + evaluator.opcodes.push(AcirOpcode::Directive(Directive::Truncate { a: lhs.expression, b: b_witness, c: c_witness, bit_size: rhs, })); - evaluator.gates.push(Gate::Arithmetic(my_constraint)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(my_constraint)); InternalVar::from(b_witness) } @@ -948,12 +965,12 @@ pub fn evaluate_udiv( let q_witness = evaluator.add_witness_to_cs(); let r_witness = evaluator.add_witness_to_cs(); let pa = mul_with_witness(evaluator, &lhs.expression, &predicate.expression); - evaluator.gates.push(Gate::Directive(Directive::Quotient { + evaluator.opcodes.push(AcirOpcode::Directive(Directive::Quotient { a: lhs.expression.clone(), b: rhs.expression.clone(), q: q_witness, r: r_witness, - predicate: Some(Box::new(predicate.expression.clone())), + predicate: Some(predicate.expression.clone()), })); //r Wit let x_witness = x.witness.unwrap(); //todo we need a witness because of the directive, but we should use an expression let m = evaluator.add_witness_to_cs(); //'inverse' of x - evaluator.gates.push(Gate::Directive(Directive::Invert { x: x_witness, result: m })); + evaluator.opcodes.push(AcirOpcode::Directive(Directive::Invert { x: x_witness, result: m })); //y=x*m y is 1 if x is not null, and 0 else let y_witness = evaluator.add_witness_to_cs(); - evaluator.gates.push(Gate::Arithmetic(Expression { + evaluator.opcodes.push(AcirOpcode::Arithmetic(Expression { mul_terms: vec![(FieldElement::one(), x_witness, m)], linear_combinations: vec![(FieldElement::one().neg(), y_witness)], q_c: FieldElement::zero(), @@ -996,7 +1013,7 @@ pub fn evaluate_zero_equality(x: &InternalVar, evaluator: &mut Evaluator) -> Wit //x=y*x let y_expr = from_witness(y_witness); let xy = mul(&from_witness(x_witness), &y_expr); - evaluator.gates.push(Gate::Arithmetic(subtract( + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract( &xy, FieldElement::one(), &from_witness(x_witness), @@ -1015,14 +1032,14 @@ fn evaluate_inverse( let inverse_expr = from_witness(inverse_witness); let x_witness = x.generate_witness(evaluator); //TODO avoid creating witnesses here. evaluator - .gates - .push(Gate::Directive(Directive::Invert { x: x_witness, result: inverse_witness })); + .opcodes + .push(AcirOpcode::Directive(Directive::Invert { x: x_witness, result: inverse_witness })); //x*inverse = 1 Expression::default(); let one = mul(&from_witness(x_witness), &inverse_expr); let lhs = mul_with_witness(evaluator, &one, &predicate.expression); - evaluator.gates.push(Gate::Arithmetic(subtract( + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract( &lhs, FieldElement::one(), &predicate.expression, @@ -1035,7 +1052,7 @@ pub fn mul_with_witness(evaluator: &mut Evaluator, a: &Expression, b: &Expressio let a_arith = if !a.mul_terms.is_empty() && !b.is_const() { let a_witness = evaluator.add_witness_to_cs(); a_arith = Expression::from(&a_witness); - evaluator.gates.push(Gate::Arithmetic(a - &a_arith)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(a - &a_arith)); &a_arith } else { a @@ -1047,7 +1064,7 @@ pub fn mul_with_witness(evaluator: &mut Evaluator, a: &Expression, b: &Expressio } else { let b_witness = evaluator.add_witness_to_cs(); b_arith = Expression::from(&b_witness); - evaluator.gates.push(Gate::Arithmetic(b - &b_arith)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(b - &b_arith)); &b_arith } } else { @@ -1246,7 +1263,7 @@ pub fn range_constraint( if num_bits == 1 { // Add a bool gate let bool_constraint = boolean(witness); - evaluator.gates.push(Gate::Arithmetic(bool_constraint)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(bool_constraint)); } else if num_bits == FieldElement::max_num_bits() { // Don't apply any constraints if the range is for the maximum number of bits let message = format!( @@ -1259,7 +1276,7 @@ pub fn range_constraint( // new witnesses; r is constrained to num_bits-1 and b is 1 bit let r_witness = evaluator.add_witness_to_cs(); let b_witness = evaluator.add_witness_to_cs(); - evaluator.gates.push(Gate::Directive(Directive::Oddrange { + evaluator.opcodes.push(AcirOpcode::Directive(Directive::OddRange { a: witness, b: b_witness, r: r_witness, @@ -1274,9 +1291,14 @@ pub fn range_constraint( f = f.pow(&FieldElement::from((num_bits - 1) as i128)); let res = add(&from_witness(r_witness), f, &from_witness(b_witness)); let my_constraint = add(&res, -FieldElement::one(), &from_witness(witness)); - evaluator.gates.push(Gate::Arithmetic(my_constraint)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(my_constraint)); } else { - evaluator.gates.push(Gate::Range(witness, num_bits)); + let gate = AcirOpcode::BlackBoxFuncCall(BlackBoxFuncCall { + name: acvm::acir::BlackBoxFunc::RANGE, + inputs: vec![FunctionInput { witness, num_bits }], + outputs: vec![], + }); + evaluator.opcodes.push(gate); } Ok(()) @@ -1298,15 +1320,15 @@ fn bound_check( let r_witness = evaluator.add_witness_to_cs(); //2^s+a-b=q*2^s +r let expr = add(&from_witness(r_witness), two_s, &from_witness(q_witness)); - evaluator.gates.push(Gate::Arithmetic(subtract(&sub, FieldElement::one(), &expr))); - evaluator.gates.push(Gate::Directive(Directive::Truncate { + evaluator.opcodes.push(AcirOpcode::Arithmetic(subtract(&sub, FieldElement::one(), &expr))); + evaluator.opcodes.push(AcirOpcode::Directive(Directive::Truncate { a: sub, b: r_witness, c: q_witness, bit_size: max_bits, })); try_range_constraint(r_witness, max_bits, evaluator); - evaluator.gates.push(Gate::Arithmetic(boolean(q_witness))); + evaluator.opcodes.push(AcirOpcode::Arithmetic(boolean(q_witness))); q_witness } @@ -1345,10 +1367,10 @@ fn bound_constraint_with_offset( if f < 3 { match f { - 0 => evaluator.gates.push(Gate::Arithmetic(aof)), + 0 => evaluator.opcodes.push(AcirOpcode::Arithmetic(aof)), 1 => { let expr = boolean_expr(&aof, evaluator); - evaluator.gates.push(Gate::Arithmetic(expr)) + evaluator.opcodes.push(AcirOpcode::Arithmetic(expr)) } 2 => { let y = InternalVar::expression_to_witness( @@ -1358,7 +1380,7 @@ fn bound_constraint_with_offset( let two = FieldElement::from(2_i128); let y_expr = from_witness(y); let eee = subtract(&mul_with_witness(evaluator, &aof, &y_expr), two, &y_expr); - evaluator.gates.push(Gate::Arithmetic(eee)); + evaluator.opcodes.push(AcirOpcode::Arithmetic(eee)); } _ => unreachable!(), } diff --git a/crates/noirc_evaluator/src/ssa/builtin.rs b/crates/noirc_evaluator/src/ssa/builtin.rs index 41f7a7ca1d7..b6e4eebb772 100644 --- a/crates/noirc_evaluator/src/ssa/builtin.rs +++ b/crates/noirc_evaluator/src/ssa/builtin.rs @@ -1,4 +1,4 @@ -use acvm::{acir::OPCODE, FieldElement}; +use acvm::{acir::BlackBoxFunc, FieldElement}; use num_bigint::BigUint; use num_traits::{One, Zero}; @@ -6,7 +6,7 @@ use super::node::ObjectType; #[derive(Clone, Debug, Hash, Copy, PartialEq, Eq)] pub enum Opcode { - LowLevel(OPCODE), + LowLevel(BlackBoxFunc), ToBits, ToRadix, } @@ -22,7 +22,7 @@ impl Opcode { match op_name { "to_bits" => Some(Opcode::ToBits), "to_radix" => Some(Opcode::ToRadix), - _ => OPCODE::lookup(op_name).map(Opcode::LowLevel), + _ => BlackBoxFunc::lookup(op_name).map(Opcode::LowLevel), } } @@ -38,14 +38,14 @@ impl Opcode { match self { Opcode::LowLevel(op) => { match op { - OPCODE::SHA256 - | OPCODE::Blake2s - | OPCODE::Pedersen - | OPCODE::FixedBaseScalarMul => BigUint::zero(), //pointers do not overflow - OPCODE::SchnorrVerify | OPCODE::EcdsaSecp256k1 | OPCODE::MerkleMembership => { - BigUint::one() - } //verify returns 0 or 1 - OPCODE::HashToField => ObjectType::NativeField.max_size(), + BlackBoxFunc::SHA256 + | BlackBoxFunc::Blake2s + | BlackBoxFunc::Pedersen + | BlackBoxFunc::FixedBaseScalarMul => BigUint::zero(), //pointers do not overflow + BlackBoxFunc::SchnorrVerify + | BlackBoxFunc::EcdsaSecp256k1 + | BlackBoxFunc::MerkleMembership => BigUint::one(), //verify returns 0 or 1 + BlackBoxFunc::HashToField128Security => ObjectType::NativeField.max_size(), _ => todo!("max value must be implemented for opcode {} ", op), } } @@ -58,15 +58,18 @@ impl Opcode { match self { Opcode::LowLevel(op) => { match op { - OPCODE::AES => (0, ObjectType::NotAnObject), //Not implemented - OPCODE::SHA256 => (32, ObjectType::Unsigned(8)), - OPCODE::Blake2s => (32, ObjectType::Unsigned(8)), - OPCODE::HashToField => (1, ObjectType::NativeField), - OPCODE::MerkleMembership => (1, ObjectType::NativeField), //or bool? - OPCODE::SchnorrVerify => (1, ObjectType::NativeField), //or bool? - OPCODE::Pedersen => (2, ObjectType::NativeField), - OPCODE::EcdsaSecp256k1 => (1, ObjectType::NativeField), //field? - OPCODE::FixedBaseScalarMul => (2, ObjectType::NativeField), + BlackBoxFunc::AES => (0, ObjectType::NotAnObject), //Not implemented + BlackBoxFunc::SHA256 => (32, ObjectType::Unsigned(8)), + BlackBoxFunc::Blake2s => (32, ObjectType::Unsigned(8)), + BlackBoxFunc::HashToField128Security => (1, ObjectType::NativeField), + BlackBoxFunc::MerkleMembership => (1, ObjectType::NativeField), //or bool? + BlackBoxFunc::SchnorrVerify => (1, ObjectType::NativeField), //or bool? + BlackBoxFunc::Pedersen => (2, ObjectType::NativeField), + BlackBoxFunc::EcdsaSecp256k1 => (1, ObjectType::NativeField), //field? + BlackBoxFunc::FixedBaseScalarMul => (2, ObjectType::NativeField), + BlackBoxFunc::AND => (1, ObjectType::NativeField), + BlackBoxFunc::XOR => (1, ObjectType::NativeField), + BlackBoxFunc::RANGE => (0, ObjectType::NotAnObject), } } Opcode::ToBits => (FieldElement::max_num_bits(), ObjectType::Boolean), diff --git a/crates/noirc_evaluator/src/ssa/context.rs b/crates/noirc_evaluator/src/ssa/context.rs index 438585d81fb..2142747aefb 100644 --- a/crates/noirc_evaluator/src/ssa/context.rs +++ b/crates/noirc_evaluator/src/ssa/context.rs @@ -585,7 +585,7 @@ impl SsaContext { // Retrieve the object conresponding to the const value given in argument // If such object does not exist, we create one pub fn get_or_create_const(&mut self, x: FieldElement, t: node::ObjectType) -> NodeId { - let value = BigUint::from_bytes_be(&x.to_bytes()); //TODO a const should be a field element + let value = BigUint::from_bytes_be(&x.to_be_bytes()); //TODO a const should be a field element if let Some(prev_const) = self.find_const_with_type(&value, t) { return prev_const; } @@ -733,10 +733,10 @@ impl SsaContext { //ACIR self.acir(evaluator)?; if enable_logging { - Acir::print_circuit(&evaluator.gates); + Acir::print_circuit(&evaluator.opcodes); println!("DONE"); } - println!("ACIR gates generated : {}", evaluator.gates.len()); + println!("ACIR opcodes generated : {}", evaluator.opcodes.len()); Ok(()) } diff --git a/crates/noirc_evaluator/src/ssa/integer.rs b/crates/noirc_evaluator/src/ssa/integer.rs index c22993853b7..7ea4ed7a9a5 100644 --- a/crates/noirc_evaluator/src/ssa/integer.rs +++ b/crates/noirc_evaluator/src/ssa/integer.rs @@ -54,7 +54,7 @@ fn get_instruction_max_operand( //TODO uses interval analysis instead if matches!(ins.res_type, ObjectType::Unsigned(_)) { if let Some(lhs_const) = ctx.get_as_constant(*lhs) { - let lhs_big = BigUint::from_bytes_be(&lhs_const.to_bytes()); + let lhs_big = BigUint::from_bytes_be(&lhs_const.to_be_bytes()); if max_map[rhs] <= lhs_big { //TODO unsigned return lhs_big; @@ -486,7 +486,7 @@ fn get_max_value(ins: &Instruction, max_map: &mut HashMap) -> B }; if ins.res_type == ObjectType::NativeField { - let field_max = BigUint::from_bytes_be(&FieldElement::one().neg().to_bytes()); + let field_max = BigUint::from_bytes_be(&FieldElement::one().neg().to_be_bytes()); //Native Field operations cannot overflow so they will not be truncated if max_value >= field_max { diff --git a/crates/noirc_evaluator/src/ssa/mem.rs b/crates/noirc_evaluator/src/ssa/mem.rs index 6d44dc18136..2a40d502bad 100644 --- a/crates/noirc_evaluator/src/ssa/mem.rs +++ b/crates/noirc_evaluator/src/ssa/mem.rs @@ -94,7 +94,7 @@ impl Memory { } pub fn as_u32(value: FieldElement) -> u32 { - let big_v = BigUint::from_bytes_be(&value.to_bytes()); + let big_v = BigUint::from_bytes_be(&value.to_be_bytes()); let mut modulus = BigUint::from(2_u32); modulus = modulus.pow(32); let result = big_v % modulus; diff --git a/crates/noirc_evaluator/src/ssa/node.rs b/crates/noirc_evaluator/src/ssa/node.rs index 420208ac734..a15414013cb 100644 --- a/crates/noirc_evaluator/src/ssa/node.rs +++ b/crates/noirc_evaluator/src/ssa/node.rs @@ -232,7 +232,7 @@ impl ObjectType { pub fn max_size(&self) -> BigUint { match self { &ObjectType::NativeField => { - BigUint::from_bytes_be(&FieldElement::from(-1_i128).to_bytes()) + BigUint::from_bytes_be(&FieldElement::from(-1_i128).to_be_bytes()) } _ => (BigUint::one() << self.bits()) - BigUint::one(), } diff --git a/crates/noirc_frontend/Cargo.toml b/crates/noirc_frontend/Cargo.toml index 4074b245e89..35046dd9f71 100644 --- a/crates/noirc_frontend/Cargo.toml +++ b/crates/noirc_frontend/Cargo.toml @@ -7,7 +7,7 @@ edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -acvm = { git = "https://github.com/noir-lang/noir" } +acvm.workspace = true noirc_abi.workspace = true noirc_errors.workspace = true fm.workspace = true diff --git a/crates/noirc_frontend/src/node_interner.rs b/crates/noirc_frontend/src/node_interner.rs index 0754a9e345d..701f3f3f6d3 100644 --- a/crates/noirc_frontend/src/node_interner.rs +++ b/crates/noirc_frontend/src/node_interner.rs @@ -1,6 +1,6 @@ use std::collections::{BTreeMap, HashMap}; -use acvm::{CustomGate, Language}; +use acvm::Language; use arena::{Arena, Index}; use fm::FileId; use iter_extended::vecmap; @@ -546,7 +546,13 @@ impl NodeInterner { self.language = language.clone(); } + #[allow(deprecated)] pub fn foreign(&self, opcode: &str) -> bool { - self.language.supports(opcode) + let is_supported = acvm::default_is_blackbox_supported(self.language.clone()); + let black_box_func = match acvm::acir::BlackBoxFunc::lookup(opcode) { + Some(black_box_func) => black_box_func, + None => return false, + }; + is_supported(&black_box_func) } } diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index b380939fd25..c0fd22eb709 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -11,8 +11,8 @@ edition.workspace = true crate-type = ["cdylib"] [dependencies] -# Compile with bn254 field as a default for now -acvm = { path = "../acvm", features = ["bn254"] } + +acvm.workspace = true noirc_driver = { path = "../noirc_driver" } console_error_panic_hook.workspace = true diff --git a/noir_stdlib/src/hash.nr b/noir_stdlib/src/hash.nr index bf22c69f264..5a90df2069c 100644 --- a/noir_stdlib/src/hash.nr +++ b/noir_stdlib/src/hash.nr @@ -7,7 +7,7 @@ fn blake2s(_input : [u8]) -> [u8; 32] {} #[foreign(pedersen)] fn pedersen(_input : [Field]) -> [Field; 2] {} -#[foreign(hash_to_field)] +#[foreign(hash_to_field_128_security)] fn hash_to_field(_input : [Field]) -> Field {} // mimc-p/p implementation