diff --git a/aptos/Cargo.toml b/aptos/Cargo.toml index 88266141..124db67d 100644 --- a/aptos/Cargo.toml +++ b/aptos/Cargo.toml @@ -45,10 +45,10 @@ sha2 = "0.9" thiserror = "1.0.58" tiny-keccak = "2.0.2" url = "2.5.0" -sphinx-derive = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "dev" } -sphinx-sdk = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "dev" } -sphinx-zkvm = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "dev" } -sphinx-helper = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "dev" } +sphinx-derive = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "plonk" } +sphinx-sdk = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "plonk", features = ["plonk"] } +sphinx-zkvm = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "plonk" } +sphinx-helper = { git = "ssh://git@github.com/lurk-lab/sphinx", branch = "plonk" } tokio = "1.37" tokio-stream = "0.1" diff --git a/aptos/README.md b/aptos/README.md index 95fb0b1b..7751ca05 100644 --- a/aptos/README.md +++ b/aptos/README.md @@ -225,21 +225,21 @@ cargo +nightly nextest run --verbose --release --profile ci --features aptos --p > Note: The `--no-capture` flag is necessary to see the logs generated by the tests. -### Groth16 proofs +### SNARK proofs (Plonk BN254) -When running any tests or benchmarks that makes Groth16 proofs, it's necessary to build the correct circuit artifacts. +When running any tests or benchmarks that makes Plonk proofs, it's necessary to build the correct circuit artifacts. Currently, if you don't manually build them, it will lead to a proof generation failure (unsatisfied constraint) due to -circuit differences. +circuit differences in Sphinx. -To build the Groth16 artifacts, do the following: +To build the Plonk artifacts, do the following: ```shell unset FRI_QUERIES cd sphinx/prover -make build-groth16 -mkdir -p ~/.sp1/circuits/groth16/9f43e920/ -cp build/* ~/.sp1/circuits/groth16/9f43e920/ +make build-plonk-bn254 +mkdir -p ~/.sp1/circuits/plonk_bn254/57ad9e7d/ +cp build/* ~/.sp1/circuits/plonk_bn254/57ad9e7d/ ``` -The trailing commit identifier after `~/.sp1/circuits/groth16/` depends on the value of `GROTH16_ARTIFACTS_COMMIT` defined [here](https://github.com/lurk-lab/sphinx/blob/3f60558d3465c51d7261c33aa8e63d7c7356ca25/prover/src/install.rs#L13), make sure to use the most up-to-date value. +The trailing commit identifier after `~/.sp1/circuits/plonk_bn254/` depends on the value of `PLONK_ARTIFACTS_COMMIT` defined [here](https://github.com/lurk-lab/sphinx/blob/df866f8872c108283dc4d0f63abb336de97a3216/prover/src/install.rs#L18), make sure to use the most up-to-date value. diff --git a/aptos/aptos-programs/artifacts/benchmarks/signature-verification-program b/aptos/aptos-programs/artifacts/benchmarks/signature-verification-program index f2b2ad7c..805ecf3a 100755 Binary files a/aptos/aptos-programs/artifacts/benchmarks/signature-verification-program and b/aptos/aptos-programs/artifacts/benchmarks/signature-verification-program differ diff --git a/aptos/aptos-programs/artifacts/epoch-change-program b/aptos/aptos-programs/artifacts/epoch-change-program index 61c859aa..4ca93e87 100755 Binary files a/aptos/aptos-programs/artifacts/epoch-change-program and b/aptos/aptos-programs/artifacts/epoch-change-program differ diff --git a/aptos/aptos-programs/artifacts/inclusion-program b/aptos/aptos-programs/artifacts/inclusion-program index e159aebe..fd611485 100755 Binary files a/aptos/aptos-programs/artifacts/inclusion-program and b/aptos/aptos-programs/artifacts/inclusion-program differ diff --git a/aptos/light-client/src/epoch_change.rs b/aptos/light-client/src/epoch_change.rs index 2e5a9244..6b69489c 100644 --- a/aptos/light-client/src/epoch_change.rs +++ b/aptos/light-client/src/epoch_change.rs @@ -164,7 +164,7 @@ mod test { #[test] #[ignore = "This test is too slow for CI"] - fn test_groth16_prove_epoch_change() { + fn test_snark_prove_epoch_change() { use super::*; use aptos_lc_core::aptos_test_utils::wrapper::AptosWrapper; use aptos_lc_core::crypto::hash::CryptoHash; @@ -201,12 +201,12 @@ mod test { let start = Instant::now(); println!("Starting generation of prove_epoch_change proof..."); - let groth16proof = client.prove_groth16(&pk, stdin).unwrap(); + let snark_proof = client.prove_plonk(&pk, stdin).unwrap(); println!("Proving took {:?}", start.elapsed()); let start = Instant::now(); println!("Starting verification of prove_epoch_change proof..."); - client.verify_groth16(&groth16proof, &vk).unwrap(); + client.verify_plonk(&snark_proof, &vk).unwrap(); println!("Verification took {:?}", start.elapsed()); } } diff --git a/aptos/light-client/src/inclusion.rs b/aptos/light-client/src/inclusion.rs index 690a2fef..48acb19c 100644 --- a/aptos/light-client/src/inclusion.rs +++ b/aptos/light-client/src/inclusion.rs @@ -298,7 +298,7 @@ mod test { #[test] #[ignore = "This test is too slow for CI"] - fn test_groth16_prove_inclusion() { + fn test_snark_prove_inclusion() { use super::*; use sphinx_sdk::ProverClient; use std::time::Instant; @@ -319,12 +319,12 @@ mod test { let start = Instant::now(); println!("Starting generation of inclusion proof..."); - let groth16proof = client.prove_groth16(&pk, stdin).unwrap(); + let snark_proof = client.prove_plonk(&pk, stdin).unwrap(); println!("Proving took {:?}", start.elapsed()); let start = Instant::now(); println!("Starting verification of inclusion proof..."); - client.verify_groth16(&groth16proof, &vk).unwrap(); + client.verify_plonk(&snark_proof, &vk).unwrap(); println!("Verification took {:?}", start.elapsed()); } } diff --git a/aptos/light-client/src/sig.rs b/aptos/light-client/src/sig.rs index badb9931..c293e193 100644 --- a/aptos/light-client/src/sig.rs +++ b/aptos/light-client/src/sig.rs @@ -114,7 +114,7 @@ mod test { #[test] #[ignore = "This test is too slow for CI"] - fn test_groth16_prove_sig() { + fn test_snark_prove_sig() { use super::*; use aptos_lc_core::aptos_test_utils::wrapper::AptosWrapper; use sphinx_sdk::ProverClient; @@ -141,12 +141,12 @@ mod test { let start = Instant::now(); println!("Starting generation of signature verification proof..."); - let groth16proof = client.prove_groth16(&pk, stdin).unwrap(); + let snark_proof = client.prove_plonk(&pk, stdin).unwrap(); println!("Proving took {:?}", start.elapsed()); let start = Instant::now(); println!("Starting verification of signature verification proof..."); - client.verify_groth16(&groth16proof, &vk).unwrap(); + client.verify_plonk(&snark_proof, &vk).unwrap(); println!("Verification took {:?}", start.elapsed()); } } diff --git a/aptos/proof-server/benches/proof_server.rs b/aptos/proof-server/benches/proof_server.rs index d9497cb4..0784213c 100644 --- a/aptos/proof-server/benches/proof_server.rs +++ b/aptos/proof-server/benches/proof_server.rs @@ -30,28 +30,28 @@ const ACCOUNT_INCLUSION_DATA_PATH: &str = "./benches/assets/account_inclusion_da const EPOCH_CHANGE_DATA_PATH: &str = "./benches/assets/epoch_change_data.bcs"; fn main() -> Result<(), anyhow::Error> { - let groth16: bool = env::var("GROTH16").unwrap_or_else(|_| "0".into()) == "1"; + let final_snark: bool = env::var("SNARK").unwrap_or_else(|_| "0".into()) == "1"; let run_serially: bool = env::var("RUN_SERIAL").unwrap_or_else(|_| "0".into()) == "1"; let rt = Runtime::new().unwrap(); // Start secondary server - let mut secondary_server_process = rt.block_on(start_secondary_server(groth16))?; + let mut secondary_server_process = rt.block_on(start_secondary_server(final_snark))?; // Start primary server - let mut primary_server_process = rt.block_on(start_primary_server(groth16))?; + let mut primary_server_process = rt.block_on(start_primary_server(final_snark))?; // Join the benchmark tasks and block until they are done let (inclusion_proof, epoch_change_proof) = if run_serially { rt.block_on(async { - let inclusion_proof = bench_proving_inclusion(groth16).await; - let epoch_change_proof = bench_proving_epoch_change(groth16).await; + let inclusion_proof = bench_proving_inclusion(final_snark).await; + let epoch_change_proof = bench_proving_epoch_change(final_snark).await; (Ok(inclusion_proof), Ok(epoch_change_proof)) }) } else { rt.block_on(async { - let inclusion_proof_task = tokio::spawn(bench_proving_inclusion(groth16)); - let epoch_change_proof_task = tokio::spawn(bench_proving_epoch_change(groth16)); + let inclusion_proof_task = tokio::spawn(bench_proving_inclusion(final_snark)); + let epoch_change_proof_task = tokio::spawn(bench_proving_epoch_change(final_snark)); let inclusion_proof = inclusion_proof_task.await.map_err(|e| anyhow!(e)); let epoch_change_proof = epoch_change_proof_task.await.map_err(|e| anyhow!(e)); @@ -74,13 +74,13 @@ fn main() -> Result<(), anyhow::Error> { Ok(()) } -async fn start_primary_server(groth16: bool) -> Result { +async fn start_primary_server(final_snark: bool) -> Result { let primary_addr = env::var("PRIMARY_ADDR").map_err(|_| anyhow::anyhow!("PRIMARY_ADDR not set"))?; let secondary_addr = env::var("SECONDARY_ADDR").map_err(|_| anyhow::anyhow!("SECONDARY_ADDR not set"))?; - let shard_size = if groth16 { "4194304" } else { "1048576" }; + let shard_size = if final_snark { "4194304" } else { "1048576" }; let process = Command::new("cargo") .args([ @@ -122,11 +122,11 @@ async fn start_primary_server(groth16: bool) -> Result { } } -async fn start_secondary_server(groth16: bool) -> Result { +async fn start_secondary_server(final_snark: bool) -> Result { let secondary_addr = env::var("SECONDARY_ADDR").map_err(|_| anyhow::anyhow!("SECONDARY_ADDR not set"))?; - let shard_size = if groth16 { "4194304" } else { "1048576" }; + let shard_size = if final_snark { "4194304" } else { "1048576" }; let process = Command::new("cargo") .args([ @@ -166,7 +166,7 @@ async fn start_secondary_server(groth16: bool) -> Result { } } -async fn bench_proving_inclusion(groth16: bool) -> Result { +async fn bench_proving_inclusion(final_snark: bool) -> Result { // Connect to primary server let primary_address = env::var("PRIMARY_ADDR").map_err(|_| anyhow::anyhow!("PRIMARY_ADDR not set"))?; @@ -187,8 +187,8 @@ async fn bench_proving_inclusion(groth16: bool) -> Result Result Result { +async fn bench_proving_epoch_change(final_snark: bool) -> Result { // Connect to primary server let primary_address = env::var("PRIMARY_ADDR").map_err(|_| anyhow::anyhow!("PRIMARY_ADDR not set"))?; @@ -230,8 +230,8 @@ async fn bench_proving_epoch_change(groth16: bool) -> Result Result<()> { write_bytes(&mut client_stream, &verified).await?; info!("Verification result sent"); } - Ok(Request::Groth16ProveInclusion(inclusion_data)) => { + Ok(Request::SnarkProveInclusion(inclusion_data)) => { let InclusionData { sparse_merkle_proof_assets, transaction_proof_assets, @@ -154,7 +154,7 @@ async fn main() -> Result<()> { ); info!("Start proving"); let proof_handle = - spawn_blocking(move || prover_client.prove_groth16(&pk, stdin)); + spawn_blocking(move || prover_client.prove_plonk(&pk, stdin)); let proof = proof_handle.await??; info!("Proof generated. Serializing"); let proof_bytes = bcs::to_bytes(&proof)?; @@ -162,17 +162,17 @@ async fn main() -> Result<()> { write_bytes(&mut client_stream, &proof_bytes).await?; info!("Proof sent"); } - Ok(Request::Groth16VerifyInclusion(proof)) => { + Ok(Request::SnarkVerifyInclusion(proof)) => { write_bytes( &mut client_stream, - &bcs::to_bytes(&prover_client.verify_groth16(&proof, &vk).is_ok())?, + &bcs::to_bytes(&prover_client.verify_plonk(&proof, &vk).is_ok())?, ) .await?; } - Ok(Request::Groth16ProveEpochChange(epoch_change_data)) => { + Ok(Request::SnarkProveEpochChange(epoch_change_data)) => { info!("Connecting to the secondary server"); let mut secondary_stream = TcpStream::connect(&*snd_addr).await?; - let secondary_request = SecondaryRequest::Groth16Prove(epoch_change_data); + let secondary_request = SecondaryRequest::SnarkProve(epoch_change_data); info!("Serializing secondary request"); let secondary_request_bytes = bcs::to_bytes(&secondary_request)?; info!("Sending secondary request"); @@ -183,10 +183,10 @@ async fn main() -> Result<()> { write_bytes(&mut client_stream, &proof_bytes).await?; info!("Proof sent"); } - Ok(Request::Groth16VerifyEpochChange(proof)) => { + Ok(Request::SnarkVerifyEpochChange(proof)) => { info!("Connecting to the secondary server"); let mut secondary_stream = TcpStream::connect(&*snd_addr).await?; - let secondary_request = SecondaryRequest::Groth16Verify(proof); + let secondary_request = SecondaryRequest::SnarkVerify(proof); info!("Serializing secondary request"); let secondary_request_bytes = bcs::to_bytes(&secondary_request)?; info!("Sending secondary request"); diff --git a/aptos/proof-server/src/bin/server_secondary.rs b/aptos/proof-server/src/bin/server_secondary.rs index 1798036c..671b69e8 100644 --- a/aptos/proof-server/src/bin/server_secondary.rs +++ b/aptos/proof-server/src/bin/server_secondary.rs @@ -85,14 +85,14 @@ async fn main() -> Result<()> { ) .await?; } - SecondaryRequest::Groth16Prove(EpochChangeData { + SecondaryRequest::SnarkProve(EpochChangeData { trusted_state, epoch_change_proof, }) => { let stdin = epoch_change::generate_stdin(&trusted_state, &epoch_change_proof); info!("Start proving"); let proof_handle = - spawn_blocking(move || prover_client.prove_groth16(&pk, stdin)); + spawn_blocking(move || prover_client.prove_plonk(&pk, stdin)); let proof = proof_handle.await??; info!("Proof generated. Serializing"); let proof_bytes = bcs::to_bytes(&proof)?; @@ -100,10 +100,10 @@ async fn main() -> Result<()> { write_bytes(&mut primary_stream, &proof_bytes).await?; info!("Proof sent"); } - SecondaryRequest::Groth16Verify(proof) => { + SecondaryRequest::SnarkVerify(proof) => { write_bytes( &mut primary_stream, - &bcs::to_bytes(&prover_client.verify_groth16(&proof, &vk).is_ok())?, + &bcs::to_bytes(&prover_client.verify_plonk(&proof, &vk).is_ok())?, ) .await?; } diff --git a/aptos/proof-server/src/types/proof_server.rs b/aptos/proof-server/src/types/proof_server.rs index 1496885e..77834210 100644 --- a/aptos/proof-server/src/types/proof_server.rs +++ b/aptos/proof-server/src/types/proof_server.rs @@ -5,7 +5,7 @@ use aptos_lc::inclusion::{ SparseMerkleProofAssets, TransactionProofAssets, ValidatorVerifierAssets, }; use serde::{Deserialize, Serialize}; -use sphinx_sdk::{SphinxGroth16Proof, SphinxProof}; +use sphinx_sdk::{SphinxPlonkBn254Proof, SphinxProof}; use std::fmt::Display; #[derive(Serialize, Deserialize)] @@ -27,10 +27,10 @@ pub enum Request { ProveEpochChange(EpochChangeData), VerifyInclusion(SphinxProof), VerifyEpochChange(SphinxProof), - Groth16ProveInclusion(InclusionData), - Groth16ProveEpochChange(EpochChangeData), - Groth16VerifyInclusion(SphinxGroth16Proof), - Groth16VerifyEpochChange(SphinxGroth16Proof), + SnarkProveInclusion(InclusionData), + SnarkProveEpochChange(EpochChangeData), + SnarkVerifyInclusion(SphinxPlonkBn254Proof), + SnarkVerifyEpochChange(SphinxPlonkBn254Proof), } impl Display for &Request { @@ -40,10 +40,10 @@ impl Display for &Request { Request::ProveEpochChange(_) => write!(f, "ProveEpochChange"), Request::VerifyInclusion(_) => write!(f, "VerifyInclusion"), Request::VerifyEpochChange(_) => write!(f, "VerifyEpochChange"), - Request::Groth16ProveInclusion(_) => write!(f, "Groth16ProveInclusion"), - Request::Groth16ProveEpochChange(_) => write!(f, "Groth16ProveEpochChange"), - Request::Groth16VerifyInclusion(_) => write!(f, "Groth16VerifyInclusion"), - Request::Groth16VerifyEpochChange(_) => write!(f, "Groth16VerifyEpochChange"), + Request::SnarkProveInclusion(_) => write!(f, "SnarkProveInclusion"), + Request::SnarkProveEpochChange(_) => write!(f, "SnarkProveEpochChange"), + Request::SnarkVerifyInclusion(_) => write!(f, "SnarkVerifyInclusion"), + Request::SnarkVerifyEpochChange(_) => write!(f, "SnarkVerifyEpochChange"), } } } @@ -52,6 +52,6 @@ impl Display for &Request { pub enum SecondaryRequest { Prove(EpochChangeData), Verify(SphinxProof), - Groth16Prove(EpochChangeData), - Groth16Verify(SphinxGroth16Proof), + SnarkProve(EpochChangeData), + SnarkVerify(SphinxPlonkBn254Proof), }