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
46
47
48
49
50
51
52
53
54
55
56
57
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use crate::SerializedCircuit;
#[derive(Serialize, Deserialize, PartialEq)]
pub struct SummarizedCircuit {
pub num_public_variables: usize,
pub num_private_variables: usize,
pub num_constraints: usize,
pub at: String,
pub bt: String,
pub ct: String,
}
fn hash_field(input: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(input.as_bytes());
let output = hasher.finalize();
hex::encode(&output[..])
}
impl From<SerializedCircuit> for SummarizedCircuit {
fn from(other: SerializedCircuit) -> Self {
Self {
num_public_variables: other.num_public_variables,
num_private_variables: other.num_private_variables,
num_constraints: other.num_constraints,
at: hash_field(&serde_json::to_string(&other.at).expect("failed to serialize at")),
bt: hash_field(&serde_json::to_string(&other.bt).expect("failed to serialize bt")),
ct: hash_field(&serde_json::to_string(&other.ct).expect("failed to serialize ct")),
}
}
}