diff --git a/.gitmodules b/.gitmodules index 0394c23..60b2db1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,4 +5,4 @@ [submodule "contracts/lib/sp1-contracts"] path = contracts/lib/sp1-contracts url = https://github.com/succinctlabs/sp1-contracts - tag = v1.1.0 + tag = v1.2.0 diff --git a/Cargo.lock b/Cargo.lock index 3f95286..831e351 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1091,6 +1091,84 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "dashu" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b3e5ac1e23ff1995ef05b912e2b012a8784506987a2651552db2c73fb3d7e0" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "dashu-macros", + "dashu-ratio", + "rustversion", +] + +[[package]] +name = "dashu-base" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0b80bf6b85aa68c58ffea2ddb040109943049ce3fbdf4385d0380aef08ef289" + +[[package]] +name = "dashu-float" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85078445a8dbd2e1bd21f04a816f352db8d333643f0c9b78ca7c3d1df71063e7" +dependencies = [ + "dashu-base", + "dashu-int", + "num-modular", + "num-order", + "rustversion", + "static_assertions", +] + +[[package]] +name = "dashu-int" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee99d08031ca34a4d044efbbb21dff9b8c54bb9d8c82a189187c0651ffdb9fbf" +dependencies = [ + "cfg-if", + "dashu-base", + "num-modular", + "num-order", + "rustversion", + "static_assertions", +] + +[[package]] +name = "dashu-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93381c3ef6366766f6e9ed9cf09e4ef9dec69499baf04f0c60e70d653cf0ab10" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "dashu-ratio", + "paste", + "proc-macro2", + "quote", + "rustversion", +] + +[[package]] +name = "dashu-ratio" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e33b04dd7ce1ccf8a02a69d3419e354f2bbfdf4eb911a0b7465487248764c9" +dependencies = [ + "dashu-base", + "dashu-float", + "dashu-int", + "num-modular", + "num-order", + "rustversion", +] + [[package]] name = "der" version = "0.7.9" @@ -1857,8 +1935,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -2752,6 +2832,21 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-modular" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f" + +[[package]] +name = "num-order" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6" +dependencies = [ + "num-modular", +] + [[package]] name = "num-rational" version = "0.4.2" @@ -4266,18 +4361,18 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.209" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" dependencies = [ "proc-macro2", "quote", @@ -4502,21 +4597,58 @@ dependencies = [ [[package]] name = "sp1-build" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "260c285956e8205d332c9a5acbd828462399b04caf72d0620718a20447bac91d" +checksum = "eae094a567949cc3bbcdb265e45591cf7ac7185f121f6f29ac64a44acb00220e" dependencies = [ "anyhow", "cargo_metadata", + "chrono", "clap", "dirs", ] [[package]] -name = "sp1-core" -version = "1.1.0" +name = "sp1-core-executor" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e916b2084e5de5e45c1dc3244dc212af9c8334dda3246acde7fc6e5ab4a7fc1" +checksum = "8fde11e88cf1e7fa272ec3accb643845b1d3a13b9b7840a0357b00acdfdbedf9" +dependencies = [ + "bincode", + "bytemuck", + "elf", + "eyre", + "generic-array 1.1.0", + "hashbrown 0.14.5", + "hex", + "itertools 0.13.0", + "log", + "nohash-hasher", + "num", + "p3-field", + "p3-keccak-air", + "p3-maybe-rayon", + "rand", + "rrs-succinct", + "serde", + "serde_with", + "sp1-curves", + "sp1-derive", + "sp1-primitives", + "sp1-stark", + "strum", + "strum_macros", + "thiserror", + "tiny-keccak", + "tracing", + "typenum", +] + +[[package]] +name = "sp1-core-machine" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "748ffa83d438905521f389f46fed2de6f3b05b1da2ffc2273194bede11a258fc" dependencies = [ "anyhow", "arrayref", @@ -4561,8 +4693,11 @@ dependencies = [ "serde_with", "size", "snowbridge-amcl", + "sp1-core-executor", + "sp1-curves", "sp1-derive", "sp1-primitives", + "sp1-stark", "static_assertions", "strum", "strum_macros", @@ -4575,11 +4710,32 @@ dependencies = [ "web-time", ] +[[package]] +name = "sp1-curves" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c19d1e60fdd17ec53b8453d7634ed3a136800151412c8d9873944f782c4bc89" +dependencies = [ + "curve25519-dalek", + "dashu", + "elliptic-curve", + "generic-array 1.1.0", + "itertools 0.13.0", + "k256", + "num", + "p3-field", + "serde", + "snowbridge-amcl", + "sp1-primitives", + "sp1-stark", + "typenum", +] + [[package]] name = "sp1-derive" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dbc1d9a05a0e83f548907d50539e5e59873bbf6a82793ce87a195345ca7ddf9" +checksum = "74d06fdae1dc74a9085b155d12180825653e530983262b8ad2e57fe15551d17a" dependencies = [ "proc-macro2", "quote", @@ -4588,32 +4744,32 @@ dependencies = [ [[package]] name = "sp1-helper" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71dce2545791b5c0c2e65f81eb76d74d51804cbbe758643978dc0bbcdbbaa127" +checksum = "4a17502b73973fedac4ea0d20fbaf33663a0cd0cfc4a6c36a3d095634bec941a" dependencies = [ - "cargo_metadata", - "chrono", "sp1-build", ] [[package]] name = "sp1-lib" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de4c2cc40e1019faac8cdbe61172c7be09960cfe240c712be46df3795c53fce8" +checksum = "bea7811abd2d3a991007fcb284f41152840b8388c171288d0c52c6793956609c" dependencies = [ "anyhow", "bincode", "cfg-if", + "hex", "serde", + "snowbridge-amcl", ] [[package]] name = "sp1-primitives" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb04c7a047b000dbab6b6e143f10e79a2cc5294d98fed74dc5dc11d374cef297" +checksum = "d13f9b8ac43071ecfe5980a135cbcecb26ecad243165adce8de5aa3746a2af59" dependencies = [ "itertools 0.13.0", "lazy_static", @@ -4625,9 +4781,9 @@ dependencies = [ [[package]] name = "sp1-prover" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "906ed35cdb4d24050b1d00aa51abfdb986883c5280ca6b34b1cd50e673cfad02" +checksum = "bf5496754989ea23332537094818b4d8bc55e04171fc4f87161493399c2219ad" dependencies = [ "anyhow", "bincode", @@ -4647,13 +4803,15 @@ dependencies = [ "serde", "serde_json", "serial_test", - "sp1-core", + "sp1-core-executor", + "sp1-core-machine", "sp1-primitives", "sp1-recursion-circuit", "sp1-recursion-compiler", "sp1-recursion-core", "sp1-recursion-gnark-ffi", "sp1-recursion-program", + "sp1-stark", "subtle-encoding", "tempfile", "thiserror", @@ -4663,9 +4821,9 @@ dependencies = [ [[package]] name = "sp1-recursion-circuit" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a620b1c84ea7776deebf9eed2a5310c040f1b5b1db0709a2b36b86516f743d" +checksum = "ab0ee89dd4928419672f046a472b3e0114e405805d96de9f39e4e83d323778ab" dependencies = [ "bincode", "itertools 0.13.0", @@ -4678,18 +4836,19 @@ dependencies = [ "p3-matrix", "p3-util", "serde", - "sp1-core", + "sp1-core-machine", "sp1-recursion-compiler", "sp1-recursion-core", "sp1-recursion-derive", "sp1-recursion-program", + "sp1-stark", ] [[package]] name = "sp1-recursion-compiler" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5ef5565d25bf41f00280f0e09ab27cd39b8c8986af12c083e85a4061a49621" +checksum = "d89d0dcf2766edd698ecc336c90d6a228759ee716fc6e24a8e3927210e2536de" dependencies = [ "backtrace", "itertools 0.13.0", @@ -4703,19 +4862,23 @@ dependencies = [ "p3-poseidon2", "p3-symmetric", "p3-util", + "rayon", "serde", - "sp1-core", + "sp1-core-machine", "sp1-primitives", "sp1-recursion-core", + "sp1-recursion-core-v2", "sp1-recursion-derive", + "sp1-stark", "tracing", + "vec_map", ] [[package]] name = "sp1-recursion-core" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5785177a892714601fd2f3e5e79af43d222bdedc415fb7cbdd52c9b1ee4dc3e2" +checksum = "fef244f580afc3c783880cdee7e26c56eb1d3c4522e2c98bd89f79366c3d92a1" dependencies = [ "arrayref", "backtrace", @@ -4739,19 +4902,62 @@ dependencies = [ "p3-util", "serde", "serde_with", - "sp1-core", + "sp1-core-executor", + "sp1-core-machine", "sp1-derive", "sp1-primitives", + "sp1-stark", "static_assertions", "tracing", "zkhash", ] +[[package]] +name = "sp1-recursion-core-v2" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82adbabcf41de013fb7394c06437937fd740c5005e760a215bfc2196f993ae" +dependencies = [ + "arrayref", + "backtrace", + "ff 0.13.0", + "hashbrown 0.14.5", + "itertools 0.13.0", + "num_cpus", + "p3-air", + "p3-baby-bear", + "p3-bn254-fr", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-fri", + "p3-matrix", + "p3-maybe-rayon", + "p3-merkle-tree", + "p3-poseidon2", + "p3-symmetric", + "p3-util", + "serde", + "serde_with", + "sp1-core-executor", + "sp1-core-machine", + "sp1-derive", + "sp1-primitives", + "sp1-recursion-core", + "sp1-stark", + "static_assertions", + "thiserror", + "tracing", + "vec_map", + "zkhash", +] + [[package]] name = "sp1-recursion-derive" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5970fa689c5b3e41d2ea4a81f9207594b9befc2ba5ad9d8727b6bdbc7ba054e" +checksum = "168c1e526a6c8b3877f360fae3fb545bdf0ce7e11e77878170775eeb87c9a043" dependencies = [ "proc-macro2", "quote", @@ -4760,9 +4966,9 @@ dependencies = [ [[package]] name = "sp1-recursion-gnark-ffi" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aacdfec9e2895f0166125b89f3f058a25cdbbdce300839a46b240d3bafbac13" +checksum = "1100ea8ab4374397aafb7f89b6d5d60ed8d5040b51f6db22bd3f9807204b13a1" dependencies = [ "anyhow", "bincode", @@ -4779,16 +4985,17 @@ dependencies = [ "serde", "serde_json", "sha2", - "sp1-core", + "sp1-core-machine", "sp1-recursion-compiler", + "sp1-stark", "tempfile", ] [[package]] name = "sp1-recursion-program" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b570d8e40b8faad877e7c8604de8bc51f61dbee8ee7e0efe3ae7610585e69c" +checksum = "35252bdd8b0bd54f37d1df5ec9ef10de0d301550e6a5fc660de134f1b126da78" dependencies = [ "itertools 0.13.0", "p3-air", @@ -4806,29 +5013,31 @@ dependencies = [ "p3-util", "rand", "serde", - "sp1-core", + "sp1-core-executor", + "sp1-core-machine", "sp1-primitives", "sp1-recursion-compiler", "sp1-recursion-core", + "sp1-stark", "stacker", "tracing", ] [[package]] name = "sp1-sdk" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6924c2ba6d0a522b17f29368f6db8ebd1bf2a424eb4d6e67308f1be4df9d860c" +checksum = "85a21138889b9cbe9b72a652162dad26b904e07dccbbbc10adb4b081abdd4f80" dependencies = [ "alloy-sol-types", "anyhow", "async-trait", - "axum", "bincode", "cfg-if", "dirs", "ethers", "futures", + "getrandom", "hashbrown 0.14.5", "hex", "indicatif", @@ -4845,8 +5054,10 @@ dependencies = [ "serde", "serde_json", "sha2", - "sp1-core", + "sp1-core-executor", + "sp1-core-machine", "sp1-prover", + "sp1-stark", "strum", "strum_macros", "sysinfo", @@ -4858,11 +5069,42 @@ dependencies = [ "vergen", ] +[[package]] +name = "sp1-stark" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfae288fe87c6c9fe5f15c04ad38605f2e8e27f86d1e4228359e36a20f003c68" +dependencies = [ + "arrayref", + "getrandom", + "hashbrown 0.14.5", + "itertools 0.13.0", + "p3-air", + "p3-baby-bear", + "p3-challenger", + "p3-commit", + "p3-dft", + "p3-field", + "p3-fri", + "p3-matrix", + "p3-maybe-rayon", + "p3-merkle-tree", + "p3-poseidon2", + "p3-symmetric", + "p3-uni-stark", + "p3-util", + "rayon-scan", + "serde", + "sp1-derive", + "sp1-primitives", + "tracing", +] + [[package]] name = "sp1-zkvm" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b4490136e03f6fe931dc49559574bb6dbf5e6a86cae1f60dc3842d2b79905ed" +checksum = "6a777787c41fffb1ce1e74229f480223ce8d0ae66763aaac689cec737a19663e" dependencies = [ "bincode", "cfg-if", @@ -5523,6 +5765,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "vergen" version = "8.3.2" diff --git a/README.md b/README.md index 65368b3..295787d 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,22 @@ that can generate a proof of any RISC-V program. ## Requirements - [Rust](https://rustup.rs/) -- [SP1](https://succinctlabs.github.io/sp1/getting-started/install.html) +- [SP1](https://docs.succinct.xyz/getting-started/install.html) ## Running the Project -There are three main ways to run this project: execute a program, generate a core proof, and +There are four main ways to run this project: build a program, execute a program, generate a core proof, and generate an EVM-compatible proof. +### Build the Program + +To build the program, run the following command: + +```sh +cd program +cargo prove build +``` + ### Execute the Program To run the program without generating a proof: @@ -33,19 +42,25 @@ cd script cargo run --release -- --prove ``` -### Generate an EVM-Compatible (PLONK) Proof +### Generate an EVM-Compatible Proof > [!WARNING] -> You will need at least 128GB RAM to generate the PLONK proof. +> You will need at least 128GB RAM to generate a PLONK or Groth16 proof. -To generate a PLONK proof that is small enough to be verified on-chain and verifiable by the EVM: +To generate a proof that is small enough to be verified on-chain and verifiable by the EVM: ```sh cd script -cargo run --release --bin evm +cargo run --release --bin evm -- --system plonk +``` + +this will generate a PLONK proof. If you want to generate a Groth16 proof, run the following command: + +```sh +cargo run --release --bin evm -- --system groth16 ``` -This command also generates a fixture that can be used to test the verification of SP1 zkVM proofs +These commands will also generate fixtures that can be used to test the verification of SP1 zkVM proofs inside Solidity. ### Retrieve the Verification Key @@ -53,7 +68,7 @@ inside Solidity. To retrieve your `programVKey` for your on-chain contract, run the following command: ```sh -cargo run --release --bin vkey +cargo prove vkey --elf elf/riscv32im-succinct-zkvm-elf ``` ## Using the Prover Network diff --git a/contracts/src/fixtures/fixture.json b/contracts/src/fixtures/fixture.json deleted file mode 100644 index 4c31d5e..0000000 --- a/contracts/src/fixtures/fixture.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "a": 6765, - "b": 10946, - "n": 20, - "vkey": "0x00b84bc28cca2115d6299b70825d7ec6117deb3981d1bbf21c3113f92dc18eb5", - "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", - "proof": "0xc430ff7f260ec07d5bc7aaa7f40ecce2529a1f7517a232cb6dfe71bda5205e79fb0e090e2cf5eb678d03adfef43dec7f919076dd47548321bf853fbe0451fea804169dca04309e083f8ded64c40c4fe018d25495fcadca19e2e3625c5e35c3ac89c71a3f2400618aec42ea7edfd3be3925791298e8b6e803c2e003cbab5259a1a63b2821136de9de013dcaf524aeca92bd77f3463e7925fa7050d02a77f5e8172da74f4a0b3bcb86fed554d084af9c1599f961ba65b4dd60bd02299d11f1b6956d5a403124c78bbed2d3d0c5af2acc79c57a8d9b6e4bb8226abd04ce096050d696fd93f01b26b5a1114ec1c5317c6caca14cc580358ead30bf53234fa5ed3de8023c98e019b9517c2e18ea6c3553a4d8b54a59651897d4bf1afcb73101a5a7295c5e90450ba2f0f71cfd1bb9e910bb97bb56f77118d3732623d8cb9ee792d38b10b080582f7ae4493c42f544af098f40d0948db857731513430f253c8a88f74098e03ffd1a524331e0801cd942b0744ad5f61531203356967e5eeceef0fe47cabcb5bbdb125c57ccfb010e06e9d7e739ddd1810ba61e3aedd7572653829ef3802c5516e921d2db577f969ba667098a71fd398e177ca2513a822a312dcbb9df393fa5572e1c42b34da0b1dd884825474a41940dacc91914a0cf183b55b738be434e744c912560828cbc15f863b35bea8c4a49d14da6f12d8422baa64b5a8b82aea3a6303c12e6782b64aaca45330f1040cc5e0f7bba4036fb5edeab2fddb7d1ab66cd44772a21cd24aab969c3ff1d1a0fcd42befd27d0f26380bfbe968a32b6ca718b75a020908705cf0be21ebb1d9ac5598e0b3eace0b4e43fb6ae8bfb752b7c951a467e1038671e1623d30955d3ad265dcfa28e71fa8739d27c083a0220dd7754acaa730f7b332c26c93cebc0651401459936e2ddbd0b086e67bdca6d6806c581c4458c2831023d95cfd5206c9d51902baff1db01f40ed1e53379c58fd9918b8b4b93240193ec7199608ab490c21208f919cb405a595f9e9a55a950d2aae6b09fe72875256e39a0cc9ea354cbd9b1bb829aca36fc28b7a5d55fc06c9d8f00e693b704292736f75b7556844eb7b96b67cce1f30434aeb2634b0bc36b33be8ba877bbf3a32a6630bd5d99ba8bd21eb9eaf0ea792340e1c8788ba2338725c27cef5a042a0918b200389157bc1352975661991d719f73785015f178f38bb6ec9d7dfb4cb0f7" -} \ No newline at end of file diff --git a/contracts/src/fixtures/groth16-fixture.json b/contracts/src/fixtures/groth16-fixture.json new file mode 100644 index 0000000..548a760 --- /dev/null +++ b/contracts/src/fixtures/groth16-fixture.json @@ -0,0 +1,8 @@ +{ + "a": 6765, + "b": 10946, + "n": 20, + "vkey": "0x00b94374c2266f0d2e01793c47156bc0badd5d4d60899e1b0963a27f09ac9475", + "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", + "proof": "0x837629d32fe646eef2ba21ec161306d496e2938a0e3ec7f8990c3b0c74f28a8211852a1c2032cbb2a143b36636e1dafa6b02ae15db4884701ca24fed869efe4b8b4471441471f2f0778a20e563eda1852c7256118a447e35790fd719b9d3722401c537802f38e055b52c3f88abb76d4ac1da35112e7180d0a5c39ac37ce97b8ae38af59e254a8dcdfb728c9c55fa25c44e7ca994c30e1585792ad16494708b66ce54d75a0e6654e0b71270401e77e94615604a270cd73e549cb923bb997134bc1e96985f12f8d42a726a65767d0ae1265d216b703ba12d41a56c1b84b9e94d51ce6df8c42c8682896b84bbe18192ed3c36b3cedf6a0f93381e1d0c7e1e1ee40cd6bc75e9" +} \ No newline at end of file diff --git a/contracts/src/fixtures/plonk-fixture.json b/contracts/src/fixtures/plonk-fixture.json new file mode 100644 index 0000000..c34adbd --- /dev/null +++ b/contracts/src/fixtures/plonk-fixture.json @@ -0,0 +1,8 @@ +{ + "a": 6765, + "b": 10946, + "n": 20, + "vkey": "0x00c138feada234bda87064e52edfabf16720cb11c57149ee53c7620c27bbc1e2", + "publicValues": "0x00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000001a6d0000000000000000000000000000000000000000000000000000000000002ac2", + "proof": "0xc865c1b61a514c662608a8828d3824a57ff2a5ba82dedba6a3d548b533b21f30e6cb04640d6f6fe37638f9c902c9fb5925777defd28852bd42de46eab219496795bec9ae10958d6e2b581dfe293a9b93f3d50f8cd3c986ccbfaec9cc22184d368573465d13306190d2335df8aff016f18b5e69475159f2fd9cb1ea0c4d4428402d3dc91324cbdac05b9a50ad0d872bd02005d52eda6c76af17af39448c50b340935f9d591d8a1d567fbb375308a5be68022ea9f1ffd57e920da331236c0943f3f38893eb1db03793c2ff89ce82798af3eeef7c0e16af0e65ecff4637dfe0f51281f9a3b32e12d4fbe83384bedb40f8e5f0b0be8ac73d794e067684ce5fa4e4ae3ab1a155183257a1899476f55a2cf1186c6e143df0f5e26287d3f0463701d631cf3b112a198909d9abba5cd0092b116f8959bb568dc1e228c67814e5b26411729df14033286f74effc2ade9861d6dba5fa6a44b878c6d42c56f6922ea4998e142a718b82233dd60620c258e207015445bf4c389374c4f27579a73139d7dea7f2dbf1cc3b0ddea9fc98068e43d112d88b4a3266215dd39c16d77ed6ee244266ae6613025c0cea1172c3b6fc6decb50cc59f770dd3a8ef48a56a5b49dd1562a2a678361bf8147a6f79767950adcef9a3d0b89984956f28d50915c6650323f5a294b98e9d381c090d108f1ad88e4d19fe6cace99b1c5ab01bb80a6013396a072b5c506bd41e0c8ebf6a1258a38cda605fbb37e8f45fa882dba6a31db4217bb3139b49a63c7b2d28550fbad359106d913ed0b1b717afcef84c4fba258b07e785212544ee3f7427e653922829b3e07fe355a94ab6c186435f9cdc8585925593ab025715d0df0d0ed7f8248529d521f643585ac1adc7918eef9f0d1080c522cee1605d7272a0ad2fdaf906814793525c4e408cd409c4e2ccae835e42721502b92ded8d266936852441204386977b84ca61d613ae8d37b153c8fe875ac3e9ffd26b5b7509cdc7122a9d8d23f4dc5f1183539fbe76a83abe6a6ad4c028f0f65838717436b4b6d3d501017c333c5d2184aac2e5e9105ba09a63f4c2265378e2d69f649c44d6f291d813e6b4e004fd4bb2654cc70e6b71206a10ed3331bec66c74819e0aff77f726910ceab6dbec93048c9c8767d28487dbac866349e43ba609ddf253e80bfc2f16c72f06a089c5cdb946e187d13f45ae0893347520ffae16eacdfa58cd5c1f29555a" +} \ No newline at end of file diff --git a/contracts/test/Fibonacci.t.sol b/contracts/test/Fibonacci.t.sol index bcbcf40..9e065f1 100644 --- a/contracts/test/Fibonacci.t.sol +++ b/contracts/test/Fibonacci.t.sol @@ -23,7 +23,7 @@ contract FibonacciTest is Test { function loadFixture() public view returns (SP1ProofFixtureJson memory) { string memory root = vm.projectRoot(); - string memory path = string.concat(root, "/src/fixtures/fixture.json"); + string memory path = string.concat(root, "/src/fixtures/plonk-fixture.json"); string memory json = vm.readFile(path); bytes memory jsonBytes = json.parseRaw("."); return abi.decode(jsonBytes, (SP1ProofFixtureJson)); diff --git a/elf/riscv32im-succinct-zkvm-elf b/elf/riscv32im-succinct-zkvm-elf index c55acc1..71e053d 100755 Binary files a/elf/riscv32im-succinct-zkvm-elf and b/elf/riscv32im-succinct-zkvm-elf differ diff --git a/program/Cargo.toml b/program/Cargo.toml index 1ca3335..b5a8bb1 100644 --- a/program/Cargo.toml +++ b/program/Cargo.toml @@ -5,5 +5,5 @@ edition = "2021" [dependencies] alloy-sol-types = { workspace = true } -sp1-zkvm = "1.1.0" -fibonacci-lib = { path = "../lib" } \ No newline at end of file +sp1-zkvm = "1.2.0" +fibonacci-lib = { path = "../lib" } diff --git a/script/Cargo.toml b/script/Cargo.toml index dcc126b..2e2ea25 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -12,12 +12,8 @@ path = "src/bin/main.rs" name = "evm" path = "src/bin/evm.rs" -[[bin]] -name = "vkey" -path = "src/bin/vkey.rs" - [dependencies] -sp1-sdk = "1.1.0" +sp1-sdk = "1.2.0" serde_json = { version = "1.0", default-features = false, features = ["alloc"] } serde = { version = "1.0", default-features = false, features = ["derive"] } clap = { version = "4.0", features = ["derive", "env"] } @@ -27,4 +23,4 @@ alloy-sol-types = { workspace = true } fibonacci-lib = { path = "../lib" } [build-dependencies] -sp1-helper = "1.1.0" +sp1-helper = "1.2.0" diff --git a/script/src/bin/evm.rs b/script/src/bin/evm.rs index 7a8977e..b2940eb 100644 --- a/script/src/bin/evm.rs +++ b/script/src/bin/evm.rs @@ -3,11 +3,15 @@ //! //! You can run this script using the following command: //! ```shell -//! RUST_LOG=info cargo run --release --bin evm +//! RUST_LOG=info cargo run --release --bin evm -- --system plonk +//! ``` +//! or +//! ```shell +//! RUST_LOG=info cargo run --release --bin evm -- --system groth16 //! ``` use alloy_sol_types::SolType; -use clap::Parser; +use clap::{Parser, ValueEnum}; use fibonacci_lib::PublicValuesStruct; use serde::{Deserialize, Serialize}; use sp1_sdk::{HashableKey, ProverClient, SP1ProofWithPublicValues, SP1Stdin, SP1VerifyingKey}; @@ -22,6 +26,15 @@ pub const FIBONACCI_ELF: &[u8] = include_bytes!("../../../elf/riscv32im-succinct struct EVMArgs { #[clap(long, default_value = "20")] n: u32, + #[clap(long, value_enum, default_value = "plonk")] + system: ProofSystem, +} + +/// Enum representing the available proof systems +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)] +enum ProofSystem { + Plonk, + Groth16, } /// A fixture that can be used to test the verification of SP1 zkVM proofs inside Solidity. @@ -54,19 +67,24 @@ fn main() { stdin.write(&args.n); println!("n: {}", args.n); + println!("Proof System: {:?}", args.system); - // Generate the proof. - let proof = client - .prove(&pk, stdin) - .plonk() - .run() - .expect("failed to generate proof"); + // Generate the proof based on the selected proof system. + let proof = match args.system { + ProofSystem::Plonk => client.prove(&pk, stdin).plonk().run(), + ProofSystem::Groth16 => client.prove(&pk, stdin).groth16().run(), + } + .expect("failed to generate proof"); - create_plonk_fixture(&proof, &vk); + create_proof_fixture(&proof, &vk, args.system); } /// Create a fixture for the given proof. -fn create_plonk_fixture(proof: &SP1ProofWithPublicValues, vk: &SP1VerifyingKey) { +fn create_proof_fixture( + proof: &SP1ProofWithPublicValues, + vk: &SP1VerifyingKey, + system: ProofSystem, +) { // Deserialize the public values. let bytes = proof.public_values.as_slice(); let PublicValuesStruct { n, a, b } = PublicValuesStruct::abi_decode(bytes, false).unwrap(); @@ -101,7 +119,7 @@ fn create_plonk_fixture(proof: &SP1ProofWithPublicValues, vk: &SP1VerifyingKey) let fixture_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../contracts/src/fixtures"); std::fs::create_dir_all(&fixture_path).expect("failed to create fixture path"); std::fs::write( - fixture_path.join("fixture.json"), + fixture_path.join(format!("{:?}-fixture.json", system).to_lowercase()), serde_json::to_string_pretty(&fixture).unwrap(), ) .expect("failed to write fixture"); diff --git a/script/src/bin/vkey.rs b/script/src/bin/vkey.rs deleted file mode 100644 index 0993301..0000000 --- a/script/src/bin/vkey.rs +++ /dev/null @@ -1,27 +0,0 @@ -//! A script to print the program verification key. -//! -//! You can run this script using the following command: -//! ```shell -//! RUST_LOG=info cargo run --bin vkey --release -//! ``` - -use sp1_sdk::{HashableKey, ProverClient}; - -/// The ELF (executable and linkable format) file for the Succinct RISC-V zkVM. -/// -/// This file is generated by running `cargo prove build` inside the `program` directory. -pub const FIBONACCI_ELF: &[u8] = include_bytes!("../../../elf/riscv32im-succinct-zkvm-elf"); - -fn main() { - // Setup the logger. - sp1_sdk::utils::setup_logger(); - - // Setup the prover client. - let client = ProverClient::new(); - - // Setup the program. - let (_, vk) = client.setup(FIBONACCI_ELF); - - // Print the verification key. - println!("Program Verification Key: {}", vk.bytes32()); -}