46 lines
1.5 KiB
Rust
Raw Normal View History

use plonky2::hash::hash_types::RichField;
2025-01-10 11:29:03 +01:00
use plonky2::iop::target::Target;
2024-12-06 09:12:02 +01:00
use plonky2::iop::witness::PartialWitness;
use plonky2::plonk::circuit_builder::CircuitBuilder;
2025-01-09 10:34:13 +01:00
use plonky2::plonk::circuit_data::CommonCircuitData;
use plonky2_field::extension::Extendable;
use plonky2_poseidon2::poseidon2_hash::poseidon2::Poseidon2;
2025-01-10 11:29:03 +01:00
use crate::Result;
2024-12-06 09:12:02 +01:00
/// InnerCircuit is the trait used to define the logic of the circuit and assign witnesses
/// to that circuit instance.
pub trait InnerCircuit<
F: RichField + Extendable<D> + Poseidon2,
const D: usize,
2024-12-06 09:12:02 +01:00
> {
type Targets;
2025-01-09 10:34:13 +01:00
type Input:Clone;
2024-12-06 09:12:02 +01:00
/// build the circuit logic and return targets to be assigned later
/// based on register_pi, registers the public input or not.
2024-12-06 09:12:02 +01:00
fn build(
&self,
2024-12-06 09:12:02 +01:00
builder: &mut CircuitBuilder<F, D>,
register_pi: bool
2025-01-10 11:29:03 +01:00
) -> Result<Self::Targets>;
2024-12-06 09:12:02 +01:00
/// assign the actual witness values for the current instance of the circuit.
fn assign_targets(
&self,
2024-12-06 09:12:02 +01:00
pw: &mut PartialWitness<F>,
targets: &Self::Targets,
input: &Self::Input,
2025-01-10 11:29:03 +01:00
) -> Result<()>;
/// from the set of the targets, return only the targets which are public
/// TODO: this can probably be replaced with enum for Public/Private targets
fn get_pub_input_targets(
targets: &Self::Targets,
2025-01-10 11:29:03 +01:00
) -> Vec<Target>;
2025-01-09 10:34:13 +01:00
/// get the common data for the inner-circuit
2025-01-09 10:34:13 +01:00
fn get_common_data(
&self
2025-01-10 11:29:03 +01:00
) -> Result<(CommonCircuitData<F, D>)>;
2024-12-06 09:12:02 +01:00
}