/
sha256.rs
45 lines (35 loc) · 1.41 KB
/
sha256.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#![allow(clippy::expect_used, clippy::unwrap_used)]
use bellpepper_core::ConstraintSystem;
use circom_scotia::{calculate_witness, r1cs::CircomConfig, synthesize};
use ff::Field;
use pasta_curves::vesta::Base as Fr;
use std::env::current_dir;
use bellpepper_core::test_cs::TestConstraintSystem;
use bellpepper_core::Comparable;
use circom_scotia::r1cs::CircomInput;
fn main() {
let root = current_dir().unwrap().join("circom/sha256");
let wtns = root.join("circom_sha256.wasm");
let r1cs = root.join("circom_sha256.r1cs");
let mut cs = TestConstraintSystem::<Fr>::new();
let cfg = CircomConfig::new(wtns, r1cs).unwrap();
let arg_in = CircomInput {
name: "arg_in".into(),
value: vec![Fr::ZERO, Fr::ZERO],
};
let input = vec![arg_in];
let witness = calculate_witness(&cfg, input, true).expect("msg");
let output = synthesize(
&mut cs.namespace(|| "sha256_circom"),
cfg.r1cs.clone(),
Some(witness),
);
let expected = "0x00000000008619b3767c057fdf8e6d99fde2680c5d8517eb06761c0878d40c40";
let output_num = format!("{:?}", output.unwrap()[0].get_value().unwrap());
assert!(output_num == expected);
assert!(cs.is_satisfied());
assert_eq!(30134, cs.num_constraints());
assert_eq!(1, cs.num_inputs());
assert_eq!(29822, cs.aux().len());
println!("Congrats! You synthesized and satisfied a circom sha256 circuit in bellpepper!");
}