diff --git a/Cargo.lock b/Cargo.lock index 4f3faab..b49dda5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3367,6 +3367,7 @@ dependencies = [ name = "helios-recursion-circuit" version = "0.1.0" dependencies = [ + "alloy-primitives 0.8.25", "alloy-sol-types 0.8.25", "beacon-electra", "borsh", @@ -3374,7 +3375,6 @@ dependencies = [ "sp1-helios-primitives", "sp1-verifier", "sp1-zkvm", - "ssz_rs", ] [[package]] @@ -6809,22 +6809,23 @@ dependencies = [ [[package]] name = "sp1-build" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62ef25d7c5d6f3a8fb695c57a248abfc7627eaab3a663b89edc3ceafee593cd0" +checksum = "5563b406d74b417ce07c0d7e0d8184b423f3bc3eacd1e98b105691a167f47c8f" dependencies = [ "anyhow", "cargo_metadata", "chrono", "clap", "dirs", + "sp1-prover", ] [[package]] name = "sp1-core-executor" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9049775ff1ab0114a6bce05d4ba9ca2f82494f781780e070f6465c8751644c8" +checksum = "291c086ca35f43725b33337a7a33c64418d89033d8d6e5586f82b9de2cf90dcb" dependencies = [ "bincode", "bytemuck", @@ -6861,9 +6862,9 @@ dependencies = [ [[package]] name = "sp1-core-machine" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76e4a9944e7be4531470f88a9436c95c944275886f8d82824986088af20e414" +checksum = "236d063c38900e8346342af0b352a23d25b9806b624ee30fcae4c0cc7ddbed27" dependencies = [ "bincode", "cbindgen", @@ -6917,9 +6918,9 @@ dependencies = [ [[package]] name = "sp1-cuda" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6f03537814ef0b91ca4c45d777e8d584cf4d401bb03fe384b7baae1d14e7707" +checksum = "d2c81ab46ba84d41e471351329a69ac43be7da1aa701ed29c70048c83c0fe28c" dependencies = [ "bincode", "ctrlc", @@ -6934,9 +6935,9 @@ dependencies = [ [[package]] name = "sp1-curves" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af6b4ff36255b8472d4c99688118638724c8fc19dcfe41b7b75e2cd817077461" +checksum = "e4d6faecc70f0ca84d0e1259ab2f5eb6d2d351d263c3cd00edf654f8530c0473" dependencies = [ "cfg-if", "dashu", @@ -6956,9 +6957,9 @@ dependencies = [ [[package]] name = "sp1-derive" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "766e1af068bafdcc15786dbc0b555c9ff2a5fa7d249944474fe1fa63560d3870" +checksum = "c25a3bd262f3b0b0ab59d9bc86638ebd895ade9c16526203023c08f926d62732" dependencies = [ "quote", "syn 1.0.109", @@ -7024,9 +7025,9 @@ dependencies = [ [[package]] name = "sp1-primitives" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6939d6b2f63e54e5fbd208a0293027608f22511741b62fe32b6f67f6c144e0c0" +checksum = "699935774a5131c1a8b371108d0666c0c80c43611045fb77fae43f2f242676d5" dependencies = [ "bincode", "blake3", @@ -7044,9 +7045,9 @@ dependencies = [ [[package]] name = "sp1-prover" -version = "5.0.1" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "361f7b36d98cf8874c0fbd7e9401cfd1293652c45d9bdde5904393826c8e54a5" +checksum = "8f9381b478115137a435d02756dae7f3da01abaa0b1b9db8c0973389bd5bfaa9" dependencies = [ "anyhow", "bincode", @@ -7089,9 +7090,9 @@ dependencies = [ [[package]] name = "sp1-recursion-circuit" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11af2fae529dd5e4e39024d0fa218dc5ec2e8bec63fe85d9fe1277467b47d6" +checksum = "e56f69b0e112a7fbba23cbef61fb37f6092ba6897425859b30c4cd2786450179" dependencies = [ "hashbrown 0.14.5", "itertools 0.13.0", @@ -7124,9 +7125,9 @@ dependencies = [ [[package]] name = "sp1-recursion-compiler" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34bb81efd405febb3ad3efb0a23c2aad461e1795f09b803a84bb0fe8cd170835" +checksum = "6101a4c46d55206a5f0d312fd6f663248cbdb49c90f1662138f20472bef31b71" dependencies = [ "backtrace", "itertools 0.13.0", @@ -7146,9 +7147,9 @@ dependencies = [ [[package]] name = "sp1-recursion-core" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9df08e7ab1319f51ea1710b0443ea26acf331f40bff3e1368e99c3ca37073604" +checksum = "13fa9644be4e3b9cf0b1f0976b2c3814dbd5b6d6f47dc8662d6a22828f2c3dd7" dependencies = [ "backtrace", "cbindgen", @@ -7189,9 +7190,9 @@ dependencies = [ [[package]] name = "sp1-recursion-derive" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5096fa5c675329bbd52de0d54d6eca0fbda8aa8b5beccf99fffa85c8700c36" +checksum = "c5e6d5c7e2620d61956e6f75026a88ef2f714dab4abf84e870f13145e6bbec79" dependencies = [ "quote", "syn 1.0.109", @@ -7199,9 +7200,9 @@ dependencies = [ [[package]] name = "sp1-recursion-gnark-ffi" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22fa911c322afa6ec75d7a5100f3bb4fbe28e823f1bb28e13774ea7c2b904ae" +checksum = "d40fc06701180ce02d6079370d00ca74b8d86c84d85909a3684eddc8bfd8c1bf" dependencies = [ "anyhow", "bincode", @@ -7225,9 +7226,9 @@ dependencies = [ [[package]] name = "sp1-sdk" -version = "5.0.4" +version = "5.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e05659d72bc760a14e2a9fb801075d5577453318316b2bd1998e0d2781cbc1b" +checksum = "05114cab7a33f251cf8d470ed85497297dd127a4727569a1a11f759f02136357" dependencies = [ "alloy-primitives 1.2.0", "anyhow", @@ -7270,9 +7271,9 @@ dependencies = [ [[package]] name = "sp1-stark" -version = "5.0.0" +version = "5.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee69877415d24d3a9b1ecedd80143aa5162da370ec653f174ecf25f14c42cb8a" +checksum = "5a795a0a309949772a6f26480f5d844e9f2fad9ef82e4caef9e7b0cec98daffe" dependencies = [ "arrayref", "hashbrown 0.14.5", @@ -7351,31 +7352,6 @@ dependencies = [ "der", ] -[[package]] -name = "ssz_rs" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057291e5631f280978fa9c8009390663ca4613359fc1318e36a8c24c392f6d1f" -dependencies = [ - "bitvec", - "hex", - "num-bigint 0.4.6", - "serde", - "sha2 0.9.9", - "ssz_rs_derive", -] - -[[package]] -name = "ssz_rs_derive" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f07d54c4d01a1713eb363b55ba51595da15f6f1211435b71466460da022aa140" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "ssz_types" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 6dee187..ea404d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ serde_json = { version = "1.0.105", features = [ borsh = { version = "1.5.5", features = ["derive"], default-features = false } itertools = { version = "0.14", default-features = false } sp1-zkvm = "5.0.0" -sp1-sdk = { version = "5.0.0", features = ["native-gnark"] } +sp1-sdk = { version = "5.0.6", features = ["native-gnark"] } sp1-verifier = "5.0.0" # alloy diff --git a/crates/integrations/sp1-helios/circuit/Cargo.toml b/crates/integrations/sp1-helios/circuit/Cargo.toml index ea9486c..60a6970 100644 --- a/crates/integrations/sp1-helios/circuit/Cargo.toml +++ b/crates/integrations/sp1-helios/circuit/Cargo.toml @@ -9,6 +9,6 @@ sp1-verifier.workspace = true borsh.workspace = true helios-recursion-types.workspace = true alloy-sol-types.workspace = true +alloy-primitives.workspace = true sp1-helios-primitives.workspace = true beacon-electra.workspace = true -ssz_rs = "0.9.0" diff --git a/crates/integrations/sp1-helios/circuit/src/blueprint.rs b/crates/integrations/sp1-helios/circuit/src/blueprint.rs index c3bfaf9..5ea2258 100644 --- a/crates/integrations/sp1-helios/circuit/src/blueprint.rs +++ b/crates/integrations/sp1-helios/circuit/src/blueprint.rs @@ -4,6 +4,7 @@ #![no_main] sp1_zkvm::entrypoint!(main); +use alloy_primitives::U256; use alloy_sol_types::SolValue; use beacon_electra::merkleize_header; use helios_recursion_types::{RecursionCircuitInputs, RecursionCircuitOutputs}; @@ -114,9 +115,11 @@ fn get_helios_outputs( if recursive_proof_outputs.is_some() { let recursive_proof_outputs = recursive_proof_outputs.expect("Failed to unwrap recursive proof outputs"); - if helios_output.prevSyncCommitteeHash != recursive_proof_outputs.active_committee - && helios_output.prevSyncCommitteeHash != recursive_proof_outputs.previous_committee - { + + // the new head must be greater than the previous head + assert!(helios_output.prevHead < helios_output.newHead); + + if helios_output.prevSyncCommitteeHash != recursive_proof_outputs.active_committee { panic!("Sync committee mismatch!"); } } @@ -134,7 +137,14 @@ fn get_helios_outputs( .try_into() .expect("Failed to unwrap recursive proof outputs"), root: state_root.to_vec().try_into().unwrap(), - height: ssz_rs::deserialize::(height).expect("Failed to deserialize block number"), + height: unpad_block_number(height), vk: recursive_proof_inputs.recursive_vk.clone(), } } + +// the block height leaf in the merkle tree was padded to 32 bytes, so we need to unpad it +fn unpad_block_number(padded: &[u8; 32]) -> u64 { + let mut bytes = [0u8; 8]; + bytes.copy_from_slice(&padded[..8]); + u64::from_le_bytes(bytes) +} diff --git a/crates/integrations/sp1-helios/circuit/src/main.rs b/crates/integrations/sp1-helios/circuit/src/main.rs index 207425d..babf694 100644 --- a/crates/integrations/sp1-helios/circuit/src/main.rs +++ b/crates/integrations/sp1-helios/circuit/src/main.rs @@ -4,6 +4,7 @@ #![no_main] sp1_zkvm::entrypoint!(main); +use alloy_primitives::U256; use alloy_sol_types::SolValue; use beacon_electra::merkleize_header; use helios_recursion_types::{RecursionCircuitInputs, RecursionCircuitOutputs}; @@ -114,9 +115,11 @@ fn get_helios_outputs( if recursive_proof_outputs.is_some() { let recursive_proof_outputs = recursive_proof_outputs.expect("Failed to unwrap recursive proof outputs"); - if helios_output.prevSyncCommitteeHash != recursive_proof_outputs.active_committee - && helios_output.prevSyncCommitteeHash != recursive_proof_outputs.previous_committee - { + + // the new head must be greater than the previous head + assert!(helios_output.prevHead < helios_output.newHead); + + if helios_output.prevSyncCommitteeHash != recursive_proof_outputs.active_committee { panic!("Sync committee mismatch!"); } } @@ -134,7 +137,14 @@ fn get_helios_outputs( .try_into() .expect("Failed to unwrap recursive proof outputs"), root: state_root.to_vec().try_into().unwrap(), - height: ssz_rs::deserialize::(height).expect("Failed to deserialize block number"), + height: unpad_block_number(height), vk: recursive_proof_inputs.recursive_vk.clone(), } } + +// the block height leaf in the merkle tree was padded to 32 bytes, so we need to unpad it +fn unpad_block_number(padded: &[u8; 32]) -> u64 { + let mut bytes = [0u8; 8]; + bytes.copy_from_slice(&padded[..8]); + u64::from_le_bytes(bytes) +} diff --git a/crates/integrations/sp1-helios/wrapper-circuit/src/main.rs b/crates/integrations/sp1-helios/wrapper-circuit/src/main.rs index 9304397..b989eb3 100644 --- a/crates/integrations/sp1-helios/wrapper-circuit/src/main.rs +++ b/crates/integrations/sp1-helios/wrapper-circuit/src/main.rs @@ -9,7 +9,7 @@ use helios_recursion_types::{ }; use sp1_verifier::Groth16Verifier; -const RECURSIVE_VK: &str = "0x007e6a423d4e8cdb5d4307fc04f0caec22af32a2b59e7ad34bd011542c0ab30a"; +const RECURSIVE_VK: &str = "0x0034e4a559df3be8975c94d57857e1e6fbfc4d26177b8f60ccd2dd86e75fd8c7"; fn main() { // Get the Groth16 verification key for proof verification diff --git a/crates/integrations/sp1-tendermint/circuit/src/blueprint.rs b/crates/integrations/sp1-tendermint/circuit/src/blueprint.rs index 27c69af..f825d0d 100644 --- a/crates/integrations/sp1-tendermint/circuit/src/blueprint.rs +++ b/crates/integrations/sp1-tendermint/circuit/src/blueprint.rs @@ -38,6 +38,14 @@ pub fn main() { if inputs.trusted_height == TRUSTED_HEIGHT { assert_eq!(tendermintx_output.trusted_header_hash, TRUSTED_ROOT); } else { + let recusive_proof_outputs: RecursionCircuitOutputs = borsh::from_slice( + &inputs + .recursive_public_values + .as_ref() + .expect("Failed to unwrap recursive public values"), + ) + .expect("Failed to deserialize Recursive Outputs"); + assert!(tendermintx_output.target_height > recusive_proof_outputs.height); Groth16Verifier::verify( &inputs .recursive_proof diff --git a/crates/integrations/sp1-tendermint/circuit/src/main.rs b/crates/integrations/sp1-tendermint/circuit/src/main.rs index ba70f6e..730c4f7 100644 --- a/crates/integrations/sp1-tendermint/circuit/src/main.rs +++ b/crates/integrations/sp1-tendermint/circuit/src/main.rs @@ -38,6 +38,14 @@ pub fn main() { if inputs.trusted_height == TRUSTED_HEIGHT { assert_eq!(tendermintx_output.trusted_header_hash, TRUSTED_ROOT); } else { + let recusive_proof_outputs: RecursionCircuitOutputs = borsh::from_slice( + &inputs + .recursive_public_values + .as_ref() + .expect("Failed to unwrap recursive public values"), + ) + .expect("Failed to deserialize Recursive Outputs"); + assert!(tendermintx_output.target_height > recusive_proof_outputs.height); Groth16Verifier::verify( &inputs .recursive_proof diff --git a/crates/integrations/sp1-tendermint/wrapper-circuit/src/main.rs b/crates/integrations/sp1-tendermint/wrapper-circuit/src/main.rs index c7847ad..d745c02 100644 --- a/crates/integrations/sp1-tendermint/wrapper-circuit/src/main.rs +++ b/crates/integrations/sp1-tendermint/wrapper-circuit/src/main.rs @@ -9,7 +9,7 @@ use tendermint_recursion_types::{ RecursionCircuitOutputs, WrapperCircuitInputs, WrapperCircuitOutputs, }; -const RECURSIVE_VK: &str = "0x007233d84afece20b8bb52baf8d0eeaa471956b609de542144fcf8ae0364affa"; +const RECURSIVE_VK: &str = "0x009094b993417fd795f3785e430cc9153705f79c798ac8f337acfabad95d4edc"; fn main() { // Get the Groth16 verification key for proof verification diff --git a/crates/service/src/preprocessor/mod.rs b/crates/service/src/preprocessor/mod.rs index 9c055c1..7b95ffd 100644 --- a/crates/service/src/preprocessor/mod.rs +++ b/crates/service/src/preprocessor/mod.rs @@ -43,18 +43,20 @@ impl Preprocessor { let checkpoint = get_checkpoint(self.trusted_slot).await?; let client = get_client(checkpoint).await?; let trusted_slot_period = &self.trusted_slot / 8192; - let latest_finalized_slot = get_latest_finalized_slot().await?; + let latest_slot = gest_latest_slot().await?; // we only get a finality update every 32 slots, so we need to wait for the // latest finalized slot to be at least 32 slots ahead of the trusted slot - info!( - "latest_finalized_slot: {}, trusted_slot: {}", - latest_finalized_slot, self.trusted_slot - ); - if latest_finalized_slot <= self.trusted_slot || latest_finalized_slot % 32 != 0 { + if latest_slot <= self.trusted_slot || latest_slot / 32 < self.trusted_slot / 32 { return Err(anyhow::anyhow!( "Waiting for new slot to be finalized, retry in 60 seconds!" )); } + + let latest_finalized_slot = latest_slot - (latest_slot % 32); + info!( + "latest_finalized_slot: {}, trusted_slot: {}", + latest_finalized_slot, self.trusted_slot + ); let latest_finalized_slot_period = latest_finalized_slot / 8192; let mut period_distance = latest_finalized_slot_period - trusted_slot_period; if period_distance == 0 { @@ -87,7 +89,7 @@ impl Preprocessor { /// /// This function makes an RPC call to the consensus client to get /// the most recently finalized slot number. -pub async fn get_latest_finalized_slot() -> Result { +pub async fn gest_latest_slot() -> Result { let consensus_url = env::var("SOURCE_CONSENSUS_RPC_URL")?; let resp: Value = reqwest::get(format!("{}/eth/v1/beacon/headers/finalized", consensus_url)) .await? diff --git a/crates/service/src/prover.rs b/crates/service/src/prover.rs index 7a0b339..f4a544f 100644 --- a/crates/service/src/prover.rs +++ b/crates/service/src/prover.rs @@ -75,6 +75,8 @@ pub async fn run_prover_loop( tracing::info!("🚀 Starting proof generation service loop..."); loop { + let round_start_time = Instant::now(); + // Clean up any existing GPU containers tracing::info!("🧹 Cleaning up GPU containers..."); cleanup_gpu_containers()?; @@ -281,6 +283,9 @@ pub async fn run_prover_loop( service_state.trusted_slot, service_state.trusted_height ); + + let round_duration = round_start_time.elapsed(); + tracing::info!("⏱️ Round completed in: {:?}", round_duration); tracing::info!("⏱️ Service uptime: {:?}", start_time.elapsed()); } } diff --git a/elfs/variable/helios-recursive-elf.bin b/elfs/variable/helios-recursive-elf.bin index a882f98..01320a1 100644 Binary files a/elfs/variable/helios-recursive-elf.bin and b/elfs/variable/helios-recursive-elf.bin differ diff --git a/elfs/variable/helios-wrapper-elf.bin b/elfs/variable/helios-wrapper-elf.bin index 214beae..2b580bb 100644 Binary files a/elfs/variable/helios-wrapper-elf.bin and b/elfs/variable/helios-wrapper-elf.bin differ diff --git a/elfs/variable/tendermint-recursive-elf.bin b/elfs/variable/tendermint-recursive-elf.bin index 01989f1..fd683f1 100644 Binary files a/elfs/variable/tendermint-recursive-elf.bin and b/elfs/variable/tendermint-recursive-elf.bin differ diff --git a/elfs/variable/tendermint-wrapper-elf.bin b/elfs/variable/tendermint-wrapper-elf.bin index 0bcb6bc..9409073 100644 Binary files a/elfs/variable/tendermint-wrapper-elf.bin and b/elfs/variable/tendermint-wrapper-elf.bin differ