Skip to content

Commit

Permalink
Merge branch 'main' into add_bn254_to_prover_example
Browse files Browse the repository at this point in the history
  • Loading branch information
jotabulacios authored Jan 28, 2025
2 parents d04f1f5 + 1e64f0a commit ce14afb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions examples/baby-snark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Below is a simple example demonstrating the usage of BabySnark:
let ssp = SquareSpanProgram::from_scs(SquareConstraintSystem::from_matrix(u, public.len()));
```

*Note:* You must ensure that the first element of the `input` is 1. In the code above we can see how to build a Span Program for an And Gate. There, the variable `witness` is of the form `[input_1, input_2, output]` (which satisfy `input_1 ∧ input_2 = output`) and the `public` variable must be `[1]`.

**Step 2:** Setup Proving and Verification Keys:
```rust
let (pk, vk) = setup(&ssp);
Expand Down
4 changes: 4 additions & 0 deletions examples/baby-snark/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Proof {
#[derive(Debug)]
pub enum Error {
WrongWitness,
FirstInputElementIsNotOne,
}

pub struct Prover;
Expand All @@ -19,6 +20,9 @@ impl Prover {
ssp: &SquareSpanProgram,
pk: &ProvingKey,
) -> Result<Proof, Error> {
if inputs[0].ne(&FrElement::one()) {
return Err(Error::FirstInputElementIsNotOne);
}
if !ssp.check_valid(inputs) {
return Err(Error::WrongWitness);
}
Expand Down
6 changes: 3 additions & 3 deletions examples/baby-snark/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn size_not_pow2() {
let input: &[i64] = &[1, 2, 3, 4, 5];

let witness = i64_vec_to_field(&[3, 4, 5]);
let public = i64_vec_to_field(&[1, 2]);
let public = i64_vec_to_field(&[1, 2]); // Note that the first element must be 1.
let input_field = i64_vec_to_field(input);
let u_field = normalize(i64_matrix_to_field(u), &input_field);

Expand All @@ -39,8 +39,8 @@ fn and_gate() {
i64_vec_to_field(&[-1, 0, 0, 2]),
i64_vec_to_field(&[-1, 2, 2, -4]),
];
let witness = i64_vec_to_field(&[1, 1, 1]);
let public = i64_vec_to_field(&[1]);
let witness = i64_vec_to_field(&[1, 1, 1]); // [input_1, input_2, output]
let public = i64_vec_to_field(&[1]); // This must be 1.

test_integration(u, witness, public)
}
Expand Down

0 comments on commit ce14afb

Please sign in to comment.