use super::*;
use crate::util::Challenges;
use bus_mapping::circuit_input_builder::keccak_inputs_sign_verify;
use halo2_proofs::{circuit::SimpleFloorPlanner, plonk::Circuit};
#[derive(Clone, Debug)]
pub struct SigCircuitTesterConfig<F: Field + halo2_base::utils::ScalarField> {
sign_verify: SigCircuitConfig<F>,
challenges: crate::util::Challenges,
}
impl<F: Field + halo2_base::utils::ScalarField> SigCircuitTesterConfig<F> {
pub(crate) fn new(meta: &mut ConstraintSystem<F>) -> Self {
let keccak_table = KeccakTable::construct(meta);
let sig_table = SigTable::construct(meta);
let challenges = Challenges::construct(meta);
let challenges_expr = challenges.exprs(meta);
let sign_verify = SigCircuitConfig::new(
meta,
SigCircuitConfigArgs {
_keccak_table: keccak_table,
challenges: challenges_expr,
sig_table,
},
);
SigCircuitTesterConfig {
sign_verify,
challenges,
}
}
}
impl<F: Field + halo2_base::utils::ScalarField> Circuit<F> for SigCircuit<F> {
type Config = SigCircuitTesterConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
type Params = ();
fn without_witnesses(&self) -> Self {
Self::default()
}
fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
SigCircuitTesterConfig::new(meta)
}
fn synthesize(
&self,
config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let challenges = config.challenges.values(&mut layouter);
self.synthesize_sub(&config.sign_verify, &challenges, &mut layouter)?;
config.sign_verify._keccak_table.dev_load(
&mut layouter,
&keccak_inputs_sign_verify(&self.signatures),
&challenges,
)?;
Ok(())
}
}