Skip to content

Commit

Permalink
feat: create Commitment struct
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobottazzi committed Nov 10, 2023
1 parent 247a20f commit 58fcc7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
12 changes: 7 additions & 5 deletions zk_prover/examples/commitment_solidity_calldata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[
"0x2e021d9bf99c5bd7267488b6a7a5cf5f7d00222a41b6a9b971899c44089e0c5",
"0x87f3e",
"0x87f3e"
]
{
"root_hash": "0x2e021d9bf99c5bd7267488b6a7a5cf5f7d00222a41b6a9b971899c44089e0c5",
"root_balances": [
"0x87f3e",
"0x87f3e"
]
}
13 changes: 7 additions & 6 deletions zk_prover/examples/gen_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use serde_json::to_string_pretty;
use std::{fs::File, io::Write};
use summa_solvency::{
circuits::types::CommitmentSolidityCallData,
circuits::utils::field_element_to_solidity_calldata,
merkle_sum_tree::{MerkleSumTree, Tree},
};
Expand All @@ -24,13 +25,13 @@ fn main() {
.map(|balance| field_element_to_solidity_calldata(*balance))
.collect();

let commitment = CommitmentSolidityCallData {
root_hash: root_hash_hex_string,
root_balances: root_balances_hex_strings,
};

// Serialize to a JSON string
let serialized_data = to_string_pretty(&vec![
root_hash_hex_string,
root_balances_hex_strings[0],
root_balances_hex_strings[1],
])
.expect("Failed to serialize data");
let serialized_data = to_string_pretty(&commitment).expect("Failed to serialize data");

// Save the serialized data to a JSON file
let mut file = File::create("./examples/commitment_solidity_calldata.json")
Expand Down
6 changes: 6 additions & 0 deletions zk_prover/src/circuits/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ pub struct ProofSolidityCallData {
pub proof: String,
pub public_inputs: Vec<U256>,
}

#[derive(Serialize, Deserialize)]
pub struct CommitmentSolidityCallData {
pub root_hash: U256,
pub root_balances: Vec<U256>,
}

0 comments on commit 58fcc7f

Please sign in to comment.