diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43bc980..91e0230 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,216 +3,139 @@ name: Noir Test on: [push, pull_request] jobs: - test-aarch64: + # macOS build + test. Runs cargo test natively and builds macOS targets + # (aarch64 native, x86_64 cross-compiled from the arm64 runner). + test-macos: runs-on: macos-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - # Cache Cargo registry and dependencies + - name: Cache Cargo registry uses: actions/cache@v4 with: path: | ~/.cargo/registry ~/.cargo/git - key: ${{ runner.os }}-aarch64-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-macos-cargo-registry-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-aarch64-cargo-registry- - - # Cache Cargo build artifacts + ${{ runner.os }}-macos-cargo-registry- + - name: Cache Cargo build uses: actions/cache@v4 with: path: | target/ - bb/target/ noir/target/ - key: ${{ runner.os }}-aarch64-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} + key: ${{ runner.os }}-macos-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} restore-keys: | - ${{ runner.os }}-aarch64-cargo-build-${{ hashFiles('**/Cargo.lock') }}- - ${{ runner.os }}-aarch64-cargo-build- - - - name: Install Rust iOS toolchain + ${{ runner.os }}-macos-cargo-build-${{ hashFiles('**/Cargo.lock') }}- + ${{ runner.os }}-macos-cargo-build- + + - name: Install Rust toolchain (macOS targets) uses: dtolnay/rust-toolchain@1.89.0 with: targets: | - aarch64-apple-ios - aarch64-apple-ios-sim aarch64-apple-darwin - aarch64-linux-android - - # Cache Nargo installation + x86_64-apple-darwin + - name: Cache Nargo uses: actions/cache@v4 with: path: | ~/.nargo - key: ${{ runner.os }}-aarch64-nargo-1.0.0-beta.8 + key: ${{ runner.os }}-macos-nargo-1.0.0-beta.19 restore-keys: | - ${{ runner.os }}-aarch64-nargo- - + ${{ runner.os }}-macos-nargo- + - name: Install Nargo uses: noir-lang/noirup@v0.1.4 with: - toolchain: 1.0.0-beta.8 - - # Cache circuit artifacts + toolchain: 1.0.0-beta.19 + - name: Cache circuit artifacts uses: actions/cache@v4 with: path: | circuits/target/ - key: ${{ runner.os }}-aarch64-circuit-artifacts-${{ hashFiles('circuits/**/*.nr', 'circuits/**/*.toml') }} + key: ${{ runner.os }}-macos-circuit-artifacts-${{ hashFiles('circuits/**/*.nr', 'circuits/**/*.toml') }} restore-keys: | - ${{ runner.os }}-aarch64-circuit-artifacts- - + ${{ runner.os }}-macos-circuit-artifacts- + - name: Build circuits run: | cd circuits + sh ./scripts/generate-bytecode-and-witness.sh product sh ./scripts/generate-bytecode-and-witness.sh keccak sh ./scripts/generate-bytecode-and-witness.sh keccak_large + - name: Test Noir # sequential execution to avoid race conditions run: | cargo test --all-features -- --test-threads=1 - - name: Build for iOS - run: | - cargo build --target aarch64-apple-ios --features ios-build - - name: Build for iOS Simulator - run: | - cargo build --target aarch64-apple-ios-sim --features ios-build - - name: Build for macOS Darwin - run: | - cargo build --target aarch64-apple-darwin --features ios-build - # Cache cargo-ndk installation - - name: Cache cargo-ndk - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/cargo-ndk - key: ${{ runner.os }}-aarch64-cargo-ndk-${{ hashFiles('~/.cargo/bin/cargo-ndk') }} - restore-keys: | - ${{ runner.os }}-aarch64-cargo-ndk- - - - name: Install cargo-ndk + + - name: Build for macOS (aarch64) run: | - if ! command -v cargo-ndk &> /dev/null; then - cargo install cargo-ndk - fi - - - name: Build for Android + cargo build --target aarch64-apple-darwin --features barretenberg + + - name: Build for macOS (x86_64, cross-compiled from arm64 runner) run: | - cargo ndk -t arm64-v8a build --features android-build + cargo build --target x86_64-apple-darwin --features barretenberg - test-x86_64: - runs-on: macos-13 + # iOS cross-compile. Needs a macOS runner but does not execute tests + # (no simulator/device). Covers iOS device (aarch64) and iOS simulator (aarch64). + test-ios: + runs-on: macos-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - # Cache Cargo registry and dependencies + - name: Cache Cargo registry uses: actions/cache@v4 with: path: | ~/.cargo/registry ~/.cargo/git - key: ${{ runner.os }}-x86_64-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + key: ${{ runner.os }}-ios-cargo-registry-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-x86_64-cargo-registry- - - # Cache Cargo build artifacts + ${{ runner.os }}-ios-cargo-registry- + - name: Cache Cargo build uses: actions/cache@v4 with: path: | target/ - bb/target/ noir/target/ - key: ${{ runner.os }}-x86_64-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} + key: ${{ runner.os }}-ios-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} restore-keys: | - ${{ runner.os }}-x86_64-cargo-build-${{ hashFiles('**/Cargo.lock') }}- - ${{ runner.os }}-x86_64-cargo-build- - - - name: Install Rust x86_64 toolchain + ${{ runner.os }}-ios-cargo-build-${{ hashFiles('**/Cargo.lock') }}- + ${{ runner.os }}-ios-cargo-build- + + - name: Install Rust toolchain (iOS targets) uses: dtolnay/rust-toolchain@1.89.0 with: targets: | - x86_64-apple-ios - x86_64-apple-darwin - x86_64-linux-android - - # Cache Nargo installation - - name: Cache Nargo - uses: actions/cache@v4 - with: - path: | - ~/.nargo - key: ${{ runner.os }}-x86_64-nargo-1.0.0-beta.8 - restore-keys: | - ${{ runner.os }}-x86_64-nargo- - - - name: Install Nargo - uses: noir-lang/noirup@v0.1.4 - with: - toolchain: 1.0.0-beta.8 - - # Cache circuit artifacts - - name: Cache circuit artifacts - uses: actions/cache@v4 - with: - path: | - circuits/target/ - key: ${{ runner.os }}-x86_64-circuit-artifacts-${{ hashFiles('circuits/**/*.nr', 'circuits/**/*.toml') }} - restore-keys: | - ${{ runner.os }}-x86_64-circuit-artifacts- - - - name: Build circuits - run: | - cd circuits - sh ./scripts/generate-bytecode-and-witness.sh keccak - sh ./scripts/generate-bytecode-and-witness.sh keccak_large - - name: Test Noir x86_64 - # sequential execution to avoid race conditions - run: | - cargo test --all-features -- --test-threads=1 x86_64 - - name: Build for iOS x86_64 - run: | - cargo build --target x86_64-apple-ios --features ios-build - - name: Build for macOS Darwin x86_64 - run: | - cargo build --target x86_64-apple-darwin --features ios-build - # Cache cargo-ndk installation - - name: Cache cargo-ndk - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/cargo-ndk - key: ${{ runner.os }}-x86_64-cargo-ndk-${{ hashFiles('~/.cargo/bin/cargo-ndk') }} - restore-keys: | - ${{ runner.os }}-x86_64-cargo-ndk- - - - name: Install cargo-ndk + aarch64-apple-ios + aarch64-apple-ios-sim + + - name: Build for iOS (aarch64) run: | - if ! command -v cargo-ndk &> /dev/null; then - cargo install cargo-ndk - fi - - - name: Build for Android x86_64 + cargo build --target aarch64-apple-ios --features ios-build + + - name: Build for iOS Simulator (aarch64) run: | - cargo ndk -t x86_64 build --features android-build + cargo build --target aarch64-apple-ios-sim --features ios-build + # Linux build + test. Runs cargo test natively and builds x86_64-unknown-linux-gnu. test-linux: runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - # Cache Cargo registry and dependencies + - name: Cache Cargo registry uses: actions/cache@v4 with: @@ -222,42 +145,38 @@ jobs: key: ${{ runner.os }}-linux-cargo-registry-${{ hashFiles('**/Cargo.lock') }} restore-keys: | ${{ runner.os }}-linux-cargo-registry- - - # Cache Cargo build artifacts + - name: Cache Cargo build uses: actions/cache@v4 with: path: | target/ - bb/target/ noir/target/ key: ${{ runner.os }}-linux-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} restore-keys: | ${{ runner.os }}-linux-cargo-build-${{ hashFiles('**/Cargo.lock') }}- ${{ runner.os }}-linux-cargo-build- - - - name: Install Rust Linux toolchain + + - name: Install Rust toolchain (Linux target) uses: dtolnay/rust-toolchain@1.89.0 with: targets: | x86_64-unknown-linux-gnu - - # Cache Nargo installation + - name: Cache Nargo uses: actions/cache@v4 with: path: | ~/.nargo - key: ${{ runner.os }}-linux-nargo-1.0.0-beta.8 + key: ${{ runner.os }}-linux-nargo-1.0.0-beta.19 restore-keys: | ${{ runner.os }}-linux-nargo- - + - name: Install Nargo uses: noir-lang/noirup@v0.1.4 with: - toolchain: 1.0.0-beta.8 - - # Cache circuit artifacts + toolchain: 1.0.0-beta.19 + - name: Cache circuit artifacts uses: actions/cache@v4 with: @@ -266,16 +185,79 @@ jobs: key: ${{ runner.os }}-linux-circuit-artifacts-${{ hashFiles('circuits/**/*.nr', 'circuits/**/*.toml') }} restore-keys: | ${{ runner.os }}-linux-circuit-artifacts- - + - name: Build circuits run: | cd circuits + sh ./scripts/generate-bytecode-and-witness.sh product sh ./scripts/generate-bytecode-and-witness.sh keccak sh ./scripts/generate-bytecode-and-witness.sh keccak_large - - name: Test Noir Linux + + - name: Test Noir # sequential execution to avoid race conditions run: | cargo test --all-features -- --test-threads=1 - - name: Build for Linux x86_64 + + - name: Build for Linux (x86_64) run: | - cargo build --target x86_64-unknown-linux-gnu + cargo build --target x86_64-unknown-linux-gnu --features barretenberg + + # Android cross-compile via cargo-ndk. Runs on ubuntu for cost; does not + # execute tests (no emulator). Covers Android arm64 and x86_64. + test-android: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + + - name: Cache Cargo registry + uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-android-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-android-cargo-registry- + + - name: Cache Cargo build + uses: actions/cache@v4 + with: + path: | + target/ + noir/target/ + key: ${{ runner.os }}-android-cargo-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/*.rs') }} + restore-keys: | + ${{ runner.os }}-android-cargo-build-${{ hashFiles('**/Cargo.lock') }}- + ${{ runner.os }}-android-cargo-build- + + - name: Install Rust toolchain (Android targets) + uses: dtolnay/rust-toolchain@1.89.0 + with: + targets: | + aarch64-linux-android + x86_64-linux-android + + - name: Cache cargo-ndk + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/cargo-ndk + key: ${{ runner.os }}-android-cargo-ndk-${{ hashFiles('~/.cargo/bin/cargo-ndk') }} + restore-keys: | + ${{ runner.os }}-android-cargo-ndk- + + - name: Install cargo-ndk + run: | + if ! command -v cargo-ndk &> /dev/null; then + cargo install cargo-ndk + fi + + - name: Build for Android (arm64-v8a) + run: | + cargo ndk -t arm64-v8a build --features android-build + + - name: Build for Android (x86_64) + run: | + cargo ndk -t x86_64 build --features android-build diff --git a/Cargo.lock b/Cargo.lock index 83632d8..6a668d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,20 +4,17 @@ version = 4 [[package]] name = "acir" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir_field", "base64", - "bincode 2.0.1", "brillig", - "color-eyre", "flate2", - "noir_protobuf", + "noirc_span", + "num-bigint", + "num-traits", "num_enum", - "prost", - "prost-build", - "protoc-prebuilt", "rmp-serde", "serde", "serde-big-array", @@ -28,8 +25,8 @@ dependencies = [ [[package]] name = "acir_field" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "ark-bn254", "ark-ff", @@ -42,14 +39,14 @@ dependencies = [ [[package]] name = "acvm" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir", "acvm_blackbox_solver", "brillig_vm", - "fxhash", "indexmap 2.11.3", + "rustc-hash", "serde", "thiserror 1.0.69", "tracing", @@ -57,19 +54,19 @@ dependencies = [ [[package]] name = "acvm_blackbox_solver" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir", + "aes", "blake2", "blake3", + "cbc", "k256", "keccak", - "libaes", "log", - "num-bigint", "p256", - "sha2", + "sha2 0.11.0", "thiserror 1.0.69", ] @@ -88,6 +85,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures 0.2.17", +] + [[package]] name = "ahash" version = "0.8.12" @@ -100,15 +108,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - [[package]] name = "allocator-api2" version = "0.2.21" @@ -205,7 +204,7 @@ dependencies = [ "educe", "fnv", "hashbrown 0.15.5", - "itertools 0.13.0", + "itertools", "num-bigint", "num-integer", "num-traits", @@ -223,9 +222,9 @@ dependencies = [ "ark-serialize", "ark-std", "arrayvec", - "digest", + "digest 0.10.7", "educe", - "itertools 0.13.0", + "itertools", "num-bigint", "num-traits", "paste", @@ -291,7 +290,7 @@ dependencies = [ "ark-serialize-derive", "ark-std", "arrayvec", - "digest", + "digest 0.10.7", "num-bigint", ] @@ -366,11 +365,26 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "barretenberg-rs" +version = "4.2.0-aztecnr-rc.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c244bbd116be1c35671e9285671c34b90a2af64e895c60cc622109f5f7545b30" +dependencies = [ + "hex", + "libc", + "rmp", + "rmp-serde", + "rmpv", + "serde", + "thiserror 1.0.69", +] + [[package]] name = "base16ct" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" [[package]] name = "base64" @@ -384,18 +398,6 @@ version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" -[[package]] -name = "bb" -version = "1.0.0-nightly.20250723" -dependencies = [ - "cc", - "chkstk_stub", - "num-bigint", - "thiserror 1.0.69", - "tracing", - "tracing-subscriber", -] - [[package]] name = "binary-merge" version = "0.1.2" @@ -411,26 +413,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bincode" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740" -dependencies = [ - "bincode_derive", - "serde", - "unty", -] - -[[package]] -name = "bincode_derive" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09" -dependencies = [ - "virtue", -] - [[package]] name = "bit-set" version = "0.8.0" @@ -463,11 +445,11 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.6" +version = "0.11.0-rc.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +checksum = "d52965399b470437fc7f4d4b51134668dbc96573fea6f1b83318a420e4605745" dependencies = [ - "digest", + "digest 0.11.2", ] [[package]] @@ -492,10 +474,28 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "block-padding" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8894febbff9f758034a5b8e12d87918f56dfc64a8e1fe757d65e29041538d93" +dependencies = [ + "generic-array", +] + [[package]] name = "bn254_blackbox_solver" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir", "acvm_blackbox_solver", @@ -504,8 +504,6 @@ dependencies = [ "ark-ff", "ark-grumpkin", "hex", - "lazy_static", - "num-bigint", ] [[package]] @@ -519,8 +517,8 @@ dependencies = [ [[package]] name = "brillig" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir_field", "serde", @@ -528,8 +526,8 @@ dependencies = [ [[package]] name = "brillig_vm" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acir", "acvm_blackbox_solver", @@ -566,6 +564,15 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.2.37" @@ -588,15 +595,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" -[[package]] -name = "chkstk_stub" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "047f6ab2f3b9bcaf23b593d1580898e4244d27eadf1a1fae99212ee5735d3d1c" -dependencies = [ - "cc", -] - [[package]] name = "chrono" version = "0.4.42" @@ -611,6 +609,16 @@ dependencies = [ "windows-link 0.2.0", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common 0.1.6", + "inout", +] + [[package]] name = "clap" version = "4.5.47" @@ -651,6 +659,12 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "cmov" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" + [[package]] name = "codespan" version = "0.11.1" @@ -672,33 +686,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "color-eyre" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5920befb47832a6d61ee3a3a846565cfa39b331331e68a3b1d1116630f2f26d" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8b88ea9df13354b55bc7234ebcce36e6ef896aca2e42a15de9e10edce01b427" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - [[package]] name = "colorchoice" version = "1.0.4" @@ -707,9 +694,9 @@ checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" [[package]] name = "const-oid" -version = "0.9.6" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" [[package]] name = "constant_time_eq" @@ -723,6 +710,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpubits" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef0c543070d296ea414df2dd7625d1b24866ce206709d8a4a424f28377f5861" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -732,6 +725,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crc32fast" version = "1.5.0" @@ -768,12 +770,16 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crypto-bigint" -version = "0.5.5" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +checksum = "42a0d26b245348befa0c121944541476763dcc46ede886c88f9d12e1697d27c3" dependencies = [ - "generic-array", - "rand_core 0.6.4", + "cpubits", + "ctutils", + "getrandom 0.4.2", + "hybrid-array", + "num-traits", + "rand_core 0.10.0", "subtle", "zeroize", ] @@ -788,6 +794,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" +dependencies = [ + "getrandom 0.4.2", + "hybrid-array", + "rand_core 0.10.0", +] + +[[package]] +name = "ctutils" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e" +dependencies = [ + "cmov", + "subtle", +] + [[package]] name = "darling" version = "0.20.11" @@ -825,9 +852,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.10" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +checksum = "71fd89660b2dc699704064e59e9dba0147b903e85319429e131620d022be411b" dependencies = [ "const-oid", "pem-rfc7468", @@ -850,10 +877,20 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", + "block-buffer 0.10.4", + "crypto-common 0.1.6", +] + +[[package]] +name = "digest" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c" +dependencies = [ + "block-buffer 0.12.0", "const-oid", - "crypto-common", - "subtle", + "crypto-common 0.2.1", + "ctutils", ] [[package]] @@ -875,16 +912,17 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "ecdsa" -version = "0.16.9" +version = "0.17.0-rc.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +checksum = "91bbdd377139884fafcad8dc43a760a3e1e681aa26db910257fa6535b70e1829" dependencies = [ "der", - "digest", + "digest 0.11.2", "elliptic-curve", "rfc6979", "signature", "spki", + "zeroize", ] [[package]] @@ -907,19 +945,21 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elliptic-curve" -version = "0.13.8" +version = "0.14.0-rc.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +checksum = "7d7a0bfd012613a7bcfe02cbfccf2b846e9ef9e1bccb641c48d461253cfb034d" dependencies = [ "base16ct", "crypto-bigint", - "digest", - "ff", - "generic-array", - "group", + "crypto-common 0.2.1", + "digest 0.11.2", + "hybrid-array", + "once_cell", "pem-rfc7468", "pkcs8", - "rand_core 0.6.4", + "rand_core 0.10.0", + "rustcrypto-ff", + "rustcrypto-group", "sec1", "subtle", "zeroize", @@ -961,32 +1001,12 @@ dependencies = [ "windows-sys 0.61.0", ] -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" -[[package]] -name = "ff" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "find-msvc-tools" version = "0.1.1" @@ -1011,8 +1031,8 @@ dependencies = [ [[package]] name = "fm" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "codespan-reporting", "iter-extended", @@ -1031,21 +1051,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared", -] - -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "form_urlencoded" version = "1.2.2" @@ -1105,15 +1110,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1122,7 +1118,6 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", - "zeroize", ] [[package]] @@ -1147,27 +1142,30 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "r-efi", + "r-efi 5.3.0", "wasi 0.14.7+wasi-0.2.4", "wasm-bindgen", ] [[package]] -name = "gimli" -version = "0.31.1" +name = "getrandom" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "rand_core 0.10.0", + "wasip2", + "wasip3", +] [[package]] -name = "group" -version = "0.13.0" +name = "gimli" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" -dependencies = [ - "ff", - "rand_core 0.6.4", - "subtle", -] +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "hashbrown" @@ -1206,11 +1204,11 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hmac" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" dependencies = [ - "digest", + "digest 0.11.2", ] [[package]] @@ -1253,6 +1251,17 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" +[[package]] +name = "hybrid-array" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3944cf8cf766b40e2a1a333ee5e9b563f854d5fa49d6a8ca2764e97c6eddb214" +dependencies = [ + "subtle", + "typenum", + "zeroize", +] + [[package]] name = "hyper" version = "1.7.0" @@ -1288,7 +1297,7 @@ dependencies = [ "tokio", "tokio-rustls", "tower-service", - "webpki-roots 1.0.2", + "webpki-roots", ] [[package]] @@ -1425,6 +1434,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "ident_case" version = "1.0.1" @@ -1467,12 +1482,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "indenter" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" - [[package]] name = "indexmap" version = "1.9.3" @@ -1496,6 +1505,16 @@ dependencies = [ "serde_core", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "block-padding", + "generic-array", +] + [[package]] name = "inplace-vec-builder" version = "0.1.1" @@ -1540,8 +1559,8 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "iter-extended" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" [[package]] name = "itertools" @@ -1552,15 +1571,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.15" @@ -1619,25 +1629,24 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.4" +version = "0.14.0-rc.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" +checksum = "f7d2c6c227649d5ec80eaae541f1736232641a0bcdb3062a52b34edb42054158" dependencies = [ - "cfg-if", + "cpubits", "ecdsa", "elliptic-curve", - "once_cell", - "sha2", + "sha2 0.11.0", "signature", ] [[package]] name = "keccak" -version = "0.1.5" +version = "0.2.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +checksum = "3d546793a04a1d3049bd192856f804cfe96356e2cf36b54b4e575155babe9f41" dependencies = [ - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -1647,10 +1656,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] -name = "libaes" -version = "0.7.0" +name = "leb128fmt" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82903360c009b816f5ab72a9b68158c27c301ee2c3f20655b55c5e589e7d3bb7" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" [[package]] name = "libc" @@ -1708,23 +1717,19 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "multimap" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" - [[package]] name = "nargo" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", + "brillig", "fm", "iter-extended", "jsonrpsee", "noir_greybox_fuzzer", "noirc_abi", + "noirc_artifacts", "noirc_driver", "noirc_errors", "noirc_frontend", @@ -1740,22 +1745,19 @@ dependencies = [ [[package]] name = "noir" -version = "1.0.0-beta.8-3" +version = "1.0.0-beta.19" dependencies = [ - "acir", "acvm", "acvm_blackbox_solver", + "barretenberg-rs", "base64", - "base64ct", - "bb", - "bincode 1.3.3", + "bincode", "bn254_blackbox_solver", "clap", "flate2", "hex", + "keccak", "nargo", - "openssl", - "proptest", "reqwest", "serde", "serde_json", @@ -1767,8 +1769,8 @@ dependencies = [ [[package]] name = "noir_greybox_fuzzer" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "build-data", @@ -1777,27 +1779,18 @@ dependencies = [ "noirc_artifacts", "num-traits", "proptest", - "rand 0.8.5", - "rand_xorshift", + "rand 0.9.2", + "rand_xorshift 0.4.0", "rayon", "sha256", "termcolor", "walkdir", ] -[[package]] -name = "noir_protobuf" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" -dependencies = [ - "color-eyre", - "prost", -] - [[package]] name = "noirc_abi" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "iter-extended", @@ -1812,83 +1805,85 @@ dependencies = [ [[package]] name = "noirc_arena" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" [[package]] name = "noirc_artifacts" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ + "acir", "acvm", + "base64", "codespan-reporting", + "flate2", "fm", "noirc_abi", - "noirc_driver", "noirc_errors", "noirc_printable_type", "serde", + "serde_json", + "thiserror 1.0.69", + "tracing", ] [[package]] name = "noirc_driver" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "build-data", "clap", "fm", - "fxhash", "iter-extended", "noirc_abi", + "noirc_artifacts", "noirc_errors", "noirc_evaluator", "noirc_frontend", "rust-embed", - "serde", + "rustc-hash", "tracing", ] [[package]] name = "noirc_errors" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ - "acvm", - "base64", - "codespan", "codespan-reporting", - "flate2", "fm", - "fxhash", - "noirc_printable_type", + "noirc_span", + "rustc-hash", "serde", - "serde_json", - "tracing", ] [[package]] name = "noirc_evaluator" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "bn254_blackbox_solver", "cfg-if", "chrono", "fm", - "fxhash", "im", + "indexmap 2.11.3", "iter-extended", + "noirc_artifacts", "noirc_errors", "noirc_frontend", "noirc_printable_type", "num-bigint", "num-integer", "num-traits", - "petgraph 0.8.2", + "petgraph", "rayon", + "rustc-hash", + "rustc-stable-hash", "serde", "serde_json", "serde_with", @@ -1900,22 +1895,22 @@ dependencies = [ [[package]] name = "noirc_frontend" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "bn254_blackbox_solver", "cfg-if", "fm", - "fxhash", "im", "iter-extended", "noirc_arena", + "noirc_artifacts", "noirc_errors", "noirc_printable_type", "num-bigint", "num-traits", - "petgraph 0.8.2", + "petgraph", "rangemap", "rustc-hash", "serde", @@ -1930,8 +1925,8 @@ dependencies = [ [[package]] name = "noirc_printable_type" -version = "1.0.0-beta.8" -source = "git+https://github.com/noir-lang/noir.git?rev=b33131574388d836341cea9b6380f3b1a8493eb8#b33131574388d836341cea9b6380f3b1a8493eb8" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" dependencies = [ "acvm", "iter-extended", @@ -1939,6 +1934,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "noirc_span" +version = "1.0.0-beta.19" +source = "git+https://github.com/noir-lang/noir.git?rev=v1.0.0-beta.19#74d6be658e1ad252f87943292ba09bdd4da80bd4" +dependencies = [ + "codespan", + "serde", +] + [[package]] name = "nu-ansi-term" version = "0.50.1" @@ -2025,70 +2029,17 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" -[[package]] -name = "openssl" -version = "0.10.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" -dependencies = [ - "bitflags", - "cfg-if", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - -[[package]] -name = "openssl-src" -version = "300.5.2+3.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d270b79e2926f5150189d475bc7e9d2c69f9c4697b185fa917d5a32b792d21b4" -dependencies = [ - "cc", -] - -[[package]] -name = "openssl-sys" -version = "0.9.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90096e2e47630d78b7d1c20952dc621f957103f8bc2c8359ec81290d75238571" -dependencies = [ - "cc", - "libc", - "openssl-src", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "owo-colors" -version = "4.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48dd4f4a2c8405440fd0462561f0e5806bd0f77e86f51c761481bdd4018b545e" - [[package]] name = "p256" -version = "0.13.2" +version = "0.14.0-rc.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +checksum = "44f0a10fe314869359cb2901342b045f4e5a962ef9febc006f03d2a8c848fe4c" dependencies = [ "ecdsa", "elliptic-curve", + "primefield", "primeorder", - "sha2", + "sha2 0.11.0", ] [[package]] @@ -2099,9 +2050,9 @@ checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pem-rfc7468" -version = "0.7.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" dependencies = [ "base64ct", ] @@ -2112,16 +2063,6 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" -[[package]] -name = "petgraph" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" -dependencies = [ - "fixedbitset", - "indexmap 2.11.3", -] - [[package]] name = "petgraph" version = "0.8.2" @@ -2168,20 +2109,14 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.10.2" +version = "0.11.0-rc.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "12922b6296c06eb741b02d7b5161e3aaa22864af38dfa025a1a3ba3f68c84577" dependencies = [ "der", "spki", ] -[[package]] -name = "pkg-config" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" - [[package]] name = "potential_utf" version = "0.1.3" @@ -2216,11 +2151,25 @@ dependencies = [ "syn 2.0.106", ] +[[package]] +name = "primefield" +version = "0.14.0-rc.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6543f5eec854fbf74ba5ef651fbdc9408919b47c3e1526623687135c16d12e9" +dependencies = [ + "crypto-bigint", + "crypto-common 0.2.1", + "rand_core 0.10.0", + "rustcrypto-ff", + "subtle", + "zeroize", +] + [[package]] name = "primeorder" -version = "0.13.6" +version = "0.14.0-rc.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +checksum = "569d9ad6ef822bb0322c7e7d84e5e286244050bd5246cac4c013535ae91c2c90" dependencies = [ "elliptic-curve", ] @@ -2256,81 +2205,11 @@ dependencies = [ "num-traits", "rand 0.8.5", "rand_chacha 0.3.1", - "rand_xorshift", + "rand_xorshift 0.3.0", "regex-syntax", - "rusty-fork", - "tempfile", "unarray", ] -[[package]] -name = "prost" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" -dependencies = [ - "bytes", - "prost-derive", -] - -[[package]] -name = "prost-build" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be769465445e8c1474e9c5dac2018218498557af32d9ed057325ec9a41ae81bf" -dependencies = [ - "heck 0.5.0", - "itertools 0.14.0", - "log", - "multimap", - "once_cell", - "petgraph 0.7.1", - "prettyplease", - "prost", - "prost-types", - "regex", - "syn 2.0.106", - "tempfile", -] - -[[package]] -name = "prost-derive" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" -dependencies = [ - "anyhow", - "itertools 0.14.0", - "proc-macro2", - "quote", - "syn 2.0.106", -] - -[[package]] -name = "prost-types" -version = "0.13.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" -dependencies = [ - "prost", -] - -[[package]] -name = "protoc-prebuilt" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d85d4641fe3b8c6e853dfd09fe35379bc6b6e66bd692ac29ed4f7087de69ed5" -dependencies = [ - "ureq", - "zip", -] - -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quinn" version = "0.11.9" @@ -2401,6 +2280,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rand" version = "0.8.5" @@ -2460,6 +2345,12 @@ dependencies = [ "getrandom 0.3.3", ] +[[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -2469,6 +2360,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_xorshift" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +dependencies = [ + "rand_core 0.9.3", +] + [[package]] name = "rand_xoshiro" version = "0.6.0" @@ -2524,29 +2424,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "regex" -version = "1.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - [[package]] name = "regex-syntax" version = "0.8.6" @@ -2590,14 +2467,14 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots 1.0.2", + "webpki-roots", ] [[package]] name = "rfc6979" -version = "0.4.0" +version = "0.5.0-rc.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +checksum = "23a3127ee32baec36af75b4107082d9bd823501ec14a4e016be4b6b37faa74ae" dependencies = [ "hmac", "subtle", @@ -2639,6 +2516,15 @@ dependencies = [ "serde", ] +[[package]] +name = "rmpv" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a4e1d4b9b938a26d2996af33229f0ca0956c652c1375067f0b45291c1df8417" +dependencies = [ + "rmp", +] + [[package]] name = "rust-embed" version = "8.7.2" @@ -2669,7 +2555,7 @@ version = "8.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6cc0c81648b20b70c491ff8cce00c1c3b223bb8ed2b5d41f0e54c6c4c0a3594" dependencies = [ - "sha2", + "sha2 0.10.9", "walkdir", ] @@ -2685,6 +2571,33 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" +[[package]] +name = "rustc-stable-hash" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "781442f29170c5c93b7185ad559492601acdc71d5bb0706f5868094f45cfcd08" + +[[package]] +name = "rustcrypto-ff" +version = "0.14.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd2a8adb347447693cd2ba0d218c4b66c62da9b0a5672b17b981e4291ec65ff6" +dependencies = [ + "rand_core 0.10.0", + "subtle", +] + +[[package]] +name = "rustcrypto-group" +version = "0.14.0-rc.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "369f9b61aa45933c062c9f6b5c3c50ab710687eca83dd3802653b140b43f85ed" +dependencies = [ + "rand_core 0.10.0", + "rustcrypto-ff", + "subtle", +] + [[package]] name = "rustix" version = "1.1.2" @@ -2704,7 +2617,6 @@ version = "0.23.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ebcbd2f03de0fc1122ad9bb24b127a5a6cd51d72604a3f3c50ac459762b6cc" dependencies = [ - "log", "once_cell", "ring", "rustls-pki-types", @@ -2740,18 +2652,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error", - "tempfile", - "wait-timeout", -] - [[package]] name = "ryu" version = "1.0.20" @@ -2840,18 +2740,24 @@ dependencies = [ [[package]] name = "sec1" -version = "0.7.3" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +checksum = "d56d437c2f19203ce5f7122e507831de96f3d2d4d3be5af44a0b0a09d8a80e4d" dependencies = [ "base16ct", + "ctutils", "der", - "generic-array", - "pkcs8", + "hybrid-array", "subtle", "zeroize", ] +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.225" @@ -2964,8 +2870,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.2", ] [[package]] @@ -2977,7 +2894,7 @@ dependencies = [ "async-trait", "bytes", "hex", - "sha2", + "sha2 0.10.9", ] [[package]] @@ -2997,12 +2914,12 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signature" -version = "2.2.0" +version = "3.0.0-rc.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +checksum = "7f1880df446116126965eeec169136b2e0251dba37c6223bcc819569550edea3" dependencies = [ - "digest", - "rand_core 0.6.4", + "digest 0.11.2", + "rand_core 0.10.0", ] [[package]] @@ -3067,9 +2984,9 @@ checksum = "bceb57dc07c92cdae60f5b27b3fa92ecaaa42fe36c55e22dbfb0b44893e0b1f7" [[package]] name = "spki" -version = "0.7.3" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f" dependencies = [ "base64ct", "der", @@ -3448,16 +3365,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-error" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" -dependencies = [ - "tracing", - "tracing-subscriber", -] - [[package]] name = "tracing-log" version = "0.2.0" @@ -3525,27 +3432,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" -[[package]] -name = "unty" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" - -[[package]] -name = "ureq" -version = "2.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" -dependencies = [ - "base64", - "log", - "once_cell", - "rustls", - "rustls-pki-types", - "url", - "webpki-roots 0.26.11", -] - [[package]] name = "url" version = "2.5.7" @@ -3576,12 +3462,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "vec-collections" version = "0.4.3" @@ -3603,21 +3483,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "virtue" -version = "0.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1" - -[[package]] -name = "wait-timeout" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" -dependencies = [ - "libc", -] - [[package]] name = "walkdir" version = "2.5.0" @@ -3658,7 +3523,16 @@ version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.46.0", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", ] [[package]] @@ -3733,6 +3607,40 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap 2.11.3", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap 2.11.3", + "semver", +] + [[package]] name = "web-sys" version = "0.3.78" @@ -3753,15 +3661,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webpki-roots" -version = "0.26.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" -dependencies = [ - "webpki-roots 1.0.2", -] - [[package]] name = "webpki-roots" version = "1.0.2" @@ -4034,6 +3933,94 @@ version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck 0.5.0", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck 0.5.0", + "indexmap 2.11.3", + "prettyplease", + "syn 2.0.106", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.106", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap 2.11.3", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap 2.11.3", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + [[package]] name = "writeable" version = "0.6.1" @@ -4157,15 +4144,3 @@ dependencies = [ "quote", "syn 2.0.106", ] - -[[package]] -name = "zip" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" -dependencies = [ - "byteorder", - "crc32fast", - "crossbeam-utils", - "flate2", -] diff --git a/Cargo.toml b/Cargo.toml index 87ff175..548a512 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["bb", "noir"] -resolver = "2" \ No newline at end of file +members = ["noir"] +resolver = "2" diff --git a/bb/.gitignore b/bb/.gitignore deleted file mode 100644 index 6985cf1..0000000 --- a/bb/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -# Generated by Cargo -# will have compiled files and executables -debug/ -target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk - -# MSVC Windows builds of rustc generate these, which store debugging information -*.pdb diff --git a/bb/Cargo.toml b/bb/Cargo.toml deleted file mode 100644 index 756f385..0000000 --- a/bb/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "bb" -version = "1.0.0-nightly.20250723" -edition = "2021" - -[dependencies] -thiserror = "1.0.58" -tracing = "0.1" -tracing-subscriber = "0.3" -num-bigint = "0.4" - -[build-dependencies] -cc = "1.2" -chkstk_stub = "0.1" \ No newline at end of file diff --git a/bb/README.md b/bb/README.md deleted file mode 100644 index 45dddf8..0000000 --- a/bb/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# bb.rs - -Rust bindings for Barretenberg C++ codebase. - -## Build - -Before you build, make sure the toolchain for your target platform is installed already. - -```sh -# Show which toolchain will be used in the current directory -rustup show -``` - -If the toolchain is not installed, you can add it using `rustup target add `. - -```sh -# Example: Add `aarch64-apple-ios-sim` target -rustup target add aarch64-apple-ios-sim -``` - -See [here](https://github.com/zkmopro/noir-rs/tree/main?tab=readme-ov-file#platform-support) for the list of supported platforms. - -#### Build Commands - -```sh -# Build on your own machine -cargo build -vvvv - -# Cross-compile for iOS -cargo build -vvvv --target - -# Cross-compile for Android -cargo build -vvvv --target -``` - -## Known issues - -### Missing `sys/random.h` - -random.h is not available in the iOS SDK includes but it is available in the MacOS SDK includes. So you can copy it from `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys` and paste it in `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys`. This will work, no compability issues, it's just not there for some reason. - -You can also run `scripts/patcher.sh` to do this (you may need to run it as `sudo`). diff --git a/bb/build.rs b/bb/build.rs deleted file mode 100644 index 224216d..0000000 --- a/bb/build.rs +++ /dev/null @@ -1,85 +0,0 @@ -use std::{env, fs, path::Path, process::Command}; - -const BB_DOWNLOAD_SCRIPT: &str = include_str!("./download_bb.sh"); -const TARGET_LIST: [&str; 8] = [ - "aarch64-apple-darwin", - "aarch64-apple-ios", - "aarch64-apple-ios-sim", - "aarch64-linux-android", - "x86_64-apple-darwin", - "x86_64-apple-ios", - "x86_64-linux-android", - "x86_64-unknown-linux-gnu", -]; - -fn main() { - // Notify Cargo to rerun this build script if `build.rs` changes. - println!("cargo:rerun-if-changed=build.rs"); - - let target = env::var("TARGET").expect("TARGET not set"); - let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); - let arch = target - .split('-') - .next() - .expect("Architecture cannot be parsed"); - - // See: https://github.com/zkmopro/chkstk_stub for more details - chkstk_stub::build(); - - // Try to list contents of the target directory - let bb_path = Path::new(&out_dir).join(Path::new("bb")); - // If the bb path is not downloaded, download it - if !bb_path.exists() { - let bb_script_path = Path::new(&out_dir).join(Path::new("download_bb.sh")); - fs::write(&bb_script_path, BB_DOWNLOAD_SCRIPT).expect("Failed to write build script"); - let child_process = Command::new("sh") - .arg(bb_script_path.to_str().unwrap()) - .spawn(); - if let Err(e) = child_process { - panic!("Failed to spawn bb download: {}", e); - } - let status = child_process.unwrap().wait(); - if let Err(e) = status { - panic!("Failed to wait for bb download: {}", e); - } else if !status.unwrap().success() { - panic!("Failed to wait for bb download"); - } - } - let absolute_lib_path = if bb_path.join(&target).exists() { - bb_path.join(&target) - } else { - bb_path.join(&arch) - }; - - // Add the library search path for Rust to find during linking. - let lib_dir; - if !(TARGET_LIST.contains(&target.as_str()) || TARGET_LIST.contains(&arch)) { - panic!("Unsupported target: {}", target); - } - lib_dir = absolute_lib_path.join("lib"); - println!("cargo:rustc-link-search={}", lib_dir.display()); - - // Link the `barretenberg` static library. - println!("cargo:rustc-link-lib=static=barretenberg"); - - // Link the `libdeflate` static library. - println!("cargo:rustc-link-lib=static=deflate"); - - if target.contains("ios") { - println!("cargo:rustc-link-lib=static=lmdb"); - } - - // Link the C++ standard library. - if cfg!(target_os = "macos") || cfg!(target_os = "ios") { - println!("cargo:rustc-link-lib=c++"); - } else { - println!("cargo:rustc-link-lib=stdc++"); - } - - // Copy the headers to the build directory. - // Fix an issue where the headers are not included in the build. - Command::new("sh") - .args(&["copy-headers.sh", &"./include"]) - .output() - .unwrap(); -} diff --git a/bb/copy-headers.sh b/bb/copy-headers.sh deleted file mode 100755 index a56bbac..0000000 --- a/bb/copy-headers.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# Check if a destination directory is provided -if [ $# -ne 1 ]; then - echo "Usage: $0 " - echo "Example: $0 /path/to/destination" - exit 1 -fi - -# Get the destination directory from the command line argument -DEST_DIR="$1" - -# Define the source directory -SRC_DIR="$(dirname "$(dirname "$(dirname "$0")")")./cpp/src" - -# Check if the source directory exists -if [ ! -d "$SRC_DIR" ]; then - echo "Error: Source directory '$SRC_DIR' does not exist." - exit 1 -fi - -# Create the destination directory if it doesn't exist -mkdir -p "$DEST_DIR" - -# Find all .hpp and .tcc files in the source directory and copy them to the destination, -# preserving the directory structure -echo "Copying .hpp and .tcc files from $SRC_DIR to $DEST_DIR..." -find "$SRC_DIR" \( -name "*.hpp" -o -name "*.tcc" \) -type f | while read -r file; do - # Get the relative path from the source directory - rel_path="${file#$SRC_DIR/}" - - # Create the destination directory structure - dest_file="$DEST_DIR/$rel_path" - dest_dir="$(dirname "$dest_file")" - mkdir -p "$dest_dir" - - # Copy the file - cp "$file" "$dest_file" - echo "Copied: $rel_path" -done - -echo "Finished copying .hpp and .tcc files to $DEST_DIR" diff --git a/bb/download_bb.sh b/bb/download_bb.sh deleted file mode 100755 index 7390c30..0000000 --- a/bb/download_bb.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -# Exit on error -set -e - -# OUT_DIR is specified by the rust build environment -if [ -z $OUT_DIR ]; then - echo "OUT_DIR not specified" - exit 1 -fi -# TARGET is specified by the rust build environment -if [ -z $TARGET ]; then - echo "TARGET not specified" - exit 1 -fi -BUILD_DIR=$OUT_DIR/bb -mkdir -p $BUILD_DIR - -download_and_unzip() { - local target="$1" - local asset_name="bb_rs-$target.tar.gz" - local zip_file="$BUILD_DIR/$asset_name" - local bb_version="1.0.0-nightly.20250723" - - echo "Downloading $asset_name..." - - # Download file with error handling - if ! curl -L -o "$zip_file" "https://github.com/zkmopro/aztec-packages/releases/download/$bb_version/$asset_name"; then - echo "Failed to download $asset_name" - return 1 # Return failure status - fi - - echo "Unzipping $zip_file..." - - # Unzip with error handling - if ! tar -xzf "$zip_file" -C "$BUILD_DIR"; then - echo "Failed to unzip $zip_file" - return 1 - fi - - echo "✅ Successfully downloaded and extracted $asset_name" -} - -# Try downloading the full target -if ! download_and_unzip "$TARGET"; then - echo "Retrying with local architecture..." - - local_arch=$(echo "$TARGET" | cut -d'-' -f1) - - if ! download_and_unzip "$local_arch"; then - echo "Download failed for both bb_rs-$TARGET.tar.gz and bb_rs-$local_arch.tar.gz" - exit 1 # Exit the script with failure - fi -fi \ No newline at end of file diff --git a/bb/rust-toolchain.toml b/bb/rust-toolchain.toml deleted file mode 100644 index 9993e93..0000000 --- a/bb/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "stable" -components = [ "rustfmt" ] diff --git a/bb/rustfmt.toml b/bb/rustfmt.toml deleted file mode 100644 index 4e727a0..0000000 --- a/bb/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -reorder_imports = true \ No newline at end of file diff --git a/bb/scripts/patcher.sh b/bb/scripts/patcher.sh deleted file mode 100755 index 6a82a0d..0000000 --- a/bb/scripts/patcher.sh +++ /dev/null @@ -1,4 +0,0 @@ -# Fix some issues that can only be fixed manually - -# Copy random.h from MacOS to iOS -cp /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/random.h /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/random.h diff --git a/bb/src/barretenberg_api/acir.rs b/bb/src/barretenberg_api/acir.rs deleted file mode 100644 index 81a4d52..0000000 --- a/bb/src/barretenberg_api/acir.rs +++ /dev/null @@ -1,280 +0,0 @@ -use super::{bindgen, models::Ptr, traits::SerializeBuffer, Buffer}; -use std::ptr; -use std::fmt::Write; -use std::env; -use num_bigint::BigUint; - -#[derive(Debug)] -pub struct CircuitSizes { - pub total: u32, - pub subgroup: u32, -} - -fn pack_proof_into_biguints(vec_u8: &[u8]) -> Vec { - // We process the vector in chunks of 32 bytes - vec_u8.chunks(32).map(|chunk| BigUint::from_bytes_be(chunk)).collect() -} - -// TODO: Enable this once we know how to format the vk as fields -/*fn pack_vk_into_biguints(vec_u8: &[u8]) -> Vec { - // We skip the first 97 bytes and then we process the rest in chunks of 32 bytes - let mut biguints: Vec = Vec::new(); - // First 8 bytes are the subgroup size - biguints.push(BigUint::from_bytes_be(&vec_u8[0..8])); - // The 8 bytes after the subgroup size are ignored - // Next 8 bytes are the number of public inputs (including the pairing inputs) - biguints.push(BigUint::from_bytes_be(&vec_u8[16..24])); - // Next 8 bytes are the public inputs offset - biguints.push(BigUint::from_bytes_be(&vec_u8[24..32])); - // What is this byte? - biguints.push(BigUint::from(vec_u8[32])); - // Another 16 bytes going from 1 to 16? - biguints.extend(vec_u8[33..97].chunks(4).map(|chunk| BigUint::from_bytes_be(chunk))); - // Then the actual vkey - biguints.extend(vec_u8[97..].chunks(32) - .flat_map(|chunk| { - let mut biguints = Vec::new(); - biguints.push(BigUint::from_bytes_be(&chunk[15..32])); - biguints.push(BigUint::from_bytes_be(&chunk[0..15])); - biguints.into_iter() - })); - biguints -}*/ - -fn from_biguints_to_hex_strings(biguints: &[BigUint]) -> Vec { - biguints.iter().map(|biguint| format!("0x{:064x}", biguint)).collect() -} - -pub unsafe fn get_circuit_sizes(constraint_system_buf: &[u8], recursive: bool) -> CircuitSizes { - let mut total = 0; - let mut subgroup = 0; - let honk_recursion = true; - bindgen::acir_get_circuit_sizes( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - &recursive, - &honk_recursion, - &mut total, - &mut subgroup, - ); - CircuitSizes { - total: total.to_be(), - subgroup: subgroup.to_be(), - } -} - -pub unsafe fn acir_prove_ultra_honk( - constraint_system_buf: &[u8], - witness_buf: &[u8], - vkey_buf: &[u8], - slow_low_memory: bool, -) -> Vec { - acir_set_slow_low_memory(slow_low_memory); - - let mut out_ptr = ptr::null_mut(); - bindgen::acir_prove_ultra_zk_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - witness_buf.to_buffer().as_slice().as_ptr(), - vkey_buf.as_ptr(), - &mut out_ptr, - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_prove_ultra_keccak_honk( - constraint_system_buf: &[u8], - witness_buf: &[u8], - vkey_buf: &[u8], - slow_low_memory: bool, -) -> Vec { - acir_set_slow_low_memory(slow_low_memory); - - let mut out_ptr = ptr::null_mut(); - bindgen::acir_prove_ultra_keccak_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - witness_buf.to_buffer().as_slice().as_ptr(), - vkey_buf.as_ptr(), - &mut out_ptr, - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_prove_ultra_keccak_zk_honk( - constraint_system_buf: &[u8], - witness_buf: &[u8], - vkey_buf: &[u8], - slow_low_memory: bool, -) -> Vec { - acir_set_slow_low_memory(slow_low_memory); - - let mut out_ptr = ptr::null_mut(); - bindgen::acir_prove_ultra_keccak_zk_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - witness_buf.to_buffer().as_slice().as_ptr(), - vkey_buf.as_ptr(), - &mut out_ptr, - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_get_ultra_honk_verification_key(constraint_system_buf: &[u8]) -> Vec { - let mut out_ptr = ptr::null_mut(); - bindgen::acir_write_vk_ultra_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - &mut out_ptr - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_get_ultra_honk_keccak_verification_key(constraint_system_buf: &[u8]) -> Vec { - let mut out_ptr = ptr::null_mut(); - bindgen::acir_write_vk_ultra_keccak_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - &mut out_ptr - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_get_ultra_honk_keccak_zk_verification_key(constraint_system_buf: &[u8]) -> Vec { - let mut out_ptr = ptr::null_mut(); - bindgen::acir_write_vk_ultra_keccak_zk_honk( - constraint_system_buf.to_buffer().as_slice().as_ptr(), - &mut out_ptr - ); - Buffer::from_ptr( - Buffer::from_ptr(out_ptr) - .unwrap() - .to_vec() - .as_slice() - .as_ptr(), - ) - .unwrap() - .to_vec() -} - -pub unsafe fn acir_verify_ultra_honk(proof_buf: &[u8], vkey_buf: &[u8]) -> bool { - let mut result = false; - bindgen::acir_verify_ultra_zk_honk( - proof_buf.to_buffer().as_ptr(), - vkey_buf.as_ptr(), - &mut result, - ); - result -} - -pub unsafe fn acir_verify_ultra_keccak_honk(proof_buf: &[u8], vkey_buf: &[u8]) -> bool { - let mut result = false; - bindgen::acir_verify_ultra_keccak_honk( - proof_buf.to_buffer().as_ptr(), - vkey_buf.as_ptr(), - &mut result, - ); - result -} - -pub unsafe fn acir_verify_ultra_keccak_zk_honk(proof_buf: &[u8], vkey_buf: &[u8]) -> bool { - let mut result = false; - bindgen::acir_verify_ultra_keccak_zk_honk( - proof_buf.to_buffer().as_ptr(), - vkey_buf.as_ptr(), - &mut result, - ); - result -} - -pub unsafe fn acir_prove_and_verify_ultra_honk(constraint_system_buf: &[u8], witness_buf: &[u8]) -> bool { - let mut result = false; - bindgen::acir_prove_and_verify_ultra_honk( - constraint_system_buf.to_buffer().as_ptr(), - witness_buf.to_buffer().as_ptr(), - &mut result, - ); - result -} - -pub unsafe fn acir_serialize_proof_into_fields( - acir_composer_ptr: &mut Ptr, - proof_buf: &[u8], - num_inner_public_inputs: u32, -) -> Vec { - let mut out_ptr = ptr::null_mut(); - bindgen::acir_serialize_proof_into_fields( - acir_composer_ptr, - proof_buf.to_buffer().as_ptr(), - &num_inner_public_inputs.to_be(), - &mut out_ptr, - ); - Buffer::from_ptr(out_ptr).unwrap().to_vec() -} - -pub unsafe fn acir_serialize_verification_key_into_fields( - acir_composer_ptr: &mut Ptr, -) -> (Vec, [u8; 32]) { - let mut out_vkey = ptr::null_mut(); - let mut out_key_hash = [0; 32]; - bindgen::acir_serialize_verification_key_into_fields( - acir_composer_ptr, - &mut out_vkey, - out_key_hash.as_mut_ptr(), - ); - (Buffer::from_ptr(out_vkey).unwrap().to_vec(), out_key_hash) -} - -pub unsafe fn acir_proof_as_fields_ultra_honk(proof_buf: &[u8]) -> Vec { - from_biguints_to_hex_strings(&pack_proof_into_biguints(&proof_buf)) -} - -pub fn acir_set_slow_low_memory(enabled: bool) { - if enabled { - env::set_var("BB_SLOW_LOW_MEMORY", "1"); - } else { - env::remove_var("BB_SLOW_LOW_MEMORY"); - } -} - -pub fn acir_get_slow_low_memory() -> bool { - env::var("BB_SLOW_LOW_MEMORY").map_or(false, |val| val == "1") -} - -/*pub unsafe fn acir_vk_as_fields_ultra_honk(vk_buf: &[u8]) -> Vec { - from_biguints_to_hex_strings(&pack_vk_into_biguints(&vk_buf)) -}*/ diff --git a/bb/src/barretenberg_api/bindings.rs b/bb/src/barretenberg_api/bindings.rs deleted file mode 100644 index 9f8fb1f..0000000 --- a/bb/src/barretenberg_api/bindings.rs +++ /dev/null @@ -1,195 +0,0 @@ -/* automatically generated by rust-bindgen 0.71.1 */ - -pub type in_buf32 = *const u8; -pub type out_buf32 = *mut u8; -pub type in_ptr = *const *mut ::std::os::raw::c_void; -unsafe extern "C" { - pub fn pedersen_commit(inputs_buffer: vec_in_buf, ctx_index: *const u32, output: out_buf); -} -unsafe extern "C" { - pub fn pedersen_hash(inputs_buffer: vec_in_buf, hash_index: *const u32, output: out_buf); -} -unsafe extern "C" { - pub fn pedersen_hashes(inputs_buffer: vec_in_buf, hash_index: *const u32, output: out_buf); -} -unsafe extern "C" { - pub fn pedersen_hash_buffer(input_buffer: *const u8, hash_index: *const u32, output: out_buf); -} -unsafe extern "C" { - pub fn poseidon2_hash(inputs_buffer: vec_in_buf, output: out_buf); -} -unsafe extern "C" { - pub fn poseidon2_hashes(inputs_buffer: vec_in_buf, output: out_buf); -} -unsafe extern "C" { - pub fn blake2s(data: *const u8, r: out_buf32); -} -unsafe extern "C" { - pub fn blake2s_to_field_(data: *const u8, r: out_buf); -} -unsafe extern "C" { - pub fn schnorr_construct_signature( - message: *const u8, - private_key: in_buf, - s: out_buf32, - e: out_buf32, - ); -} -unsafe extern "C" { - pub fn schnorr_verify_signature( - message: *const u8, - pub_key: in_buf, - sig_s: in_buf32, - sig_e: in_buf32, - result: *mut bool, - ); -} -unsafe extern "C" { - pub fn schnorr_multisig_create_multisig_public_key( - private_key: in_buf, - multisig_pubkey_buf: out_buf, - ); -} -unsafe extern "C" { - pub fn schnorr_multisig_validate_and_combine_signer_pubkeys( - signer_pubkey_buf: vec_in_buf, - combined_key_buf: out_buf, - success: *mut bool, - ); -} -unsafe extern "C" { - pub fn schnorr_multisig_construct_signature_round_1( - round_one_public_output_buf: out_buf, - round_one_private_output_buf: out_buf, - ); -} -unsafe extern "C" { - pub fn schnorr_multisig_construct_signature_round_2( - message: *const u8, - private_key: in_buf, - signer_round_one_private_buf: in_buf, - signer_pubkeys_buf: vec_in_buf, - round_one_public_buf: vec_in_buf, - round_two_buf: out_buf, - success: *mut bool, - ); -} -unsafe extern "C" { - pub fn schnorr_multisig_combine_signatures( - message: *const u8, - signer_pubkeys_buf: vec_in_buf, - round_one_buf: vec_in_buf, - round_two_buf: vec_in_buf, - s: out_buf32, - e: out_buf32, - success: *mut bool, - ); -} -unsafe extern "C" { - pub fn srs_init_srs(points_buf: *const u8, num_points: *const u32, g2_point_buf: *const u8); -} -unsafe extern "C" { - pub fn srs_init_grumpkin_srs(points_buf: *const u8, num_points: *const u32); -} -unsafe extern "C" { - pub fn test_threads(threads: *const u32, iterations: *const u32, out: *mut u32); -} -unsafe extern "C" { - pub fn common_init_slab_allocator(circuit_size: *const u32); -} -unsafe extern "C" { - pub fn acir_get_circuit_sizes( - constraint_system_buf: *const u8, - recursive: *const bool, - honk_recursion: *const bool, - total: *mut u32, - subgroup: *mut u32, - ); -} -unsafe extern "C" { - #[doc = " @brief Construct and verify an UltraHonk proof\n"] - pub fn acir_prove_and_verify_ultra_honk( - constraint_system_buf: *const u8, - witness_buf: *const u8, - result: *mut bool, - ); -} -unsafe extern "C" { - pub fn acir_prove_aztec_client( - ivc_inputs_buf: *const u8, - out_proof: *mut *mut u8, - out_vk: *mut *mut u8, - ); -} -unsafe extern "C" { - pub fn acir_verify_aztec_client(proof_buf: *const u8, vk_buf: *const u8, result: *mut bool); -} -unsafe extern "C" { - pub fn acir_serialize_proof_into_fields( - acir_composer_ptr: in_ptr, - proof_buf: *const u8, - num_inner_public_inputs: *const u32, - out: vec_out_buf, - ); -} -unsafe extern "C" { - pub fn acir_serialize_verification_key_into_fields( - acir_composer_ptr: in_ptr, - out_vkey: vec_out_buf, - out_key_hash: out_buf, - ); -} -unsafe extern "C" { - pub fn acir_prove_ultra_zk_honk( - acir_vec: *const u8, - witness_vec: *const u8, - vk_buf: *const u8, - out: *mut *mut u8, - ); -} -unsafe extern "C" { - pub fn acir_prove_ultra_keccak_honk( - acir_vec: *const u8, - witness_vec: *const u8, - vk_buf: *const u8, - out: *mut *mut u8, - ); -} -unsafe extern "C" { - pub fn acir_prove_ultra_keccak_zk_honk( - acir_vec: *const u8, - witness_vec: *const u8, - vk_buf: *const u8, - out: *mut *mut u8, - ); -} -unsafe extern "C" { - pub fn acir_verify_ultra_zk_honk(proof_buf: *const u8, vk_buf: *const u8, result: *mut bool); -} -unsafe extern "C" { - pub fn acir_verify_ultra_keccak_honk( - proof_buf: *const u8, - vk_buf: *const u8, - result: *mut bool, - ); -} -unsafe extern "C" { - pub fn acir_verify_ultra_keccak_zk_honk( - proof_buf: *const u8, - vk_buf: *const u8, - result: *mut bool, - ); -} -unsafe extern "C" { - pub fn acir_write_vk_ultra_honk(acir_vec: *const u8, out: *mut *mut u8); -} -unsafe extern "C" { - pub fn acir_write_vk_ultra_keccak_honk(acir_vec: *const u8, out: *mut *mut u8); -} -unsafe extern "C" { - pub fn acir_write_vk_ultra_keccak_zk_honk(acir_vec: *const u8, out: *mut *mut u8); -} -pub type vec_in_buf = *const u8; -pub type out_buf = *mut u8; -pub type vec_out_buf = *mut *mut u8; -pub type in_buf = *const u8; diff --git a/bb/src/barretenberg_api/blake2s.rs b/bb/src/barretenberg_api/blake2s.rs deleted file mode 100644 index 8dcc0e6..0000000 --- a/bb/src/barretenberg_api/blake2s.rs +++ /dev/null @@ -1,19 +0,0 @@ -use super::{ - bindgen, - models::Fr, - traits::{DeserializeBuffer, SerializeBuffer}, -}; - -pub fn blake2s(inputs: &[u8]) -> [u8; 32] { - let mut output = [0; 32]; - unsafe { bindgen::blake2s(inputs.to_buffer().as_slice().as_ptr(), output.as_mut_ptr()) }; - output -} - -pub fn blake2s_to_field(inputs: &[u8]) -> Fr { - let mut output: ::Slice = [0; 32]; - unsafe { - bindgen::blake2s_to_field_(inputs.to_buffer().as_slice().as_ptr(), output.as_mut_ptr()) - }; - Fr::from_buffer(output) -} diff --git a/bb/src/barretenberg_api/mod.rs b/bb/src/barretenberg_api/mod.rs deleted file mode 100644 index cb25770..0000000 --- a/bb/src/barretenberg_api/mod.rs +++ /dev/null @@ -1,90 +0,0 @@ -pub mod acir; -pub mod blake2s; -pub mod models; -pub mod pedersen; -pub mod poseidon2; -pub mod schnorr; -pub mod srs; -pub mod traits; - -#[cfg(test)] -pub mod tests; - -mod bindgen { - // This matches bindgen::Builder output - include!("bindings.rs"); -} - -use self::traits::SerializeBuffer; -use std::{ffi::CStr, slice}; - -#[derive(Debug, thiserror::Error)] -pub enum BufferError { - #[error("Binding call error")] - Null, -} - -pub struct Buffer { - data: Vec, -} - -impl Buffer { - /// Constructs a Buffer from a raw pointer, reading a u32 length followed by that many bytes. - /// - /// # Safety - /// This method is unsafe because it trusts the caller to ensure that `ptr` is a valid pointer - /// pointing to at least `u32` bytes plus the length indicated by the u32 value. - pub unsafe fn from_ptr(ptr: *const u8) -> Result { - if ptr.is_null() { - return Err(BufferError::Null); - } - let len_slice = slice::from_raw_parts(ptr, 4); - let len = u32::from_be_bytes([len_slice[0], len_slice[1], len_slice[2], len_slice[3]]); - let data_ptr = ptr.add(4); - let data = slice::from_raw_parts(data_ptr, len as usize); - Ok(Self { - data: data.to_vec(), - }) - } - - /// Returns a reference to the buffer's data as a slice. - pub fn as_slice(&self) -> &[u8] { - &self.data - } - - /// Consumes the Buffer, returning its underlying data as a Vec. - pub fn to_vec(self) -> Vec { - self.data - } -} - -/// Parses a C string from a raw pointer and returns a Rust String. -/// -/// # Safety -/// This function is unsafe because it trusts the caller to provide a valid null-terminated -/// C string. Dereferencing an invalid pointer can cause undefined behavior. -pub unsafe fn parse_c_str(ptr: *const ::std::os::raw::c_char) -> Option { - if ptr.is_null() { - return None; - } - CStr::from_ptr(ptr) - .to_str() - .map_or(None, |s| Some(s.to_string())) -} - -impl SerializeBuffer for &[T] { - fn to_buffer(&self) -> Vec { - let mut buffer = Vec::new(); - buffer.extend_from_slice(&(self.len() as u32).to_be_bytes()); - for elem in self.iter() { - buffer.extend_from_slice(&elem.to_buffer()); - } - buffer - } -} - -impl SerializeBuffer for u8 { - fn to_buffer(&self) -> Vec { - vec![*self] - } -} diff --git a/bb/src/barretenberg_api/models.rs b/bb/src/barretenberg_api/models.rs deleted file mode 100644 index 63c78c5..0000000 --- a/bb/src/barretenberg_api/models.rs +++ /dev/null @@ -1,70 +0,0 @@ -use super::traits::{DeserializeBuffer, SerializeBuffer}; -use std::ffi::c_void; - -pub type Ptr = *mut c_void; - -#[derive(Debug, PartialEq)] -pub struct Fr { - pub data: [u8; 32], -} - -impl SerializeBuffer for Fr { - fn to_buffer(&self) -> Vec { - self.data.to_vec() - } -} - -impl DeserializeBuffer for Fr { - type Slice = [u8; 32]; - fn from_buffer(buf: Self::Slice) -> Self { - Fr { data: buf } - } -} - -#[derive(Debug, PartialEq)] -pub struct Fq { - pub data: [u8; 32], -} - -impl SerializeBuffer for Fq { - fn to_buffer(&self) -> Vec { - self.data.to_vec() - } -} - -impl DeserializeBuffer for Fq { - type Slice = [u8; 32]; - fn from_buffer(buf: Self::Slice) -> Self { - Fq { data: buf } - } -} - -#[derive(Debug, PartialEq)] -pub struct Point { - pub x: Fr, - pub y: Fr, -} - -impl SerializeBuffer for Point { - fn to_buffer(&self) -> Vec { - self.x - .to_buffer() - .into_iter() - .chain(self.y.to_buffer()) - .collect() - } -} - -impl DeserializeBuffer for Point { - type Slice = [u8; 64]; - fn from_buffer(buf: Self::Slice) -> Self { - let mut fr1: ::Slice = [0; 32]; - let mut fr2: ::Slice = [0; 32]; - fr1.clone_from_slice(&buf[..32]); - fr2.clone_from_slice(&buf[32..]); - Self { - x: Fr::from_buffer(fr1), - y: Fr::from_buffer(fr2), - } - } -} diff --git a/bb/src/barretenberg_api/pedersen.rs b/bb/src/barretenberg_api/pedersen.rs deleted file mode 100644 index 616ec9c..0000000 --- a/bb/src/barretenberg_api/pedersen.rs +++ /dev/null @@ -1,47 +0,0 @@ -use super::{ - bindgen, - models::{Fr, Point}, - traits::SerializeBuffer, -}; -use crate::barretenberg_api::traits::DeserializeBuffer; - -pub unsafe fn pedersen_commit(inputs: &[Fr]) -> Point { - let mut output: ::Slice = [0; 64]; - let offset: u32 = 0; - bindgen::pedersen_commit( - inputs.to_buffer().as_slice().as_ptr(), - offset.to_be_bytes().as_ptr() as *const u32, - output.as_mut_ptr(), - ); - Point::from_buffer(output) -} - -pub unsafe fn pedersen_hash(inputs: &[Fr], hash_index: u32) -> Fr { - let mut output: ::Slice = [0; 32]; - bindgen::pedersen_hash( - inputs.to_buffer().as_slice().as_ptr(), - hash_index.to_be_bytes().as_ptr() as *const u32, - output.as_mut_ptr(), - ); - Fr::from_buffer(output) -} - -pub unsafe fn pedersen_hashes(inputs: &[Fr], hash_index: u32) -> Fr { - let mut output: ::Slice = [0; 32]; - bindgen::pedersen_hashes( - inputs.to_buffer().as_slice().as_ptr(), - hash_index.to_be_bytes().as_ptr() as *const u32, - output.as_mut_ptr(), - ); - Fr::from_buffer(output) -} - -pub unsafe fn pedersen_hash_buffer(inputs: &[u8], hash_index: u32) -> Fr { - let mut output: ::Slice = [0; 32]; - bindgen::pedersen_hashes( - inputs.as_ptr(), - hash_index.to_be_bytes().as_ptr() as *const u32, - output.as_mut_ptr(), - ); - Fr::from_buffer(output) -} diff --git a/bb/src/barretenberg_api/poseidon2.rs b/bb/src/barretenberg_api/poseidon2.rs deleted file mode 100644 index 117639e..0000000 --- a/bb/src/barretenberg_api/poseidon2.rs +++ /dev/null @@ -1,17 +0,0 @@ -use super::{ - bindgen, - models::Fr, - traits::{DeserializeBuffer, SerializeBuffer}, -}; - -pub unsafe fn poseidon2_hash(inputs: &[Fr]) -> Fr { - let mut output: ::Slice = [0; 32]; - bindgen::poseidon2_hash(inputs.to_buffer().as_slice().as_ptr(), output.as_mut_ptr()); - Fr::from_buffer(output) -} - -pub unsafe fn poseidon2_hashes(inputs: &[Fr]) -> Fr { - let mut output: ::Slice = [0; 32]; - bindgen::poseidon2_hashes(inputs.to_buffer().as_slice().as_ptr(), output.as_mut_ptr()); - Fr::from_buffer(output) -} diff --git a/bb/src/barretenberg_api/schnorr.rs b/bb/src/barretenberg_api/schnorr.rs deleted file mode 100644 index db5bcde..0000000 --- a/bb/src/barretenberg_api/schnorr.rs +++ /dev/null @@ -1,46 +0,0 @@ -use super::{ - bindgen, - models::{Fq, Fr, Point}, - traits::{DeserializeBuffer, SerializeBuffer}, -}; - -pub unsafe fn schnorr_construct_signature( - message: &[u8], - private_key: &Fr, -) -> ([u8; 32], [u8; 32]) { - let mut s = [0; 32]; - let mut e = [0; 32]; - bindgen::schnorr_construct_signature( - message.to_buffer().as_slice().as_ptr(), - private_key.to_buffer().as_slice().as_ptr(), - s.as_mut_ptr(), - e.as_mut_ptr(), - ); - (s, e) -} - -pub unsafe fn schnorr_verify_signature( - message: &[u8], - public_key: &Point, - sig_s: &mut [u8; 32], - sig_e: &mut [u8; 32], -) -> bool { - let mut result = false; - bindgen::schnorr_verify_signature( - message.to_buffer().as_slice().as_ptr(), - public_key.to_buffer().as_slice().as_ptr(), - sig_s.as_mut_ptr(), - sig_e.as_mut_ptr(), - &mut result, - ); - result -} - -pub unsafe fn schnorr_multisig_create_multisig_public_key(public_key: &Fq) -> [u8; 128] { - let mut result = [0; 128]; - bindgen::schnorr_multisig_create_multisig_public_key( - public_key.to_buffer().as_slice().as_ptr(), - result.as_mut_ptr(), - ); - result -} diff --git a/bb/src/barretenberg_api/srs.rs b/bb/src/barretenberg_api/srs.rs deleted file mode 100644 index fda2b47..0000000 --- a/bb/src/barretenberg_api/srs.rs +++ /dev/null @@ -1,9 +0,0 @@ -use super::bindgen; - -pub unsafe fn init_srs(points_buf: &[u8], num_points: u32, g2_point_buf: &[u8]) { - bindgen::srs_init_srs( - points_buf.as_ptr(), - &num_points.to_be(), - g2_point_buf.as_ptr(), - ); -} diff --git a/bb/src/barretenberg_api/tests/acir.rs b/bb/src/barretenberg_api/tests/acir.rs deleted file mode 100644 index adfb71f..0000000 --- a/bb/src/barretenberg_api/tests/acir.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::barretenberg_api::acir; - -#[test] -fn test_acir_get_circuit_size() { - let constraint_system_buf = [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 49, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 51, 48, 54, 52, 52, 101, 55, 50, 101, 49, 51, 49, 97, 48, 50, 57, 98, 56, 53, 48, 52, 53, 98, 54, 56, 49, 56, 49, 53, 56, 53, 100, 50, 56, 51, 51, 101, 56, 52, 56, 55, 57, 98, 57, 55, 48, 57, 49, 52, 51, 101, 49, 102, 53, 57, 51, 102, 48, 48, 48, 48, 48, 48, 48, 2, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - let circuit_sizes = unsafe { acir::get_circuit_sizes(&constraint_system_buf, true) }; - println!("{:?}", circuit_sizes); - assert_eq!(circuit_sizes.total, 3560); - assert_eq!(circuit_sizes.subgroup, 4096); -} diff --git a/bb/src/barretenberg_api/tests/blake2s.rs b/bb/src/barretenberg_api/tests/blake2s.rs deleted file mode 100644 index f962ad5..0000000 --- a/bb/src/barretenberg_api/tests/blake2s.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::barretenberg_api::blake2s; - -#[test] -fn test_blake2s() { - let input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"; - assert!( - blake2s::blake2s(input.as_bytes()) - == [ - 0x44, 0xdd, 0xdb, 0x39, 0xbd, 0xb2, 0xaf, 0x80, 0xc1, 0x47, 0x89, 0x4c, 0x1d, 0x75, - 0x6a, 0xda, 0x3d, 0x1c, 0x2a, 0xc2, 0xb1, 0x00, 0x54, 0x1e, 0x04, 0xfe, 0x87, 0xb4, - 0xa5, 0x9e, 0x12, 0x43 - ] - ); -} diff --git a/bb/src/barretenberg_api/tests/mod.rs b/bb/src/barretenberg_api/tests/mod.rs deleted file mode 100644 index 55e9aca..0000000 --- a/bb/src/barretenberg_api/tests/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod blake2s; -pub mod acir; \ No newline at end of file diff --git a/bb/src/barretenberg_api/traits.rs b/bb/src/barretenberg_api/traits.rs deleted file mode 100644 index f6b5e87..0000000 --- a/bb/src/barretenberg_api/traits.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub trait SerializeBuffer { - fn to_buffer(&self) -> Vec; -} - -pub trait DeserializeBuffer { - type Slice; - fn from_buffer(val: Self::Slice) -> Self; -} diff --git a/bb/src/lib.rs b/bb/src/lib.rs deleted file mode 100644 index bc1fafc..0000000 --- a/bb/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::ffi::{c_char, CStr}; -use tracing::debug; - -pub mod barretenberg_api; - -#[no_mangle] -extern "C" fn logstr(char_ptr: *const c_char) { - let c_str = unsafe { CStr::from_ptr(char_ptr) }; - debug!("{}", c_str.to_str().unwrap()); -} - -#[no_mangle] -extern "C" fn env_hardware_concurrency() -> u32 { - std::thread::available_parallelism() - .map(|p| p.get() as u32) - .unwrap_or(1) -} \ No newline at end of file diff --git a/noir/Cargo.toml b/noir/Cargo.toml index 478675d..48965ff 100644 --- a/noir/Cargo.toml +++ b/noir/Cargo.toml @@ -1,45 +1,42 @@ [package] name = "noir" -version = "1.0.0-beta.8-3" +version = "1.0.0-beta.19" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -acir = { git = "https://github.com/noir-lang/noir.git", rev = "b33131574388d836341cea9b6380f3b1a8493eb8" } -acvm = { git = "https://github.com/noir-lang/noir.git", rev = "b33131574388d836341cea9b6380f3b1a8493eb8" } -acvm_blackbox_solver = { git = "https://github.com/noir-lang/noir.git", rev = "b33131574388d836341cea9b6380f3b1a8493eb8" } +acvm = { git = "https://github.com/noir-lang/noir.git", rev = "v1.0.0-beta.19" } +acvm_blackbox_solver = { git = "https://github.com/noir-lang/noir.git", rev = "v1.0.0-beta.19" } base64 = "0.22.0" bincode = "1.3.3" -bn254_blackbox_solver = { git = "https://github.com/noir-lang/noir.git", rev = "b33131574388d836341cea9b6380f3b1a8493eb8" } +bn254_blackbox_solver = { git = "https://github.com/noir-lang/noir.git", rev = "v1.0.0-beta.19" } flate2 = "1.0.28" hex = "0.4.3" -nargo = { git = "https://github.com/noir-lang/noir.git", rev = "b33131574388d836341cea9b6380f3b1a8493eb8" } +# Fix to address a breaking change not following semver guidelines +# TODO: remove when updating to a new version of Noir that supports this new change +keccak = "=0.2.0-rc.0" +nargo = { git = "https://github.com/noir-lang/noir.git", rev = "v1.0.0-beta.19" } reqwest = { version = "0.12.1", default-features = false, features = [ - "json", - "rustls-tls", "blocking", + "rustls-tls", ] } -serde = "1.0.197" +serde = { version = "1.0.197", features = ["derive"] } thiserror = "1.0.58" tracing = "0.1" tracing-subscriber = "0.3" serde_json = "1.0.125" clap = { version = "4.4.8", features = ["derive"] } -proptest = "=1.6.0" -base64ct = { version = "=1.7" } # Optional dependencies -bb = { path = "../bb", optional = true } -openssl = { version = "0.10", features = ["vendored"], optional = true } +barretenberg-rs = { version = "=4.2.0-aztecnr-rc.2", default-features = false, features = ["ffi"], optional = true } [features] default = [] -barretenberg = ["bb"] -android-compat = ["openssl"] +barretenberg = ["barretenberg-rs"] srs-downloader = ["barretenberg"] ios-build = ["barretenberg"] -android-build = ["barretenberg", "openssl"] +android-build = ["barretenberg"] [[bin]] name = "srs_downloader" diff --git a/noir/src/backends/barretenberg/api.rs b/noir/src/backends/barretenberg/api.rs new file mode 100644 index 0000000..8ff41e6 --- /dev/null +++ b/noir/src/backends/barretenberg/api.rs @@ -0,0 +1,149 @@ +use barretenberg_rs::{ + backends::FfiBackend, + generated_types::{ + CircuitComputeVkResponse, CircuitInfoResponse, CircuitInput, CircuitInputNoVK, + CircuitProveResponse, ProofSystemSettings, + }, + BarretenbergApi, +}; + +pub const FIELD_ELEMENT_SIZE: usize = 32; + +fn get_api() -> BarretenbergApi { + let backend = FfiBackend::new().expect("Failed to initialize FfiBackend"); + BarretenbergApi::new(backend) +} + +pub fn settings_ultra_honk_poseidon2() -> ProofSystemSettings { + ProofSystemSettings { + ipa_accumulation: false, + oracle_hash_type: "poseidon2".to_string(), + disable_zk: false, + optimized_solidity_verifier: false, + } +} + +pub fn settings_ultra_honk_keccak(disable_zk: bool) -> ProofSystemSettings { + ProofSystemSettings { + ipa_accumulation: false, + oracle_hash_type: "keccak".to_string(), + disable_zk, + optimized_solidity_verifier: false, + } +} + +/// Flatten chunked proof fields (Vec>) into a flat byte vector. +pub fn proof_fields_to_bytes(proof_fields: &[Vec]) -> Vec { + proof_fields + .iter() + .flat_map(|f| f.iter().copied()) + .collect() +} + +/// Split a flat byte vector into 32-byte field elements. +pub fn proof_bytes_to_fields(proof_bytes: &[u8]) -> Vec> { + proof_bytes + .chunks(FIELD_ELEMENT_SIZE) + .map(|chunk| chunk.to_vec()) + .collect() +} + +pub fn circuit_prove( + acir_buffer: &[u8], + witness: &[u8], + verification_key: &[u8], + settings: &ProofSystemSettings, +) -> Result { + let circuit = CircuitInput { + name: String::new(), + bytecode: acir_buffer.to_vec(), + verification_key: verification_key.to_vec(), + }; + let mut api = get_api(); + api.circuit_prove(circuit, witness, settings.clone()) + .map_err(|e| format!("circuit_prove failed: {}", e)) +} + +pub fn circuit_compute_vk( + acir_buffer: &[u8], + settings: &ProofSystemSettings, +) -> Result { + let circuit = CircuitInputNoVK { + name: String::new(), + bytecode: acir_buffer.to_vec(), + }; + let mut api = get_api(); + api.circuit_compute_vk(circuit, settings.clone()) + .map_err(|e| format!("circuit_compute_vk failed: {}", e)) +} + +pub fn circuit_verify( + verification_key: &[u8], + public_inputs: Vec>, + proof: Vec>, + settings: &ProofSystemSettings, +) -> Result { + let mut api = get_api(); + let response = api + .circuit_verify(verification_key, public_inputs, proof, settings.clone()) + .map_err(|e| format!("circuit_verify failed: {}", e))?; + Ok(response.verified) +} + +pub fn circuit_stats( + acir_buffer: &[u8], + settings: &ProofSystemSettings, +) -> Result { + let circuit = CircuitInput { + name: String::new(), + bytecode: acir_buffer.to_vec(), + verification_key: vec![], + }; + let mut api = get_api(); + api.circuit_stats(circuit, false, settings.clone()) + .map_err(|e| format!("circuit_stats failed: {}", e)) +} + +pub fn srs_init(g1_data: &[u8], num_points: u32, g2_data: &[u8]) -> Result<(), String> { + let mut api = get_api(); + api.srs_init_srs(g1_data, num_points, g2_data) + .map_err(|e| format!("srs_init failed: {}", e))?; + Ok(()) +} + +// Direct FFI access to barretenberg global memory configuration variables. +// These are file-scope C++ globals in barretenberg/polynomials/backing_memory.cpp. +extern "C" { + static mut slow_low_memory: bool; + static mut storage_budget: usize; +} + +/// Configure barretenberg's low memory mode. +/// +/// When enabled, barretenberg uses file-backed memory for polynomial storage, +/// which significantly reduces RAM usage at the cost of slower proving (~2x). +/// +/// # Safety +/// +/// Sets global C++ variables via FFI. Must be called before proving/vk operations. +pub fn configure_memory(enabled: bool, max_storage_usage: Option) { + if enabled { + std::env::set_var("BB_SLOW_LOW_MEMORY", "1"); + } else { + std::env::set_var("BB_SLOW_LOW_MEMORY", "0"); + } + if let Some(budget) = max_storage_usage { + std::env::set_var("BB_STORAGE_BUDGET", format!("{}", budget)); + } + unsafe { + slow_low_memory = enabled; + if let Some(budget) = max_storage_usage { + storage_budget = budget as usize; + } + } +} + +/// Check if slow low memory mode is currently enabled. +pub fn get_slow_low_memory() -> bool { + unsafe { slow_low_memory } +} diff --git a/noir/src/backends/barretenberg/mod.rs b/noir/src/backends/barretenberg/mod.rs index d2941f5..ab2570e 100644 --- a/noir/src/backends/barretenberg/mod.rs +++ b/noir/src/backends/barretenberg/mod.rs @@ -1,8 +1,8 @@ +pub mod api; pub mod prove; -pub mod verify; -//pub mod recursion; -pub mod utils; pub mod srs; +pub mod utils; +pub mod verify; #[cfg(test)] -pub mod tests; \ No newline at end of file +pub mod tests; diff --git a/noir/src/backends/barretenberg/prove.rs b/noir/src/backends/barretenberg/prove.rs index ac5df2f..4da6680 100644 --- a/noir/src/backends/barretenberg/prove.rs +++ b/noir/src/backends/barretenberg/prove.rs @@ -1,52 +1,87 @@ -use acir::{native_types::WitnessMap, FieldElement}; -use bb::barretenberg_api::acir::{ acir_prove_ultra_honk, acir_prove_ultra_keccak_honk, acir_prove_ultra_keccak_zk_honk}; +use acvm::acir::{native_types::WitnessMap, FieldElement}; -use crate::execute::execute; +use crate::backends::barretenberg::api::{ + self, configure_memory, proof_fields_to_bytes, settings_ultra_honk_keccak, + settings_ultra_honk_poseidon2, +}; use crate::circuit::get_acir_buffer_uncompressed; +use crate::execute::execute; use crate::witness::serialize_witness; -/// Generate an Ultra Honk proof for the given circuit bytecode and initial witness -/// Will execute the circuit to make sure it is solved -/// +/// Generate an Ultra Honk proof for the given circuit bytecode and initial witness. +/// Will execute the circuit to make sure it is solved. +/// +/// Uses poseidon2 as the oracle hash function (suitable for recursive verification in Noir). +/// /// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to prove -/// * initial_witness: The initial witness to use for the proof -/// * verification_key: The verification key to use for the proof -/// +/// +/// * `circuit_bytecode` - The base64-encoded circuit bytecode +/// * `initial_witness` - The initial witness to use for the proof +/// * `verification_key` - The verification key to use for the proof +/// * `low_memory_mode` - Whether to use file-backed memory (slower but uses less RAM) +/// /// # Returns -/// * The proof +/// * The proof as a flat byte vector: [public_inputs_bytes][proof_bytes] pub fn prove_ultra_honk( circuit_bytecode: &str, initial_witness: WitnessMap, verification_key: Vec, low_memory_mode: bool, ) -> Result, String> { + prove_ultra_honk_with_options( + circuit_bytecode, + initial_witness, + verification_key, + low_memory_mode, + None, + ) +} + +/// Generate an Ultra Honk proof with extended options. +/// +/// Same as `prove_ultra_honk` but with optional storage budget control. +pub fn prove_ultra_honk_with_options( + circuit_bytecode: &str, + initial_witness: WitnessMap, + verification_key: Vec, + low_memory_mode: bool, + max_storage_usage: Option, +) -> Result, String> { + configure_memory(low_memory_mode, max_storage_usage); let witness_stack = execute(circuit_bytecode, initial_witness)?; let serialized_solved_witness = serialize_witness(witness_stack)?; let acir_buffer_uncompressed = get_acir_buffer_uncompressed(circuit_bytecode)?; - Ok(unsafe { - acir_prove_ultra_honk(&acir_buffer_uncompressed, &serialized_solved_witness, &verification_key, low_memory_mode) - }) + let settings = settings_ultra_honk_poseidon2(); + let response = api::circuit_prove( + &acir_buffer_uncompressed, + &serialized_solved_witness, + &verification_key, + &settings, + )?; + + // Encode as: [num_public_inputs (4 bytes BE)] [public_inputs] [proof] + // The prefix lets verify_ultra_honk split inputs from proof fields. + let num_pub = response.public_inputs.len() as u32; + let mut result = num_pub.to_be_bytes().to_vec(); + result.extend(proof_fields_to_bytes(&response.public_inputs)); + result.extend(proof_fields_to_bytes(&response.proof)); + Ok(result) } -/// Generate an Ultra Honk proof for the given circuit bytecode and initial witness -/// Will execute the circuit to make sure it is solved -/// Unlike the standard Ultra Honk proof, this proof uses the Keccak hash function -/// instead of Poseidon hash function for the random oracle -/// -/// If zk is true, the proof will be fully zero-knowledge -/// +/// Generate an Ultra Honk proof using Keccak as the oracle hash function. +/// This is suitable for on-chain (EVM/Solidity) verification. +/// /// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to prove -/// * initial_witness: The initial witness to use for the proof -/// * verification_key: The verification key to use for the proof -/// * disable_zk: Whether to disable the zero-knowledge property of the proof -/// +/// +/// * `circuit_bytecode` - The base64-encoded circuit bytecode +/// * `initial_witness` - The initial witness to use for the proof +/// * `verification_key` - The verification key to use for the proof +/// * `disable_zk` - Whether to disable the zero-knowledge property of the proof +/// * `low_memory_mode` - Whether to use file-backed memory (slower but uses less RAM) +/// /// # Returns -/// * The proof +/// * The proof as a flat byte vector: [public_inputs_bytes][proof_bytes] pub fn prove_ultra_honk_keccak( circuit_bytecode: &str, initial_witness: WitnessMap, @@ -54,15 +89,44 @@ pub fn prove_ultra_honk_keccak( disable_zk: bool, low_memory_mode: bool, ) -> Result, String> { + prove_ultra_honk_keccak_with_options( + circuit_bytecode, + initial_witness, + verification_key, + disable_zk, + low_memory_mode, + None, + ) +} + +/// Generate an Ultra Honk Keccak proof with extended options. +/// +/// Same as `prove_ultra_honk_keccak` but with optional storage budget control. +pub fn prove_ultra_honk_keccak_with_options( + circuit_bytecode: &str, + initial_witness: WitnessMap, + verification_key: Vec, + disable_zk: bool, + low_memory_mode: bool, + max_storage_usage: Option, +) -> Result, String> { + configure_memory(low_memory_mode, max_storage_usage); let witness_stack = execute(circuit_bytecode, initial_witness)?; let serialized_solved_witness = serialize_witness(witness_stack)?; let acir_buffer_uncompressed = get_acir_buffer_uncompressed(circuit_bytecode)?; - Ok(unsafe { - if disable_zk { - acir_prove_ultra_keccak_honk(&acir_buffer_uncompressed, &serialized_solved_witness, &verification_key, low_memory_mode) - } else { - acir_prove_ultra_keccak_zk_honk(&acir_buffer_uncompressed, &serialized_solved_witness, &verification_key, low_memory_mode) - } - }) -} \ No newline at end of file + let settings = settings_ultra_honk_keccak(disable_zk); + let response = api::circuit_prove( + &acir_buffer_uncompressed, + &serialized_solved_witness, + &verification_key, + &settings, + )?; + + // Encode as: [num_public_inputs (4 bytes BE)] [public_inputs] [proof] + let num_pub = response.public_inputs.len() as u32; + let mut result = num_pub.to_be_bytes().to_vec(); + result.extend(proof_fields_to_bytes(&response.public_inputs)); + result.extend(proof_fields_to_bytes(&response.proof)); + Ok(result) +} diff --git a/noir/src/backends/barretenberg/recursion.rs b/noir/src/backends/barretenberg/recursion.rs deleted file mode 100644 index ba6bc48..0000000 --- a/noir/src/backends/barretenberg/recursion.rs +++ /dev/null @@ -1,22 +0,0 @@ -use bb_rs::barretenberg_api::acir::{ - acir_vk_as_fields_ultra_honk, acir_proof_as_fields_ultra_honk -}; - -/*pub fn generate_recursive_honk_proof_artifacts( -proof_bytes: Vec, -vk_bytes: Vec -) -> Result<(Vec, Vec), String> { -Ok(unsafe { - let proof = acir_proof_as_fields_ultra_honk(&proof_bytes); - let vk = acir_vk_as_fields_ultra_honk(&vk_bytes); - // Get the number of public inputs from the third field of the proof - // by parsing from hex to usize - let num_public_inputs = usize::from_str_radix(proof[1].trim_start_matches("0x"), 16).unwrap(); - let end_index_for_proof_without_public_inputs = 3 + num_public_inputs; - // We keep the first 3 fields but remove the following public inputs and keep the rest - let mut proof_without_public_inputs: Vec = Vec::from(&proof[..3]); - proof_without_public_inputs.extend_from_slice(&proof[end_index_for_proof_without_public_inputs..]); - - (proof_without_public_inputs, vk) -}) -}*/ \ No newline at end of file diff --git a/noir/src/backends/barretenberg/srs/mod.rs b/noir/src/backends/barretenberg/srs/mod.rs index 453da08..232b6bb 100644 --- a/noir/src/backends/barretenberg/srs/mod.rs +++ b/noir/src/backends/barretenberg/srs/mod.rs @@ -2,10 +2,19 @@ pub mod localsrs; pub mod netsrs; use serde::{Deserialize, Serialize}; -use crate::backends::barretenberg::utils::{get_circuit_size, compute_subgroup_size}; +use crate::backends::barretenberg::api; +use crate::backends::barretenberg::utils::{compute_subgroup_size, get_circuit_size}; // G2 is a small fixed group, so we can hardcode it here -const G2: [u8; 128] = [1, 24, 196, 213, 184, 55, 188, 194, 188, 137, 181, 179, 152, 181, 151, 78, 159, 89, 68, 7, 59, 50, 7, 139, 126, 35, 31, 236, 147, 136, 131, 176, 38, 14, 1, 178, 81, 246, 241, 199, 231, 255, 78, 88, 7, 145, 222, 232, 234, 81, 216, 122, 53, 142, 3, 139, 78, 254, 48, 250, 192, 147, 131, 193, 34, 254, 189, 163, 192, 192, 99, 42, 86, 71, 91, 66, 20, 229, 97, 94, 17, 230, 221, 63, 150, 230, 206, 162, 133, 74, 135, 212, 218, 204, 94, 85, 4, 252, 99, 105, 247, 17, 15, 227, 210, 81, 86, 193, 187, 154, 114, 133, 156, 242, 160, 70, 65, 249, 155, 164, 238, 65, 60, 128, 218, 106, 95, 228]; +const G2: [u8; 128] = [ + 1, 24, 196, 213, 184, 55, 188, 194, 188, 137, 181, 179, 152, 181, 151, 78, 159, 89, 68, 7, 59, + 50, 7, 139, 126, 35, 31, 236, 147, 136, 131, 176, 38, 14, 1, 178, 81, 246, 241, 199, 231, 255, + 78, 88, 7, 145, 222, 232, 234, 81, 216, 122, 53, 142, 3, 139, 78, 254, 48, 250, 192, 147, 131, + 193, 34, 254, 189, 163, 192, 192, 99, 42, 86, 71, 91, 66, 20, 229, 97, 94, 17, 230, 221, 63, + 150, 230, 206, 162, 133, 74, 135, 212, 218, 204, 94, 85, 4, 252, 99, 105, 247, 17, 15, 227, + 210, 81, 86, 193, 187, 154, 114, 133, 156, 242, 160, 70, 65, 249, 155, 164, 238, 65, 60, 128, + 218, 106, 95, 228, +]; #[derive(Serialize, Deserialize, PartialEq, Debug)] pub struct Srs { @@ -21,13 +30,12 @@ impl Srs { _ => Srs { g1_data: self.g1_data[..=(num_points * 64 - 1) as usize].to_vec(), g2_data: self.g2_data, - num_points: num_points, + num_points, }, } } } - pub fn get_srs(subgroup_size: u32, srs_path: Option<&str>) -> Srs { match srs_path { Some(path) => { @@ -48,16 +56,36 @@ pub fn get_srs(subgroup_size: u32, srs_path: Option<&str>) -> Srs { } } -pub fn setup_srs(circuit_size: u32, srs_path: Option<&str>) -> Result { +/// UltraHonk SRS point multiplier applied when deriving SRS size from a raw +/// circuit gate count. The prover needs SRS points not just for the gates but +/// also for witness/permutation/lookup polynomials. Empirically ~8x the dyadic +/// gate count for standard UltraHonk configurations. +const ULTRA_HONK_SRS_MULTIPLIER: u32 = 8; + +/// Initialize barretenberg's SRS sized for the given circuit_size. +/// +/// `circuit_size` is interpreted as the final desired subgroup size (no scaling +/// applied). Callers deriving a size from gate counts should use +/// [`setup_srs_from_bytecode`] which applies the UltraHonk overhead multiplier. +pub fn setup_srs(circuit_size: u32, srs_path: Option<&str>) -> Result { let subgroup_size = compute_subgroup_size(circuit_size); let srs = get_srs(subgroup_size, srs_path); - unsafe { - bb::barretenberg_api::srs::init_srs(&srs.g1_data, srs.num_points, &srs.g2_data); - } + + api::srs_init(&srs.g1_data, srs.num_points, &srs.g2_data)?; + Ok(srs.num_points) } -pub fn setup_srs_from_bytecode(circuit_bytecode: &str, srs_path: Option<&str>, recursive: bool) -> Result { +/// Initialize barretenberg's SRS sized for the circuit in the given bytecode. +/// +/// Queries `circuit_stats` for the dyadic gate count and multiplies by the +/// UltraHonk overhead (see [`ULTRA_HONK_SRS_MULTIPLIER`]) before calling +/// [`setup_srs`]. +pub fn setup_srs_from_bytecode( + circuit_bytecode: &str, + srs_path: Option<&str>, + recursive: bool, +) -> Result { let circuit_size = get_circuit_size(circuit_bytecode, recursive); - setup_srs(circuit_size, srs_path) -} \ No newline at end of file + setup_srs(circuit_size * ULTRA_HONK_SRS_MULTIPLIER, srs_path) +} diff --git a/noir/src/backends/barretenberg/srs/netsrs.rs b/noir/src/backends/barretenberg/srs/netsrs.rs index 8f57386..7fdccce 100644 --- a/noir/src/backends/barretenberg/srs/netsrs.rs +++ b/noir/src/backends/barretenberg/srs/netsrs.rs @@ -1,6 +1,7 @@ use reqwest::blocking::Client; use reqwest::header::{HeaderMap, RANGE}; use std::ops::Deref; +use std::time::Duration; use super::{Srs, G2}; @@ -26,34 +27,41 @@ impl NetSrs { self.0 } + /// Build a blocking HTTP client with a generous timeout. + /// + /// The default reqwest blocking client has no overall timeout but uses TCP + /// keepalive defaults that can trip on CI runners with slow/flaky network + /// paths to crs.aztec.network. A 5 minute timeout covers legitimate large + /// SRS downloads (tens of MB) while still failing fast on genuine outages. + fn http_client() -> Client { + Client::builder() + .timeout(Duration::from_secs(300)) + .build() + .expect("failed to build reqwest client") + } + fn download_g1_data(num_points: u32) -> Vec { let g1_end: u32 = num_points * 64 - 1; let mut headers = HeaderMap::new(); - headers.insert( - RANGE, - format!("bytes={}-{}", 0, g1_end).parse().unwrap(), - ); - - let response = Client::new() - .get( - "https://crs.aztec.network/g1.dat", - ) + headers.insert(RANGE, format!("bytes={}-{}", 0, g1_end).parse().unwrap()); + + let response = Self::http_client() + .get("https://crs.aztec.network/g1.dat") .headers(headers) .send() - .unwrap(); + .expect("failed to request g1 SRS data"); - response.bytes().unwrap().to_vec() + response.bytes().expect("failed to read g1 SRS body").to_vec() } + #[allow(dead_code)] fn download_g2_data() -> Vec { - let response = Client::new() - .get( - "https://crs.aztec.network/g2.dat", - ) + let response = Self::http_client() + .get("https://crs.aztec.network/g2.dat") .send() - .unwrap(); + .expect("failed to request g2 SRS data"); - response.bytes().unwrap().to_vec() + response.bytes().expect("failed to read g2 SRS body").to_vec() } } diff --git a/noir/src/backends/barretenberg/tests/mod.rs b/noir/src/backends/barretenberg/tests/mod.rs index f752523..ebdf595 100644 --- a/noir/src/backends/barretenberg/tests/mod.rs +++ b/noir/src/backends/barretenberg/tests/mod.rs @@ -1,22 +1,33 @@ +use crate::backends::barretenberg::{ + api::get_slow_low_memory, + prove::{prove_ultra_honk, prove_ultra_honk_keccak}, + srs::{setup_srs, setup_srs_from_bytecode}, + utils::compute_subgroup_size, + verify::{ + get_ultra_honk_keccak_verification_key, get_ultra_honk_verification_key, verify_ultra_honk, + verify_ultra_honk_keccak, + }, +}; use tracing::info; -use bb::barretenberg_api::{acir::{get_circuit_sizes, acir_get_slow_low_memory}, srs::init_srs}; -use crate::backends::barretenberg::{srs::{setup_srs_from_bytecode, setup_srs, netsrs::NetSrs}, verify::{verify_ultra_honk, verify_ultra_honk_keccak, get_ultra_honk_verification_key, get_ultra_honk_keccak_verification_key}, prove::{prove_ultra_honk, prove_ultra_honk_keccak}, utils::compute_subgroup_size}; -use acir::{FieldElement, native_types::{Witness, WitnessMap}}; -use crate::{witness, circuit}; + +use crate::{circuit, witness}; mod proof_utils; use serde_json; -use std::path::PathBuf; use std::env; +use std::path::PathBuf; -const BYTECODE: &str = "H4sIAAAAAAAA/62QQQqAMAwErfigpEna5OZXLLb/f4KKLZbiTQdCQg7Dsm66mc9x00O717rhG9ico5cgMOfoMxJu4C2pAEsKioqisnslysoaLVkEQ6aMRYxKFc//ZYQr29L10XfhXv4jB52E+OpMAQAA"; +/// Load the product circuit bytecode from the compiled JSON artifact. +/// Run `cd circuits && nargo compile --package product` to regenerate. +fn load_product_bytecode() -> String { + let circuit_path = get_circuit_path("product.json"); + let circuit_txt = std::fs::read_to_string(&circuit_path) + .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", circuit_path)); + let circuit: serde_json::Value = serde_json::from_str(&circuit_txt).unwrap(); + circuit["bytecode"].as_str().unwrap().to_string() +} /// Helper function to construct robust paths to circuit files -/// This function tries multiple strategies to find the correct path: -/// 1. First tries to use CARGO_MANIFEST_DIR if available -/// 2. Falls back to searching from current directory -/// 3. Finally tries relative paths as last resort fn get_circuit_path(filename: &str) -> PathBuf { - // Try to use CARGO_MANIFEST_DIR first (most reliable) if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { let mut path = PathBuf::from(manifest_dir); path.push(".."); @@ -27,12 +38,9 @@ fn get_circuit_path(filename: &str) -> PathBuf { return path; } } - - // Try to find from current directory by going up to workspace root + if let Ok(current_dir) = env::current_dir() { let mut path = current_dir.clone(); - - // Try to go up to workspace root and find circuits/target while path.parent().is_some() { let test_path = path.join("circuits").join("target").join(filename); if test_path.exists() { @@ -41,147 +49,138 @@ fn get_circuit_path(filename: &str) -> PathBuf { path = path.parent().unwrap().to_path_buf(); } } - - // Fallback: try relative paths (less reliable but might work in some cases) + let relative_paths = [ format!("../circuits/target/{}", filename), format!("../../circuits/target/{}", filename), format!("circuits/target/{}", filename), ]; - + for relative_path in relative_paths.iter() { let path = PathBuf::from(relative_path); if path.exists() { return path; } } - - // If all else fails, return the expected path and let the caller handle the error + PathBuf::from(format!("circuits/target/{}", filename)) } - #[test] fn test_acir_get_circuit_size() { - let (_, constraint_system_buf) = circuit::decode_circuit(BYTECODE).unwrap(); - let circuit_sizes = unsafe { - get_circuit_sizes(&constraint_system_buf, false) - }; - assert_eq!(circuit_sizes.total, 3560); - assert_eq!(circuit_sizes.subgroup, 4096); + use crate::backends::barretenberg::utils::get_circuit_size; + let bytecode = load_product_bytecode(); + let circuit_size = get_circuit_size(&bytecode, false); + assert!(circuit_size > 0, "Circuit size should be > 0"); } #[test] fn test_prove_and_verify_ultra_honk() { let _ = tracing_subscriber::fmt::try_init(); - // Setup SRS - println!("setting up srs"); - setup_srs_from_bytecode(BYTECODE, None, false).unwrap(); - println!("srs setup"); + let bytecode = load_product_bytecode(); - // Ultra Honk + // Setup SRS + setup_srs_from_bytecode(&bytecode, None, false).unwrap(); - // Get the witness map from the vector of field elements - // The vector items can be either a FieldElement, an unsigned integer - // For hex or decimal strings, use from_vec_str_to_witness_map - println!("getting initial witness"); - let initial_witness = witness::from_vec_to_witness_map(vec![5 as u128, 6 as u128, 30 as u128]).unwrap(); - println!("initial witness: {:?}", initial_witness); + // Get the witness map (product circuit: a * b == result, i.e. 5 * 6 == 30) + let initial_witness = + witness::from_vec_to_witness_map(vec![5 as u128, 6 as u128, 30 as u128]).unwrap(); let start = std::time::Instant::now(); - println!("getting vk"); - let vk = get_ultra_honk_verification_key(BYTECODE, false).unwrap(); - println!("vk: {:?}", vk); - assert_eq!(acir_get_slow_low_memory(), false); + let vk = get_ultra_honk_verification_key(&bytecode, false).unwrap(); - let proof = prove_ultra_honk(BYTECODE, initial_witness, vk.clone(), false).unwrap(); + let proof = prove_ultra_honk(&bytecode, initial_witness, vk.clone(), false).unwrap(); info!("ultra honk proof generation time: {:?}", start.elapsed()); - assert_eq!(acir_get_slow_low_memory(), false); let verdict = verify_ultra_honk(proof, vk).unwrap(); - info!("honk proof verification verdict: {}", verdict); + assert!(verdict, "Ultra Honk proof verification should succeed"); } #[test] fn test_ultra_honk_keccak() { let _ = tracing_subscriber::fmt::try_init(); - // Read the JSON manifest of the circuit let keccak_circuit_path = get_circuit_path("keccak.json"); let keccak_circuit_txt = std::fs::read_to_string(&keccak_circuit_path) .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", keccak_circuit_path)); - // Parse the JSON manifest into a dictionary let keccak_circuit: serde_json::Value = serde_json::from_str(&keccak_circuit_txt).unwrap(); - // Get the bytecode from the dictionary let keccak_circuit_bytecode = keccak_circuit["bytecode"].as_str().unwrap(); - - // Setup SRS - setup_srs_from_bytecode(keccak_circuit_bytecode, None, false).unwrap(); - // Ultra Honk + setup_srs_from_bytecode(keccak_circuit_bytecode, None, false).unwrap(); - // Get the witness map from the vector of field elements - // The vector items can be either a FieldElement, an unsigned integer - // For hex or decimal strings, use from_vec_str_to_witness_map - let initial_witness = witness::from_vec_to_witness_map(vec![2 as u128, 5 as u128, 10 as u128, 15 as u128, 20 as u128]).unwrap(); + let initial_witness = witness::from_vec_to_witness_map(vec![ + 2 as u128, 5 as u128, 10 as u128, 15 as u128, 20 as u128, + ]) + .unwrap(); let start = std::time::Instant::now(); let vk = get_ultra_honk_keccak_verification_key(keccak_circuit_bytecode, false, false).unwrap(); - assert_eq!(acir_get_slow_low_memory(), false); - - let proof = prove_ultra_honk_keccak(keccak_circuit_bytecode, initial_witness, vk.clone(), false, false).unwrap(); - info!("ultra honk proof generation time: {:?}", start.elapsed()); - assert_eq!(acir_get_slow_low_memory(), false); + + let proof = prove_ultra_honk_keccak( + keccak_circuit_bytecode, + initial_witness, + vk.clone(), + false, + false, + ) + .unwrap(); + info!( + "ultra honk keccak proof generation time: {:?}", + start.elapsed() + ); let verdict = verify_ultra_honk_keccak(proof, vk, false).unwrap(); - info!("honk proof verification verdict: {}", verdict); + assert!( + verdict, + "Ultra Honk Keccak proof verification should succeed" + ); } #[test] fn test_ultra_honk_low_memory() { let _ = tracing_subscriber::fmt::try_init(); - // Read the JSON manifest of the circuit let circuit_path = get_circuit_path("keccak_large.json"); let circuit_txt = std::fs::read_to_string(&circuit_path) .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", circuit_path)); - // Parse the JSON manifest into a dictionary let circuit: serde_json::Value = serde_json::from_str(&circuit_txt).unwrap(); - // Get the bytecode from the dictionary let circuit_bytecode = circuit["bytecode"].as_str().unwrap(); - - // Setup SRS - setup_srs_from_bytecode(circuit_bytecode, None, false).unwrap(); - // Ultra Honk + setup_srs_from_bytecode(circuit_bytecode, None, false).unwrap(); - // Get the witness map from the vector of field elements - // The vector items can be either a FieldElement, an unsigned integer - // For hex or decimal strings, use from_vec_str_to_witness_map - let initial_witness = witness::from_vec_to_witness_map(vec![2 as u128, 5 as u128, 10 as u128, 15 as u128, 20 as u128]).unwrap(); + let initial_witness = witness::from_vec_to_witness_map(vec![ + 2 as u128, 5 as u128, 10 as u128, 15 as u128, 20 as u128, + ]) + .unwrap(); let start = std::time::Instant::now(); let vk = get_ultra_honk_verification_key(circuit_bytecode, true).unwrap(); - assert_eq!(acir_get_slow_low_memory(), true); - + assert_eq!(get_slow_low_memory(), true); + let proof = prove_ultra_honk(circuit_bytecode, initial_witness, vk.clone(), true).unwrap(); - info!("ultra honk proof generation time: {:?}", start.elapsed()); - assert_eq!(acir_get_slow_low_memory(), true); + info!( + "ultra honk low memory proof generation time: {:?}", + start.elapsed() + ); + assert_eq!(get_slow_low_memory(), true); let verdict = verify_ultra_honk(proof, vk).unwrap(); - info!("honk proof verification verdict: {}", verdict); + assert!( + verdict, + "Ultra Honk low memory proof verification should succeed" + ); } #[test] fn test_srs_setup_from_bytecode() { let _ = tracing_subscriber::fmt::try_init(); + let bytecode = load_product_bytecode(); let start = std::time::Instant::now(); - let srs = setup_srs_from_bytecode(BYTECODE, None, false).unwrap(); + let srs = setup_srs_from_bytecode(&bytecode, None, false).unwrap(); info!("srs setup time: {:?}", start.elapsed()); - // 2^5 + 1 = 33 - assert_eq!(srs, 4097); + assert!(srs > 0, "SRS num_points should be > 0"); } #[test] @@ -192,7 +191,6 @@ fn test_srs_setup_from_circuit_size() { let circuit_size = 22; let srs = setup_srs(circuit_size, None).unwrap(); info!("srs setup time: {:?}", start.elapsed()); - // 2^5 + 1 = 33 assert_eq!(srs, 33); } @@ -215,7 +213,7 @@ fn test_compute_subgroup_size() { subgroup_size = compute_subgroup_size(100000); assert_eq!(subgroup_size, 131072); - + subgroup_size = compute_subgroup_size(200000); assert_eq!(subgroup_size, 262144); @@ -223,74 +221,26 @@ fn test_compute_subgroup_size() { assert_eq!(subgroup_size, 524288); subgroup_size = compute_subgroup_size(1000000); - assert_eq!(subgroup_size, 1048576); + assert_eq!(subgroup_size, 1048576); } -/*#[test] -fn test_ultra_honk_recursive_proving() { - // Read the JSON manifest of the circuit - let recursed_circuit_path = get_circuit_path("recursed.json"); - let recursed_circuit_txt = std::fs::read_to_string(&recursed_circuit_path) - .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", recursed_circuit_path)); - // Parse the JSON manifest into a dictionary - let recursed_circuit: serde_json::Value = serde_json::from_str(&recursed_circuit_txt).unwrap(); - // Get the bytecode from the dictionary - let recursed_circuit_bytecode = recursed_circuit["bytecode"].as_str().unwrap(); - - setup_srs(String::from(recursed_circuit_bytecode), None, true).unwrap(); - - let mut initial_witness = WitnessMap::new(); - // x - initial_witness.insert(Witness(0), FieldElement::from(5u128)); - // y - initial_witness.insert(Witness(1), FieldElement::from(25u128)); - - let (recursed_proof, recursed_vk) = prove_ultra_honk(recursed_circuit_bytecode, initial_witness, true).unwrap(); - - let (proof_as_fields, vk_as_fields, key_hash) = recursion::generate_recursive_honk_proof_artifacts(recursed_proof, recursed_vk).unwrap(); - - //println!("proof: {:?}", proof_as_fields); - //println!("vk: {:?}", vk_as_fields); - //println!("key_hash: {:?}", key_hash); - - assert_eq!(proof_as_fields.len(), 463); - assert_eq!(vk_as_fields.len(), 128); - //assert_eq!(key_hash, "0x25240793a378438025d0dbe8a4e197c93ec663864a5c9b01699199423dab1008"); - - // Read the JSON manifest of the circuit - let recursive_circuit_path = get_circuit_path("recursive.json"); - let recursive_circuit_txt = std::fs::read_to_string(&recursive_circuit_path) - .unwrap_or_else(|_| panic!("Failed to read circuit file at: {:?}", recursive_circuit_path)); - // Parse the JSON manifest into a dictionary - let recursive_circuit: serde_json::Value = serde_json::from_str(&recursive_circuit_txt).unwrap(); - // Get the bytecode from the dictionary - let recursive_circuit_bytecode = recursive_circuit["bytecode"].as_str().unwrap(); - println!("recursive_circuit_bytecode: {:?}", recursive_circuit_bytecode); - - // IMPORTANT: Likely to run into a timeout for the net srs, replace None with a path to a local srs file - // before running this test - setup_srs(String::from(recursive_circuit_bytecode), None, true).unwrap(); - - let mut initial_witness_recursive = WitnessMap::new(); - let mut index = 0; - // Verification key - vk_as_fields.iter().for_each(|v| { - initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(v).unwrap()); - index += 1; - }); - // Proof - proof_as_fields.iter().for_each(|v| { - initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(v).unwrap()); - index += 1; - }); - // Public inputs - initial_witness_recursive.insert(Witness(index), FieldElement::from(25u128)); - index += 1; - // Key hash - initial_witness_recursive.insert(Witness(index), FieldElement::try_from_str(&key_hash).unwrap()); - - let (proof, vk) = prove_ultra_honk(recursive_circuit_bytecode, initial_witness_recursive, true).unwrap(); +// --- New tests from eng review --- - let verdict = verify_ultra_honk(proof, vk).unwrap(); - assert!(verdict); -}*/ +#[test] +fn test_invalid_witness_input_error() { + let result = witness::from_vec_str_to_witness_map(vec!["not_a_number"]); + assert!(result.is_err(), "Invalid witness input should return Err"); +} + +#[test] +fn test_circuit_format_round_trip() { + // Decode program from bytecode, re-serialize, decode again, compare + let bytecode = load_product_bytecode(); + let program1 = circuit::get_program(&bytecode).unwrap(); + let reserialized = acvm::acir::circuit::Program::serialize_program(&program1); + let program2 = acvm::acir::circuit::Program::::deserialize_program( + &reserialized, + ) + .unwrap(); + assert_eq!(program1.functions.len(), program2.functions.len()); +} diff --git a/noir/src/backends/barretenberg/tests/proof_utils.rs b/noir/src/backends/barretenberg/tests/proof_utils.rs index 95883e6..d79be34 100644 --- a/noir/src/backends/barretenberg/tests/proof_utils.rs +++ b/noir/src/backends/barretenberg/tests/proof_utils.rs @@ -1,40 +1,54 @@ -use crate::utils::proof_utils::*; -use crate::witness::from_vec_to_witness_map; use crate::backends::barretenberg::{ - srs::setup_srs_from_bytecode, prove::prove_ultra_honk_keccak, - verify::{verify_ultra_honk_keccak, get_ultra_honk_keccak_verification_key}, + srs::setup_srs_from_bytecode, + verify::{get_ultra_honk_keccak_verification_key, verify_ultra_honk_keccak}, }; +use crate::utils::proof_utils::*; +use crate::witness::from_vec_to_witness_map; + +use super::load_product_bytecode; -// Multiplier2 circuit bytecode -// This circuit multiplies x * y == result with result as public input -const MULTIPLIER2_BYTECODE: &str = "H4sIAAAAAAAA/62QQQqAMAwErfigpEna5OZXLLb/f4KKLZbiTQdCQg7Dsm66mc9x00O717rhG9ico5cgMOfoMxJu4C2pAEsKioqisnslysoaLVkEQ6aMRYxKFc//ZYQr29L10XfhXv4jB52E+OpMAQAA"; +// Product circuit: a * b == result, with `result` as public input #[test] -fn test_get_num_public_inputs_multiplier2() { - let num_public_inputs = get_num_public_inputs_from_circuit(MULTIPLIER2_BYTECODE).unwrap(); - - // Multiplier2 circuit has 1 public input: result - assert_eq!(num_public_inputs, 1, "Multiplier2 circuit should have 1 public inputs"); +fn test_get_num_public_inputs_product() { + let bytecode = load_product_bytecode(); + let num_public_inputs = get_num_public_inputs_from_circuit(&bytecode).unwrap(); + + // Product circuit has 1 public input: result + assert_eq!( + num_public_inputs, 1, + "Product circuit should have 1 public input" + ); } #[test] -fn test_prove_and_verify_ultra_honk_keccak_multiplier2() { - let num_public_inputs = get_num_public_inputs_from_circuit(MULTIPLIER2_BYTECODE).unwrap(); - assert_eq!(num_public_inputs, 1, "Multiplier2 circuit should have 1 public inputs"); +fn test_prove_and_verify_ultra_honk_keccak_product() { + let bytecode = load_product_bytecode(); + let num_public_inputs = get_num_public_inputs_from_circuit(&bytecode).unwrap(); + assert_eq!( + num_public_inputs, 1, + "Product circuit should have 1 public input" + ); - setup_srs_from_bytecode(MULTIPLIER2_BYTECODE, None, false).unwrap(); + setup_srs_from_bytecode(&bytecode, None, false).unwrap(); + // a=3, b=5, result=15 let initial_witness = from_vec_to_witness_map(vec![3 as u128, 5 as u128, 15 as u128]).unwrap(); - let vk = get_ultra_honk_keccak_verification_key(MULTIPLIER2_BYTECODE, false, false).unwrap(); - let proof = prove_ultra_honk_keccak(MULTIPLIER2_BYTECODE, initial_witness, vk.clone(), false, false).unwrap(); + let vk = get_ultra_honk_keccak_verification_key(&bytecode, false, false).unwrap(); + let proof = + prove_ultra_honk_keccak(&bytecode, initial_witness, vk.clone(), false, false).unwrap(); // Parse the proof into separated components - let proof_with_public_inputs = parse_proof_with_public_inputs(&proof, num_public_inputs).unwrap(); + let proof_with_public_inputs = + parse_proof_with_public_inputs(&proof, num_public_inputs).unwrap(); // Combine the proof and public inputs back into a single byte vector - let combined_proof = combine_proof_and_public_inputs(proof_with_public_inputs.proof, proof_with_public_inputs.public_inputs); + let combined_proof = combine_proof_and_public_inputs( + proof_with_public_inputs.proof, + proof_with_public_inputs.public_inputs, + ); let verdict = verify_ultra_honk_keccak(combined_proof, vk, false).unwrap(); - assert_eq!(verdict, true, "Multiplier2 circuit should be valid"); + assert_eq!(verdict, true, "Product circuit should verify"); } diff --git a/noir/src/backends/barretenberg/utils.rs b/noir/src/backends/barretenberg/utils.rs index 4abaf1f..ac69062 100644 --- a/noir/src/backends/barretenberg/utils.rs +++ b/noir/src/backends/barretenberg/utils.rs @@ -1,25 +1,48 @@ -use bb::barretenberg_api::acir::get_circuit_sizes; - +use crate::backends::barretenberg::api::{self, settings_ultra_honk_poseidon2}; use crate::circuit::decode_circuit; pub fn compute_subgroup_size(circuit_size: u32) -> u32 { let log_value = (circuit_size as f64).log2().ceil() as u32; - let subgroup_size = 2u32.pow(log_value); - subgroup_size + 2u32.pow(log_value) +} + +/// Get the circuit size suitable for SRS allocation. +/// +/// Returns `num_gates_dyadic` (the next power of 2 above num_gates). UltraHonk needs +/// SRS points for witness, permutation, and lookup polynomials, so this dyadic size +/// gives a safe lower bound for SRS setup. +pub fn get_circuit_size(circuit_bytecode: &str, _recursion: bool) -> u32 { + let (_, acir_buffer_uncompressed) = if let Ok(decoded) = decode_circuit(circuit_bytecode) { + decoded + } else { + return 0; + }; + + let settings = settings_ultra_honk_poseidon2(); + + match api::circuit_stats(&acir_buffer_uncompressed, &settings) { + Ok(info) => info.num_gates_dyadic, + Err(_) => 0, + } } -pub fn get_circuit_size(circuit_bytecode: &str, recursion: bool) -> u32 { - let (_, acir_buffer_uncompressed) = if let Ok(acir_buffer_uncompressed) = decode_circuit(circuit_bytecode) { - acir_buffer_uncompressed +/// Get the dyadic (next power-of-two) circuit size for the given bytecode. +pub fn get_circuit_size_dyadic(circuit_bytecode: &str) -> u32 { + let (_, acir_buffer_uncompressed) = if let Ok(decoded) = decode_circuit(circuit_bytecode) { + decoded } else { return 0; }; - let circuit_size = unsafe { get_circuit_sizes(&acir_buffer_uncompressed, recursion) }; - circuit_size.total + let settings = settings_ultra_honk_poseidon2(); + + match api::circuit_stats(&acir_buffer_uncompressed, &settings) { + Ok(info) => info.num_gates_dyadic, + Err(_) => 0, + } } pub fn get_subgroup_size(circuit_bytecode: &str, recursion: bool) -> u32 { let circuit_size = get_circuit_size(circuit_bytecode, recursion); compute_subgroup_size(circuit_size) -} \ No newline at end of file +} diff --git a/noir/src/backends/barretenberg/verify.rs b/noir/src/backends/barretenberg/verify.rs index c650eee..26668a3 100644 --- a/noir/src/backends/barretenberg/verify.rs +++ b/noir/src/backends/barretenberg/verify.rs @@ -1,47 +1,67 @@ -use bb::barretenberg_api::acir::{ - acir_verify_ultra_honk, acir_verify_ultra_keccak_honk, acir_verify_ultra_keccak_zk_honk, - acir_get_ultra_honk_verification_key, acir_get_ultra_honk_keccak_verification_key, - acir_get_ultra_honk_keccak_zk_verification_key, acir_set_slow_low_memory +use crate::backends::barretenberg::api::{ + self, configure_memory, proof_bytes_to_fields, settings_ultra_honk_keccak, + settings_ultra_honk_poseidon2, FIELD_ELEMENT_SIZE, }; use crate::circuit::decode_circuit; -pub fn get_ultra_honk_verification_key(circuit_bytecode: &str, low_memory_mode: bool) -> Result, String> { - let (_, acir_buffer_uncompressed) = decode_circuit(circuit_bytecode) - .map_err(|e| format!("Failed to decode circuit: {}", e))?; +/// Split a proof byte vector into public_inputs and proof fields. +/// +/// Expected format: [num_public_inputs (4 bytes BE)] [public_input fields] [proof fields] +/// Each field is FIELD_ELEMENT_SIZE (32) bytes. +fn split_proof(proof: &[u8]) -> Result<(Vec>, Vec>), String> { + if proof.len() < 4 { + return Err("Proof too short to contain public inputs count".to_string()); + } + let num_pub = u32::from_be_bytes( + proof[0..4] + .try_into() + .map_err(|_| "Failed to read num_public_inputs")?, + ) as usize; + let pub_bytes_len = num_pub * FIELD_ELEMENT_SIZE; + if proof.len() < 4 + pub_bytes_len { + return Err(format!( + "Proof too short: expected at least {} bytes for {} public inputs, got {}", + 4 + pub_bytes_len, + num_pub, + proof.len() + )); + } + let public_inputs = proof_bytes_to_fields(&proof[4..4 + pub_bytes_len]); + let proof_fields = proof_bytes_to_fields(&proof[4 + pub_bytes_len..]); + Ok((public_inputs, proof_fields)) +} - acir_set_slow_low_memory(low_memory_mode); +pub fn get_ultra_honk_verification_key( + circuit_bytecode: &str, + low_memory_mode: bool, +) -> Result, String> { + configure_memory(low_memory_mode, None); + let (_, acir_buffer_uncompressed) = + decode_circuit(circuit_bytecode).map_err(|e| format!("Failed to decode circuit: {}", e))?; - let result = unsafe { - acir_get_ultra_honk_verification_key(&acir_buffer_uncompressed) - }; - Ok(result) + let settings = settings_ultra_honk_poseidon2(); + let vk_response = api::circuit_compute_vk(&acir_buffer_uncompressed, &settings)?; + Ok(vk_response.bytes) } -pub fn verify_ultra_honk( - proof: Vec, - verification_key: Vec, -) -> Result { - Ok(unsafe { - let result = acir_verify_ultra_honk(&proof, &verification_key); - result - }) +pub fn verify_ultra_honk(proof: Vec, verification_key: Vec) -> Result { + let settings = settings_ultra_honk_poseidon2(); + let (public_inputs, proof_fields) = split_proof(&proof)?; + api::circuit_verify(&verification_key, public_inputs, proof_fields, &settings) } -pub fn get_ultra_honk_keccak_verification_key(circuit_bytecode: &str, disable_zk: bool, low_memory_mode: bool) -> Result, String> { - let (_, acir_buffer_uncompressed) = decode_circuit(circuit_bytecode) - .map_err(|e| format!("Failed to decode circuit: {}", e))?; - - acir_set_slow_low_memory(low_memory_mode); - - let result = unsafe { - if disable_zk { - acir_get_ultra_honk_keccak_verification_key(&acir_buffer_uncompressed) - } else { - acir_get_ultra_honk_keccak_zk_verification_key(&acir_buffer_uncompressed) - } - }; +pub fn get_ultra_honk_keccak_verification_key( + circuit_bytecode: &str, + disable_zk: bool, + low_memory_mode: bool, +) -> Result, String> { + configure_memory(low_memory_mode, None); + let (_, acir_buffer_uncompressed) = + decode_circuit(circuit_bytecode).map_err(|e| format!("Failed to decode circuit: {}", e))?; - Ok(result) + let settings = settings_ultra_honk_keccak(disable_zk); + let vk_response = api::circuit_compute_vk(&acir_buffer_uncompressed, &settings)?; + Ok(vk_response.bytes) } pub fn verify_ultra_honk_keccak( @@ -49,11 +69,7 @@ pub fn verify_ultra_honk_keccak( verification_key: Vec, disable_zk: bool, ) -> Result { - Ok(unsafe { - if disable_zk { - acir_verify_ultra_keccak_honk(&proof, &verification_key) - } else { - acir_verify_ultra_keccak_zk_honk(&proof, &verification_key) - } - }) -} \ No newline at end of file + let settings = settings_ultra_honk_keccak(disable_zk); + let (public_inputs, proof_fields) = split_proof(&proof)?; + api::circuit_verify(&verification_key, public_inputs, proof_fields, &settings) +} diff --git a/noir/src/backends/mod.rs b/noir/src/backends/mod.rs index cd81662..1b33c9d 100644 --- a/noir/src/backends/mod.rs +++ b/noir/src/backends/mod.rs @@ -1,2 +1,2 @@ #[cfg(feature = "barretenberg")] -pub mod barretenberg; \ No newline at end of file +pub mod barretenberg; diff --git a/noir/src/bin/srs_downloader.rs b/noir/src/bin/srs_downloader.rs index ba70f8f..72ee220 100644 --- a/noir/src/bin/srs_downloader.rs +++ b/noir/src/bin/srs_downloader.rs @@ -1,7 +1,7 @@ // This is a modified version of scripts/srs_downloader/src/main.rs the file from https://github.com/madztheo/noir-react-native-starter -use std::path::{Path, PathBuf}; use std::fs; +use std::path::{Path, PathBuf}; use clap::Parser; use noir::barretenberg::{ @@ -17,10 +17,18 @@ struct Args { #[clap(short, long, help = "Path to the circuit JSON manifest file.")] circuit_path: Option, - #[clap(short, long, help = "Specific output path to save the SRS file. If not provided, saves to a default directory.")] + #[clap( + short, + long, + help = "Specific output path to save the SRS file. If not provided, saves to a default directory." + )] output_path: Option, - #[clap(short, long, help = "Enable recursive mode for circuit size calculation.")] + #[clap( + short, + long, + help = "Enable recursive mode for circuit size calculation." + )] recursive: bool, } @@ -35,12 +43,26 @@ fn main() -> Result<(), Box> { let circuit_file_path = Path::new(path_str); println!("Reading circuit from: {}", circuit_file_path.display()); - let manifest = fs::read(circuit_file_path).map_err(|e| format!("Failed to read circuit file {}: {}", circuit_file_path.display(), e))?; - let manifest_value: Value = - serde_json::from_slice(&manifest).map_err(|e| format!("Failed to decode JSON from {}: {}", circuit_file_path.display(), e))?; - let bytecode = manifest_value["bytecode"] - .as_str() - .ok_or_else(|| format!("Failed to get bytecode from {}", circuit_file_path.display()))?; + let manifest = fs::read(circuit_file_path).map_err(|e| { + format!( + "Failed to read circuit file {}: {}", + circuit_file_path.display(), + e + ) + })?; + let manifest_value: Value = serde_json::from_slice(&manifest).map_err(|e| { + format!( + "Failed to decode JSON from {}: {}", + circuit_file_path.display(), + e + ) + })?; + let bytecode = manifest_value["bytecode"].as_str().ok_or_else(|| { + format!( + "Failed to get bytecode from {}", + circuit_file_path.display() + ) + })?; if let Some(name) = circuit_file_path.file_stem().and_then(|s| s.to_str()) { circuit_name = name.to_string(); @@ -73,10 +95,16 @@ fn main() -> Result<(), Box> { path } }; - + if let Some(parent) = save_path_buf.parent() { if !parent.exists() { - fs::create_dir_all(parent).map_err(|e| format!("Failed to create parent directory {}: {}", parent.display(), e))?; + fs::create_dir_all(parent).map_err(|e| { + format!( + "Failed to create parent directory {}: {}", + parent.display(), + e + ) + })?; } } @@ -101,7 +129,7 @@ mod tests { recursive: false, } } - + #[test] fn test_args_parsing_defaults() { let args = create_args(None, None); @@ -145,13 +173,13 @@ mod tests { }; assert_eq!(args.recursive, true); } - + #[test] fn test_save_path_default_no_circuit() { let args = create_args(None, None); let circuit_name = "default_18"; let expected_path = PathBuf::from(DEFAULT_SRS_DIR).join(format!("{}.srs", circuit_name)); - + let save_path_buf: PathBuf = match &args.output_path { Some(path_str) => PathBuf::from(path_str), None => { @@ -172,11 +200,16 @@ mod tests { writeln!(file, "{{\"bytecode\": \"0x010203\"}}").unwrap(); let args = create_args(Some(dummy_circuit_path.to_str().unwrap()), None); - - let circuit_file_path = Path::new(args.circuit_path.as_ref().unwrap()); - let circuit_name_for_path = circuit_file_path.file_stem().and_then(|s| s.to_str()).unwrap_or("default_circuit").to_string(); - let expected_path = PathBuf::from(DEFAULT_SRS_DIR).join(format!("{}.srs", circuit_name_for_path)); + let circuit_file_path = Path::new(args.circuit_path.as_ref().unwrap()); + let circuit_name_for_path = circuit_file_path + .file_stem() + .and_then(|s| s.to_str()) + .unwrap_or("default_circuit") + .to_string(); + + let expected_path = + PathBuf::from(DEFAULT_SRS_DIR).join(format!("{}.srs", circuit_name_for_path)); let save_path_buf: PathBuf = match &args.output_path { Some(path_str) => PathBuf::from(path_str), diff --git a/noir/src/circuit.rs b/noir/src/circuit.rs index 07c3319..2694a82 100644 --- a/noir/src/circuit.rs +++ b/noir/src/circuit.rs @@ -1,35 +1,19 @@ use std::io::Read; -use acir::{circuit::Program, FieldElement}; +use acvm::acir::{circuit::Program, FieldElement}; use base64::engine::{general_purpose, Engine}; use flate2::bufread::GzDecoder; /// Get the acir buffer (compressed) from the circuit bytecode -/// -/// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to get the acir buffer from -/// -/// # Returns -/// -/// The acir buffer (compressed) pub fn get_acir_buffer(circuit_bytecode: &str) -> Result, String> { let acir_buffer = general_purpose::STANDARD .decode(circuit_bytecode) .map_err(|e| e.to_string())?; - + Ok(acir_buffer) } /// Uncompress the acir buffer -/// -/// # Arguments -/// -/// * acir_buffer: The acir buffer to uncompress -/// -/// # Returns -/// -/// The uncompressed acir buffer pub fn uncompress_acir_buffer(acir_buffer: Vec) -> Result, String> { let mut decoder = GzDecoder::new(acir_buffer.as_slice()); let mut acir_buffer_uncompressed = Vec::::new(); @@ -40,29 +24,21 @@ pub fn uncompress_acir_buffer(acir_buffer: Vec) -> Result, String> { Ok(acir_buffer_uncompressed) } -/// Get the acir buffer (uncompressed) from the circuit bytecode -/// -/// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to get the acir buffer from -/// -/// # Returns -/// -/// The acir buffer (uncompressed) +/// Get the acir buffer (uncompressed) from the circuit bytecode. +/// +/// Round-trips through `Program` deserialization/serialization to ensure +/// the output format matches the `NOIR_SERIALIZATION_FORMAT` env var +/// (e.g. msgpack-compact for barretenberg compatibility). pub fn get_acir_buffer_uncompressed(circuit_bytecode: &str) -> Result, String> { let acir_buffer = get_acir_buffer(circuit_bytecode)?; - uncompress_acir_buffer(acir_buffer) + // Round-trip through Program to re-serialize in the current format + let program: Program = Program::deserialize_program(&acir_buffer) + .map_err(|e| format!("Failed to deserialize program: {}", e))?; + let reserialized = Program::serialize_program(&program); + uncompress_acir_buffer(reserialized) } -/// Decode the circuit bytecode into an acir buffer -/// -/// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to decode -/// -/// # Returns -/// -/// The acir buffer and the uncompressed acir buffer +/// Decode the circuit bytecode into compressed and uncompressed acir buffers pub fn decode_circuit(circuit_bytecode: &str) -> Result<(Vec, Vec), String> { let acir_buffer = get_acir_buffer(circuit_bytecode)?; let acir_buffer_uncompressed = get_acir_buffer_uncompressed(circuit_bytecode)?; @@ -71,15 +47,7 @@ pub fn decode_circuit(circuit_bytecode: &str) -> Result<(Vec, Vec), Stri } /// Get the program from the circuit bytecode -/// -/// # Arguments -/// -/// * circuit_bytecode: The circuit bytecode to get the program from -/// -/// # Returns -/// -/// The program pub fn get_program(circuit_bytecode: &str) -> Result, String> { let acir_buffer: Vec = get_acir_buffer(circuit_bytecode)?; Program::deserialize_program(&acir_buffer).map_err(|e| e.to_string()) -} \ No newline at end of file +} diff --git a/noir/src/execute.rs b/noir/src/execute.rs index ae09084..f063d0f 100644 --- a/noir/src/execute.rs +++ b/noir/src/execute.rs @@ -1,28 +1,39 @@ -use acir::{native_types::{WitnessMap, WitnessStack}, FieldElement}; +use acvm::acir::{ + native_types::{WitnessMap, WitnessStack}, + FieldElement, +}; use bn254_blackbox_solver::Bn254BlackBoxSolver; -use nargo::ops::execute_program; use nargo::foreign_calls::default::DefaultForeignCallBuilder; +use nargo::ops::execute_program; use crate::circuit::get_program; -/// Execute the circuit and return the serialized solved witness stack -/// +/// Execute the circuit and return the solved witness stack +/// /// # Arguments -/// +/// /// * circuit_bytecode: The circuit bytecode to execute /// * initial_witness: The initial witness to use for the execution -/// +/// /// # Returns -/// +/// /// The Witness Stack -pub fn execute(circuit_bytecode: &str, initial_witness: WitnessMap) -> Result, String> { +pub fn execute( + circuit_bytecode: &str, + initial_witness: WitnessMap, +) -> Result, String> { let program = get_program(circuit_bytecode)?; let blackbox_solver = Bn254BlackBoxSolver::default(); let mut foreign_call_executor = DefaultForeignCallBuilder::default().build(); - let solved_witness = - execute_program(&program, initial_witness, &blackbox_solver, &mut foreign_call_executor).map_err(|e| e.to_string())?; + let solved_witness = execute_program( + &program, + initial_witness, + &blackbox_solver, + &mut foreign_call_executor, + ) + .map_err(|e| e.to_string())?; Ok(solved_witness) -} \ No newline at end of file +} diff --git a/noir/src/lib.rs b/noir/src/lib.rs index 2a4d9bb..88fe87d 100644 --- a/noir/src/lib.rs +++ b/noir/src/lib.rs @@ -1,11 +1,10 @@ -pub use acir::*; pub use acvm::*; -pub mod execute; -pub mod witness; +mod backends; pub mod circuit; +pub mod execute; pub mod utils; -mod backends; +pub mod witness; #[cfg(feature = "barretenberg")] pub use backends::barretenberg; diff --git a/noir/src/utils/mod.rs b/noir/src/utils/mod.rs index ccd7e84..6d8547a 100644 --- a/noir/src/utils/mod.rs +++ b/noir/src/utils/mod.rs @@ -2,8 +2,6 @@ pub mod proof_utils; // Re-export commonly used items for convenience pub use proof_utils::{ - ProofWithPublicInputs, - get_num_public_inputs_from_circuit, - parse_proof_with_public_inputs, - combine_proof_and_public_inputs, -}; \ No newline at end of file + combine_proof_and_public_inputs, get_num_public_inputs_from_circuit, + parse_proof_with_public_inputs, ProofWithPublicInputs, +}; diff --git a/noir/src/utils/proof_utils.rs b/noir/src/utils/proof_utils.rs index 673f669..7ecefac 100644 --- a/noir/src/utils/proof_utils.rs +++ b/noir/src/utils/proof_utils.rs @@ -11,42 +11,65 @@ pub struct ProofWithPublicInputs { pub num_public_inputs: usize, } -/// Get the number of public inputs from a circuit's bytecode -/// This extracts the circuit information to count public parameters +/// Get the number of public inputs from a circuit's bytecode. +/// This extracts the circuit information to count public parameters. pub fn get_num_public_inputs_from_circuit(circuit_bytecode: &str) -> Result { - let program = get_program(circuit_bytecode) - .map_err(|e| format!("Failed to get program: {}", e))?; + let program = + get_program(circuit_bytecode).map_err(|e| format!("Failed to get program: {}", e))?; - // Get the first function (main function) - let main_function = program.functions.first() + let main_function = program + .functions + .first() .ok_or("No functions found in program")?; - - // Count public parameters directly from the circuit + let num_public_inputs = main_function.public_parameters.0.len(); Ok(num_public_inputs) } -/// Parse a combined proof (proof + public inputs) into separated components +/// Parse a proof (produced by `prove_ultra_honk` / `prove_ultra_honk_keccak`) into +/// separated components. +/// +/// The expected proof format is: +/// `[num_public_inputs (4 bytes BE)] [public_inputs (32 bytes each)] [proof fields]` +/// +/// The `num_public_inputs` parameter is retained for API compatibility and cross-checked +/// against the 4-byte prefix embedded in the proof. pub fn parse_proof_with_public_inputs( - combined_proof: &[u8], - num_public_inputs: usize + combined_proof: &[u8], + num_public_inputs: usize, ) -> Result { - let public_inputs_size = num_public_inputs * 32; // Each field element is 32 bytes - - if combined_proof.len() < public_inputs_size { + if combined_proof.len() < 4 { + return Err("Combined proof too short to contain public inputs count".to_string()); + } + let embedded_num_pub = u32::from_be_bytes( + combined_proof[0..4] + .try_into() + .map_err(|_| "Failed to read num_public_inputs prefix")?, + ) as usize; + + if embedded_num_pub != num_public_inputs { return Err(format!( - "Combined proof too small: {} bytes, expected at least {} bytes for {} public inputs", - combined_proof.len(), - public_inputs_size, + "Public input count mismatch: caller passed {}, proof embeds {}", + num_public_inputs, embedded_num_pub + )); + } + + let public_inputs_size = num_public_inputs * 32; + let required_len = 4 + public_inputs_size; + + if combined_proof.len() < required_len { + return Err(format!( + "Combined proof too small: {} bytes, expected at least {} bytes for {} public inputs", + combined_proof.len(), + required_len, num_public_inputs )); } - - // Public inputs are at the beginning of the combined proof - let public_inputs_bytes = combined_proof[..public_inputs_size].to_vec(); - let proof_data = combined_proof[public_inputs_size..].to_vec(); - + + let public_inputs_bytes = combined_proof[4..required_len].to_vec(); + let proof_data = combined_proof[required_len..].to_vec(); + if proof_data.len() % 32 != 0 { return Err("Proof data must be a multiple of 32 bytes".to_string()); } @@ -55,27 +78,27 @@ pub fn parse_proof_with_public_inputs( .chunks(32) .map(|chunk| chunk.to_vec()) .collect(); - + Ok(ProofWithPublicInputs { proof: proof_data, - public_inputs: public_inputs, + public_inputs, num_public_inputs, }) } -/// Combine proof and public inputs back into a single proof with public inputs -pub fn combine_proof_and_public_inputs( - proof: Vec, - public_inputs: Vec>, -) -> Vec { - let mut combined = Vec::new(); - - // Add public inputs first (32 bytes each) +/// Combine proof bytes and public inputs back into a single proof. +/// +/// Produces the format expected by `verify_ultra_honk` / `verify_ultra_honk_keccak`: +/// `[num_public_inputs (4 bytes BE)] [public_inputs (32 bytes each)] [proof fields]` +pub fn combine_proof_and_public_inputs(proof: Vec, public_inputs: Vec>) -> Vec { + let num_pub = public_inputs.len() as u32; + let mut combined = num_pub.to_be_bytes().to_vec(); + for public_input in &public_inputs { combined.extend_from_slice(public_input); } combined.extend_from_slice(&proof); - + combined } diff --git a/noir/src/witness.rs b/noir/src/witness.rs index 12612ff..17f1c13 100644 --- a/noir/src/witness.rs +++ b/noir/src/witness.rs @@ -1,19 +1,25 @@ -use acir::{native_types::{WitnessMap, WitnessStack, Witness}, FieldElement}; +use std::io::Read; + +use acvm::acir::{ + native_types::{Witness, WitnessMap, WitnessStack}, + FieldElement, +}; +use flate2::read::GzDecoder; /// Convert a vector of field elements to a witness map -/// +/// /// # Arguments -/// +/// /// * witness_vec: The vector of field elements to convert to a witness map /// The actual type of the vector items can be either a FieldElement or an unsigned integer -/// +/// /// # Returns -/// +/// /// The witness map pub fn from_vec_to_witness_map(witness_vec: Vec) -> Result, String> where T: Copy, - FieldElement: From + FieldElement: From, { let mut witness_map = WitnessMap::new(); @@ -25,65 +31,50 @@ where } /// Convert a vector of strings to a witness map -/// -/// # Arguments -/// -/// * witness_vec: The vector of strings to convert to a witness map -/// Each string is expected to be a valid hexadecimal or decimal string -/// -/// # Returns -/// -/// The witness map -pub fn from_vec_str_to_witness_map(witness_vec: Vec<&str>) -> Result, String> { +/// +/// Each string is expected to be a valid hexadecimal or decimal string. +/// Returns an error if any string cannot be parsed as a field element. +pub fn from_vec_str_to_witness_map( + witness_vec: Vec<&str>, +) -> Result, String> { let mut witness_map = WitnessMap::new(); for (i, witness) in witness_vec.iter().enumerate() { - witness_map.insert(Witness(i as u32), FieldElement::try_from_str(*witness).unwrap_or_default()); + let field = FieldElement::try_from_str(*witness) + .ok_or_else(|| format!("Failed to parse witness at index {}: '{}'", i, witness))?; + witness_map.insert(Witness(i as u32), field); } Ok(witness_map) } /// Wrap the witness map into a witness stack -/// -/// # Arguments -/// -/// * witness_map: The witness map to wrap into a witness stack -/// -/// # Returns -/// -/// The witness stack -pub fn witness_map_to_witness_stack(witness_map: WitnessMap) -> Result, String> { +pub fn witness_map_to_witness_stack( + witness_map: WitnessMap, +) -> Result, String> { let witness_stack = WitnessStack::try_from(witness_map).map_err(|e| e.to_string())?; Ok(witness_stack) } -/// Serialize the witness stack to a bincode encoded vector -/// -/// # Arguments -/// -/// * witness_stack: The witness stack to serialize -/// -/// # Returns -/// -/// The serialized witness stack +/// Serialize the witness stack using the format from `NOIR_SERIALIZATION_FORMAT`. +/// +/// The result is the raw (uncompressed) serialized witness suitable for passing +/// to barretenberg. pub fn serialize_witness(witness_stack: WitnessStack) -> Result, String> { - let serialized_witness = - bincode::serialize(&witness_stack).map_err(|e| e.to_string())?; - - Ok(serialized_witness) + // WitnessStack::serialize() respects NOIR_SERIALIZATION_FORMAT and gzip-compresses + let compressed = witness_stack.serialize().map_err(|e| e.to_string())?; + // Decompress to get raw bytes for barretenberg + let mut decoder = GzDecoder::new(compressed.as_slice()); + let mut buf = Vec::new(); + decoder.read_to_end(&mut buf).map_err(|e| e.to_string())?; + Ok(buf) } /// Deserialize the witness stack from a bincode encoded vector -/// -/// # Arguments -/// -/// * serialized_witness_stack: The serialized witness stack to deserialize -/// -/// # Returns -/// -/// The witness stack -pub fn deserialize_witness(serialized_witness_stack: Vec) -> Result, String> { - let witness_stack = bincode::deserialize(&serialized_witness_stack).map_err(|e| e.to_string())?; +pub fn deserialize_witness( + serialized_witness_stack: Vec, +) -> Result, String> { + let witness_stack = + bincode::deserialize(&serialized_witness_stack).map_err(|e| e.to_string())?; Ok(witness_stack) -} \ No newline at end of file +}