mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-09 01:03:08 +00:00
* Automatically select FRI reduction arities This way when a proof's degree changes, we won't need to manually update the `FriConfig`s of any recursive proofs on top of it. For now I've added two methods of selecting arities. The first, `ConstantArityBits`, just applies a fixed reduciton arity until the degree has shrunk below a certain threshold. The second, `MinSize`, searches for the sequence of arities that minimizes proof size. Note that this optimization is approximate -- e.g. it doesn't account for the effect of compression, and doesn't count some minor contributions to proof size, like the Merkle roots from the commit phase. It also assumes we're not using Merkle caps in serialized proofs, and that we're inferring one of the evaluations, even though we haven't made those changes yet. I think we should generally use `ConstantArityBits` for proofs that we will recurse on, since using a single arity tends to be more recursion-friendly. We could use `MinSize` for generating final bridge proofs, since we won't do further recursion on top of those. * Fix tests * Feedback
61 lines
2.0 KiB
Rust
61 lines
2.0 KiB
Rust
use anyhow::Result;
|
|
use env_logger::Env;
|
|
use log::info;
|
|
use plonky2::field::crandall_field::CrandallField;
|
|
use plonky2::field::extension_field::Extendable;
|
|
use plonky2::field::field_types::RichField;
|
|
use plonky2::fri::reduction_strategies::FriReductionStrategy;
|
|
use plonky2::fri::FriConfig;
|
|
use plonky2::hash::hashing::SPONGE_WIDTH;
|
|
use plonky2::iop::witness::PartialWitness;
|
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
|
use plonky2::plonk::circuit_data::CircuitConfig;
|
|
|
|
fn main() -> Result<()> {
|
|
// Set the default log filter. This can be overridden using the `RUST_LOG` environment variable,
|
|
// e.g. `RUST_LOG=debug`.
|
|
// We default to debug for now, since there aren't many logs anyway, but we should probably
|
|
// change this to info or warn later.
|
|
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
|
|
|
|
bench_prove::<CrandallField, 4>()
|
|
}
|
|
|
|
fn bench_prove<F: RichField + Extendable<D>, const D: usize>() -> Result<()> {
|
|
let config = CircuitConfig {
|
|
num_wires: 126,
|
|
num_routed_wires: 33,
|
|
security_bits: 128,
|
|
rate_bits: 3,
|
|
num_challenges: 3,
|
|
zero_knowledge: false,
|
|
cap_height: 1,
|
|
fri_config: FriConfig {
|
|
proof_of_work_bits: 15,
|
|
reduction_strategy: FriReductionStrategy::ConstantArityBits(3, 5),
|
|
num_query_rounds: 35,
|
|
},
|
|
};
|
|
|
|
let inputs = PartialWitness::new();
|
|
let mut builder = CircuitBuilder::<F, D>::new(config);
|
|
|
|
let zero = builder.zero();
|
|
let zero_ext = builder.zero_extension();
|
|
|
|
let mut state = [zero; SPONGE_WIDTH];
|
|
for _ in 0..10000 {
|
|
state = builder.permute(state);
|
|
}
|
|
|
|
// Random other gates.
|
|
builder.add(zero, zero);
|
|
builder.add_extension(zero_ext, zero_ext);
|
|
|
|
let circuit = builder.build();
|
|
let proof_with_pis = circuit.prove(inputs)?;
|
|
let proof_bytes = serde_cbor::to_vec(&proof_with_pis).unwrap();
|
|
info!("Proof length: {} bytes", proof_bytes.len());
|
|
circuit.verify(proof_with_pis)
|
|
}
|