Skip to content

Commit

Permalink
refactor: better circuit default implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Apr 9, 2024
1 parent 8810a39 commit 6641bbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
const DIGIT_SUM_CIRCUIT_SIZE_PARAMETER: u32 = 5;

/// The circuit implementation for digit sum
#[derive(Default)]
pub struct DigitSumCircuit<F: PrimeField> {
/// The number with which to compute the digit sum in decimal representation
pub number: [Value<F>; NUMBER_LENGTH],
Expand All @@ -30,6 +29,12 @@ pub struct DigitSumCircuit<F: PrimeField> {
pub k: u32,
}

impl<F: PrimeField> Default for DigitSumCircuit<F> {
fn default() -> Self {
Self::new(0).unwrap()
}
}

impl<F: PrimeField> DigitSumCircuit<F> {
/// Creates a new digit sum circuit
pub fn new(number: u64) -> StdResult<Self> {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub struct GraphCommand {
impl GraphCommand {
/// Main command execution
pub fn execute(&self) -> StdResult<()> {
let secret_witness_number = 1;
let circuit = DigitSumCircuit::<Fp>::new(secret_witness_number)?;
let circuit = DigitSumCircuit::<Fp>::default();

let graph_layout_title = "Digit Sum Circuit";
let graph_layout_dimensions = (self.graph_width, self.graph_height);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl VerifyCommand {
let proof = read(proof_import_path)?;
let proof = hex::decode(proof)?;

let circuit = DigitSumCircuit::<Fp>::new(0)?;
let circuit = DigitSumCircuit::<Fp>::default();
circuit.verify(&[self.statement.into()], &proof)?;
println!(">> Proof verified!");

Expand Down

0 comments on commit 6641bbd

Please sign in to comment.