diff --git a/plonky2/examples/factorial.rs b/plonky2/examples/factorial.rs index 9f292372..518532c3 100644 --- a/plonky2/examples/factorial.rs +++ b/plonky2/examples/factorial.rs @@ -5,21 +5,26 @@ use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; +/// An example of using Plonky2 to prove a statement of the form +/// "I know n * (n + 1) * ... * (n + 99)". +/// When n == 1, this is proving knowledge of 100!. fn main() -> Result<()> { const D: usize = 2; type C = PoseidonGoldilocksConfig; type F = >::F; let config = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(config); + // The arithmetic circuit. let initial = builder.add_virtual_target(); let mut cur_target = initial; for i in 2..101 { let i_target = builder.constant(F::from_canonical_u32(i)); cur_target = builder.mul(cur_target, i_target); } + + // Public inputs are the initial value (provided below) and the result (which is generated). builder.register_public_input(initial); builder.register_public_input(cur_target); diff --git a/plonky2/examples/fibonacci.rs b/plonky2/examples/fibonacci.rs index d7a47c02..80bf8d8f 100644 --- a/plonky2/examples/fibonacci.rs +++ b/plonky2/examples/fibonacci.rs @@ -5,15 +5,18 @@ use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; +/// An example of using Plonky2 to prove a statement of the form +/// "I know the 100th element of the Fibonacci sequence, starting with constants a and b." +/// When a == 0 and b == 1, this is proving knowledge of the 100th (standard) Fibonacci number. fn main() -> Result<()> { const D: usize = 2; type C = PoseidonGoldilocksConfig; type F = >::F; let config = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(config); + // The arithmetic circuit. let initial_a = builder.add_virtual_target(); let initial_b = builder.add_virtual_target(); let mut prev_target = initial_a; @@ -23,10 +26,13 @@ fn main() -> Result<()> { prev_target = cur_target; cur_target = temp; } + + // Public inputs are the two initial values (provided below) and the result (which is generated). builder.register_public_input(initial_a); builder.register_public_input(initial_b); builder.register_public_input(cur_target); + // Provide initial values. let mut pw = PartialWitness::new(); pw.set_target(initial_a, F::ZERO); pw.set_target(initial_b, F::ONE);