From b6ef7793ae5ab1a34e78756bb4ee5983b85a00fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= <4142+huitseeker@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:26:29 -0400 Subject: [PATCH] Expose plonk verification through sphinx's gnark-ffi (#3) * chore: remove nix stuff * ci: add new CI workflow - Introduced a new CI workflow to automate building and testing on GitHub for each push or pull request made to the main branch. * chore: rebuild * feat: expose plonk verification * ci: setup SRS * test: adapt the fixture test --- .github/workflows/ci.yml | 52 ++++++++ .gitignore | 15 +++ Cargo.lock | 238 +++++++++++++++------------------- Cargo.toml | 20 ++- README.md | 35 +---- assets/fibonacci_fixture.json | 5 + flake.lock | 120 ----------------- flake.nix | 60 --------- src/PlonkVerify.hs | 6 +- src/lib.rs | 183 ++++++++++++++++++++------ 10 files changed, 344 insertions(+), 390 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 assets/fibonacci_fixture.json delete mode 100644 flake.lock delete mode 100644 flake.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..192b380 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + # Step 1: Set up Rust and build with Cargo + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Build with Cargo + run: cargo build --release + + # Step 2: Set up Haskell and build with Cabal + - name: Set up Haskell + uses: haskell/actions/setup@v1 + with: + ghc-version: '9.2.5' + cabal-version: '3.6.2.0' + + - name: Build with Cabal + run: cabal build + + # Download and untar the required file + - name: Download and untar PLONK params + run: | + mkdir -p ~/.sp1/circuits/plonk_bn254/v1.0.8-testnet + wget https://sphinx-plonk-params.s3.amazonaws.com/v1.0.8-testnet.tar.gz -O plonk_params.tar.gz + tar -xzf plonk_params.tar.gz -C ~/.sp1/circuits/plonk_bn254/v1.0.8-testnet + rm plonk_params.tar.gz + + # Install and run nextest + - name: Install nextest + uses: taiki-e/install-action@nextest + + - name: Run tests with nextest + run: cargo nextest run --release --no-fail-fast \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4d0e979 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +# Cargo build +**/target + +# MacOS nuisances +.DS_Store + +# Environment +.env + +# Build files +*.a +*.hi +*.o +libsphinxgnark.h +Main diff --git a/Cargo.lock b/Cargo.lock index a59e48b..d019850 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,18 +15,18 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" dependencies = [ "gimli", ] [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "ahash" @@ -79,21 +79,11 @@ dependencies = [ "winapi", ] -[[package]] -name = "antlion" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd743dc9b5cf465db1be79d28b4bfd7fa143d289546afeea5dc933551883e1f6" -dependencies = [ - "proc-macro2", - "quote", -] - [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8" [[package]] name = "ark-ff" @@ -111,7 +101,7 @@ dependencies = [ "num-bigint 0.4.6", "num-traits", "paste", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "zeroize", ] @@ -173,13 +163,13 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "async-trait" -version = "0.1.81" +version = "0.1.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" +checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -190,18 +180,18 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.73" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" dependencies = [ "addr2line", - "cc", "cfg-if", "libc", "miniz_oxide", "object", "rustc-demangle", "serde", + "windows-targets", ] [[package]] @@ -250,7 +240,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.76", + "syn 2.0.77", "which", ] @@ -350,9 +340,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" +checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae" [[package]] name = "byteorder" @@ -362,9 +352,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.1.15" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6" +checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" dependencies = [ "shlex", ] @@ -428,9 +418,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ "libc", ] @@ -498,7 +488,7 @@ dependencies = [ "cpufeatures", "curve25519-dalek-derive", "fiat-crypto", - "rustc_version 0.4.0", + "rustc_version 0.4.1", "subtle", "zeroize", ] @@ -511,7 +501,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -535,7 +525,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -546,7 +536,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -600,7 +590,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -842,9 +832,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.29.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" [[package]] name = "glob" @@ -953,9 +943,9 @@ dependencies = [ [[package]] name = "hs-bindgen" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9723a81f9f23c3e52b01ce72db20c7ab384c8618b1032eea04985260d10fc7" +checksum = "25586ce217507e994a21a92efbc56456e024aa61969ba9b0f91698d1e7b06376" dependencies = [ "hs-bindgen-attribute", "hs-bindgen-traits", @@ -963,15 +953,15 @@ dependencies = [ [[package]] name = "hs-bindgen-attribute" -version = "0.8.0" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e57fc3cb0491f749fc50e7cf186c189b64af557edb9f78e36eb78bb9021d6624" +checksum = "cf0c7ca61a6f04e432eb50b569d5322a3a34ba4f61e6a84503d9a3f25e623098" dependencies = [ - "antlion", "displaydoc", "hs-bindgen-types", "lazy_static", "quote", + "reflexive", "rustc_version 0.2.3", "semver 1.0.23", "serde", @@ -982,16 +972,17 @@ dependencies = [ [[package]] name = "hs-bindgen-traits" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e92e839254ee5975299f64183e8346548c4ba5e4ee0253a05426891a6f135a6a" +checksum = "ac4ec8936241746802cfe99813764d0ab06f023a7350df3967e287be456f29fc" [[package]] name = "hs-bindgen-types" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2d986de5641ea4aa8025589d7243e403961fb0f5572c4dd4764a1bb4a01768c" +checksum = "aef6c1c28eb3c9a7fd73cb380e2a5114d511ef44b5ffaf5e76559669563abb05" dependencies = [ + "cfg-if", "displaydoc", "proc-macro2", "quote", @@ -1049,9 +1040,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", @@ -1210,11 +1201,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ - "adler", + "adler2", ] [[package]] @@ -1366,9 +1357,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.3" +version = "0.36.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" dependencies = [ "memchr", ] @@ -1411,7 +1402,7 @@ dependencies = [ [[package]] name = "p3-baby-bear" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "num-bigint 0.4.6", "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1485,7 +1476,7 @@ dependencies = [ [[package]] name = "p3-dft" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", "p3-matrix 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1510,7 +1501,7 @@ dependencies = [ [[package]] name = "p3-field" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "num-bigint 0.4.6", @@ -1587,7 +1578,7 @@ dependencies = [ [[package]] name = "p3-matrix" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1609,7 +1600,7 @@ dependencies = [ [[package]] name = "p3-maybe-rayon" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" [[package]] name = "p3-mds" @@ -1628,7 +1619,7 @@ dependencies = [ [[package]] name = "p3-mds" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-dft 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1670,7 +1661,7 @@ dependencies = [ [[package]] name = "p3-poseidon2" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "gcd", "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1692,7 +1683,7 @@ dependencies = [ [[package]] name = "p3-symmetric" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "itertools 0.12.1", "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", @@ -1728,7 +1719,7 @@ dependencies = [ [[package]] name = "p3-util" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#5c26090fc284202335641438a9ee300d4bbe6f69" +source = "git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new#a0b9287038ab11e165c78df1fbc2402609a7d6b5" dependencies = [ "serde", ] @@ -1838,13 +1829,16 @@ version = "0.1.0" dependencies = [ "async-trait", "getrandom", + "hex", + "home", "hs-bindgen", + "num-bigint 0.4.6", "p3-baby-bear 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1-new)", - "sphinx-core", - "sphinx-recursion-core", + "serde", + "serde_json", + "sha2", "sphinx-recursion-gnark-ffi", - "sphinx-recursion-program", ] [[package]] @@ -1869,7 +1863,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -1974,6 +1968,16 @@ dependencies = [ "bitflags", ] +[[package]] +name = "reflexive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a88ef05e7d63adad0f2c5f5873903226c03b7f27d219df7f37fb05ab98b5d420" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "regex" version = "1.10.6" @@ -2061,18 +2065,18 @@ dependencies = [ [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ "semver 1.0.23", ] [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" dependencies = [ "bitflags", "errno", @@ -2095,9 +2099,9 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scc" -version = "2.1.16" +version = "2.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb7ac86243095b70a7920639507b71d51a63390d1ba26c4f60a552fbb914a37" +checksum = "0c947adb109a8afce5fc9c7bf951f87f146e9147b3a6a58413105628fb1d1e66" dependencies = [ "sdd", ] @@ -2110,9 +2114,9 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sdd" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0495e4577c672de8254beb68d01a9b62d0e8a13c099edecdbedccce3223cd29f" +checksum = "60a7b59a5d9b0099720b417b6325d91a52cbf5b3dcb5041d864be53eefa58abc" [[package]] name = "sec1" @@ -2151,29 +2155,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", "memchr", @@ -2191,7 +2195,7 @@ dependencies = [ "chrono", "hex", "indexmap 1.9.3", - "indexmap 2.4.0", + "indexmap 2.5.0", "serde", "serde_derive", "serde_json", @@ -2208,7 +2212,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2233,7 +2237,7 @@ checksum = "82fe9db325bcef1fbcde82e078a5cc4efdf787e96b3b9cf45b50b529f2083d67" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2306,7 +2310,7 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "sphinx-core" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "anyhow", "arrayref", @@ -2368,7 +2372,7 @@ dependencies = [ [[package]] name = "sphinx-derive" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "proc-macro2", "quote", @@ -2378,7 +2382,7 @@ dependencies = [ [[package]] name = "sphinx-precompiles" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "anyhow", "bincode", @@ -2392,7 +2396,7 @@ dependencies = [ [[package]] name = "sphinx-primitives" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "itertools 0.12.1", "lazy_static", @@ -2405,7 +2409,7 @@ dependencies = [ [[package]] name = "sphinx-recursion-compiler" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "backtrace", "hashbrown 0.14.5", @@ -2431,7 +2435,7 @@ dependencies = [ [[package]] name = "sphinx-recursion-core" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "arrayref", "backtrace", @@ -2465,7 +2469,7 @@ dependencies = [ [[package]] name = "sphinx-recursion-derive" version = "0.1.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "proc-macro2", "quote", @@ -2475,7 +2479,7 @@ dependencies = [ [[package]] name = "sphinx-recursion-gnark-ffi" version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" +source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#f51436fe14e6d029313546e8284cf6762f81f776" dependencies = [ "anyhow", "bincode", @@ -2496,34 +2500,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "sphinx-recursion-program" -version = "1.0.0" -source = "git+https://github.com/argumentcomputer/sphinx.git?branch=dev#d392acca56fbaa0e4dd0b73cfab0414b4e321348" -dependencies = [ - "itertools 0.12.1", - "p3-air", - "p3-baby-bear 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-challenger", - "p3-commit", - "p3-dft 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-field 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-fri", - "p3-matrix 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-maybe-rayon 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-merkle-tree", - "p3-poseidon2 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-symmetric 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "p3-util 0.1.0 (git+https://github.com/argumentcomputer/Plonky3.git?branch=sp1)", - "rand", - "serde", - "sphinx-core", - "sphinx-primitives", - "sphinx-recursion-compiler", - "sphinx-recursion-core", - "tracing", -] - [[package]] name = "spin" version = "0.9.8" @@ -2568,7 +2544,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2590,9 +2566,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.76" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -2635,7 +2611,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2709,7 +2685,7 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.4.0", + "indexmap 2.5.0", "toml_datetime", "winnow", ] @@ -2733,7 +2709,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -2840,7 +2816,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-shared", ] @@ -2862,7 +2838,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3044,7 +3020,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] @@ -3064,7 +3040,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.76", + "syn 2.0.77", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d1d3223..74a2fcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,19 +2,27 @@ name = "plonk-verify" version = "0.1.0" edition = "2021" +license = "MIT OR Apache-2.0" +repository = "https://github.com/argumentcomputer/lurk-hs" [dependencies] -hs-bindgen = { version = "0.8.0", features = ["full"] } -sphinx-core = { git = "https://github.com/argumentcomputer/sphinx.git", branch = "dev"} -sphinx-recursion-core = { git = "https://github.com/argumentcomputer/sphinx.git", branch = "dev"} -sphinx-recursion-gnark-ffi = { git = "https://github.com/argumentcomputer/sphinx.git", branch = "dev"} -sphinx-recursion-program = { git = "https://github.com/argumentcomputer/sphinx.git", branch = "dev"} +hs-bindgen = { version = "0.9.0", features = ["full"] } +# sphinx-recursion-gnark-ffi = { path = "../sphinx/recursion/gnark-ffi", features = ["native"]} +sphinx-recursion-gnark-ffi = { git = "https://github.com/argumentcomputer/sphinx.git", branch = "dev", features = ["native"]} getrandom = "=0.2.14" async-trait = "0.1.81" p3-field = { git = "https://github.com/argumentcomputer/Plonky3.git", branch = "sp1-new" } p3-baby-bear = { git = "https://github.com/argumentcomputer/Plonky3.git", branch = "sp1-new", features = [ "nightly-features", ]} +num-bigint = { version = "0.4.6", default-features = false } +serde = "1.0.207" [lib] -crate-type = ["cdylib", "staticlib"] +crate-type = ["staticlib"] + +[dev-dependencies] +hex = "0.4.3" +home = "0.5.9" +serde_json = "1.0.128" +sha2 = "0.10.8" diff --git a/README.md b/README.md index f429988..ca23317 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ Build steps: -1. `nix develop` (if needed) -2. `cargo build` -3. `cabal build` +1. `cargo build` +2. `cabal build` Test with @@ -16,32 +15,4 @@ ghci> babybearinv 1 ghci> babybearinv 2 1006632961 ghci> -``` - -Note that `nix build` is broken and will error with - -``` -warning: Git tree '/home/jcb/plonk-verify' is dirty -error: builder for '/nix/store/lz6zm8mfif4bh7wsai8dx6blpzymrvz1-plonk-verify-deps-0.1.0.drv' failed with exit code 101; - last 10 log lines: - > - > Caused by: - > failed to parse manifest at `/nix/store/nix47gay33f6mqmrp3xb77189llkfcil-git-dependencies/sphinx-recursion-program-1.0.0-dev/Cargo.toml` - > - > Caused by: - > error inheriting `edition` from workspace root manifest's `workspace.package.edition` - > - > Caused by: - > failed to find a workspace root - > [naersk] cargo returned with exit code 101, exiting - For full logs, run 'nix log /nix/store/lz6zm8mfif4bh7wsai8dx6blpzymrvz1-plonk-verify-deps-0.1.0.drv'. -error: 1 dependencies of derivation '/nix/store/dazvfzn454x9x93gxr0fpdg93m3vv7di-plonk-verify-0.1.0.drv' failed to build -``` - -This is likely a naersk workspace inheritance issue related to: - -- https://github.com/nix-community/naersk/issues/318 -- https://github.com/nix-community/crate2nix/issues/311 -- https://github.com/ipetkov/crane/pull/224 -- https://github.com/nix-community/naersk/issues/310 - +``` \ No newline at end of file diff --git a/assets/fibonacci_fixture.json b/assets/fibonacci_fixture.json new file mode 100644 index 0000000..7659def --- /dev/null +++ b/assets/fibonacci_fixture.json @@ -0,0 +1,5 @@ +{ + "vkey": "0x2acfe95638a7aa71feaa167c1d53339708571ba2082f000d39bedebac6c872", + "publicValues": "0x190e5a3ed690bd3b533c087ef7339d00e25113d217f7dac4575a01b79dacd553", + "proof": "0x070ebe597360e09c92562b810cfd411a4cadac13904a6f5ef80597d31992b55611cc3d8557ad399cb5153cf87460901db1fd8dc92f16c5ea2ba1e8f357a1c5dd192120e7e19011e6e8028677870b4d59c1688fc0e729a547691ff7b9760aefbf242cfd52dbf3b98ddc003d31c8b86f2acf5f02ac891f990accba9a9c8477eb701d9f43bbd2c0566e7f48469c84a1769c17e74b8ed53602ce12f7f9a0181e9ab70548028c15e5a49611db64135b80545bf38afa4195e95d1289e20b945d7139ef1a94705f2ddbd481817316ef262053e9ee6a2419c63de7e3f339cac54bfa8c222e740ee8470ead68edb38aae2e9519fe01ce2f20707d6f81bc8643f0306c61ed1d37a65d87c876e13b3353bb42f02ab86423b4da43341e7bc5461b185a3946691d1015cb04fd6ffc38f9e7f52c92cffc3c44de7c58c9728d71e9f4c8266a831c2484b36f3ea92dd827d668dcf59ab7a0dee33f46fe289b90df06b15e4d288a5f1bee1bc0214e6a77647db6a2f4f51df8b100b1ddaef494618b3a3b0369ca18631f2d81effd2f9185afed9a0712d302b1d439c31d44a2ca3f20fd5f70a95eb30c132f39448df14f1e5311b906d22068ca160ac7d574df55605555df41208c9ab41634986f88e8af3b475ca428eb66e17f35c5d5808f358ec9884317db04d11a2d07200c82c257f1fdf6de2265f8cfd280c9728303f36dd0af7fc797b5ac232ae60000000720e4c44119a39f2303913d419ccff44f27639a1efe8634c93d82e581a4af1dee26b61ebb2d1eac5fe7e918786ced3a2a6b441dee0e8574341bb2e5bcbb27dc4f294ecca8cf684af42cecc403954747d3fb9b8ffb2a8081f2a809d3315f96bfca10d8e46e711998c3cd612849af775cb156caebcd3e2ce2bc7f6c7825dc536e310d69f3e8a506635f24f681b32fc30435c93d82ee0f93c83d7daf695d33acd87e1dbd2d55668d9a07c45d1f261173e9155bf35ce61b73becdc86ea76ca228f45a264f228a3b4f5b02022cd03bd8604a5ad62fd3a3706713bbc4f9846b31856b9608e7cdef78fc19f96cf6d5ada170bd3332f797f3a67756b83fa53e628f1db9a121042af248f08e8df4c9b046dc8807f7b514eb1dd7e6e2b6b80d060097a296cf22b56debdb623976250d281713f6e34b96ef5f71e92e748106d84675e30f9dc6000000010a0b17cbd37bd5c99d4ee00bf0a469c39494d8df9bbdbf57342e5d43e167dba20b659c2534a428edb9063ad60ddfb4867608b0520457348b535d1e5c1d040704" +} \ No newline at end of file diff --git a/flake.lock b/flake.lock deleted file mode 100644 index edeedfd..0000000 --- a/flake.lock +++ /dev/null @@ -1,120 +0,0 @@ -{ - "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1724740262, - "narHash": "sha256-cpFasbzOTlwLi4fNas6hDznVUdCJn/lMLxi7MAMG6hg=", - "owner": "nix-community", - "repo": "fenix", - "rev": "703efdd9b5c6a7d5824afa348a24fbbf8ff226be", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "naersk": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1721727458, - "narHash": "sha256-r/xppY958gmZ4oTfLiHN0ZGuQ+RSTijDblVgVLFi1mw=", - "owner": "nix-community", - "repo": "naersk", - "rev": "3fb418eaf352498f6b6c30592e3beb63df42ef11", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "naersk", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1724479785, - "narHash": "sha256-pP3Azj5d6M5nmG68Fu4JqZmdGt4S4vqI5f8te+E/FTw=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d0e1602ddde669d5beb01aec49d71a51937ed7be", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "root": { - "inputs": { - "fenix": "fenix", - "flake-utils": "flake-utils", - "naersk": "naersk", - "nixpkgs": "nixpkgs" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1724666781, - "narHash": "sha256-nOQDgjTDlWe0/+Ptf3o2p6UrznQFHnXBHRV1ZAsSpe8=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "095926ea6f008477a15a2ec6b0b8797e2e5be0e5", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index f6682cb..0000000 --- a/flake.nix +++ /dev/null @@ -1,60 +0,0 @@ -{ - inputs = { - nixpkgs.url = "nixpkgs/nixos-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - naersk = { - url = "github:nix-community/naersk"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { self, nixpkgs, flake-utils, naersk, fenix }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = (import nixpkgs) { - inherit system; - }; - - toolchain = with fenix.packages.${system}; fromToolchainFile { - file = ./rust-toolchain.toml; # alternatively, dir = ./.; - sha256 = "sha256-3jVIIf5XPnUU1CRaTyAiO0XHVbJl12MSx3eucTXCjtE="; - }; - - in rec { - defaultPackage = (naersk.lib.${system}.override { - # For `nix build` & `nix run`: - cargo = toolchain; - rustc = toolchain; - }).buildPackage { - src = ./.; - nativeBuildInputs = with pkgs; [ - go - pkg-config - libclang - ]; - LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; - }; - - # For `nix develop` or `direnv allow`: - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - go - pkg-config - openssl - ocl-icd - toolchain - rust-analyzer - clang - libclang - cabal-install - ghc - ]; - LIBCLANG_PATH = "${pkgs.libclang.lib}/lib"; - }; - } - ); -} diff --git a/src/PlonkVerify.hs b/src/PlonkVerify.hs index 10d5742..6a3449e 100644 --- a/src/PlonkVerify.hs +++ b/src/PlonkVerify.hs @@ -16,7 +16,7 @@ {-# OPTIONS_GHC -Wno-unused-imports #-} -module PlonkVerify (babybearextinv, babybearinv, hello) where +module PlonkVerify (verify_plonk_bn254) where import Data.Int import Data.Word @@ -24,6 +24,4 @@ import Foreign.C.String import Foreign.C.Types import Foreign.Ptr -foreign import ccall safe "__c_babybearextinv" babybearextinv :: CUInt -> CUInt -> CUInt -> CUInt -> CUInt -> IO (CUInt) -foreign import ccall safe "__c_babybearinv" babybearinv :: CUInt -> IO (CUInt) -foreign import ccall safe "__c_hello" hello :: CString -> IO (()) \ No newline at end of file +foreign import ccall safe "__c_verify_plonk_bn254" verify_plonk_bn254 :: CString -> CString -> CString -> CString -> IO (CUInt) \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 7185a51..68b2769 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,46 +1,155 @@ use hs_bindgen::*; -use p3_baby_bear::BabyBear; -use p3_field::PrimeField32; -use p3_field::{extension::BinomialExtensionField, AbstractExtensionField, AbstractField, Field}; - use sphinx_recursion_gnark_ffi::ffi; -//#[hs_bindgen] -//#[no_mangle] -//pub fn verify_plonk_bn254( -// data_dir: &str, -// proof: &str, -// vkey_hash: &str, -// committed_values_digest: &str, -//) -> u32 { -// if ffi::verify_plonk_bn254(data_dir, proof, vkey_hash, committed_values_digest).is_ok() { -// 1u32 -// } else { -// 0u32 -// } -//} - +// Facade exposing a bindgen anchor #[hs_bindgen] -#[no_mangle] -pub(crate) extern "C" fn babybearextinv(a: u32, b: u32, c: u32, d: u32, i: u32) -> u32 { - let a = BabyBear::from_wrapped_u32(a); - let b = BabyBear::from_wrapped_u32(b); - let c = BabyBear::from_wrapped_u32(c); - let d = BabyBear::from_wrapped_u32(d); - let inv = BinomialExtensionField::::from_base_slice(&[a, b, c, d]).inverse(); - let inv: &[BabyBear] = inv.as_base_slice(); - inv[i as usize].as_canonical_u32() -} +pub fn verify_plonk_bn254( + build_dir_str: &str, + proof_str: &str, + vkey_hash_str: &str, + committed_values_digest_str: &str, +) -> u32 { + // TODO: sanity-check the inputs by parsing the build_dir_str, vkey_hash_str, and committed_values_digest_str + let res = ffi::verify_plonk_bn254( + build_dir_str, + proof_str, + vkey_hash_str, + committed_values_digest_str, + ); -#[hs_bindgen] -#[no_mangle] -pub(crate) extern "C" fn babybearinv(a: u32) -> u32 { - let a = BabyBear::from_wrapped_u32(a); - a.inverse().as_canonical_u32() + // Call the actual function in sphinx_recursion_gnark_ffi + if let Err(e) = res { + eprintln!("Error in verify_plonk_bn254: {e}"); + 0u32 // Return 0 for failure + } else { + 1u32 // Return 1 for success + } } -#[hs_bindgen] -fn hello(name: &str) { - println!("Hello, {name}!"); +#[cfg(test)] +mod tests { + use ffi::verify_plonk_bn254; + use num_bigint::BigUint; + use serde::{Deserialize, Serialize}; + use sha2::{Digest as _, Sha256}; + use std::{ + fs, + path::{Path, PathBuf}, + }; + + use super::*; + + // this assumes that the artifacts are installed in ~/.sp1/circuits/plonk_bn254/dev + pub fn plonk_bn254_artifacts_dev_dir() -> PathBuf { + home::home_dir() + .unwrap() + .join(".sp1") + .join("circuits") + .join("plonk_bn254") + .join("v1.0.8-testnet") + } + + pub fn asset_directory() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets") + } + + fn is_fixture_file(entry: &Path) -> bool { + entry.extension().and_then(|ext| ext.to_str()) == Some("json") + } + + pub fn get_vkey_hash(build_dir: &Path) -> [u8; 32] { + let vkey_path = build_dir.join("vk.bin"); + let vk_bin_bytes = std::fs::read(vkey_path).unwrap(); + Sha256::digest(vk_bin_bytes).into() + } + + const MIN_PROOF_LENGTH: usize = 3*64 + 192 + 160 + 64 + 32 + 64 + 64; // 768 + + #[test] + fn test_plonk_bn254_prover() { + let mut results: Vec<_> = Vec::new(); + + // Iterate over all "*.fixture" files in the asset directory + for entry in fs::read_dir(asset_directory()).expect("Failed to read assets directory") { + let entry = entry.expect("Failed to read directory entry"); + let path = entry.path(); + + // Check if the file has the ".json" extension + if is_fixture_file(&path) { + println!("Testing fixture: {:?}", path); + + // Load the fixture from the file + let fixture_data = + std::fs::read_to_string(&path).expect("Failed to read fixture file"); + + // Deserialize the Solidity fixture to use in the test + let fixture: SolidityFixture = + serde_json::from_str(&fixture_data).expect("Failed to deserialize fixture"); + + // Helper function to remove "0x" if present + fn strip_hex_prefix(hex: &str) -> &str { + hex.strip_prefix("0x").unwrap_or(hex) + } + + // Parse vkey, public values, and proof after stripping "0x" + let vkey = strip_hex_prefix(&fixture.vkey); + let public_values = strip_hex_prefix(&fixture.public_values); + let proof = strip_hex_prefix(&fixture.proof); + + // Sanity-check the proof length + // l_com: 64 bytes, + // r_com: 64 bytes, + // o_com: 64 bytes, + // h0, h1, h2: 64 bytes x 3 = 192 bytes, + // l_at_zeta, r_at_zeta, o_at_zeta, s1_at_zeta, s2_at_zeta: 32 bytes x 5 = 160 bytes, + // grand_product_commitment_x, grand_product_commitment_y: 32 bytes x 2 = 64 bytes, + // grand_product_at_zeta_omega: 32 bytes, + // skip the claimed value of the linearised polynomial at zeta, recomputed in the verifier + // opening_at_zeta_proof: 64 bytes, + // opening_at_zeta_omega_proof: 64 bytes, + // selector_commit_api_at_zeta: variable, + // wire_committed_commitments: variable, + assert!(proof.len() >= MIN_PROOF_LENGTH); + + // Parse the BigNum arguments + let vkey_biguint = BigUint::parse_bytes(vkey.as_bytes(), 16).expect("Failed to parse vkey"); + let public_values_biguint = BigUint::parse_bytes(public_values.as_bytes(), 16).expect("Failed to parse public values"); + + eprintln!("vkey: {:?}", vkey_biguint); + eprintln!("public_values: {:?}", public_values_biguint); + + // Fetch the prover's asset directory + let build_dir = plonk_bn254_artifacts_dev_dir(); + let result = verify_plonk_bn254( + build_dir.to_str().unwrap(), + &proof, + &vkey_biguint.to_string(), + &public_values_biguint.to_string(), + ); + + // Push the result of this verification to the results list + match result { + Ok(_) => results.push(Ok(())), + Err(e) => { + results.push(Err(format!("Verification failed for {:?}: {:?}", path, e))) + } + } + + println!("Test completed for fixture: {:?}", path); + } + } + // Unwrap results after the loop + for result in results.iter() { + result.as_ref().unwrap(); + } + } + + #[derive(Debug, Clone, Serialize, Deserialize)] + #[serde(rename_all = "camelCase")] + struct SolidityFixture { + vkey: String, + public_values: String, + proof: String, + } }