diff --git a/Cargo.lock b/Cargo.lock index 2720001169..a767224545 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2589,6 +2589,13 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "tendermint-example" +version = "0.1.0" +dependencies = [ + "succinct-core", +] + [[package]] name = "thiserror" version = "1.0.56" diff --git a/core/src/cpu/air/mod.rs b/core/src/cpu/air/mod.rs index 0743542906..8eb5b26ce8 100644 --- a/core/src/cpu/air/mod.rs +++ b/core/src/cpu/air/mod.rs @@ -193,6 +193,7 @@ impl CpuChip { // Verify that the word form of next.pc is correct for both jump instructions. builder + .when_transition() .when(local.selectors.is_jal + local.selectors.is_jalr) .assert_eq(jump_columns.next_pc.reduce::(), next.pc); diff --git a/core/src/cpu/trace.rs b/core/src/cpu/trace.rs index 79c71ada7e..9f82b47758 100644 --- a/core/src/cpu/trace.rs +++ b/core/src/cpu/trace.rs @@ -1,8 +1,3 @@ -use p3_field::PrimeField; -use p3_matrix::dense::RowMajorMatrix; -use std::borrow::BorrowMut; -use std::collections::HashMap; - use super::columns::{ AUIPCCols, BranchCols, JumpCols, CPU_COL_MAP, NUM_AUIPC_COLS, NUM_BRANCH_COLS, NUM_CPU_COLS, NUM_JUMP_COLS, NUM_MEMORY_COLUMNS, @@ -18,6 +13,13 @@ use crate::field::event::FieldEvent; use crate::memory::MemoryCols; use crate::runtime::{ExecutionRecord, Opcode}; use crate::utils::env; +use p3_field::PrimeField; +use p3_matrix::dense::RowMajorMatrix; +use p3_maybe_rayon::prelude::IntoParallelRefIterator; +use p3_maybe_rayon::prelude::ParallelIterator; +use std::borrow::BorrowMut; +use std::collections::HashMap; +use tracing::instrument; impl MachineAir for CpuChip { fn name(&self) -> String { @@ -44,33 +46,35 @@ impl MachineAir for CpuChip { true } + #[instrument(name = "generate CPU trace", skip_all)] fn generate_trace(&self, record: &mut ExecutionRecord) -> RowMajorMatrix { - let mut new_blu_events = Vec::new(); let mut new_alu_events = HashMap::new(); - let mut new_field_events = Vec::new(); + let mut new_blu_events = Vec::new(); + let mut new_field_events: Vec = Vec::new(); // Generate the trace rows for each event. - let rows = record + let rows_with_events = record .cpu_events - .iter() - .map(|op| { - self.event_to_row( - *op, - &mut new_alu_events, - &mut new_blu_events, - &mut new_field_events, - ) - }) + .par_iter() + .map(|op: &CpuEvent| self.event_to_row::(*op)) .collect::>(); + let mut rows = Vec::::new(); + rows_with_events.into_iter().for_each(|row_with_events| { + let (row, alu_events, blu_events, field_events) = row_with_events; + rows.extend(row); + new_alu_events.extend(alu_events); + new_blu_events.extend(blu_events); + new_field_events.extend(field_events); + }); + // Add the dependency events to the shard. record.add_alu_events(new_alu_events); record.add_byte_lookup_events(new_blu_events); record.field_events.extend(new_field_events); // Convert the trace to a row major matrix. - let mut trace = - RowMajorMatrix::new(rows.into_iter().flatten().collect::>(), NUM_CPU_COLS); + let mut trace = RowMajorMatrix::new(rows, NUM_CPU_COLS); // Pad the trace to a power of two. Self::pad_to_power_of_two::(&mut trace.values); @@ -84,10 +88,16 @@ impl CpuChip { fn event_to_row( &self, event: CpuEvent, - new_alu_events: &mut HashMap>, - new_blu_events: &mut Vec, - new_field_events: &mut Vec, - ) -> [F; NUM_CPU_COLS] { + ) -> ( + [F; NUM_CPU_COLS], + HashMap>, + Vec, + Vec, + ) { + let mut new_alu_events = HashMap::new(); + let mut new_blu_events = Vec::new(); + let mut new_field_events = Vec::new(); + let mut row = [F::zero(); NUM_CPU_COLS]; let cols: &mut CpuCols = row.as_mut_slice().borrow_mut(); @@ -103,13 +113,13 @@ impl CpuChip { // Populate memory accesses for a, b, and c. if let Some(record) = event.a_record { - cols.op_a_access.populate(record, new_field_events) + cols.op_a_access.populate(record, &mut new_field_events) } if let Some(MemoryRecordEnum::Read(record)) = event.b_record { - cols.op_b_access.populate(record, new_field_events) + cols.op_b_access.populate(record, &mut new_field_events) } if let Some(MemoryRecordEnum::Read(record)) = event.c_record { - cols.op_c_access.populate(record, new_field_events) + cols.op_c_access.populate(record, &mut new_field_events) } // Populate memory accesses for reading from memory. @@ -119,19 +129,19 @@ impl CpuChip { if let Some(record) = event.memory_record { memory_columns .memory_access - .populate(record, new_field_events) + .populate(record, &mut new_field_events) } // Populate memory, branch, jump, and auipc specific fields. - self.populate_memory(cols, event, new_alu_events, new_blu_events); - self.populate_branch(cols, event, new_alu_events); - self.populate_jump(cols, event, new_alu_events); - self.populate_auipc(cols, event, new_alu_events); + self.populate_memory(cols, event, &mut new_alu_events, &mut new_blu_events); + self.populate_branch(cols, event, &mut new_alu_events); + self.populate_jump(cols, event, &mut new_alu_events); + self.populate_auipc(cols, event, &mut new_alu_events); // Assert that the instruction is not a no-op. cols.is_real = F::one(); - row + (row, new_alu_events, new_blu_events, new_field_events) } /// Populates columns related to memory. diff --git a/core/src/field/mod.rs b/core/src/field/mod.rs index 46f0f55465..91019e0746 100644 --- a/core/src/field/mod.rs +++ b/core/src/field/mod.rs @@ -16,6 +16,8 @@ use crate::runtime::ExecutionRecord; use crate::utils::env; use crate::utils::pad_to_power_of_two; +use tracing::instrument; + /// The number of main trace columns for `FieldLTUChip`. pub const NUM_FIELD_COLS: usize = size_of::>(); @@ -63,6 +65,7 @@ impl MachineAir for FieldLTUChip { !record.field_events.is_empty() } + #[instrument(name = "generate FieldLTU trace", skip_all)] fn generate_trace(&self, record: &mut ExecutionRecord) -> RowMajorMatrix { // Generate the trace rows for each event. let rows = record diff --git a/core/src/lib.rs b/core/src/lib.rs index 5f4a42cd99..be913fb341 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -68,7 +68,9 @@ impl SuccinctProver { let program = Program::from(elf); let mut runtime = Runtime::new(program); runtime.write_stdin_slice(&stdin.buffer.data); - runtime.run(); + tracing::info_span!("runtime.run(...)").in_scope(|| { + runtime.run(); + }); let proof = prove_core(&mut runtime); Ok(SuccinctProofWithIO { proof, diff --git a/core/src/memory/global.rs b/core/src/memory/global.rs index d9d11548bd..cd91c5ef45 100644 --- a/core/src/memory/global.rs +++ b/core/src/memory/global.rs @@ -217,7 +217,6 @@ mod tests { setup_logger(); let program = sha_extend_program(); let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); runtime.run(); let (machine, _prover_data) = RiscvStark::init(BabyBearPoseidon2::new()); @@ -233,7 +232,6 @@ mod tests { setup_logger(); let program = sha_extend_program(); let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); runtime.run(); let (machine, _prover_data) = RiscvStark::init(BabyBearPoseidon2::new()); diff --git a/core/src/runtime/mod.rs b/core/src/runtime/mod.rs index 850f5798c7..8dc5274de2 100644 --- a/core/src/runtime/mod.rs +++ b/core/src/runtime/mod.rs @@ -741,10 +741,12 @@ impl Runtime { /// Execute the program. pub fn run(&mut self) { - // First load the memory image into the memory table. - for (addr, value) in self.program.memory_image.iter() { - self.state.memory.insert(*addr, (*value, 0, 0)); - } + tracing::info_span!("load memory").in_scope(|| { + // First load the memory image into the memory table. + for (addr, value) in self.program.memory_image.iter() { + self.state.memory.insert(*addr, (*value, 0, 0)); + } + }); let max_syscall_cycles = self.max_syscall_cycles(); @@ -799,7 +801,7 @@ impl Runtime { // Call postprocess to set up all variables needed for global accounts, like memory // argument or any other deferred tables. - self.postprocess(); + tracing::info_span!("postprocess").in_scope(|| self.postprocess()); } fn postprocess(&mut self) { diff --git a/core/src/stark/machine.rs b/core/src/stark/machine.rs index d2b0b8719b..65349da220 100644 --- a/core/src/stark/machine.rs +++ b/core/src/stark/machine.rs @@ -230,13 +230,22 @@ where // Get the local and global chips. let chips = self.chips(); + tracing::info!("Generating trace for each chip."); + // Display the statistics about the workload. This is incomplete because it's run before + // generate_trace, which can adds events to the record. + tracing::info!( + "Record stats before generate_trace (incomplete): {:#?}", + record.stats() + ); + // Generate the trace for each chip to collect events emitted from chips with dependencies. chips.iter().for_each(|chip| { chip.generate_trace(record); }); - // Display the statistics about the workload. - tracing::info!("{:#?}", record.stats()); + // Display the statistics about the workload after generate_trace. + tracing::info!("Record stats finalized {:#?}", record.stats()); + tracing::info!("Sharding execution record by chip."); // For each chip, shard the events into segments. let mut shards: Vec = Vec::new(); @@ -244,12 +253,15 @@ where chip.shard(record, &mut shards); }); + tracing::info!("Generating and commiting traces for each shard."); // Generate and commit the traces for each segment. let (shard_commits, shard_data) = P::commit_shards(&self.config, &mut shards, &chips); // Observe the challenges for each segment. - shard_commits.into_iter().for_each(|commitment| { - challenger.observe(commitment); + tracing::info_span!("observing all challenges").in_scope(|| { + shard_commits.into_iter().for_each(|commitment| { + challenger.observe(commitment); + }); }); // Generate a proof for each segment. Note that we clone the challenger so we can observe @@ -257,20 +269,23 @@ where let shard_proofs = shard_data .into_par_iter() .map(|data| { - let data = data.materialize().expect("failed to load shard main data"); + let data = tracing::info_span!("materializing data") + .in_scope(|| data.materialize().expect("failed to load shard main data")); let chips = self .chips() .into_iter() .filter(|chip| data.chip_ids.contains(&chip.name())) .collect::>(); - P::prove_shard( - &self.config, - &mut challenger.clone(), - &chips, - data, - &prover_data.preprocessed_traces, - &prover_data.preprocessed_data, - ) + tracing::info_span!("proving shard").in_scope(|| { + P::prove_shard( + &self.config, + &mut challenger.clone(), + &chips, + data, + &prover_data.preprocessed_traces, + &prover_data.preprocessed_data, + ) + }) }) .collect::>(); diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index 622bd22ff6..33a731c237 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -25,6 +25,7 @@ use super::{types::*, ChipRef, StarkGenericConfig}; use crate::air::MachineAir; use crate::runtime::ExecutionRecord; use crate::stark::permutation::generate_permutation_trace; +use crate::utils::env; #[cfg(not(feature = "perf"))] use crate::stark::debug_constraints; @@ -125,7 +126,7 @@ where // Generate the permutation traces. let mut permutation_traces = Vec::with_capacity(chips.len()); let mut cumulative_sums = Vec::with_capacity(chips.len()); - tracing::debug_span!("generate permutation traces").in_scope(|| { + tracing::info_span!("generate permutation traces").in_scope(|| { sends .par_iter() .zip(receives.par_iter()) @@ -166,7 +167,7 @@ where } // Commit to the permutation traces. - let flattened_permutation_traces = tracing::debug_span!("flatten permutation traces") + let flattened_permutation_traces = tracing::info_span!("flatten permutation traces") .in_scope(|| { permutation_traces .par_iter() @@ -174,13 +175,13 @@ where .collect::>() }); let (permutation_commit, permutation_data) = - tracing::debug_span!("commit permutation traces") + tracing::info_span!("commit permutation traces") .in_scope(|| config.pcs().commit_batches(flattened_permutation_traces)); challenger.observe(permutation_commit.clone()); // For each chip, compute the quotient polynomial. let log_stride_for_quotient = config.pcs().log_blowup() - log_quotient_degree; - let main_ldes = tracing::debug_span!("get main ldes").in_scope(|| { + let main_ldes = tracing::info_span!("get main ldes").in_scope(|| { config .pcs() .get_ldes(&main_data.main_data) @@ -188,7 +189,7 @@ where .map(|lde| lde.vertically_strided(1 << log_stride_for_quotient, 0)) .collect::>() }); - let permutation_ldes = tracing::debug_span!("get perm ldes").in_scope(|| { + let permutation_ldes = tracing::info_span!("get perm ldes").in_scope(|| { config .pcs() .get_ldes(&permutation_data) @@ -199,7 +200,7 @@ where let alpha: SC::Challenge = challenger.sample_ext_element::(); // Compute the quotient values. - let quotient_values = tracing::debug_span!("compute quotient values").in_scope(|| { + let quotient_values = tracing::info_span!("compute quotient values").in_scope(|| { (0..chips.len()) .into_par_iter() .map(|i| { @@ -218,7 +219,7 @@ where }); // Compute the quotient chunks. - let quotient_chunks = tracing::debug_span!("decompose and flatten").in_scope(|| { + let quotient_chunks = tracing::info_span!("decompose and flatten").in_scope(|| { quotient_values .into_iter() .map(|values| { @@ -239,14 +240,14 @@ where } let num_quotient_chunks = quotient_chunks.len(); - let coset_shifts = tracing::debug_span!("coset shift").in_scope(|| { + let coset_shifts = tracing::info_span!("coset shift").in_scope(|| { let shift = config .pcs() .coset_shift() .exp_power_of_2(log_quotient_degree); vec![shift; chips.len()] }); - let (quotient_commit, quotient_data) = tracing::debug_span!("commit shifted batches") + let (quotient_commit, quotient_data) = tracing::info_span!("commit shifted batches") .in_scope(|| { config .pcs() @@ -260,7 +261,7 @@ where let zeta: SC::Challenge = challenger.sample_ext_element(); let trace_opening_points = - tracing::debug_span!("compute trace opening points").in_scope(|| { + tracing::info_span!("compute trace opening points").in_scope(|| { g_subgroups .iter() .map(|g| vec![zeta, zeta * *g]) @@ -272,7 +273,7 @@ where .map(|_| vec![zeta_quot_pow]) .collect::>(); - let (openings, opening_proof) = tracing::debug_span!("open multi batches").in_scope(|| { + let (openings, opening_proof) = tracing::info_span!("open multi batches").in_scope(|| { config.pcs().open_multi_batches( &[ (&main_data.main_data, &trace_opening_points), @@ -560,27 +561,29 @@ where MainData: Serialize + DeserializeOwned, { let num_shards = shards.len(); + tracing::info!("num_shards={}", num_shards); + // Get the number of shards that is the threshold for saving shards to disk instead of + // keeping all the shards in memory. + let save_disk_threshold = env::save_disk_threshold(); // Batch into at most 16 chunks (and at least 1) to limit parallelism. let chunk_size = max(shards.len() / 16, 1); let (commitments, shard_main_data): (Vec<_>, Vec<_>) = tracing::info_span!("commit main for all shards").in_scope(|| { shards - .chunks_mut(chunk_size) - .par_bridge() - .flat_map(|shards| { + .par_chunks_mut(chunk_size) + .flat_map_iter(|shards| { shards .iter_mut() .map(|shard| { let data = - tracing::debug_span!("shard commit main", shard = shard.index) + tracing::info_span!("shard commit main", shard = shard.index) .in_scope(|| Self::commit_main(config, chips, shard)); let commitment = data.main_commit.clone(); let file = tempfile::tempfile().unwrap(); - // TODO: make this logic configurable? - // At around 64 shards * 1 GB per shard, saving to disk starts - // to become necessary. - let data = if num_shards > 64 { - data.save(file).expect("failed to save shard main data") + let data = if num_shards > save_disk_threshold { + tracing::info_span!("saving trace to disk").in_scope(|| { + data.save(file).expect("failed to save shard main data") + }) } else { data.to_in_memory() }; diff --git a/core/src/stark/types.rs b/core/src/stark/types.rs index 90e64346e0..e9966f205b 100644 --- a/core/src/stark/types.rs +++ b/core/src/stark/types.rs @@ -60,17 +60,14 @@ impl MainData { where MainData: Serialize, { - let start = std::time::Instant::now(); let mut writer = BufWriter::new(&file); bincode::serialize_into(&mut writer, self)?; drop(writer); - let elapsed = start.elapsed(); let metadata = file.metadata()?; let bytes_written = metadata.len(); trace!( - "wrote {} after {:?}", - Size::from_bytes(bytes_written), - elapsed + "wrote {} while saving MainData", + Size::from_bytes(bytes_written) ); Ok(MainDataWrapper::TempFile(file, bytes_written)) } diff --git a/core/src/syscall/precompiles/edwards/ed_add.rs b/core/src/syscall/precompiles/edwards/ed_add.rs index 242bdc3da0..610e1309e4 100644 --- a/core/src/syscall/precompiles/edwards/ed_add.rs +++ b/core/src/syscall/precompiles/edwards/ed_add.rs @@ -31,6 +31,7 @@ use p3_matrix::dense::RowMajorMatrix; use p3_matrix::MatrixRowSlices; use std::fmt::Debug; use std::marker::PhantomData; +use tracing::instrument; use valida_derive::AlignedBorrow; pub const NUM_ED_ADD_COLS: usize = size_of::>(); @@ -130,6 +131,7 @@ impl MachineAir for EdAddAssi !record.ed_add_events.is_empty() } + #[instrument(name = "generate Ed Add trace", skip_all)] fn generate_trace(&self, record: &mut ExecutionRecord) -> RowMajorMatrix { let mut rows = Vec::new(); diff --git a/core/src/syscall/precompiles/keccak256/mod.rs b/core/src/syscall/precompiles/keccak256/mod.rs index 24d89d73c2..e06ab82343 100644 --- a/core/src/syscall/precompiles/keccak256/mod.rs +++ b/core/src/syscall/precompiles/keccak256/mod.rs @@ -74,7 +74,6 @@ pub mod permute_tests { pub fn test_keccak_permute_program_execute() { let program = keccak_permute_program(); let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); runtime.run() } @@ -85,17 +84,11 @@ pub mod permute_tests { let mut challenger = config.challenger(); let program = keccak_permute_program(); - let mut runtime = tracing::info_span!("runtime.run(...)").in_scope(|| { - let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); - runtime.run(); - runtime - }); + let mut runtime = Runtime::new(program); + runtime.run(); let (machine, prover_data) = RiscvStark::init(config); - tracing::info_span!("runtime.prove(...)").in_scope(|| { - machine.prove::>(&prover_data, &mut runtime.record, &mut challenger); - }); + machine.prove::>(&prover_data, &mut runtime.record, &mut challenger); } #[test] diff --git a/core/src/syscall/precompiles/sha256/compress/mod.rs b/core/src/syscall/precompiles/sha256/compress/mod.rs index 9980ce1574..bb01f41b49 100644 --- a/core/src/syscall/precompiles/sha256/compress/mod.rs +++ b/core/src/syscall/precompiles/sha256/compress/mod.rs @@ -70,7 +70,6 @@ pub mod compress_tests { let program = sha_compress_program(); let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); runtime.run(); let (machine, prover_data) = RiscvStark::init(config); diff --git a/core/src/syscall/precompiles/sha256/extend/mod.rs b/core/src/syscall/precompiles/sha256/extend/mod.rs index c71e7f6b15..00b723bf78 100644 --- a/core/src/syscall/precompiles/sha256/extend/mod.rs +++ b/core/src/syscall/precompiles/sha256/extend/mod.rs @@ -87,7 +87,6 @@ pub mod extend_tests { let program = sha_extend_program(); let mut runtime = Runtime::new(program); - runtime.write_stdin_slice(&[10]); runtime.run(); let (machine, prover_data) = RiscvStark::init(config); diff --git a/core/src/utils/env.rs b/core/src/utils/env.rs index ab364a729f..2c65298377 100644 --- a/core/src/utils/env.rs +++ b/core/src/utils/env.rs @@ -9,3 +9,12 @@ pub fn shard_size() -> usize { assert!(value != 0 && (value & (value - 1)) == 0); value } + +/// Gets the number of shards after which we should save the shard commits to disk. +pub fn save_disk_threshold() -> usize { + let value = match std::env::var("SAVE_DISK_THRESHOLD") { + Ok(val) => val.parse().unwrap(), + Err(_) => 8, + }; + value +} diff --git a/core/src/utils/logger.rs b/core/src/utils/logger.rs index 4137a171bf..16212d3a76 100644 --- a/core/src/utils/logger.rs +++ b/core/src/utils/logger.rs @@ -2,6 +2,7 @@ use std::sync::Once; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::EnvFilter; +use tracing_subscriber::fmt::format::FmtSpan; static INIT: Once = Once::new(); @@ -19,6 +20,7 @@ pub fn setup_logger() { .with_target(false) .with_thread_names(false) .with_env_filter(env_filter) + .with_span_events(FmtSpan::CLOSE) .finish() .init(); }); diff --git a/examples/fibonacci-io/src/main.rs b/examples/fibonacci-io/src/main.rs index 117e497bd8..346b913f84 100644 --- a/examples/fibonacci-io/src/main.rs +++ b/examples/fibonacci-io/src/main.rs @@ -1,9 +1,11 @@ -use succinct_core::{SuccinctProver, SuccinctStdin, SuccinctVerifier}; +use succinct_core::{utils, SuccinctProver, SuccinctStdin, SuccinctVerifier}; const FIBONACCI_IO_ELF: &[u8] = include_bytes!("../../../programs/demo/fibonacci-io/elf/riscv32im-succinct-zkvm-elf"); fn main() { + // utils::setup_logger(); + utils::setup_tracer(); // Generate proof. let mut stdin = SuccinctStdin::new(); stdin.write(&5000u32); diff --git a/examples/tendermint/Cargo.toml b/examples/tendermint/Cargo.toml new file mode 100644 index 0000000000..f18953e3c9 --- /dev/null +++ b/examples/tendermint/Cargo.toml @@ -0,0 +1,7 @@ +[package] +version = "0.1.0" +name = "tendermint-example" +edition = "2021" + +[dependencies] +succinct-core = { path = "../../core" } diff --git a/examples/tendermint/src/main.rs b/examples/tendermint/src/main.rs new file mode 100644 index 0000000000..02014816f3 --- /dev/null +++ b/examples/tendermint/src/main.rs @@ -0,0 +1,22 @@ +use succinct_core::{utils, SuccinctProver, SuccinctStdin, SuccinctVerifier}; + +const ED25519_ELF: &[u8] = + include_bytes!("../../../programs/demo/tendermint/elf/riscv32im-succinct-zkvm-elf"); + +fn main() { + // // // // Generate proof. + // utils::setup_tracer(); + utils::setup_logger(); + let stdin = SuccinctStdin::new(); + let proof = SuccinctProver::prove(ED25519_ELF, stdin).expect("proving failed"); + + // Verify proof. + SuccinctVerifier::verify(ED25519_ELF, &proof).expect("verification failed"); + + // Save proof. + proof + .save("proof-with-pis.json") + .expect("saving proof failed"); + + println!("succesfully generated and verified proof for the program!") +} diff --git a/programs/demo/ed25519/Cargo.lock b/programs/demo/ed25519/Cargo.lock index 498133cd35..b034f20d7b 100644 --- a/programs/demo/ed25519/Cargo.lock +++ b/programs/demo/ed25519/Cargo.lock @@ -544,3 +544,8 @@ name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" + +[[patch.unused]] +name = "sha2" +version = "0.10.6" +source = "git+https://github.com/succinctbot/RustCrypto-hashes.git?branch=main#482efd7c1a750c300f3740a2c75dda9eb4eb1ddd" diff --git a/programs/demo/ed25519/Cargo.toml b/programs/demo/ed25519/Cargo.toml index e213e39567..898df098fc 100644 --- a/programs/demo/ed25519/Cargo.toml +++ b/programs/demo/ed25519/Cargo.toml @@ -7,4 +7,10 @@ edition = "2021" [dependencies] succinct-zkvm = { path = "../../../zkvm" } ed25519-dalek = { git = "https://github.com/dalek-cryptography/curve25519-dalek.git", rev = "0b45e00", version = "2.1.0" } -hex-literal = "0.4.1" \ No newline at end of file +hex-literal = "0.4.1" + +[patch.crates-io] +# Patch sha2 so we can use sha precompiles +sha2-v0-10-6 = { git = "https://github.com/succinctbot/RustCrypto-hashes.git", package = "sha2", branch = "main" } + + diff --git a/programs/demo/ssz-withdrawals/Cargo.lock b/programs/demo/ssz-withdrawals/Cargo.lock index 949bb34c2d..975b885822 100644 --- a/programs/demo/ssz-withdrawals/Cargo.lock +++ b/programs/demo/ssz-withdrawals/Cargo.lock @@ -1741,3 +1741,8 @@ dependencies = [ "quote", "syn 2.0.48", ] + +[[patch.unused]] +name = "sha2" +version = "0.9.8" +source = "git+https://github.com/succinctbot/RustCrypto-hashes.git?branch=v0.9.8#0b578688db61bb53e15353f5beaa2c11ad93f037" diff --git a/programs/demo/ssz-withdrawals/Cargo.toml b/programs/demo/ssz-withdrawals/Cargo.toml index 31908ff19d..0844d960c4 100644 --- a/programs/demo/ssz-withdrawals/Cargo.toml +++ b/programs/demo/ssz-withdrawals/Cargo.toml @@ -13,4 +13,8 @@ serde_json = "1.0.111" hex = "0.4.3" serde_with = { version = "3.4.0", features = ["hex"] } serde = { version = "1.0.195", features = ["derive"] } -alloy-primitives = "0.6.0" \ No newline at end of file +alloy-primitives = "0.6.0" + +[patch.crates-io] +# Patch sha2 so we can use sha precompiles +sha2-v0-9-8 = { git = "https://github.com/succinctbot/RustCrypto-hashes.git", package = "sha2", branch = "v0.9.8" } \ No newline at end of file diff --git a/programs/demo/tendermint/Cargo.lock b/programs/demo/tendermint/Cargo.lock index 69b173f69b..337081f1ed 100644 --- a/programs/demo/tendermint/Cargo.lock +++ b/programs/demo/tendermint/Cargo.lock @@ -14,6 +14,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64ct" version = "1.6.0" @@ -29,6 +35,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -83,6 +101,18 @@ dependencies = [ "libc", ] +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -96,8 +126,7 @@ dependencies = [ [[package]] name = "curve25519-dalek-ng" version = "4.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" +source = "git+ssh://git@github.com/succinctlabs/dalek-ng-private.git#01f43665631d2c33385708d41d0c26dbb1baa0ea" dependencies = [ "byteorder", "digest 0.9.0", @@ -152,7 +181,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", + "const-oid", "crypto-common", + "subtle", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] @@ -168,13 +213,12 @@ dependencies = [ [[package]] name = "ed25519-consensus" version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c8465edc8ee7436ffea81d21a019b16676ee3db267aa8d5a8d729581ecf998b" +source = "git+ssh://git@github.com/succinctlabs/ed25519-consensus-private.git#e9f03604509ceabedaf31f66a70c28297d7af6c2" dependencies = [ "curve25519-dalek-ng", "hex", "rand_core", - "sha2 0.9.9", + "sha2 0.9.8", "zeroize", ] @@ -184,6 +228,37 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "tap", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + [[package]] name = "flex-error" version = "0.4.4" @@ -193,6 +268,12 @@ dependencies = [ "paste", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "futures" version = "0.3.30" @@ -262,6 +343,29 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", ] [[package]] @@ -270,6 +374,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "itertools" version = "0.11.0" @@ -285,6 +398,20 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.6", + "signature", +] + [[package]] name = "libc" version = "0.2.153" @@ -357,6 +484,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.78" @@ -407,11 +540,51 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] [[package]] name = "ryu" @@ -419,6 +592,20 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "serde" version = "1.0.196" @@ -472,9 +659,8 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +version = "0.9.8" +source = "git+ssh://git@github.com/succinctbot/RustCrypto-hashes.git?branch=v0.9.8#0b578688db61bb53e15353f5beaa2c11ad93f037" dependencies = [ "block-buffer 0.9.0", "cfg-if", @@ -485,9 +671,8 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +version = "0.10.6" +source = "git+ssh://git@github.com/succinctbot/RustCrypto-hashes.git?branch=main#482efd7c1a750c300f3740a2c75dda9eb4eb1ddd" dependencies = [ "cfg-if", "cpufeatures", @@ -499,6 +684,10 @@ name = "signature" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core", +] [[package]] name = "spki" @@ -531,15 +720,16 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" -[[package]] -name = "succinct-build" -version = "0.1.0" - [[package]] name = "succinct-zkvm" version = "0.1.0" dependencies = [ + "anyhow", "bincode", + "cfg-if", + "getrandom", + "k256", + "rand", "serde", ] @@ -565,6 +755,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tendermint" version = "0.34.0" @@ -585,7 +781,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.8", + "sha2 0.10.6", "signature", "subtle", "subtle-encoding", @@ -631,7 +827,6 @@ version = "0.1.0" dependencies = [ "serde", "serde_json", - "succinct-build", "succinct-zkvm", "tendermint", "tendermint-light-client-verifier", @@ -682,6 +877,21 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "zeroize" version = "1.7.0" diff --git a/programs/demo/tendermint/Cargo.toml b/programs/demo/tendermint/Cargo.toml index 5d9ac36d55..c9d760a0b8 100644 --- a/programs/demo/tendermint/Cargo.toml +++ b/programs/demo/tendermint/Cargo.toml @@ -11,4 +11,9 @@ serde = { version = "1.0", default-features = false, features = ["derive"] } tendermint = { version = "0.34.0", default-features = false } tendermint-light-client-verifier = { version = "0.34.0", default-features = false, features = [ "rust-crypto", -] } \ No newline at end of file +] } + +[patch.crates-io] +sha2-v0-9-8 = { git = "ssh://git@github.com/succinctbot/RustCrypto-hashes.git", package = "sha2", branch = "v0.9.8" } +ed25519-consensus = { git = "ssh://git@github.com/succinctlabs/ed25519-consensus-private.git" } +sha2-v0-10-8 = { git = "ssh://git@github.com/succinctbot/RustCrypto-hashes.git", package = "sha2", branch = "main" } \ No newline at end of file diff --git a/programs/demo/tendermint/elf/riscv32im-succinct-zkvm-elf b/programs/demo/tendermint/elf/riscv32im-succinct-zkvm-elf index ba38fb2e08..3816b52769 100755 Binary files a/programs/demo/tendermint/elf/riscv32im-succinct-zkvm-elf and b/programs/demo/tendermint/elf/riscv32im-succinct-zkvm-elf differ