-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Tree
trait
#179
feat: Tree
trait
#179
Changes from 17 commits
15a6d0a
400fc49
d538b28
c750083
be0f52d
022dde6
b3990eb
35478ec
e17e493
d3c5562
391f37c
2f14b36
3e8c855
c80e964
d42af95
0c5153b
4e180b2
5a9120f
c575a29
3afa5d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,35 +9,37 @@ use summa_backend::{ | |
address_ownership::AddressOwnership, | ||
round::{MstInclusionProof, Round}, | ||
}, | ||
contracts::signer::AddressInput, | ||
contracts::signer::{AddressInput, SummaSigner}, | ||
sample_entries::*, | ||
tests::initialize_test_env, | ||
}; | ||
use summa_solvency::merkle_sum_tree::utils::generate_leaf_hash; | ||
use summa_solvency::merkle_sum_tree::{utils::generate_leaf_hash, MerkleSumTree}; | ||
|
||
const N_ASSETS: usize = 2; | ||
const USER_INDEX: usize = 0; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
// Initialize test environment without `address_ownership` instance from `initialize_test_env` function. | ||
let (anvil, _, _, _, summa_contract) = initialize_test_env().await; | ||
let (anvil, _, _, _, summa_contract) = initialize_test_env(None).await; | ||
|
||
// 1. Submit ownership proof | ||
// | ||
// Each CEX prepares its own `signature` CSV file. | ||
let signature_csv_path = "src/apis/csv/signatures.csv"; | ||
|
||
// The signer instance would be shared with `address_ownership` and `round` instances | ||
// | ||
// Using AddressInput::Address to directly provide the summa_contract's address. | ||
// For deployed contracts, if the address is stored in a config file, | ||
// you can alternatively use AddressInput::Path to specify the file's path. | ||
let mut address_ownership_client = AddressOwnership::new( | ||
let signer = SummaSigner::new( | ||
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", | ||
anvil.chain_id(), | ||
anvil.endpoint().as_str(), | ||
AddressInput::Address(summa_contract.address()), | ||
signature_csv_path, | ||
) | ||
.unwrap(); | ||
.await?; | ||
|
||
// Each CEX prepares its own `signature` CSV file. | ||
let signature_csv_path = "src/apis/csv/signatures.csv"; | ||
let mut address_ownership_client = AddressOwnership::new(&signer, signature_csv_path).unwrap(); | ||
|
||
// Dispatch the proof of address ownership. | ||
// the `dispatch_proof_of_address_ownership` function sends a transaction to the Summa contract. | ||
|
@@ -47,30 +49,24 @@ async fn main() -> Result<(), Box<dyn Error>> { | |
|
||
println!("1. Ownership proofs are submitted successfully!"); | ||
|
||
// 2. Submit solvency proof | ||
// 2. Submit Commitment | ||
// | ||
// Initialize the `Round` instance to submit the proof of solvency. | ||
let asset_csv = "src/apis/csv/assets.csv"; | ||
let entry_csv = "../zk_prover/src/merkle_sum_tree/csv/entry_16.csv"; | ||
// Initialize the `Round` instance to submit the liability commitment. | ||
let params_path = "ptau/hermez-raw-11"; | ||
let assets_csv_path = "src/apis/csv/assets.csv"; | ||
|
||
// Using the `round` instance, the solvency proof is dispatched to the Summa contract with the `dispatch_solvency_proof` method. | ||
let mut round = Round::<4, 2, 14>::new( | ||
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", // anvil account [0] | ||
anvil.chain_id(), | ||
anvil.endpoint().as_str(), | ||
AddressInput::Address(summa_contract.address()), | ||
entry_csv, | ||
asset_csv, | ||
params_path, | ||
1, | ||
) | ||
.unwrap(); | ||
let entries = get_sample_entries(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated at 5a9120f |
||
let mst = MerkleSumTree::from_entries(entries, false).unwrap(); | ||
|
||
// Using the `round` instance, the commitment is dispatched to the Summa contract with the `dispatch_commitment` method. | ||
let timestamp = 1u64; | ||
let mut round = | ||
Round::<4, 2, 14>::new(&signer, mst, assets_csv_path, params_path, timestamp).unwrap(); | ||
|
||
// Sends the solvency proof, which should ideally complete without errors. | ||
round.dispatch_solvency_proof().await?; | ||
// Sends the commitment, which should ideally complete without errors. | ||
round.dispatch_commitment().await?; | ||
|
||
println!("2. Solvency proof is submitted successfully!"); | ||
println!("2. Commitment is submitted successfully!"); | ||
|
||
// 3. Generate Inclusion Proof | ||
// | ||
|
@@ -115,10 +111,10 @@ async fn main() -> Result<(), Box<dyn Error>> { | |
); | ||
|
||
// Get `mst_root` from contract. the `mst_root` is disptached by CEX with specific time `snapshot_time`. | ||
let mst_root = summa_contract.mst_roots(snapshot_time).call().await?; | ||
let commitment = summa_contract.commitments(snapshot_time).call().await?; | ||
|
||
// Match the `mst_root` with the `root_hash` derived from the proof. | ||
assert_eq!(mst_root, public_inputs[1]); | ||
assert_eq!(commitment, public_inputs[1]); | ||
|
||
// Validate the inclusion proof using the contract verifier. | ||
let proof = inclusion_proof.get_proof(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
chain;asset_name;amount | ||
ETH;ETH;556863 | ||
ETH;USDT;556863 | ||
chain;asset_name | ||
ETH;ETH | ||
ETH;USDT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an example of such config file? Can you add it to the comments if possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is "backend/src/contracts/deployments.json".
I will add comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated c575a29