mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-03-17 01:43:08 +00:00
In preparation for adding the zkEVM aggregation circuit. Mainly, - Adds a `WitnessWrite` trait, a sub-trait of `Witness`, and move the write methods to it. `GeneratedValues` impls `WitnessWrite`, which lets generators like `DummyProofGenerator` access all our write methods like `set_proof_with_pis_target`. Also removes some duplication. - Remove `set_cyclic_recursion_data_target` - now that dummy proof data is automatically populated, all that remains is populating `condition` and the cyclic proof + VK. I think it's easy enough for callers to do this; the steps are the same as with `conditionally_verify_proof`. This way there's no cyclic-recursion-specific API to learn about. - Split `cyclic_recursion` into two variants, one which checks the current circuit or a dummy, and a more general one which checks the current circuit or some other circuit. We can use the latter to build a more efficient aggregation circuit, where we check another aggregation proof or an EVM proof, with no dummy proofs involved.
34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
use plonky2::field::types::{Field, PrimeField64};
|
|
use plonky2::iop::generator::GeneratedValues;
|
|
use plonky2::iop::witness::{Witness, WitnessWrite};
|
|
|
|
use crate::gadgets::arithmetic_u32::U32Target;
|
|
|
|
pub trait WitnessU32<F: PrimeField64>: Witness<F> {
|
|
fn set_u32_target(&mut self, target: U32Target, value: u32);
|
|
fn get_u32_target(&self, target: U32Target) -> (u32, u32);
|
|
}
|
|
|
|
impl<T: Witness<F>, F: PrimeField64> WitnessU32<F> for T {
|
|
fn set_u32_target(&mut self, target: U32Target, value: u32) {
|
|
self.set_target(target.0, F::from_canonical_u32(value));
|
|
}
|
|
|
|
fn get_u32_target(&self, target: U32Target) -> (u32, u32) {
|
|
let x_u64 = self.get_target(target.0).to_canonical_u64();
|
|
let low = x_u64 as u32;
|
|
let high = (x_u64 >> 32) as u32;
|
|
(low, high)
|
|
}
|
|
}
|
|
|
|
pub trait GeneratedValuesU32<F: Field> {
|
|
fn set_u32_target(&mut self, target: U32Target, value: u32);
|
|
}
|
|
|
|
impl<F: Field> GeneratedValuesU32<F> for GeneratedValues<F> {
|
|
fn set_u32_target(&mut self, target: U32Target, value: u32) {
|
|
self.set_target(target.0, F::from_canonical_u32(value))
|
|
}
|
|
}
|