Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single stark bench #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keccak-air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ p3-uni-stark = { path = "../uni-stark" }
rand = "0.8.5"
tracing-subscriber = { version = "0.3.17", features = ["std", "env-filter"] }
tracing-forest = { version = "0.1.6", features = ["ansi", "smallvec"] }
postcard = { version = "1.0.0", default-features = false, features = ["alloc"] }

[[example]]
name = "prove_baby_bear_keccak"
Expand Down
8 changes: 8 additions & 0 deletions keccak-air/examples/prove_baby_bear_keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ fn main() -> Result<(), VerificationError> {

let inputs = (0..NUM_HASHES).map(|_| random()).collect::<Vec<_>>();
let trace = generate_trace_rows::<Val>(inputs);
println!(
"trace height: {}, trace width: {}",
trace.height(),
trace.width()
);
let proof = prove::<MyConfig, _>(&config, &KeccakAir {}, &mut challenger, trace);

let serialized_proof = postcard::to_allocvec(&proof).expect("unable to serialize proof");
tracing::info!("serialized_proof len: {} bytes", serialized_proof.len());

let mut challenger = Challenger::new(perm);
verify(&config, &KeccakAir {}, &mut challenger, &proof)
}
10 changes: 10 additions & 0 deletions keccak-air/examples/prove_baby_bear_poseidon2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ fn main() -> Result<(), VerificationError> {

let inputs = (0..NUM_HASHES).map(|_| random()).collect::<Vec<_>>();
let trace = generate_trace_rows::<Val>(inputs);
// print trace height and width in one line
println!(
"trace height: {}, trace width: {}",
trace.height(),
trace.width()
);

let proof = prove::<MyConfig, _>(&config, &KeccakAir {}, &mut challenger, trace);

let serialized_proof = postcard::to_allocvec(&proof).expect("unable to serialize proof");
tracing::info!("serialized_proof len: {} bytes", serialized_proof.len());

let mut challenger = Challenger::new(perm);
verify(&config, &KeccakAir {}, &mut challenger, &proof)
}
8 changes: 8 additions & 0 deletions keccak-air/examples/prove_goldilocks_keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,16 @@ fn main() -> Result<(), VerificationError> {

let inputs = (0..NUM_HASHES).map(|_| random()).collect::<Vec<_>>();
let trace = generate_trace_rows::<Val>(inputs);
println!(
"trace height: {}, trace width: {}",
trace.height(),
trace.width()
);
let proof = prove::<MyConfig, _>(&config, &KeccakAir {}, &mut challenger, trace);

let serialized_proof = postcard::to_allocvec(&proof).expect("unable to serialize proof");
tracing::info!("serialized_proof len: {} bytes", serialized_proof.len());

let mut challenger = Challenger::new(perm);
verify(&config, &KeccakAir {}, &mut challenger, &proof)
}
1 change: 1 addition & 0 deletions uni-stark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ p3-dft = { path = "../dft" }
p3-matrix = { path = "../matrix" }
p3-maybe-rayon = { path = "../maybe-rayon" }
p3-util = { path = "../util" }
p3-keccak = { path = "../keccak" }
itertools = "0.12.0"
tracing = "0.1.37"
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
100 changes: 86 additions & 14 deletions uni-stark/tests/mul_air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use p3_dft::Radix2DitParallel;
use p3_field::extension::BinomialExtensionField;
use p3_field::Field;
use p3_fri::{FriConfig, TwoAdicFriPcs, TwoAdicFriPcsConfig};
use p3_goldilocks::Goldilocks;
use p3_keccak::Keccak256Hash;
use p3_matrix::dense::RowMajorMatrix;
use p3_matrix::MatrixRowSlices;
use p3_matrix::{Matrix, MatrixRowSlices};
use p3_mds::coset_mds::CosetMds;
use p3_merkle_tree::FieldMerkleTreeMmcs;
use p3_poseidon2::{DiffusionMatrixBabybear, Poseidon2};
use p3_symmetric::{PaddingFreeSponge, TruncatedPermutation};
use p3_poseidon2::{DiffusionMatrixBabybear, DiffusionMatrixGoldilocks, Poseidon2};
use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher32, SerializingHasher64};
use p3_uni_stark::{prove, verify, StarkConfigImpl, VerificationError};
use rand::distributions::{Distribution, Standard};
use rand::{thread_rng, Rng};
Expand All @@ -22,8 +24,9 @@ use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{EnvFilter, Registry};

/// How many `a * b = c` operations to do per row in the AIR.
const REPETITIONS: usize = 10;
const REPETITIONS: usize = 911;
const TRACE_WIDTH: usize = REPETITIONS * 3;
const HEIGHT: usize = 1 << 14;

struct MulAir;

