Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Dec 4, 2024
1 parent 012efa5 commit 75b90be
Show file tree
Hide file tree
Showing 15 changed files with 10,485 additions and 285 deletions.
7,735 changes: 7,735 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ sp1-zkvm = { path = "crates/zkvm/entrypoint", version = "=4.0.0-rc.1", default-f
test-artifacts = { path = "crates/test-artifacts", version = "=4.0.0-rc.1" }

# For testing.
test-artifacts = { path = "crates/test-artifacts", version = "3.0.0" }
# test-artifacts = { path = "crates/test-artifacts", version = "3.0.0" }

# p3
# p3-air = "0.1.4-succinct"
Expand Down
11 changes: 2 additions & 9 deletions crates/core/executor/src/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ pub type BoxedHook<'a> = Arc<RwLock<dyn Hook + Send + Sync + 'a>>;
pub const FD_K1_ECRECOVER_HOOK: u32 = 5;
/// The file descriptor through which to access `hook_r1_ecrecover`.
pub const FD_R1_ECRECOVER_HOOK: u32 = 6;

// Note: we skip 6 because we have an eddsa hook in dev.

/// The file descriptor through which to access `hook_ecrecover_2`.
pub const FD_ECRECOVER_HOOK_2: u32 = 7;

/// The file descriptor through which to access `hook_ed_decompress`.
pub const FD_EDDECOMPRESS: u32 = 8;

Expand Down Expand Up @@ -90,7 +84,6 @@ impl<'a> Default for HookRegistry<'a> {
// add an assertion to the test `hook_fds_match` below.
(FD_K1_ECRECOVER_HOOK, hookify(hook_k1_ecrecover)),
(FD_R1_ECRECOVER_HOOK, hookify(hook_r1_ecrecover)),
(FD_ECRECOVER_HOOK, hookify(hook_ecrecover_v2)),
(FD_EDDECOMPRESS, hookify(hook_ed_decompress)),
]);

