Skip to content

Commit

Permalink
chore: move csv folder to root
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobottazzi committed Dec 1, 2023
1 parent 7b886b1 commit be69046
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 56 deletions.
2 changes: 1 addition & 1 deletion backend/examples/summa_solvency_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.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.
Expand Down
2 changes: 1 addition & 1 deletion backend/src/apis/csv_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions zk_prover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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

Expand Down
27 changes: 9 additions & 18 deletions zk_prover/src/circuits/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ mod test {
#[test]
fn test_valid_merkle_sum_tree() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

for user_index in 0..16 {
// get proof for entry ˆuser_indexˆ
Expand Down Expand Up @@ -56,8 +55,7 @@ mod test {
let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap();

let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -93,8 +91,7 @@ mod test {
#[test]
fn test_invalid_root_hash() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();
let user_index = 0;

let merkle_proof = merkle_sum_tree.generate_proof(user_index).unwrap();
Expand Down Expand Up @@ -133,8 +130,7 @@ mod test {
let (params, pk, vk) = generate_setup_artifacts(K, None, circuit).unwrap();

let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -162,8 +158,7 @@ mod test {
#[test]
fn test_invalid_entry_balance_as_witness() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -238,8 +233,7 @@ mod test {
#[test]
fn test_invalid_leaf_hash_as_instance() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -276,8 +270,7 @@ mod test {
#[test]
fn test_non_binary_index() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -441,8 +434,7 @@ mod test {
#[test]
fn test_swapping_index() {
let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down Expand Up @@ -482,8 +474,7 @@ mod test {
use plotters::prelude::*;

let merkle_sum_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let user_index = 0;

Expand Down
46 changes: 15 additions & 31 deletions zk_prover/src/merkle_sum_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ mod test {
fn test_mst() {
// create new merkle tree
let merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

// get root
let root = merkle_tree.root();
Expand All @@ -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::<N_CURRENCIES, N_BYTES>::new(
"src/merkle_sum_tree/csv/entry_16_switched_order.csv",
)
.unwrap();
let merkle_tree_2 =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16_switched_order.csv")
.unwrap();
assert_ne!(root.hash, merkle_tree_2.root().hash);

// the balance total should be the same
Expand Down Expand Up @@ -71,16 +69,13 @@ mod test {
#[test]
fn test_update_mst_leaf() {
let merkle_tree_1 =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::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::<N_CURRENCIES, N_BYTES>::new(
"src/merkle_sum_tree/csv/entry_16_modified.csv",
)
.unwrap();
let mut merkle_tree_2 =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16_modified.csv").unwrap();

let root_hash_2 = merkle_tree_2.root().hash;
assert!(root_hash_1 != root_hash_2);
Expand All @@ -99,8 +94,7 @@ mod test {
#[test]
fn test_update_invalid_mst_leaf() {
let mut merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new_sorted("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::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
Expand All @@ -115,15 +109,13 @@ mod test {
#[test]
fn test_sorted_mst() {
let merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::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::<N_CURRENCIES, N_BYTES>::new_sorted("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::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;
Expand All @@ -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::<N_CURRENCIES, N_BYTES>::new(
"src/merkle_sum_tree/csv/entry_16_overflow.csv",
);
let result = MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16_overflow.csv");

if let Err(e) = result {
assert_eq!(
Expand All @@ -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::<N_CURRENCIES, N_BYTES>::new(
"src/merkle_sum_tree/csv/entry_16_overflow_2.csv",
);
let result = MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16_overflow_2.csv");

if let Err(e) = result {
assert_eq!(
Expand All @@ -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::<N_CURRENCIES, N_BYTES>::new(
"src/merkle_sum_tree/csv/entry_16_no_overflow.csv",
);
let result = MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16_no_overflow.csv");
assert!(result.is_ok());
}

Expand Down Expand Up @@ -198,8 +184,7 @@ mod test {
#[test]
fn get_middle_node_hash_preimage() {
let merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

let depth = *merkle_tree.depth();

Expand Down Expand Up @@ -228,8 +213,7 @@ mod test {
#[test]
fn get_leaf_node_hash_preimage() {
let merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("src/merkle_sum_tree/csv/entry_16.csv")
.unwrap();
MerkleSumTree::<N_CURRENCIES, N_BYTES>::new("../csv/entry_16.csv").unwrap();

// Generate a random number between 0 and 15
let mut rng = rand::thread_rng();
Expand Down

0 comments on commit be69046

Please sign in to comment.