Expand Down Expand Up @@ -69,8 +72,6 @@ fn test_prove_baby_bear() -> Result<(), VerificationError> {
.with(ForestLayer::default())
.init();

const HEIGHT: usize = 1 << 6;

type Val = BabyBear;
type Domain = Val;
type Challenge = BinomialExtensionField<Val, 4>;
Expand All @@ -82,13 +83,13 @@ fn test_prove_baby_bear() -> Result<(), VerificationError> {
type Perm = Poseidon2<Val, MyMds, DiffusionMatrixBabybear, 16, 7>;
let perm = Perm::new_from_rng(8, 22, mds, DiffusionMatrixBabybear, &mut thread_rng());

type MyHash = PaddingFreeSponge<Perm, 16, 8, 8>;
let hash = MyHash::new(perm.clone());
type MyHash = SerializingHasher32<Keccak256Hash>;
let hash = MyHash::new(Keccak256Hash {});

type MyCompress = TruncatedPermutation<Perm, 2, 8, 16>;
let compress = MyCompress::new(perm.clone());
type MyCompress = CompressionFunctionFromHasher<Val, MyHash, 2, 8>;
let compress = MyCompress::new(hash);

type ValMmcs = FieldMerkleTreeMmcs<<Val as Field>::Packing, MyHash, MyCompress, 8>;
type ValMmcs = FieldMerkleTreeMmcs<Val, MyHash, MyCompress, 8>;
let val_mmcs = ValMmcs::new(hash, compress);

type ChallengeMmcs = ExtensionMmcs<Val, Challenge, ValMmcs>;
Expand All @@ -101,8 +102,74 @@ fn test_prove_baby_bear() -> Result<(), VerificationError> {

let fri_config = FriConfig {
log_blowup: 1,
num_queries: 40,
proof_of_work_bits: 8,
num_queries: 100,
proof_of_work_bits: 16,
mmcs: challenge_mmcs,
};
type Pcs =
TwoAdicFriPcs<TwoAdicFriPcsConfig<Val, Challenge, Challenger, Dft, ValMmcs, ChallengeMmcs>>;
let pcs = Pcs::new(fri_config, dft, val_mmcs);

type MyConfig = StarkConfigImpl<Val, Challenge, PackedChallenge, Pcs, Challenger>;
let config = StarkConfigImpl::new(pcs);

let mut challenger = Challenger::new(perm.clone());
let trace = random_valid_trace::<Val>(HEIGHT);
tracing::info!(
"trace height: {}, trace width: {}",
trace.height(),
trace.width()
);
let proof = prove::<MyConfig, _>(&config, &MulAir, &mut challenger, trace);

let serialized_proof = postcard::to_allocvec(&proof).expect("unable to serialize proof");
tracing::info!("serialized_proof len: {} bytes", serialized_proof.len());

let deserialized_proof =
postcard::from_bytes(&serialized_proof).expect("unable to deserialize proof");

let mut challenger = Challenger::new(perm);
verify(&config, &MulAir, &mut challenger, &deserialized_proof)
}

#[test]
fn test_prove_goldilocks() -> Result<(), VerificationError> {
Registry::default()
.with(EnvFilter::from_default_env())
.with(ForestLayer::default())
.init();

type Val = Goldilocks;
type Domain = Val;
type Challenge = BinomialExtensionField<Val, 2>;
type PackedChallenge = BinomialExtensionField<<Domain as Field>::Packing, 2>;

type MyMds = CosetMds<Val, 8>;
let mds = MyMds::default();

type Perm = Poseidon2<Val, MyMds, DiffusionMatrixGoldilocks, 8, 7>;
let perm = Perm::new_from_rng(8, 22, mds, DiffusionMatrixGoldilocks, &mut thread_rng());

type MyHash = SerializingHasher64<Keccak256Hash>;
let hash = MyHash::new(Keccak256Hash {});
type MyCompress = CompressionFunctionFromHasher<Val, MyHash, 2, 4>;
let compress = MyCompress::new(hash);

type ValMmcs = FieldMerkleTreeMmcs<Val, MyHash, MyCompress, 4>;
let val_mmcs = ValMmcs::new(hash, compress);

type ChallengeMmcs = ExtensionMmcs<Val, Challenge, ValMmcs>;
let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone());

type Dft = Radix2DitParallel;
let dft = Dft {};

type Challenger = DuplexChallenger<Val, Perm, 8>;

let fri_config = FriConfig {
log_blowup: 1,
num_queries: 100,
proof_of_work_bits: 16,
mmcs: challenge_mmcs,
};
type Pcs =
Expand All @@ -114,10 +181,15 @@ fn test_prove_baby_bear() -> Result<(), VerificationError> {

let mut challenger = Challenger::new(perm.clone());
let trace = random_valid_trace::<Val>(HEIGHT);
tracing::info!(
"trace height: {}, trace width: {}",
trace.height(),
trace.width()
);
let proof = prove::<MyConfig, _>(&config, &MulAir, &mut challenger, trace);

let serialized_proof = postcard::to_allocvec(&proof).expect("unable to serialize proof");
tracing::debug!("serialized_proof len: {} bytes", serialized_proof.len());
tracing::info!("serialized_proof len: {} bytes", serialized_proof.len());

let deserialized_proof =
postcard::from_bytes(&serialized_proof).expect("unable to deserialize proof");
Expand Down