diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7bd88f3474..e57346e040 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,7 +35,7 @@ jobs: with: command: test toolchain: nightly-2024-04-17 - args: --release -p sp1-sdk --features plonk_bn254 -- test_e2e_prove_plonk_bn254 --nocapture + args: --release -p sp1-sdk --features plonk -- test_e2e_prove_plonk --nocapture env: RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native RUST_BACKTRACE: 1 \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 093d9fcefe..7e0ba76dd3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -45,7 +45,7 @@ jobs: with: command: test toolchain: nightly-2024-04-17 - args: --release --features plonk_bn254 + args: --release --features plonk env: RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native RUST_BACKTRACE: 1 @@ -76,7 +76,7 @@ jobs: with: command: test toolchain: nightly-2024-04-17 - args: --release --features plonk_bn254 + args: --release --features plonk env: RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 -C target-cpu=native RUST_BACKTRACE: 1 diff --git a/book/verifying-proofs/solidity-and-evm.md b/book/verifying-proofs/solidity-and-evm.md index 117ee69a19..294023c5b8 100644 --- a/book/verifying-proofs/solidity-and-evm.md +++ b/book/verifying-proofs/solidity-and-evm.md @@ -5,13 +5,13 @@ of using SP1 for on-chain usecases, refer to the [SP1 Project Template](https:// ## Generating a Plonk Bn254 Proof -By default, the proofs generated by SP1 are not verifiable onchain, as they are non-constant size and STARK verification on Ethereum is very expensive. To generate a proof that can be verified onchain, we use performant STARK recursion to combine SP1 shard proofs into a single STARK proof and then wrap that in a SNARK proof. Our `ProverClient` has a function for this called `prove_plonk_bn254`. Behind the scenes, this function will first generate a normal SP1 proof, then recursively combine all of them into a single proof using the STARK recursion protocol. Finally, the proof is wrapped in a SNARK proof using PLONK. +By default, the proofs generated by SP1 are not verifiable onchain, as they are non-constant size and STARK verification on Ethereum is very expensive. To generate a proof that can be verified onchain, we use performant STARK recursion to combine SP1 shard proofs into a single STARK proof and then wrap that in a SNARK proof. Our `ProverClient` has a function for this called `prove_plonk`. Behind the scenes, this function will first generate a normal SP1 proof, then recursively combine all of them into a single proof using the STARK recursion protocol. Finally, the proof is wrapped in a SNARK proof using PLONK. -**Due to the fact that PLONK Bn254 proofs require a trusted setup, the PLONK Bn254 prover is only guaranteed to work on official releases of SP1.** +**The PLONK Bn254 prover is only guaranteed to work on official releases of SP1.** -To use PLONK proving & verification locally, enable the `plonk_bn254` feature flag in the sp1-sdk and ensure that Go >1.22.1 is installed. +To use PLONK proving & verification locally, enable the `plonk` feature flag in the sp1-sdk and ensure that Go >1.22.1 is installed. ```toml -sp1-sdk = { features = ["plonk_bn254"] } +sp1-sdk = { features = ["plonk"] } ``` diff --git a/examples/aggregation/script/Cargo.toml b/examples/aggregation/script/Cargo.toml index ae46141d2b..7f28d4c105 100644 --- a/examples/aggregation/script/Cargo.toml +++ b/examples/aggregation/script/Cargo.toml @@ -6,7 +6,7 @@ default-run = "sp1-aggregation-example-script" [dependencies] hex = "0.4.3" -sp1-sdk = { path = "../../../sdk", features = ["plonk_bn254"] } +sp1-sdk = { path = "../../../sdk", features = ["plonk"] } tracing = "0.1.40" [build-dependencies] diff --git a/examples/aggregation/script/src/main.rs b/examples/aggregation/script/src/main.rs index 5759d64b34..2520343431 100644 --- a/examples/aggregation/script/src/main.rs +++ b/examples/aggregation/script/src/main.rs @@ -95,7 +95,7 @@ fn main() { // Generate the plonk bn254 proof. client - .prove_plonk_bn254(&aggregation_pk, stdin) + .prove_plonk(&aggregation_pk, stdin) .expect("proving failed"); }); } diff --git a/examples/fibonacci/script/bin/plonk_bn254.rs b/examples/fibonacci/script/bin/plonk_bn254.rs index 5628b80c48..7057f20fab 100644 --- a/examples/fibonacci/script/bin/plonk_bn254.rs +++ b/examples/fibonacci/script/bin/plonk_bn254.rs @@ -16,7 +16,7 @@ fn main() { // Generate the proof for the given program and input. let client = ProverClient::new(); let (pk, vk) = client.setup(ELF); - let mut proof = client.prove_plonk_bn254(&pk, stdin).unwrap(); + let mut proof = client.prove_plonk(&pk, stdin).unwrap(); println!("generated proof"); @@ -29,7 +29,7 @@ fn main() { // Verify proof and public values client - .verify_plonk_bn254(&proof, &vk) + .verify_plonk(&proof, &vk) .expect("verification failed"); // Save the proof. diff --git a/prover/Cargo.toml b/prover/Cargo.toml index 42f014de9f..fb10228f5d 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -53,7 +53,7 @@ name = "e2e" path = "scripts/e2e.rs" [features] -default = ["plonk_bn254"] +default = ["plonk"] neon = ["sp1-core/neon"] -plonk_bn254 = ["sp1-recursion-gnark-ffi/plonk_bn254"] +plonk = ["sp1-recursion-gnark-ffi/plonk"] diff --git a/recursion/gnark-ffi/Cargo.toml b/recursion/gnark-ffi/Cargo.toml index cc3373baea..a5270d58da 100644 --- a/recursion/gnark-ffi/Cargo.toml +++ b/recursion/gnark-ffi/Cargo.toml @@ -21,6 +21,6 @@ cc = "1.0" cfg-if = "1.0" [features] -default = ["plonk_bn254"] +default = ["plonk"] -plonk_bn254 = [] +plonk = [] diff --git a/recursion/gnark-ffi/build.rs b/recursion/gnark-ffi/build.rs index fae3c68ed3..35c3f63f10 100644 --- a/recursion/gnark-ffi/build.rs +++ b/recursion/gnark-ffi/build.rs @@ -9,7 +9,7 @@ use bindgen::CargoCallbacks; /// Build the go library, generate Rust bindings for the exposed functions, and link the library. fn main() { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { println!("cargo:rerun-if-changed=go"); // Define the output directory let out_dir = env::var("OUT_DIR").unwrap(); diff --git a/recursion/gnark-ffi/src/ffi.rs b/recursion/gnark-ffi/src/ffi.rs index 49cbeadcb1..3ab6914cb7 100644 --- a/recursion/gnark-ffi/src/ffi.rs +++ b/recursion/gnark-ffi/src/ffi.rs @@ -9,14 +9,14 @@ use std::ffi::{c_char, CString}; #[allow(warnings, clippy::all)] mod bind { - #[cfg(feature = "plonk_bn254")] + #[cfg(feature = "plonk")] include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } use bind::*; pub fn prove_plonk_bn254(data_dir: &str, witness_path: &str) -> PlonkBn254Proof { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { let data_dir = CString::new(data_dir).expect("CString::new failed"); let witness_path = CString::new(witness_path).expect("CString::new failed"); @@ -31,21 +31,21 @@ pub fn prove_plonk_bn254(data_dir: &str, witness_path: &str) -> PlonkBn254Proof proof.into_rust() } else { - panic!("plonk_bn254 feature not enabled"); + panic!("plonk feature not enabled"); } } } pub fn build_plonk_bn254(data_dir: &str) { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { let data_dir = CString::new(data_dir).expect("CString::new failed"); unsafe { bind::BuildPlonkBn254(data_dir.as_ptr() as *mut c_char); } } else { - panic!("plonk_bn254 feature not enabled"); + panic!("plonk feature not enabled"); } } @@ -58,7 +58,7 @@ pub fn verify_plonk_bn254( committed_values_digest: &str, ) -> Result<(), String> { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { let data_dir = CString::new(data_dir).expect("CString::new failed"); let proof = CString::new(proof).expect("CString::new failed"); let vkey_hash = CString::new(vkey_hash).expect("CString::new failed"); @@ -81,14 +81,14 @@ pub fn verify_plonk_bn254( Err(err.into_string().unwrap()) } } else { - panic!("plonk_bn254 feature not enabled"); + panic!("plonk feature not enabled"); } } } pub fn test_plonk_bn254(witness_json: &str, constraints_json: &str) { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { unsafe { let witness_json = CString::new(witness_json).expect("CString::new failed"); let build_dir = CString::new(constraints_json).expect("CString::new failed"); @@ -103,7 +103,7 @@ pub fn test_plonk_bn254(witness_json: &str, constraints_json: &str) { } } } else { - panic!("plonk_bn254 feature not enabled"); + panic!("plonk feature not enabled"); } } } @@ -121,7 +121,7 @@ unsafe fn c_char_ptr_to_string(input: *mut c_char) -> String { } } -#[cfg(feature = "plonk_bn254")] +#[cfg(feature = "plonk")] impl C_PlonkBn254Proof { /// Converts a C PlonkBn254Proof into a Rust PlonkBn254Proof, freeing the C strings. fn into_rust(self) -> PlonkBn254Proof { diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 3f08546bf7..3b7a122ff6 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -40,7 +40,7 @@ ethers = { version = "2", default-features = false } [features] neon = ["sp1-core/neon"] -plonk_bn254 = ["sp1-prover/plonk_bn254"] +plonk = ["sp1-prover/plonk"] [build-dependencies] vergen = { version = "8", default-features = false, features = [ diff --git a/sdk/src/artifacts.rs b/sdk/src/artifacts.rs index 059f79a404..2cc7be7d0d 100644 --- a/sdk/src/artifacts.rs +++ b/sdk/src/artifacts.rs @@ -8,7 +8,7 @@ pub use sp1_prover::build::{ build_plonk_bn254_artifacts_with_dummy, try_install_plonk_bn254_artifacts, }; -/// Exports the soliditiy verifier for PLONK proofs to the specified output directory. +/// Exports the solidity verifier for PLONK proofs to the specified output directory. /// /// WARNING: If you are on development mode, this function assumes that the PLONK artifacts have /// already been built. diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index ba90d84596..389586bcfb 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -54,7 +54,7 @@ pub type SP1ProofVerificationError = MachineVerificationError; pub type SP1CompressedProof = SP1ProofWithPublicValues>; pub type SP1CompressedProofVerificationError = MachineVerificationError; -/// A [SP1ProofWithPublicValues] generated with [ProverClient::prove_plonk_bn254]. +/// A [SP1ProofWithPublicValues] generated with [ProverClient::prove_plonk]. pub type SP1PlonkBn254Proof = SP1ProofWithPublicValues; impl ProverClient { @@ -197,7 +197,7 @@ impl ProverClient { /// /// Returns a proof of the program's execution. By default the proof generated will not be /// compressed to constant size. To create a more succinct proof, use the [Self::prove_compressed], - /// [Self::prove_plonk_bn254], or [Self::prove_plonk] methods. + /// [Self::prove_plonk], or [Self::prove_plonk] methods. /// /// ### Examples /// ```no_run @@ -279,15 +279,11 @@ impl ProverClient { /// stdin.write(&10usize); /// /// // Generate the proof. - /// let proof = client.prove_plonk_bn254(&pk, stdin).unwrap(); + /// let proof = client.prove_plonk(&pk, stdin).unwrap(); /// ``` /// Generates a plonk bn254 proof, verifiable onchain, of the given elf and stdin. - pub fn prove_plonk_bn254( - &self, - pk: &SP1ProvingKey, - stdin: SP1Stdin, - ) -> Result { - self.prover.prove_plonk_bn254(pk, stdin) + pub fn prove_plonk(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { + self.prover.prove_plonk(pk, stdin) } /// Verifies that the given proof is valid and matches the given verification key produced by @@ -366,17 +362,13 @@ impl ProverClient { /// stdin.write(&10usize); /// /// // Generate the proof. - /// let proof = client.prove_plonk_bn254(&pk, stdin).unwrap(); + /// let proof = client.prove_plonk(&pk, stdin).unwrap(); /// /// // Verify the proof. - /// client.verify_plonk_bn254(&proof, &vk).unwrap(); + /// client.verify_plonk(&proof, &vk).unwrap(); /// ``` - pub fn verify_plonk_bn254( - &self, - proof: &SP1PlonkBn254Proof, - vkey: &SP1VerifyingKey, - ) -> Result<()> { - self.prover.verify_plonk_bn254(proof, vkey) + pub fn verify_plonk(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> { + self.prover.verify_plonk(proof, vkey) } } @@ -447,7 +439,7 @@ mod tests { } #[test] - fn test_e2e_prove_plonk_bn254() { + fn test_e2e_prove_plonk() { utils::setup_logger(); let client = ProverClient::local(); let elf = @@ -455,8 +447,8 @@ mod tests { let (pk, vk) = client.setup(elf); let mut stdin = SP1Stdin::new(); stdin.write(&10usize); - let proof = client.prove_plonk_bn254(&pk, stdin).unwrap(); - client.verify_plonk_bn254(&proof, &vk).unwrap(); + let proof = client.prove_plonk(&pk, stdin).unwrap(); + client.verify_plonk(&proof, &vk).unwrap(); } #[test] @@ -473,7 +465,7 @@ mod tests { } #[test] - fn test_e2e_prove_plonk_bn254_mock() { + fn test_e2e_prove_plonk_mock() { utils::setup_logger(); let client = ProverClient::mock(); let elf = @@ -481,7 +473,7 @@ mod tests { let (pk, vk) = client.setup(elf); let mut stdin = SP1Stdin::new(); stdin.write(&10usize); - let proof = client.prove_plonk_bn254(&pk, stdin).unwrap(); - client.verify_plonk_bn254(&proof, &vk).unwrap(); + let proof = client.prove_plonk(&pk, stdin).unwrap(); + client.verify_plonk(&proof, &vk).unwrap(); } } diff --git a/sdk/src/provers/local.rs b/sdk/src/provers/local.rs index 82664c2aad..87379e164d 100644 --- a/sdk/src/provers/local.rs +++ b/sdk/src/provers/local.rs @@ -54,9 +54,9 @@ impl Prover for LocalProver { }) } - fn prove_plonk_bn254(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { + fn prove_plonk(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { cfg_if! { - if #[cfg(feature = "plonk_bn254")] { + if #[cfg(feature = "plonk")] { let proof = self.prover.prove_core(pk, &stdin)?; let deferred_proofs = stdin.proofs.iter().map(|p| p.0.clone()).collect(); diff --git a/sdk/src/provers/mock.rs b/sdk/src/provers/mock.rs index 239127c99e..66b0dda205 100644 --- a/sdk/src/provers/mock.rs +++ b/sdk/src/provers/mock.rs @@ -52,7 +52,7 @@ impl Prover for MockProver { unimplemented!() } - fn prove_plonk_bn254(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { + fn prove_plonk(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { let public_values = SP1Prover::execute(&pk.elf, &stdin)?; Ok(SP1PlonkBn254Proof { proof: PlonkBn254Proof { @@ -84,7 +84,7 @@ impl Prover for MockProver { Ok(()) } - fn verify_plonk_bn254(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> { + fn verify_plonk(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> { verify_plonk_bn254_public_inputs(vkey, &proof.public_values, &proof.proof.public_inputs)?; Ok(()) } diff --git a/sdk/src/provers/mod.rs b/sdk/src/provers/mod.rs index 0f52511573..c18770333c 100644 --- a/sdk/src/provers/mod.rs +++ b/sdk/src/provers/mod.rs @@ -29,7 +29,7 @@ pub trait Prover: Send + Sync { fn prove_compressed(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result; /// Given an SP1 program and input, generate a PLONK proof that can be verified on-chain. - fn prove_plonk_bn254(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result; + fn prove_plonk(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result; /// Verify that an SP1 proof is valid given its vkey and metadata. fn verify( @@ -55,7 +55,7 @@ pub trait Prover: Send + Sync { /// Verify that a SP1 PLONK proof is valid. Verify that the public inputs of the PlonkBn254 proof match /// the hash of the VK and the committed public values of the SP1ProofWithPublicValues. - fn verify_plonk_bn254(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> { + fn verify_plonk(&self, proof: &SP1PlonkBn254Proof, vkey: &SP1VerifyingKey) -> Result<()> { let sp1_prover = self.sp1_prover(); let plonk_bn254_aritfacts = if sp1_prover::build::sp1_dev_mode() { diff --git a/sdk/src/provers/network.rs b/sdk/src/provers/network.rs index 5b67f1cabf..f86900e266 100644 --- a/sdk/src/provers/network.rs +++ b/sdk/src/provers/network.rs @@ -171,7 +171,7 @@ impl Prover for NetworkProver { block_on(self.prove_async(&pk.elf, stdin, ProofMode::Compressed)) } - fn prove_plonk_bn254(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { + fn prove_plonk(&self, pk: &SP1ProvingKey, stdin: SP1Stdin) -> Result { block_on(self.prove_async(&pk.elf, stdin, ProofMode::Plonk)) } }