Skip to content

Commit

Permalink
fix: rename statement to public input
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed Apr 13, 2024
1 parent 6641bbd commit 3597766
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 38 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ Here are the available commands:
$ ./digitsum prove --help
Run the prover for the digit sum circuit

Usage: digitsum prove [OPTIONS] --witness <WITNESS> --statement <STATEMENT>
Usage: digitsum prove [OPTIONS] --witness <WITNESS> --public-input <PUBLIC_INPUT>

Options:
-w, --witness <WITNESS>
Secret number that Alice knows (a.k.a. the witness)
-s, --statement <STATEMENT>
Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the statement)
-p, --public-input <PUBLIC_INPUT>
Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the public input)
--proof-file-name <PROOF_FILE_NAME>
Proof export filename [default: proof.hex]
--proof-export-dir <PROOF_EXPORT_DIR>
Expand All @@ -126,11 +126,11 @@ Options:
$ ./digitsum verify --help
Run the verifier for the digit sum circuit

Usage: digitsum verify [OPTIONS] --statement <STATEMENT>
Usage: digitsum verify [OPTIONS] --public-input <PUBLIC_INPUT>

Options:
-s, --statement <STATEMENT>
Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the statement)
-p, --public-input <PUBLIC_INPUT>
Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the public input)
--proof-file-name <PROOF_FILE_NAME>
Proof import filename [default: proof.hex]
--proof-import-dir <PROOF_IMPORT_DIR>
Expand Down Expand Up @@ -169,7 +169,7 @@ Options:
Create a proof with the `prove` sub-command:

```bash
$ ./digitsum prove --witness 123 --statement 6 --proof-file-name proof.hex
$ ./digitsum prove --witness 123 --public-input 6 --proof-file-name proof.hex
>> Proof generated to "./proof.hex"
```

Expand All @@ -178,7 +178,7 @@ $ ./digitsum prove --witness 123 --statement 6 --proof-file-name proof.hex
Verify a proof with the `verify` sub-command:

```bash
$ ./digitsum verify --statement 6 --proof-file-name proof.hex
$ ./digitsum verify --public-input 6 --proof-file-name proof.hex
>> Proof verified!
```

Expand Down
20 changes: 7 additions & 13 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,42 +129,36 @@ impl CircuitVerifier<EqAffine, Fp> for DigitSumCircuit<Fp> {
mod tests {
use halo2_proofs::{dev::MockProver, pasta::Fp};

use crate::DigitSumPublicStatement;
use crate::DigitSumPublicInput;

use super::*;

#[test]
fn test_digit_sum_circuit_proof_succeeds_if_valid_statement() {
fn test_digit_sum_circuit_proof_succeeds_if_valid_public_input() {
let secret_witness_number = 12340000;
let public_statement_digitsum = 10;
let public_input_digitsum = 10;

let circuit = DigitSumCircuit::<Fp>::new(secret_witness_number).unwrap();
let prover = MockProver::run(
circuit.k,
&circuit,
vec![vec![DigitSumPublicStatement::new(
public_statement_digitsum,
)
.into()]],
vec![vec![DigitSumPublicInput::new(public_input_digitsum).into()]],
)
.unwrap();

prover.verify().expect("the proof should be valid");
}

#[test]
fn test_digit_sum_circuit_proof_fails_if_invalid_statement() {
fn test_digit_sum_circuit_proof_fails_if_invalid_public_input() {
let secret_witness_number = 10000000;
let public_statement_digitsum = 2;
let public_input_digitsum = 2;

let circuit = DigitSumCircuit::<Fp>::new(secret_witness_number).unwrap();
let prover = MockProver::run(
circuit.k,
&circuit,
vec![vec![DigitSumPublicStatement::new(
public_statement_digitsum,
)
.into()]],
vec![vec![DigitSumPublicInput::new(public_input_digitsum).into()]],
)
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The command module contains the command line interface for the digit sum circuit:
//! - `prove` generates a proof for a given number (witness) and digit sum (statement)
//! - `verify` verifies a proof for a given number (witness) and digit sum (statement)
//! - `prove` generates a proof for a given number (witness) and digit sum (public input)
//! - `verify` verifies a proof for a given number (witness) and digit sum (public input)
//! - `graph` generates a graph representation of the circuit

mod graph;
Expand Down
8 changes: 4 additions & 4 deletions src/commands/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub struct ProveCommand {
#[clap(long, short = 'w')]
witness: u64,

/// Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the statement).
#[clap(long, short = 's')]
statement: u64,
/// Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the public input).
#[clap(long, short = 'p')]
public_input: u64,

/// Proof export filename.
#[clap(long, default_value = "proof.hex")]
Expand All @@ -28,7 +28,7 @@ impl ProveCommand {
pub fn execute(&self) -> StdResult<()> {
let secret_witness_number = self.witness;
let circuit = DigitSumCircuit::<Fp>::new(secret_witness_number)?;
let proof = circuit.prove(&[self.statement.into()])?;
let proof = circuit.prove(&[self.public_input.into()])?;

let proof_hex = hex::encode(proof);
let proof_export_path = self.proof_export_dir.join(&self.proof_file_name);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::{CircuitVerifier, DigitSumCircuit, StdResult};

#[derive(Parser, Debug, Clone)]
pub struct VerifyCommand {
/// Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the statement).
#[clap(long, short = 's')]
statement: u64,
/// Public number that Bob knows and which represents the sum of the digits of the witness (a.k.a. the public input).
#[clap(long, short = 'p')]
public_input: u64,

/// Proof import filename.
#[clap(long, default_value = "proof.hex")]
Expand All @@ -28,7 +28,7 @@ impl VerifyCommand {
let proof = hex::decode(proof)?;

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

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! The development of the circuit is split into two modules:
//! - `digitsum` contains the implementation of the digit sum circuit.
//! - `circuit` contains the final circuit that uses one or more chips to implement the desired proof system.
//! - `model` contains the public statement and secret witness types for the digit sum circuit.
//! - `model` contains the public input and secret witness types for the digit sum circuit.
//! - `command` contains the command line interface for the digit sum circuit.
//! - `proof_system` contains the proof system implementation for the digit sum circuit.

Expand Down
12 changes: 6 additions & 6 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ impl<F: PrimeField> TryFrom<DigitSumSecretWitness<F>> for [Value<F>; NUMBER_LENG
}
}

/// The public statement for the digit sum circuit
/// The public input for the digit sum circuit
#[derive(Clone, Debug)]
pub struct DigitSumPublicStatement {
pub struct DigitSumPublicInput {
number: u64,
}

impl DigitSumPublicStatement {
/// Creates a new public statement
impl DigitSumPublicInput {
/// Creates a new public input
pub fn new(number: u64) -> Self {
Self { number }
}
}

impl From<DigitSumPublicStatement> for Fp {
fn from(other: DigitSumPublicStatement) -> Fp {
impl From<DigitSumPublicInput> for Fp {
fn from(other: DigitSumPublicInput) -> Fp {
Fp::from(other.number)
}
}
Expand Down

0 comments on commit 3597766

Please sign in to comment.