Expand Down Expand Up @@ -217,8 +210,8 @@ pub mod tests {
#[test]
pub fn hook_fds_match() {
use sp1_zkvm::lib::io;
assert_eq!(K1_ECRECOVER_HOOK, io::K1_ECRECOVER_HOOK);
assert_eq!(R1_ECRECOVER_HOOK, io::R1_ECRECOVER_HOOK);
assert_eq!(FD_K1_ECRECOVER_HOOK, io::FD_K1_ECRECOVER_HOOK);
assert_eq!(FD_R1_ECRECOVER_HOOK, io::FD_R1_ECRECOVER_HOOK);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ mod tests {
utils::{run_test, setup_logger},
};

use crate::utils::{run_test, setup_logger};

#[test]
fn test_secp256k1_add_simple() {
setup_logger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ mod tests {
BLS12381_DECOMPRESS_ELF, SECP256K1_DECOMPRESS_ELF, SECP256R1_DECOMPRESS_ELF,
};

use crate::utils::run_test_io;

#[test]
fn test_weierstrass_bls_decompress() {
utils::setup_logger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ pub mod tests {
utils::{run_test, setup_logger},
};

use crate::utils::{run_test, setup_logger};

#[test]
fn test_secp256k1_double_simple() {
setup_logger();
Expand Down
1 change: 0 additions & 1 deletion crates/core/machine/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub use prove::*;
use sp1_curves::params::Limbs;
pub use span::*;
pub use test::*;
pub use tracer::*;
pub use uni_stark::*;

use crate::memory::MemoryCols;
Expand Down
140 changes: 71 additions & 69 deletions crates/prover/scripts/fibonacci_groth16.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,80 @@
//! Tests end-to-end performance of wrapping a recursion proof to PLONK.
fn main() {}

use std::time::Instant;
// //! Tests end-to-end performance of wrapping a recursion proof to PLONK.

use itertools::iproduct;
use sp1_core_executor::SP1Context;
use sp1_core_machine::io::SP1Stdin;
use sp1_prover::components::DefaultProverComponents;
use sp1_prover::SP1Prover;
use sp1_stark::SP1ProverOpts;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;
// use std::time::Instant;

fn main() {
// Setup tracer.
let default_filter = "off";
let log_appender = tracing_appender::rolling::never("scripts/results", "fibonacci_groth16.log");
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new(default_filter))
.add_directive("p3_keccak_air=off".parse().unwrap())
.add_directive("p3_fri=off".parse().unwrap())
.add_directive("p3_challenger=off".parse().unwrap())
.add_directive("p3_dft=off".parse().unwrap())
.add_directive("sp1_core=off".parse().unwrap());
tracing_subscriber::fmt::Subscriber::builder()
.with_ansi(false)
.with_file(false)
.with_target(false)
.with_thread_names(false)
.with_env_filter(env_filter)
.with_span_events(FmtSpan::CLOSE)
.with_writer(log_appender)
.finish()
.init();
// use itertools::iproduct;
// use sp1_core_executor::SP1Context;
// use sp1_core_machine::io::SP1Stdin;
// use sp1_prover::components::DefaultProverComponents;
// use sp1_prover::SP1Prover;
// use sp1_stark::SP1ProverOpts;
// use tracing_subscriber::fmt::format::FmtSpan;
// use tracing_subscriber::util::SubscriberInitExt;
// use tracing_subscriber::EnvFilter;

// Setup environment variables.
std::env::set_var("RECONSTRUCT_COMMITMENTS", "false");
// fn main() {
// // Setup tracer.
// let default_filter = "off";
// let log_appender = tracing_appender::rolling::never("scripts/results", "fibonacci_groth16.log");
// let env_filter = EnvFilter::try_from_default_env()
// .unwrap_or_else(|_| EnvFilter::new(default_filter))
// .add_directive("p3_keccak_air=off".parse().unwrap())
// .add_directive("p3_fri=off".parse().unwrap())
// .add_directive("p3_challenger=off".parse().unwrap())
// .add_directive("p3_dft=off".parse().unwrap())
// .add_directive("sp1_core=off".parse().unwrap());
// tracing_subscriber::fmt::Subscriber::builder()
// .with_ansi(false)
// .with_file(false)
// .with_target(false)
// .with_thread_names(false)
// .with_env_filter(env_filter)
// .with_span_events(FmtSpan::CLOSE)
// .with_writer(log_appender)
// .finish()
// .init();

// Initialize prover.
let prover = SP1Prover::<DefaultProverComponents>::new();
// // Setup environment variables.
// std::env::set_var("RECONSTRUCT_COMMITMENTS", "false");

// Setup sweep.
let iterations = [480000u32];
let shard_sizes = [1 << 22];
let batch_sizes = [2];
let elf = test_artifacts::FIBONACCI_ELF;
let (pk, vk) = prover.setup(elf);
// // Initialize prover.
// let prover = SP1Prover::<DefaultProverComponents>::new();

for (shard_size, iterations, batch_size) in iproduct!(shard_sizes, iterations, batch_sizes) {
tracing::info!(
"running: shard_size={}, iterations={}, batch_size={}",
shard_size,
iterations,
batch_size
);
std::env::set_var("SHARD_SIZE", shard_size.to_string());
// // Setup sweep.
// let iterations = [480000u32];
// let shard_sizes = [1 << 22];
// let batch_sizes = [2];
// let elf = test_artifacts::FIBONACCI_ELF;
// let (pk, vk, _, _) = prover.setup(elf);

tracing::info!("proving leaves");
let stdin = SP1Stdin {
buffer: vec![bincode::serialize::<u32>(&iterations).unwrap()],
ptr: 0,
proofs: vec![],
};
let leaf_proving_start = Instant::now();
let proof = prover
.prove_core(&pk, &stdin, SP1ProverOpts::default(), SP1Context::default())
.unwrap();
let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();
tracing::info!("leaf_proving_duration={}", leaf_proving_duration);
// for (shard_size, iterations, batch_size) in iproduct!(shard_sizes, iterations, batch_sizes) {
// tracing::info!(
// "running: shard_size={}, iterations={}, batch_size={}",
// shard_size,
// iterations,
// batch_size
// );
// std::env::set_var("SHARD_SIZE", shard_size.to_string());

tracing::info!("proving inner");
let recursion_proving_start = Instant::now();
let _ = prover.compress(&vk, proof, vec![], SP1ProverOpts::default());
let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();
tracing::info!("recursion_proving_duration={}", recursion_proving_duration);
}
}
// tracing::info!("proving leaves");
// let stdin = SP1Stdin {
// buffer: vec![bincode::serialize::<u32>(&iterations).unwrap()],
// ptr: 0,
// proofs: vec![],
// };
// let leaf_proving_start = Instant::now();
// let proof = prover
// .prove_core(&pk, &stdin, SP1ProverOpts::default(), SP1Context::default())
// .unwrap();
// let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();
// tracing::info!("leaf_proving_duration={}", leaf_proving_duration);

// tracing::info!("proving inner");
// let recursion_proving_start = Instant::now();
// let _ = prover.compress(&vk, proof, vec![], SP1ProverOpts::default());
// let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();
// tracing::info!("recursion_proving_duration={}", recursion_proving_duration);
// }
// }
156 changes: 79 additions & 77 deletions crates/prover/scripts/fibonacci_sweep.rs
Original file line number Diff line number Diff line change
@@ -1,89 +1,91 @@
//! Sweeps end-to-end prover performance across a wide range of parameters for Fibonacci.
fn main() {}

use std::{fs::File, io::BufWriter, io::Write, time::Instant};
// //! Sweeps end-to-end prover performance across a wide range of parameters for Fibonacci.

use itertools::iproduct;
use sp1_core_executor::SP1Context;
use sp1_core_machine::io::SP1Stdin;
use sp1_prover::components::DefaultProverComponents;
use sp1_prover::SP1Prover;
use sp1_stark::SP1ProverOpts;
use tracing_subscriber::EnvFilter;
use tracing_subscriber::{fmt::format::FmtSpan, util::SubscriberInitExt};
// use std::{fs::File, io::BufWriter, io::Write, time::Instant};

fn main() {
// Setup tracer.
let default_filter = "off";
let log_appender = tracing_appender::rolling::never("scripts/results", "fibonacci_sweep.log");
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new(default_filter))
.add_directive("p3_keccak_air=off".parse().unwrap())
.add_directive("p3_fri=off".parse().unwrap())
.add_directive("p3_challenger=off".parse().unwrap())
.add_directive("p3_dft=off".parse().unwrap())
.add_directive("sp1_core=off".parse().unwrap());
tracing_subscriber::fmt::Subscriber::builder()
.with_ansi(false)
.with_file(false)
.with_target(false)
.with_thread_names(false)
.with_env_filter(env_filter)
.with_span_events(FmtSpan::CLOSE)
.with_writer(log_appender)
.finish()
.init();
// use itertools::iproduct;
// use sp1_core_executor::SP1Context;
// use sp1_core_machine::io::SP1Stdin;
// use sp1_prover::components::DefaultProverComponents;
// use sp1_prover::SP1Prover;
// use sp1_stark::SP1ProverOpts;
// use tracing_subscriber::EnvFilter;
// use tracing_subscriber::{fmt::format::FmtSpan, util::SubscriberInitExt};

// Setup environment variables.
std::env::set_var("RECONSTRUCT_COMMITMENTS", "false");
// fn main() {
// // Setup tracer.
// let default_filter = "off";
// let log_appender = tracing_appender::rolling::never("scripts/results", "fibonacci_sweep.log");
// let env_filter = EnvFilter::try_from_default_env()
// .unwrap_or_else(|_| EnvFilter::new(default_filter))
// .add_directive("p3_keccak_air=off".parse().unwrap())
// .add_directive("p3_fri=off".parse().unwrap())
// .add_directive("p3_challenger=off".parse().unwrap())
// .add_directive("p3_dft=off".parse().unwrap())
// .add_directive("sp1_core=off".parse().unwrap());
// tracing_subscriber::fmt::Subscriber::builder()
// .with_ansi(false)
// .with_file(false)
// .with_target(false)
// .with_thread_names(false)
// .with_env_filter(env_filter)
// .with_span_events(FmtSpan::CLOSE)
// .with_writer(log_appender)
// .finish()
// .init();

// Initialize prover.
let prover = SP1Prover::<DefaultProverComponents>::new();
// // Setup environment variables.
// std::env::set_var("RECONSTRUCT_COMMITMENTS", "false");

// Setup sweep.
let iterations = [480000u32];
let shard_sizes = [1 << 19, 1 << 20, 1 << 21, 1 << 22];
let batch_sizes = [2, 3, 4];
let elf = test_artifacts::FIBONACCI_ELF;
let (pk, vk) = prover.setup(elf);
// // Initialize prover.
// let prover = SP1Prover::<DefaultProverComponents>::new();

let mut lines =
vec!["iterations,shard_size,batch_size,leaf_proving_duration,recursion_proving_duration"
.to_string()];
for (shard_size, iterations, batch_size) in iproduct!(shard_sizes, iterations, batch_sizes) {
tracing::info!(
"running: shard_size={}, iterations={}, batch_size={}",
shard_size,
iterations,
batch_size
);
std::env::set_var("SHARD_SIZE", shard_size.to_string());
// // Setup sweep.
// let iterations = [480000u32];
// let shard_sizes = [1 << 19, 1 << 20, 1 << 21, 1 << 22];
// let batch_sizes = [2, 3, 4];
// let elf = test_artifacts::FIBONACCI_ELF;
// let (pk, vk, program, _) = prover.setup(elf);

let stdin = SP1Stdin {
buffer: vec![bincode::serialize::<u32>(&iterations).unwrap()],
ptr: 0,
proofs: vec![],
};
let leaf_proving_start = Instant::now();
let proof = prover
.prove_core(&pk, &stdin, SP1ProverOpts::default(), SP1Context::default())
.unwrap();
let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();
// let mut lines =
// vec!["iterations,shard_size,batch_size,leaf_proving_duration,recursion_proving_duration"
// .to_string()];
// for (shard_size, iterations, batch_size) in iproduct!(shard_sizes, iterations, batch_sizes) {
// tracing::info!(
// "running: shard_size={}, iterations={}, batch_size={}",
// shard_size,
// iterations,
// batch_size
// );
// std::env::set_var("SHARD_SIZE", shard_size.to_string());

let recursion_proving_start = Instant::now();
let _ = prover.compress(&vk, proof, vec![], SP1ProverOpts::default());
let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();
// let stdin = SP1Stdin {
// buffer: vec![bincode::serialize::<u32>(&iterations).unwrap()],
// ptr: 0,
// proofs: vec![],
// };
// let leaf_proving_start = Instant::now();
// let proof = prover
// .prove_core(&pk, program, &stdin, SP1ProverOpts::default(), SP1Context::default())
// .unwrap();
// let leaf_proving_duration = leaf_proving_start.elapsed().as_secs_f64();

lines.push(format!(
"{},{},{},{},{}",
iterations, shard_size, batch_size, leaf_proving_duration, recursion_proving_duration
));
}
// let recursion_proving_start = Instant::now();
// let _ = prover.compress(&vk, proof, vec![], SP1ProverOpts::default());
// let recursion_proving_duration = recursion_proving_start.elapsed().as_secs_f64();

let file = File::create("scripts/results/fibonacci_sweep.csv").unwrap();
let mut writer = BufWriter::new(file);
for line in lines.clone() {
writeln!(writer, "{}", line).unwrap();
}
// lines.push(format!(
// "{},{},{},{},{}",
// iterations, shard_size, batch_size, leaf_proving_duration, recursion_proving_duration
// ));
// }

println!("{:#?}", lines);
}
// let file = File::create("scripts/results/fibonacci_sweep.csv").unwrap();
// let mut writer = BufWriter::new(file);
// for line in lines.clone() {
// writeln!(writer, "{}", line).unwrap();
// }

// println!("{:#?}", lines);
// }
Loading

0 comments on commit 75b90be

Please sign in to comment.