From 58fcc7f81a26b19a2439856199f2c69bb2127c6f Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:39:27 +0100 Subject: [PATCH] feat: create `Commitment` struct --- .../examples/commitment_solidity_calldata.json | 12 +++++++----- zk_prover/examples/gen_commitment.rs | 13 +++++++------ zk_prover/src/circuits/types.rs | 6 ++++++ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/zk_prover/examples/commitment_solidity_calldata.json b/zk_prover/examples/commitment_solidity_calldata.json index 5f6f611f..4f4891d9 100644 --- a/zk_prover/examples/commitment_solidity_calldata.json +++ b/zk_prover/examples/commitment_solidity_calldata.json @@ -1,5 +1,7 @@ -[ - "0x2e021d9bf99c5bd7267488b6a7a5cf5f7d00222a41b6a9b971899c44089e0c5", - "0x87f3e", - "0x87f3e" -] \ No newline at end of file +{ + "root_hash": "0x2e021d9bf99c5bd7267488b6a7a5cf5f7d00222a41b6a9b971899c44089e0c5", + "root_balances": [ + "0x87f3e", + "0x87f3e" + ] +} \ No newline at end of file diff --git a/zk_prover/examples/gen_commitment.rs b/zk_prover/examples/gen_commitment.rs index 5455ea06..f0a820ce 100644 --- a/zk_prover/examples/gen_commitment.rs +++ b/zk_prover/examples/gen_commitment.rs @@ -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}, }; @@ -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") diff --git a/zk_prover/src/circuits/types.rs b/zk_prover/src/circuits/types.rs index d6a1cee8..4a546666 100644 --- a/zk_prover/src/circuits/types.rs +++ b/zk_prover/src/circuits/types.rs @@ -6,3 +6,9 @@ pub struct ProofSolidityCallData { pub proof: String, pub public_inputs: Vec, } + +#[derive(Serialize, Deserialize)] +pub struct CommitmentSolidityCallData { + pub root_hash: U256, + pub root_balances: Vec, +}