diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fd9638665e2..1183cb75ce9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,43 +25,7 @@ permissions: contents: write jobs: - build-barretenberg: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ inputs.tag || env.GITHUB_REF }} - - - name: Collect locked barretenberg rev - run: | - echo "BB_REV=$(jq -r .nodes.barretenberg.locked.rev ./flake.lock)" >> $GITHUB_ENV - - - uses: cachix/install-nix-action@v20 - with: - nix_path: nixpkgs=channel:nixos-22.11 - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - uses: cachix/cachix-action@v12 - with: - name: barretenberg - - # Upload does not work with symlinks, using this workaround: - # https://github.com/actions/upload-artifact/issues/92#issuecomment-1080347032 - - name: Build barretenberg as libbarretenberg-wasm32 - run: | - nix build "github:AztecProtocol/barretenberg/${{ env.BB_REV }}#wasm32" - echo "ARTIFACT_UPLOAD_PATH=$(readlink -f result)" >> $GITHUB_ENV - - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ env.ARTIFACT_UPLOAD_PATH }} - retention-days: 3 - build-apple-darwin: - needs: [build-barretenberg] runs-on: macos-latest env: CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml @@ -94,22 +58,14 @@ jobs: path: ${{ env.CACHED_PATHS }} key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Download artifact - uses: actions/download-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ github.workspace }}/libbarretenberg-wasm32 - - name: Setup toolchain uses: dtolnay/rust-toolchain@1.66.0 with: targets: ${{ matrix.target }} - name: Build environment and Compile - env: - BARRETENBERG_BIN_DIR: ${{ github.workspace }}/libbarretenberg-wasm32/bin run: | - cargo build --package nargo_cli --release --target ${{ matrix.target }} --no-default-features --features "plonk_bn254_wasm ${{ inputs.features }}" + cargo build --package nargo_cli --release --target ${{ matrix.target }} --no-default-features --features "${{ inputs.features }}" - uses: actions/cache/save@v3 # Don't create cache entries for the merge queue. @@ -152,7 +108,6 @@ jobs: tag: ${{ inputs.tag || 'nightly' }} # This will fail if `inputs.tag` is not a tag (e.g. testing a branch) build-linux: - needs: [build-barretenberg] runs-on: ubuntu-22.04 env: CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml @@ -169,8 +124,6 @@ jobs: [ x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, - aarch64-unknown-linux-gnu, - aarch64-unknown-linux-musl, ] steps: @@ -185,23 +138,15 @@ jobs: path: ${{ env.CACHED_PATHS }} key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Download artifact - uses: actions/download-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ github.workspace }}/libbarretenberg-wasm32 - - name: Setup toolchain uses: dtolnay/rust-toolchain@1.66.0 with: targets: ${{ matrix.target }} - name: Build Nargo - env: - BARRETENBERG_BIN_DIR: ${{ github.workspace }}/libbarretenberg-wasm32/bin run: | cargo install cross --version 0.2.5 --force - cross build --package nargo_cli --release --target=${{ matrix.target }} --no-default-features --features "plonk_bn254_wasm ${{ inputs.features }}" + cross build --package nargo_cli --release --target=${{ matrix.target }} --no-default-features --features "${{ inputs.features }}" - uses: actions/cache/save@v3 # Don't create cache entries for the merge queue. @@ -242,87 +187,3 @@ jobs: asset_name: nargo-${{ matrix.target }}.tar.gz overwrite: true tag: ${{ inputs.tag || 'nightly' }} # This will fail if `inputs.tag` is not a tag (e.g. testing a branch) - - build-windows: - needs: [build-barretenberg] - runs-on: windows-2022 - env: - CROSS_CONFIG: ${{ github.workspace }}/.github/Cross.toml - CACHED_PATHS: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - strategy: - matrix: - target: [x86_64-pc-windows-msvc] - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - ref: ${{ inputs.tag || env.GITHUB_REF }} - - - uses: actions/cache/restore@v3 - id: cache - with: - path: ${{ env.CACHED_PATHS }} - key: ${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Download artifact - uses: actions/download-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ github.workspace }}/libbarretenberg-wasm32 - - - name: Setup toolchain - uses: dtolnay/rust-toolchain@1.66.0 - with: - targets: ${{ matrix.target }} - - - name: Build environment and Compile - env: - BARRETENBERG_BIN_DIR: ${{ github.workspace }}/libbarretenberg-wasm32/bin - run: | - cargo build --package nargo_cli --release --target ${{ matrix.target }} --no-default-features --features "plonk_bn254_wasm ${{ inputs.features }}" - - - uses: actions/cache/save@v3 - # Don't create cache entries for the merge queue. - if: ${{ steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} - with: - path: ${{ env.CACHED_PATHS }} - key: ${{ steps.cache.outputs.cache-primary-key }} - - - name: Package artifacts - run: | - mkdir dist - cp ./target/${{ matrix.target }}/release/nargo.exe ./dist/nargo.exe - 7z a -tzip nargo-${{ matrix.target }}.zip ./dist/* - - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: nargo-${{ matrix.target }} - path: ./dist/* - retention-days: 3 - - - name: Test built artifact - shell: powershell - run: | - cp ./target/${{ matrix.target }}/release/nargo.exe ~/.cargo/bin/ - - cd release-tests - yarn install - yarn test - - - name: Upload binaries to release tag - uses: svenstaro/upload-release-action@v2 - if: ${{ inputs.publish || github.event_name == 'schedule' }} - with: - repo_name: noir-lang/noir - repo_token: ${{ secrets.GITHUB_TOKEN }} - file: ./nargo-${{ matrix.target }}.zip - asset_name: nargo-${{ matrix.target }}.zip - overwrite: true - tag: ${{ inputs.tag || 'nightly' }} # This will fail if `inputs.tag` is not a tag (e.g. testing a branch) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23a6716ab59..4db556503f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,12 @@ jobs: runs-on: ${{ matrix.runner }} timeout-minutes: 30 env: - CACHED_PATH: /tmp/nix-cache + CACHED_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ strategy: fail-fast: false @@ -23,50 +28,30 @@ jobs: include: - os: ubuntu runner: ubuntu-latest - target: x86_64-linux + target: x86_64-unknown-linux-gnu steps: - name: Checkout uses: actions/checkout@v3 - - uses: cachix/install-nix-action@v22 - with: - nix_path: nixpkgs=channel:nixos-22.11 - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - uses: cachix/cachix-action@v12 - with: - name: barretenberg - - name: Restore nix store cache uses: actions/cache/restore@v3 id: cache with: - path: ${{ env.CACHED_PATH }} + path: ${{ env.CACHED_PATHS }} key: ${{ runner.os }}-flake-${{ hashFiles('*.lock') }} - # Based on https://github.com/marigold-dev/deku/blob/b5016f0cf4bf6ac48db9111b70dd7fb49b969dfd/.github/workflows/build.yml#L26 - - name: Copy cache into nix store - if: steps.cache.outputs.cache-hit == 'true' - # We don't check the signature because we're the one that created the cache - run: | - for narinfo in ${{ env.CACHED_PATH }}/*.narinfo; do - path=$(head -n 1 "$narinfo" | awk '{print $2}') - nix copy --no-check-sigs --from "file://${{ env.CACHED_PATH }}" "$path" - done - - - name: Run `nix flake check` - run: | - nix flake check -L + - name: Setup toolchain + uses: dtolnay/rust-toolchain@1.66.0 + with: + targets: ${{ matrix.target }} - - name: Export cache from nix store - if: ${{ always() && steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} - run: | - nix copy --to "file://${{ env.CACHED_PATH }}?compression=zstd¶llel-compression=true" .#native-cargo-artifacts + - name: Run tests + run: cargo test --workspace --locked --release - uses: actions/cache/save@v3 # Write a cache entry even if the tests fail but don't create any for the merge queue. if: ${{ always() && steps.cache.outputs.cache-hit != 'true' && github.event_name != 'merge_group' }} with: - path: ${{ env.CACHED_PATH }} + path: ${{ env.CACHED_PATHS }} key: ${{ steps.cache.outputs.cache-primary-key }} diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index ecf2fab06ba..3a451f9d957 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -9,45 +9,7 @@ concurrency: cancel-in-progress: true jobs: - # TODO: Replace this step with downloading a wasm binary from a set release of Barretenberg - build-barretenberg: - runs-on: ubuntu-latest - steps: - - name: Checkout Noir repo - uses: actions/checkout@v3 - - - name: Collect locked barretenberg rev - run: | - echo "BB_REV=$(jq -r .nodes.barretenberg.locked.rev ./flake.lock)" >> $GITHUB_ENV - echo "BB_REV is ${{ env.BB_REV }}" - - - uses: cachix/install-nix-action@v20 - with: - nix_path: nixpkgs=channel:nixos-22.11 - github_access_token: ${{ secrets.GITHUB_TOKEN }} - - - uses: cachix/cachix-action@v12 - with: - name: barretenberg - authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - # Upload does not work with symlinks, using this workaround: - # https://github.com/actions/upload-artifact/issues/92#issuecomment-1080347032 - - name: Build barretenberg as libbarretenberg-wasm32 - run: | - echo "BB_REV is ${{ env.BB_REV }}" - nix build "github:AztecProtocol/barretenberg/${{ env.BB_REV }}#wasm32" - echo "ARTIFACT_UPLOAD_PATH=$(readlink -f result)" >> $GITHUB_ENV - - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ env.ARTIFACT_UPLOAD_PATH }} - retention-days: 3 - build-nargo: - needs: [build-barretenberg] runs-on: ubuntu-22.04 env: CACHED_PATHS: | @@ -67,20 +29,11 @@ jobs: path: ${{ env.CACHED_PATHS }} key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Download artifact - uses: actions/download-artifact@v3 - with: - name: libbarretenberg-wasm32 - path: ${{ github.workspace }}/libbarretenberg-wasm32 - - name: Setup toolchain uses: dtolnay/rust-toolchain@1.66.0 - name: Build Nargo - env: - BARRETENBERG_BIN_DIR: ${{ github.workspace }}/libbarretenberg-wasm32/bin - run: | - cargo build --package nargo_cli --release --no-default-features --features plonk_bn254_wasm + run: cargo build --package nargo_cli --release - uses: actions/cache/save@v3 # Don't create cache entries for the merge queue. diff --git a/Cargo.lock b/Cargo.lock index c323c50adf0..00f51294521 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "acir" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86577747c44f23e2e8e6d972287d01341c0eea42a78ce15c5efd212a39d0fc27" +checksum = "2dab15381940b2eb3ecca70e78adcfb547df5b49123b2872c2333b0ee965beae" dependencies = [ "acir_field", "bincode", @@ -18,9 +18,9 @@ dependencies = [ [[package]] name = "acir_field" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4239156a8eddd55b2ae8bd25aa169d012bae70e0fd7c635f08f68ada54a8cb6c" +checksum = "16ae84a2d0f6e5087a499c56d41ca8227fd26abea01b527694c601b230b27111" dependencies = [ "ark-bn254", "ark-ff", @@ -32,14 +32,13 @@ dependencies = [ [[package]] name = "acvm" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74351bab6e0fd2ec1bd631abc73260f374cc28d2baf85c0e11300c0c989d5e53" +checksum = "1cc5bd62182c728ec5d3a080319765b0c86f294fc74f90fd6657008ae789d797" dependencies = [ "acir", "acvm_blackbox_solver", "acvm_stdlib", - "async-trait", "brillig_vm", "indexmap 1.9.3", "num-bigint", @@ -49,44 +48,51 @@ dependencies = [ [[package]] name = "acvm-backend-barretenberg" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "438eb3837cfc37e0798e18f4a0ebae595e4cbe32a3f4cecfb47ccc1354180dc8" +checksum = "8b2c96a9e4ea5b057e027b6f673dfd78260046aef67bdfcd867480575baa1d53" dependencies = [ "acvm", - "barretenberg-sys", - "bincode", - "bytesize", - "getrandom", - "pkg-config", + "base64", + "build-target", + "const_format", + "dirs 5.0.1", + "flate2", "reqwest", - "rust-embed", - "serde", - "serde-big-array", + "tar", + "tempfile", "thiserror", - "wasmer", ] [[package]] name = "acvm_blackbox_solver" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a362499180c6498acc0ebf77bd919be8ccd9adabc84a695d4af44ca180ba0709" +checksum = "b79e031466b5075260257a61359eb9775c5ef92dce27621af1c36bfd0a6eb511" dependencies = [ "acir", "blake2", + "flate2", + "getrandom", + "js-sys", "k256", "p256", + "pkg-config", + "reqwest", + "rust-embed", "sha2", "sha3", + "tar", "thiserror", + "wasm-bindgen-futures", + "wasmer", ] [[package]] name = "acvm_stdlib" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e485b3bc3331eaa10bc92fb092ca14275936c8935c3ae7ec89fb0bd48246ab42" +checksum = "1389b884c07b5eb0c15e5f5395317de060bcf1a6a5f476893c4d65f50de5de1f" dependencies = [ "acir", ] @@ -388,17 +394,6 @@ dependencies = [ "waitpid-any", ] -[[package]] -name = "async-trait" -version = "0.1.71" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a564d521dd56509c4c47480d00b80ee55f7e385ae48db5744c67ad50c92d2ebf" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.26", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -420,20 +415,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "barretenberg-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f8fd58d1ca43e920a1a3b55d52c65ac25cd29f2820d4b2b1c24adafa2c403c" -dependencies = [ - "bindgen", - "cc", - "color-eyre", - "link-cplusplus", - "pkg-config", - "thiserror", -] - [[package]] name = "base16ct" version = "0.1.1" @@ -461,28 +442,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bindgen" -version = "0.64.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn 1.0.109", - "which", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -536,9 +495,9 @@ dependencies = [ [[package]] name = "brillig" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d64df3df7d2d96fc2519e4dd64bc6bc23eee2949ee86725d9041ef7703c283ab" +checksum = "dd5fe44d05264a0d9a6d5c5dca8a6c976f3fcdfdfb0244d75e458bf13fcb8f21" dependencies = [ "acir_field", "serde", @@ -546,9 +505,9 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b306b3d79b6da192fd2ed68b94ab07712496f39bb5d50fedce44dac3f4953065" +checksum = "733be2c7fea117e0b0be985b9b99c15aeca01fb342528fac9c3f70a7f844ec50" dependencies = [ "acir", "acvm_blackbox_solver", @@ -578,6 +537,12 @@ dependencies = [ "safe-regex", ] +[[package]] +name = "build-target" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "832133bbabbbaa9fbdba793456a2827627a7d2b8fb96032fa1e7666d7895832b" + [[package]] name = "bumpalo" version = "3.13.0" @@ -624,12 +589,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" -[[package]] -name = "bytesize" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" - [[package]] name = "cast" version = "0.3.0" @@ -642,15 +601,6 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.0" @@ -709,17 +659,6 @@ dependencies = [ "half", ] -[[package]] -name = "clang-sys" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "clap" version = "4.3.19" @@ -1223,7 +1162,16 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys 0.4.1", ] [[package]] @@ -1247,6 +1195,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1420,6 +1380,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "filetime" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "windows-sys 0.48.0", +] + [[package]] name = "findshlibs" version = "0.10.2" @@ -1626,12 +1598,6 @@ version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "globset" version = "0.4.11" @@ -2051,12 +2017,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "leb128" version = "0.2.5" @@ -2069,25 +2029,6 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" -[[package]] -name = "libloading" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" -dependencies = [ - "cfg-if", - "winapi", -] - -[[package]] -name = "link-cplusplus" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" -dependencies = [ - "cc", -] - [[package]] name = "linux-raw-sys" version = "0.3.8" @@ -2190,12 +2131,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -2254,7 +2189,7 @@ dependencies = [ "color-eyre", "const_format", "criterion", - "dirs", + "dirs 4.0.0", "fm", "hex", "iai", @@ -2286,7 +2221,7 @@ dependencies = [ name = "nargo_toml" version = "0.10.5" dependencies = [ - "dirs", + "dirs 4.0.0", "fm", "nargo", "noirc_frontend", @@ -2437,16 +2372,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -2524,6 +2449,12 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "owo-colors" version = "3.5.0" @@ -2570,12 +2501,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - [[package]] name = "percent-encoding" version = "2.3.0" @@ -3348,15 +3273,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-big-array" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" -dependencies = [ - "serde", -] - [[package]] name = "serde-wasm-bindgen" version = "0.4.5" @@ -3487,15 +3403,9 @@ version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ccc8076840c4da029af4f87e4e8daeb0fca6b87bbb02e10cb60b791450e11e4" dependencies = [ - "dirs", + "dirs 4.0.0", ] -[[package]] -name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - [[package]] name = "signature" version = "1.6.4" @@ -3700,6 +3610,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "target-lexicon" version = "0.12.10" @@ -3861,6 +3782,7 @@ dependencies = [ "bytes", "libc", "mio", + "num_cpus", "pin-project-lite", "socket2", "tokio-macros", @@ -4287,6 +4209,8 @@ dependencies = [ "wasmer-derive", "wasmer-types", "wasmer-vm", + "wasmparser 0.83.0", + "wasmparser 0.95.0", "wat", "winapi", ] @@ -4310,7 +4234,7 @@ dependencies = [ "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser", + "wasmparser 0.95.0", "winapi", ] @@ -4388,6 +4312,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "wasmparser" +version = "0.83.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" + [[package]] name = "wasmparser" version = "0.95.0" @@ -4448,17 +4378,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "which" -version = "4.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" -dependencies = [ - "either", - "libc", - "once_cell", -] - [[package]] name = "winapi" version = "0.3.9" @@ -4635,6 +4554,15 @@ dependencies = [ "tap", ] +[[package]] +name = "xattr" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4686009f71ff3e5c4dbcf1a282d0a44db3f021ba69350cd42086b3e5f1c6985" +dependencies = [ + "libc", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 8addf94e93f..fe383867bed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "crates/wasm", ] default-members = ["crates/nargo_cli"] +resolver = "2" [workspace.package] # x-release-please-start-version @@ -26,7 +27,7 @@ edition = "2021" rust-version = "1.66" [workspace.dependencies] -acvm = "0.22.0" +acvm = "0.23.0" arena = { path = "crates/arena" } fm = { path = "crates/fm" } iter-extended = { path = "crates/iter-extended" } @@ -58,4 +59,4 @@ tower = "0.4" url = "2.2.0" wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] } wasm-bindgen-test = "0.3.33" -base64 = "0.21.2" \ No newline at end of file +base64 = "0.21.2" diff --git a/crates/nargo/src/ops/codegen_verifier.rs b/crates/nargo/src/ops/codegen_verifier.rs index 851f735ae55..5893854ce22 100644 --- a/crates/nargo/src/ops/codegen_verifier.rs +++ b/crates/nargo/src/ops/codegen_verifier.rs @@ -2,9 +2,10 @@ use acvm::{acir::circuit::Circuit, SmartContract}; pub fn codegen_verifier( backend: &B, - common_reference_string: &[u8], circuit: &Circuit, - verification_key: &[u8], ) -> Result { - backend.eth_contract_from_vk(common_reference_string, circuit, verification_key) + // Nargo no longer handles logic related to proving/verifying with keys or the CRS. + let common_reference_string = Vec::new(); + let verification_key = Vec::new(); + backend.eth_contract_from_vk(&common_reference_string, circuit, &verification_key) } diff --git a/crates/nargo/src/ops/execute.rs b/crates/nargo/src/ops/execute.rs index 2a126443468..3914215de95 100644 --- a/crates/nargo/src/ops/execute.rs +++ b/crates/nargo/src/ops/execute.rs @@ -6,13 +6,13 @@ use crate::NargoError; use super::foreign_calls::ForeignCall; -pub fn execute_circuit( - _backend: &B, +pub fn execute_circuit( + blackbox_solver: &B, circuit: Circuit, initial_witness: WitnessMap, show_output: bool, ) -> Result { - let mut acvm = ACVM::new(B::default(), circuit.opcodes, initial_witness); + let mut acvm = ACVM::new(blackbox_solver, circuit.opcodes, initial_witness); loop { let solver_status = acvm.solve(); diff --git a/crates/nargo/src/ops/prove.rs b/crates/nargo/src/ops/prove.rs index 16839a1b060..e881d3c3043 100644 --- a/crates/nargo/src/ops/prove.rs +++ b/crates/nargo/src/ops/prove.rs @@ -3,11 +3,12 @@ use acvm::ProofSystemCompiler; pub fn prove_execution( backend: &B, - common_reference_string: &[u8], circuit: &Circuit, solved_witness: WitnessMap, - proving_key: &[u8], ) -> Result, B::Error> { // TODO(#1569): update from not just accepting `false` once we get nargo to interop with dynamic backend - backend.prove_with_pk(common_reference_string, circuit, solved_witness, proving_key, false) + // Nargo no longer handles logic related to proving/verifying with keys or the CRS. + let common_reference_string = Vec::new(); + let proving_key = Vec::new(); + backend.prove_with_pk(&common_reference_string, circuit, solved_witness, &proving_key, false) } diff --git a/crates/nargo/src/ops/test.rs b/crates/nargo/src/ops/test.rs index 9ac3fa46f35..93bd72a7b2e 100644 --- a/crates/nargo/src/ops/test.rs +++ b/crates/nargo/src/ops/test.rs @@ -11,8 +11,8 @@ pub enum TestStatus { CompileError(FileDiagnostic), } -pub fn run_test( - backend: &B, +pub fn run_test( + blackbox_solver: &B, context: &Context, test_function: TestFunction, show_output: bool, @@ -24,7 +24,7 @@ pub fn run_test( // Run the backend to ensure the PWG evaluates functions like std::hash::pedersen, // otherwise constraints involving these expressions will not error. let circuit_execution = - execute_circuit(backend, program.circuit, WitnessMap::new(), show_output); + execute_circuit(blackbox_solver, program.circuit, WitnessMap::new(), show_output); if test_function.should_fail() { match circuit_execution { diff --git a/crates/nargo/src/ops/verify.rs b/crates/nargo/src/ops/verify.rs index 4cc6c9ce34b..2d8d9c40d6c 100644 --- a/crates/nargo/src/ops/verify.rs +++ b/crates/nargo/src/ops/verify.rs @@ -3,19 +3,20 @@ use acvm::ProofSystemCompiler; pub fn verify_proof( backend: &B, - common_reference_string: &[u8], circuit: &Circuit, proof: &[u8], public_inputs: WitnessMap, - verification_key: &[u8], ) -> Result { // TODO(#1569): update from not just accepting `false` once we get nargo to interop with dynamic backend + // Nargo no longer handles logic related to proving/verifying with keys or the CRS. + let common_reference_string = Vec::new(); + let verification_key = Vec::new(); backend.verify_with_vk( - common_reference_string, + &common_reference_string, proof, public_inputs, circuit, - verification_key, + &verification_key, false, ) } diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index ef1cbf70621..a7a0ae5786c 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -49,7 +49,7 @@ tokio = { version = "1.0", features = ["io-std"] } tokio-util = { version = "0.7.8", features = ["compat"] } # Backends -acvm-backend-barretenberg = { version = "0.11.0", default-features = false } +acvm-backend-barretenberg = "0.12.0" [dev-dependencies] tempdir = "0.3.7" @@ -73,9 +73,3 @@ harness = false [[bench]] name = "iai" harness = false - -[features] -default = ["plonk_bn254"] -# The plonk backend can only use bn254, so we do not specify the field -plonk_bn254 = ["acvm-backend-barretenberg/native"] -plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"] \ No newline at end of file diff --git a/crates/nargo_cli/build.rs b/crates/nargo_cli/build.rs index 629d6fea340..5a5616e21aa 100644 --- a/crates/nargo_cli/build.rs +++ b/crates/nargo_cli/build.rs @@ -115,7 +115,8 @@ fn compile_success_empty_{test_name}() {{ .and(predicate::str::contains("| Language")) .and(predicate::str::contains("| ACIR Opcodes | Backend Circuit Size |")) .and(predicate::str::contains("| PLONKCSat {{ width: 3 }} |")) - .and(predicate::str::contains("| 0 | 1 |"))); + // This currently matches on there being zero acir opcodes due to the width of the cell. + .and(predicate::str::contains("| 0 |"))); }} "#, test_dir = test_dir.display(), diff --git a/crates/nargo_cli/src/backends.rs b/crates/nargo_cli/src/backends.rs index bbec5c99006..71ff5a0c73a 100644 --- a/crates/nargo_cli/src/backends.rs +++ b/crates/nargo_cli/src/backends.rs @@ -1,9 +1 @@ pub(crate) use acvm_backend_barretenberg::Barretenberg as ConcreteBackend; - -#[cfg(not(any(feature = "plonk_bn254", feature = "plonk_bn254_wasm")))] -compile_error!("please specify a backend to compile with"); - -#[cfg(all(feature = "plonk_bn254", feature = "plonk_bn254_wasm"))] -compile_error!( - "feature \"plonk_bn254\" and feature \"plonk_bn254_wasm\" cannot be enabled at the same time" -); diff --git a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs index 8f6f613897b..04c7114a565 100644 --- a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -3,15 +3,7 @@ use std::path::PathBuf; use super::NargoConfig; use super::{ compile_cmd::compile_package, - fs::{ - common_reference_string::{ - read_cached_common_reference_string, update_common_reference_string, - write_cached_common_reference_string, - }, - create_named_dir, - program::read_program_from_file, - write_to_file, - }, + fs::{create_named_dir, program::read_program_from_file, write_to_file}, }; use crate::errors::CliError; use acvm::Backend; @@ -90,27 +82,8 @@ fn smart_contract_for_package( } }; - let common_reference_string = read_cached_common_reference_string(); - let common_reference_string = update_common_reference_string( - backend, - &common_reference_string, - &preprocessed_program.bytecode, - ) - .map_err(CliError::CommonReferenceStringError)?; - - let (_, verification_key) = backend - .preprocess(&common_reference_string, &preprocessed_program.bytecode) - .map_err(CliError::ProofSystemCompilerError)?; - - let smart_contract_string = codegen_verifier( - backend, - &common_reference_string, - &preprocessed_program.bytecode, - &verification_key, - ) - .map_err(CliError::SmartContractError)?; - - write_cached_common_reference_string(&common_reference_string); + let smart_contract_string = codegen_verifier(backend, &preprocessed_program.bytecode) + .map_err(CliError::SmartContractError)?; Ok(smart_contract_string) } diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index 878d27362a7..ba6da305721 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -1,5 +1,5 @@ use acvm::{acir::circuit::Circuit, compiler::AcirTransformationMap, Backend}; -use iter_extended::try_vecmap; +use iter_extended::{try_vecmap, vecmap}; use nargo::artifacts::contract::PreprocessedContractFunction; use nargo::artifacts::debug::DebugArtifact; use nargo::artifacts::program::PreprocessedProgram; @@ -19,13 +19,8 @@ use clap::Args; use crate::errors::{CliError, CompileError}; -use super::fs::program::save_debug_artifact_to_file; -use super::fs::{ - common_reference_string::{ - read_cached_common_reference_string, update_common_reference_string, - write_cached_common_reference_string, - }, - program::{save_contract_to_file, save_program_to_file}, +use super::fs::program::{ + save_contract_to_file, save_debug_artifact_to_file, save_program_to_file, }; use super::NargoConfig; @@ -67,8 +62,6 @@ pub(crate) fn run( let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let circuit_dir = workspace.target_directory_path(); - let mut common_reference_string = read_cached_common_reference_string(); - for package in &workspace { let (mut context, crate_id) = prepare_package(package); // If `contract` package type, we're compiling every function in a 'contract' rather than just 'main'. @@ -82,44 +75,35 @@ pub(crate) fn run( // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) // are compiled via nargo-core and then the PreprocessedContract is constructed here. // This is due to EACH function needing it's own CRS, PKey, and VKey from the backend. - let preprocessed_contracts: Result< - Vec<(PreprocessedContract, Vec)>, - CliError, - > = try_vecmap(optimized_contracts, |contract| { - let preprocess_result = try_vecmap(contract.functions, |func| { - common_reference_string = update_common_reference_string( - backend, - &common_reference_string, - &func.bytecode, - ) - .map_err(CliError::CommonReferenceStringError)?; - - Ok::<_, CliError>(( - PreprocessedContractFunction { - name: func.name, - function_type: func.function_type, - is_internal: func.is_internal, - abi: func.abi, - - bytecode: func.bytecode, + let preprocessed_contracts: Vec<(PreprocessedContract, Vec)> = + vecmap(optimized_contracts, |contract| { + let preprocess_result = vecmap(contract.functions, |func| { + ( + PreprocessedContractFunction { + name: func.name, + function_type: func.function_type, + is_internal: func.is_internal, + abi: func.abi, + + bytecode: func.bytecode, + }, + func.debug, + ) + }); + + let (preprocessed_contract_functions, debug_infos): (Vec<_>, Vec<_>) = + preprocess_result.into_iter().unzip(); + + ( + PreprocessedContract { + name: contract.name, + backend: String::from(BACKEND_IDENTIFIER), + functions: preprocessed_contract_functions, }, - func.debug, - )) - })?; - - let (preprocessed_contract_functions, debug_infos): (Vec<_>, Vec<_>) = - preprocess_result.into_iter().unzip(); - - Ok(( - PreprocessedContract { - name: contract.name, - backend: String::from(BACKEND_IDENTIFIER), - functions: preprocessed_contract_functions, - }, - debug_infos, - )) - }); - for (contract, debug_infos) in preprocessed_contracts? { + debug_infos, + ) + }); + for (contract, debug_infos) in preprocessed_contracts { save_contract_to_file( &contract, &format!("{}-{}", package.name, contract.name), @@ -138,10 +122,6 @@ pub(crate) fn run( } else { let (context, program) = compile_package(backend, package, &args.compile_options)?; - common_reference_string = - update_common_reference_string(backend, &common_reference_string, &program.circuit) - .map_err(CliError::CommonReferenceStringError)?; - let preprocessed_program = PreprocessedProgram { backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, @@ -158,8 +138,6 @@ pub(crate) fn run( } } - write_cached_common_reference_string(&common_reference_string); - Ok(()) } diff --git a/crates/nargo_cli/src/cli/execute_cmd.rs b/crates/nargo_cli/src/cli/execute_cmd.rs index 0a391ac71a8..30ba6e28322 100644 --- a/crates/nargo_cli/src/cli/execute_cmd.rs +++ b/crates/nargo_cli/src/cli/execute_cmd.rs @@ -162,14 +162,19 @@ fn report_error_with_opcode_location( } pub(crate) fn execute_program( - backend: &B, + _backend: &B, circuit: Circuit, abi: &Abi, inputs_map: &InputMap, debug_data: Option<(DebugInfo, Context)>, ) -> Result> { + #[allow(deprecated)] + let blackbox_solver = acvm::blackbox_solver::BarretenbergSolver::new(); + let initial_witness = abi.encode(inputs_map, None)?; - let solved_witness_err = nargo::ops::execute_circuit(backend, circuit, initial_witness, true); + + let solved_witness_err = + nargo::ops::execute_circuit(&blackbox_solver, circuit, initial_witness, true); match solved_witness_err { Ok(solved_witness) => Ok(solved_witness), Err(err) => { diff --git a/crates/nargo_cli/src/cli/fs/common_reference_string.rs b/crates/nargo_cli/src/cli/fs/common_reference_string.rs deleted file mode 100644 index a22c819d402..00000000000 --- a/crates/nargo_cli/src/cli/fs/common_reference_string.rs +++ /dev/null @@ -1,55 +0,0 @@ -use std::{env, path::PathBuf}; - -use acvm::{acir::circuit::Circuit, CommonReferenceString}; - -use super::{create_named_dir, write_to_file}; - -// TODO(#1388): pull this from backend. -const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; -const TRANSCRIPT_NAME: &str = "common-reference-string.bin"; - -fn common_reference_string_location() -> PathBuf { - let cache_dir = match env::var("NARGO_BACKEND_CACHE_DIR") { - Ok(cache_dir) => PathBuf::from(cache_dir), - Err(_) => dirs::home_dir().unwrap().join(".nargo").join("backends"), - }; - cache_dir.join(BACKEND_IDENTIFIER).join(TRANSCRIPT_NAME) -} - -pub(crate) fn read_cached_common_reference_string() -> Vec { - let crs_path = common_reference_string_location(); - - // TODO(#1390): Implement checksum - match std::fs::read(crs_path) { - Ok(common_reference_string) => common_reference_string, - Err(_) => vec![], - } -} - -pub(crate) fn update_common_reference_string( - backend: &B, - common_reference_string: &[u8], - circuit: &Circuit, -) -> Result, B::Error> { - use tokio::runtime::Builder; - - let runtime = Builder::new_current_thread().enable_all().build().unwrap(); - - // TODO(#1391): Implement retries - // If the read data is empty, we don't have a CRS and need to generate one - let fut = if common_reference_string.is_empty() { - backend.generate_common_reference_string(circuit) - } else { - backend.update_common_reference_string(common_reference_string.to_vec(), circuit) - }; - - runtime.block_on(fut) -} - -pub(crate) fn write_cached_common_reference_string(common_reference_string: &[u8]) { - let crs_path = common_reference_string_location(); - - create_named_dir(crs_path.parent().unwrap(), "crs"); - - write_to_file(common_reference_string, &crs_path); -} diff --git a/crates/nargo_cli/src/cli/fs/mod.rs b/crates/nargo_cli/src/cli/fs/mod.rs index 73229e0476c..4ebce3b3325 100644 --- a/crates/nargo_cli/src/cli/fs/mod.rs +++ b/crates/nargo_cli/src/cli/fs/mod.rs @@ -6,7 +6,6 @@ use std::{ use crate::errors::FilesystemError; -pub(super) mod common_reference_string; pub(super) mod inputs; pub(super) mod program; pub(super) mod proof; diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 2603db3ce19..030eb114541 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -74,7 +74,7 @@ pub(crate) fn start_cli() -> eyre::Result<()> { config.program_dir = find_package_root(&config.program_dir)?; } - let backend = crate::backends::ConcreteBackend::default(); + let backend = crate::backends::ConcreteBackend; match command { NargoCommand::New(args) => new_cmd::run(&backend, args, config), diff --git a/crates/nargo_cli/src/cli/prove_cmd.rs b/crates/nargo_cli/src/cli/prove_cmd.rs index 2f647123629..2ec1df2fdd4 100644 --- a/crates/nargo_cli/src/cli/prove_cmd.rs +++ b/crates/nargo_cli/src/cli/prove_cmd.rs @@ -12,9 +12,7 @@ use noirc_driver::CompileOptions; use noirc_frontend::graph::CrateName; use super::compile_cmd::compile_package; -use super::fs::common_reference_string::update_common_reference_string; use super::fs::{ - common_reference_string::read_cached_common_reference_string, inputs::{read_inputs_from_file, write_inputs_to_file}, program::read_program_from_file, proof::save_proof_to_dir, @@ -107,18 +105,6 @@ pub(crate) fn prove_package( (preprocessed_program, Some((program.debug, context))) }; - let common_reference_string = read_cached_common_reference_string(); - let common_reference_string = update_common_reference_string( - backend, - &common_reference_string, - &preprocessed_program.bytecode, - ) - .map_err(CliError::CommonReferenceStringError)?; - - let (proving_key, verification_key) = backend - .preprocess(&common_reference_string, &preprocessed_program.bytecode) - .map_err(CliError::ProofSystemCompilerError)?; - let PreprocessedProgram { abi, bytecode, .. } = preprocessed_program; // Parse the initial witness values from Prover.toml @@ -140,21 +126,13 @@ pub(crate) fn prove_package( Format::Toml, )?; - let proof = - prove_execution(backend, &common_reference_string, &bytecode, solved_witness, &proving_key) - .map_err(CliError::ProofSystemCompilerError)?; + let proof = prove_execution(backend, &bytecode, solved_witness) + .map_err(CliError::ProofSystemCompilerError)?; if check_proof { let public_inputs = public_abi.encode(&public_inputs, return_value)?; - let valid_proof = verify_proof( - backend, - &common_reference_string, - &bytecode, - &proof, - public_inputs, - &verification_key, - ) - .map_err(CliError::ProofSystemCompilerError)?; + let valid_proof = verify_proof(backend, &bytecode, &proof, public_inputs) + .map_err(CliError::ProofSystemCompilerError)?; if !valid_proof { return Err(CliError::InvalidProof("".into())); diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 2369e172377..a37766ad152 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -1,6 +1,6 @@ use std::io::Write; -use acvm::Backend; +use acvm::{Backend, BlackBoxFunctionSolver}; use clap::Args; use nargo::{ ops::{run_test, TestStatus}, @@ -43,7 +43,7 @@ pub(crate) struct TestCommand { } pub(crate) fn run( - backend: &B, + _backend: &B, args: TestCommand, config: NargoConfig, ) -> Result<(), CliError> { @@ -64,17 +64,19 @@ pub(crate) fn run( None => FunctionNameMatch::Anything, }; + #[allow(deprecated)] + let blackbox_solver = acvm::blackbox_solver::BarretenbergSolver::new(); for package in &workspace { // By unwrapping here with `?`, we stop the test runner upon a package failing // TODO: We should run the whole suite even if there are failures in a package - run_tests(backend, package, pattern, args.show_output, &args.compile_options)?; + run_tests(&blackbox_solver, package, pattern, args.show_output, &args.compile_options)?; } Ok(()) } -fn run_tests( - backend: &B, +fn run_tests( + blackbox_solver: &S, package: &Package, test_name: FunctionNameMatch, show_output: bool, @@ -96,7 +98,7 @@ fn run_tests( .expect("Failed to write to stdout"); writer.flush().expect("Failed to flush writer"); - match run_test(backend, &context, test_function, show_output, compile_options) { + match run_test(blackbox_solver, &context, test_function, show_output, compile_options) { TestStatus::Pass { .. } => { writer .set_color(ColorSpec::new().set_fg(Some(Color::Green))) diff --git a/crates/nargo_cli/src/cli/verify_cmd.rs b/crates/nargo_cli/src/cli/verify_cmd.rs index c13bb9cdafa..dfae743c0c7 100644 --- a/crates/nargo_cli/src/cli/verify_cmd.rs +++ b/crates/nargo_cli/src/cli/verify_cmd.rs @@ -1,6 +1,3 @@ -use super::fs::common_reference_string::{ - read_cached_common_reference_string, update_common_reference_string, -}; use super::NargoConfig; use super::{ compile_cmd::compile_package, @@ -91,18 +88,6 @@ fn verify_package( } }; - let common_reference_string = read_cached_common_reference_string(); - let common_reference_string = update_common_reference_string( - backend, - &common_reference_string, - &preprocessed_program.bytecode, - ) - .map_err(CliError::CommonReferenceStringError)?; - - let (_, verification_key) = backend - .preprocess(&common_reference_string, &preprocessed_program.bytecode) - .map_err(CliError::ProofSystemCompilerError)?; - let PreprocessedProgram { abi, bytecode, .. } = preprocessed_program; // Load public inputs (if any) from `verifier_name`. @@ -113,15 +98,8 @@ fn verify_package( let public_inputs = public_abi.encode(&public_inputs_map, return_value)?; let proof = load_hex_data(proof_path)?; - let valid_proof = verify_proof( - backend, - &common_reference_string, - &bytecode, - &proof, - public_inputs, - &verification_key, - ) - .map_err(CliError::ProofSystemCompilerError)?; + let valid_proof = verify_proof(backend, &bytecode, &proof, public_inputs) + .map_err(CliError::ProofSystemCompilerError)?; if valid_proof { Ok(()) diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index dade4262431..ac59576692b 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -1,7 +1,4 @@ -use acvm::{ - acir::native_types::WitnessMapError, Backend, CommonReferenceString, ProofSystemCompiler, - SmartContract, -}; +use acvm::{acir::native_types::WitnessMapError, Backend, ProofSystemCompiler, SmartContract}; use hex::FromHexError; use nargo::NargoError; use nargo_toml::ManifestError; @@ -74,10 +71,6 @@ pub(crate) enum CliError { /// Backend error caused by a function on the ProofSystemCompiler trait #[error(transparent)] ProofSystemCompilerError(::Error), // Unfortunately, Rust won't let us `impl From` over an Associated Type on a generic - - /// Backend error caused by a function on the CommonReferenceString trait - #[error(transparent)] - CommonReferenceStringError(::Error), // Unfortunately, Rust won't let us `impl From` over an Associated Type on a generic } /// Errors covering situations where a package cannot be compiled. diff --git a/flake.nix b/flake.nix index 1117025745e..2bdddaad263 100644 --- a/flake.nix +++ b/flake.nix @@ -76,6 +76,11 @@ sharedEnvironment = { # We enable backtraces on any failure for help with debugging RUST_BACKTRACE = "1"; + + BARRETENBERG_ARCHIVE = builtins.fetchurl { + url = "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.5/acvm_backend.wasm.tar.gz"; + sha256 = "sha256:0z24yhvxc0dr13xj7y4xs9p42lzxwpazrmsrdpcgynfajkk6vqy4"; + }; }; nativeEnvironment = sharedEnvironment // { @@ -113,6 +118,12 @@ # Need libiconv and apple Security on Darwin. See https://github.com/ipetkov/crane/issues/156 pkgs.libiconv pkgs.darwin.apple_sdk.frameworks.Security + ] ++ [ + # Need to install various packages used by the `bb` binary. + pkgs.curl + stdenv.cc.cc.lib + pkgs.gcc.cc.lib + pkgs.gzip ]; sharedArgs = { @@ -144,6 +155,9 @@ pkgs.pkg-config # This provides the `lld` linker to cargo pkgs.llvmPackages.bintools + ] ++ pkgs.lib.optionals stdenv.isLinux [ + # This is linux specific and used to patch the rpath and interpreter of the bb binary + pkgs.patchelf ]; buildInputs = [ @@ -152,16 +166,6 @@ ] ++ extraBuildInputs; }; - # Combine the environment and other configuration needed for crane to build with the wasm feature - wasmArgs = wasmEnvironment // sharedArgs // { - pname = "noir-wasm"; - - # We disable the default "plonk_bn254" feature and enable the "plonk_bn254_wasm" feature - cargoExtraArgs = "--no-default-features --features='plonk_bn254_wasm'"; - - buildInputs = [ ] ++ extraBuildInputs; - }; - # Combine the environmnet with cargo args needed to build wasm package noirWasmArgs = sharedEnvironment // sharedArgs // { pname = "noir_wasm"; @@ -175,11 +179,35 @@ doCheck = false; }; + # Conditionally download the binary based on whether it is linux or mac + bb_binary = let + platformSpecificUrl = if stdenv.hostPlatform.isLinux then + "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.3/bb-ubuntu.tar.gz" + else if stdenv.hostPlatform.isDarwin then + "https://github.com/AztecProtocol/barretenberg/releases/download/barretenberg-v0.4.3/barretenberg-x86_64-apple-darwin.tar.gz" + else + throw "Unsupported platform"; + + platformSpecificHash = if stdenv.hostPlatform.isLinux then + "sha256:0rcsjws87f4v28cw9734c10pg7c49apigf4lg3m0ji5vbhhmfnhr" + else if stdenv.hostPlatform.isDarwin then + "sha256:0pnsd56z0vkai7m0advawfgcvq9jbnpqm7lk98n5flqj583x3w35" + else + throw "Unsupported platform"; + in builtins.fetchurl { + url = platformSpecificUrl; + sha256 = platformSpecificHash; + }; + # The `port` is parameterized to support parallel test runs without colliding static servers testArgs = port: testEnvironment // { + BB_BINARY_PATH = "/tmp/backend_binary"; + + BB_BINARY_URL = "http://0.0.0.0:${toString port}/${builtins.baseNameOf bb_binary}"; + # We provide `barretenberg-transcript00` from the overlay to the tests as a URL hosted via a static server # This is necessary because the Nix sandbox has no network access and downloading during tests would fail - TRANSCRIPT_URL = "http://0.0.0.0:${toString port}/${builtins.baseNameOf pkgs.barretenberg-transcript00}"; + BARRETENBERG_TRANSCRIPT_URL = "http://0.0.0.0:${toString port}/${builtins.baseNameOf pkgs.barretenberg-transcript00}"; # This copies the `barretenberg-transcript00` from the Nix store into this sandbox # which avoids exposing the entire Nix store to the static server it starts @@ -188,6 +216,24 @@ # We also set the NARGO_BACKEND_CACHE_DIR environment variable to the $TMP directory so we can successfully cache # the transcript; which isn't possible with the default path because the Nix sandbox disabled $HOME preCheck = '' + echo "Extracting bb binary" + mkdir extracted + tar -xf ${bb_binary} -C extracted + + # Conditionally patch the binary for Linux + ${if stdenv.hostPlatform.isLinux then '' + + cp extracted/cpp/build/bin/bb /tmp/backend_binary + + echo "Patching bb binary for Linux" + patchelf --set-rpath "${stdenv.cc.cc.lib}/lib:${pkgs.gcc.cc.lib}/lib" /tmp/backend_binary + patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 /tmp/backend_binary + '' else if stdenv.hostPlatform.isDarwin then '' + cp extracted/bb /tmp/backend_binary + '' else + throw "Unsupported platform" + } + export NARGO_BACKEND_CACHE_DIR=$TMP cp ${pkgs.barretenberg-transcript00} . echo "Starting simple static server" @@ -202,7 +248,6 @@ # Build *just* the cargo dependencies, so we can reuse all of that work between runs native-cargo-artifacts = craneLib.buildDepsOnly nativeArgs; - wasm-cargo-artifacts = craneLib.buildDepsOnly wasmArgs; noir-wasm-cargo-artifacts = craneLib.buildDepsOnly noirWasmArgs; noir-native = craneLib.buildPackage (nativeArgs // { @@ -214,15 +259,6 @@ doCheck = false; }); - noir-wasm = craneLib.buildPackage (wasmArgs // { - inherit GIT_COMMIT GIT_DIRTY; - - cargoArtifacts = wasm-cargo-artifacts; - - # We don't want to run checks or tests when just building the project - doCheck = false; - }); - wasm-bindgen-cli = pkgs.callPackage ./wasm-bindgen-cli.nix { rustPlatform = pkgs.makeRustPlatform { rustc = rustToolchain; @@ -256,11 +292,9 @@ default = noir-native; inherit noir-native; - inherit noir-wasm; # We expose the `*-cargo-artifacts` derivations so we can cache our cargo dependencies in CI inherit native-cargo-artifacts; - inherit wasm-cargo-artifacts; inherit noir-wasm-cargo-artifacts; }; @@ -274,6 +308,8 @@ inputsFrom = builtins.attrValues checks; nativeBuildInputs = with pkgs; [ + curl + gzip which starship git