From be690462ddb12b01225fa5ad2add0bf6fe9a7d4e Mon Sep 17 00:00:00 2001 From: Enrico Bottazzi <85900164+enricobottazzi@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:42:24 +0100 Subject: [PATCH] chore: move `csv` folder to root --- backend/examples/summa_solvency_flow.rs | 2 +- backend/src/apis/csv_parser.rs | 2 +- backend/src/tests.rs | 6 +-- .../merkle_sum_tree/csv => csv}/entry_16.csv | 0 .../csv => csv}/entry_16_bigints.csv | 0 .../csv => csv}/entry_16_modified.csv | 0 .../csv => csv}/entry_16_no_overflow.csv | 0 .../csv => csv}/entry_16_overflow.csv | 0 .../csv => csv}/entry_16_overflow_2.csv | 0 .../csv => csv}/entry_16_switched_order.csv | 0 {backend/src/apis/csv => csv}/signatures.csv | 0 zk_prover/README.md | 4 +- zk_prover/src/circuits/tests.rs | 27 ++++------- zk_prover/src/merkle_sum_tree/tests.rs | 46 ++++++------------- 14 files changed, 31 insertions(+), 56 deletions(-) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_bigints.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_modified.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_no_overflow.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_overflow.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_overflow_2.csv (100%) rename {zk_prover/src/merkle_sum_tree/csv => csv}/entry_16_switched_order.csv (100%) rename {backend/src/apis/csv => csv}/signatures.csv (100%) diff --git a/backend/examples/summa_solvency_flow.rs b/backend/examples/summa_solvency_flow.rs index c182a2fe..35f22696 100644 --- a/backend/examples/summa_solvency_flow.rs +++ b/backend/examples/summa_solvency_flow.rs @@ -43,7 +43,7 @@ async fn main() -> Result<(), Box> { .await?; // Each CEX prepares its own `signature` CSV file. - let signature_csv_path = "src/apis/csv/signatures.csv"; + let signature_csv_path = "../csv/signatures.csv"; let mut address_ownership_client = AddressOwnership::new(&signer, signature_csv_path).unwrap(); // Dispatch the proof of address ownership. diff --git a/backend/src/apis/csv_parser.rs b/backend/src/apis/csv_parser.rs index ff65681a..672fd14d 100644 --- a/backend/src/apis/csv_parser.rs +++ b/backend/src/apis/csv_parser.rs @@ -52,7 +52,7 @@ mod tests { #[test] fn test_parse_csv_to_signature() { - let path = "src/apis/csv/signatures.csv"; + let path = "../csv/signatures.csv"; let address_ownership = parse_signature_csv(path).unwrap(); let first_address_ownership = AddressOwnershipProof { diff --git a/backend/src/tests.rs b/backend/src/tests.rs index cf06dc7d..95d1efab 100644 --- a/backend/src/tests.rs +++ b/backend/src/tests.rs @@ -157,7 +157,7 @@ mod test { .await?; let params_path = "ptau/hermez-raw-11"; - let entry_csv = "../zk_prover/src/merkle_sum_tree/csv/entry_16.csv"; + let entry_csv = "../csv/entry_16.csv"; let mst = MerkleSumTree::new(entry_csv).unwrap(); let mut round_one = @@ -202,7 +202,7 @@ mod test { .await?; let mut address_ownership_client = - AddressOwnership::new(&signer, "src/apis/csv/signatures.csv").unwrap(); + AddressOwnership::new(&signer, "../csv/signatures.csv").unwrap(); address_ownership_client .dispatch_proof_of_address_ownership() @@ -236,7 +236,7 @@ mod test { // Initialize round let params_path = "ptau/hermez-raw-11"; - let entry_csv = "../zk_prover/src/merkle_sum_tree/csv/entry_16.csv"; + let entry_csv = "../csv/entry_16.csv"; let mst = MerkleSumTree::new(entry_csv).unwrap(); let mut round = Round::<4, 2, 14>::new(&signer, Box::new(mst), params_path, 1).unwrap(); diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16.csv b/csv/entry_16.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16.csv rename to csv/entry_16.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_bigints.csv b/csv/entry_16_bigints.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_bigints.csv rename to csv/entry_16_bigints.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_modified.csv b/csv/entry_16_modified.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_modified.csv rename to csv/entry_16_modified.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_no_overflow.csv b/csv/entry_16_no_overflow.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_no_overflow.csv rename to csv/entry_16_no_overflow.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_overflow.csv b/csv/entry_16_overflow.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_overflow.csv rename to csv/entry_16_overflow.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_overflow_2.csv b/csv/entry_16_overflow_2.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_overflow_2.csv rename to csv/entry_16_overflow_2.csv diff --git a/zk_prover/src/merkle_sum_tree/csv/entry_16_switched_order.csv b/csv/entry_16_switched_order.csv similarity index 100% rename from zk_prover/src/merkle_sum_tree/csv/entry_16_switched_order.csv rename to csv/entry_16_switched_order.csv diff --git a/backend/src/apis/csv/signatures.csv b/csv/signatures.csv similarity index 100% rename from backend/src/apis/csv/signatures.csv rename to csv/signatures.csv diff --git a/zk_prover/README.md b/zk_prover/README.md index 9d5ea277..d92bd631 100644 --- a/zk_prover/README.md +++ b/zk_prover/README.md @@ -26,7 +26,7 @@ For real-world situations, you must provide the path of a specific `ptau` file t ## Build a Commitment -A `gen_commitment.rs` script is provided to generate a commitment out of a Merkle Sum Tree. In particular, the example takes a csv file located in "src/merkle_sum_tree/csv/entry_16.csv", build a Merkle Sum Tree and extract a commitment out it. The commitment is made of the `root_hash` and the `root_balances`. +A `gen_commitment.rs` script is provided to generate a commitment out of a Merkle Sum Tree. In particular, the example takes a csv file located in "../csv/entry_16.csv", build a Merkle Sum Tree and extract a commitment out it. The commitment is made of the `root_hash` and the `root_balances`. The script will eventually generate a `commitment_solidity_calldata.json` file that contains some testing calldata to be used within `contracts` and `backend` to test the publishing of the commitment to the Summa Smart Contract. @@ -52,7 +52,7 @@ Note that the generic parameters of the circuits `LEVELS`, `N_CURRENCIES` and `N The verifier are generated based on an unsafe setup. For a production ready verifier, the setup should be generated by providing a `ptau` file generated after a trusted setup ceremony to `generate_setup_artifacts` function. -On top of that the script will also generate a `inclusion_proof_solidity_calldata.json` file that contains some testing calldata to be used within `contracts` and `backend` to test the verifier. Again, in the example, the proof is generated based on the `src/merkle_sum_tree/csv/entry_16.csv` file for a specific `user_index`, which is set to 0 by default. If you want to generate a testing proof for a different file, you can change the path in the script. If you want to generate a proof for a different `user_index`, you can change the `user_index` in the script. +On top of that the script will also generate a `inclusion_proof_solidity_calldata.json` file that contains some testing calldata to be used within `contracts` and `backend` to test the verifier. Again, in the example, the proof is generated based on the `../csv/entry_16.csv` file for a specific `user_index`, which is set to 0 by default. If you want to generate a testing proof for a different file, you can change the path in the script. If you want to generate a proof for a different `user_index`, you can change the `user_index` in the script. ## Incremental Nova Verifier diff --git a/zk_prover/src/circuits/tests.rs b/zk_prover/src/circuits/tests.rs index ea61585b..5a021059 100644 --- a/zk_prover/src/circuits/tests.rs +++ b/zk_prover/src/circuits/tests.rs @@ -25,8 +25,7 @@ mod test { #[test] fn test_valid_merkle_sum_tree() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); for user_index in 0..16 { // get proof for entry ˆuser_indexˆ @@ -56,8 +55,7 @@ mod test { let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap(); let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -93,8 +91,7 @@ mod test { #[test] fn test_invalid_root_hash() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap(); @@ -133,8 +130,7 @@ mod test { let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap(); let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -162,8 +158,7 @@ mod test { #[test] fn test_invalid_entry_balance_as_witness() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -238,8 +233,7 @@ mod test { #[test] fn test_invalid_leaf_hash_as_instance() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -276,8 +270,7 @@ mod test { #[test] fn test_non_binary_index() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -441,8 +434,7 @@ mod test { #[test] fn test_swapping_index() { let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; @@ -482,8 +474,7 @@ mod test { use plotters::prelude::*; let merkle_sum_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let user_index = 0; diff --git a/zk_prover/src/merkle_sum_tree/tests.rs b/zk_prover/src/merkle_sum_tree/tests.rs index 36941696..4d1f25bd 100644 --- a/zk_prover/src/merkle_sum_tree/tests.rs +++ b/zk_prover/src/merkle_sum_tree/tests.rs @@ -13,8 +13,7 @@ mod test { fn test_mst() { // create new merkle tree let merkle_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); // get root let root = merkle_tree.root(); @@ -33,10 +32,9 @@ mod test { assert!(merkle_tree.verify_proof(&proof)); // Should generate different root hashes when changing the entry order - let merkle_tree_2 = MerkleSumTree::::new( - "src/merkle_sum_tree/csv/entry_16_switched_order.csv", - ) - .unwrap(); + let merkle_tree_2 = + MerkleSumTree::::new("../csv/entry_16_switched_order.csv") + .unwrap(); assert_ne!(root.hash, merkle_tree_2.root().hash); // the balance total should be the same @@ -71,16 +69,13 @@ mod test { #[test] fn test_update_mst_leaf() { let merkle_tree_1 = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let root_hash_1 = merkle_tree_1.root().hash; //Create the second tree with the 7th entry different from the the first tree - let mut merkle_tree_2 = MerkleSumTree::::new( - "src/merkle_sum_tree/csv/entry_16_modified.csv", - ) - .unwrap(); + let mut merkle_tree_2 = + MerkleSumTree::::new("../csv/entry_16_modified.csv").unwrap(); let root_hash_2 = merkle_tree_2.root().hash; assert!(root_hash_1 != root_hash_2); @@ -99,8 +94,7 @@ mod test { #[test] fn test_update_invalid_mst_leaf() { let mut merkle_tree = - MerkleSumTree::::new_sorted("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new_sorted("../csv/entry_16.csv").unwrap(); let new_root = merkle_tree.update_leaf( "non_existing_user", //This username is not present in the tree @@ -115,15 +109,13 @@ mod test { #[test] fn test_sorted_mst() { let merkle_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let old_root_balances = merkle_tree.root().balances; let old_root_hash = merkle_tree.root().hash; let sorted_merkle_tree = - MerkleSumTree::::new_sorted("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new_sorted("../csv/entry_16.csv").unwrap(); let new_root_balances = sorted_merkle_tree.root().balances; let new_root_hash = sorted_merkle_tree.root().hash; @@ -137,9 +129,7 @@ mod test { // Passing a csv file with a single entry that has a balance that is not in the expected range will fail #[test] fn test_mst_overflow_1() { - let result = MerkleSumTree::::new( - "src/merkle_sum_tree/csv/entry_16_overflow.csv", - ); + let result = MerkleSumTree::::new("../csv/entry_16_overflow.csv"); if let Err(e) = result { assert_eq!( @@ -152,9 +142,7 @@ mod test { #[test] // Passing a csv file in which the entries have a balance in the range, but while summing it generates a ndoe in which the balance is not in the expected range will fail fn test_mst_overflow_2() { - let result = MerkleSumTree::::new( - "src/merkle_sum_tree/csv/entry_16_overflow_2.csv", - ); + let result = MerkleSumTree::::new("../csv/entry_16_overflow_2.csv"); if let Err(e) = result { assert_eq!( @@ -167,9 +155,7 @@ mod test { // Passing a csv file with a single entry that has a balance that is the maximum that can fit in the expected range will not fail #[test] fn test_mst_no_overflow() { - let result = MerkleSumTree::::new( - "src/merkle_sum_tree/csv/entry_16_no_overflow.csv", - ); + let result = MerkleSumTree::::new("../csv/entry_16_no_overflow.csv"); assert!(result.is_ok()); } @@ -198,8 +184,7 @@ mod test { #[test] fn get_middle_node_hash_preimage() { let merkle_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); let depth = *merkle_tree.depth(); @@ -228,8 +213,7 @@ mod test { #[test] fn get_leaf_node_hash_preimage() { let merkle_tree = - MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") - .unwrap(); + MerkleSumTree::::new("../csv/entry_16.csv").unwrap(); // Generate a random number between 0 and 15 let mut rng = rand::thread_rng();