diff --git a/backend/examples/summa_solvency_flow.rs b/backend/examples/summa_solvency_flow.rs index 90267224..f5f0753d 100644 --- a/backend/examples/summa_solvency_flow.rs +++ b/backend/examples/summa_solvency_flow.rs @@ -25,9 +25,6 @@ async fn main() -> Result<(), Box> { // 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. diff --git a/backend/src/apis/csv/assets.csv b/backend/src/apis/csv/assets.csv deleted file mode 100644 index bb2e38f0..00000000 --- a/backend/src/apis/csv/assets.csv +++ /dev/null @@ -1,3 +0,0 @@ -chain;asset_name;amount -ETH;ETH;556863 -ETH;USDT;556863 diff --git a/backend/src/apis/csv/signatures.csv b/backend/src/apis/csv/signatures.csv deleted file mode 100644 index 89e4ba16..00000000 --- a/backend/src/apis/csv/signatures.csv +++ /dev/null @@ -1,3 +0,0 @@ -chain;address;signature;message -ETH;0x70997970C51812dc3A010C7d01b50e0d17dc79C8;0x089b32327d332c295dc3b8873c205b72153211de6dc1c51235782b091cefb9d06d6df2661b86a7d441cd322f125b84901486b150e684221a7b7636eb8182af551b;Summa proof of solvency for CryptoExchange -ETH;0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC;0xb17a9e25265d3b88de7bfad81e7accad6e3d5612308ff83cc0fef76a34152b0444309e8fc3dea5139e49b6fc83a8553071a7af3d0cfd3fb8c1aea2a4c171729c1c;Summa proof of solvency for CryptoExchange diff --git a/backend/src/apis/csv_parser.rs b/backend/src/apis/csv_parser.rs deleted file mode 100644 index 3bde75e1..00000000 --- a/backend/src/apis/csv_parser.rs +++ /dev/null @@ -1,129 +0,0 @@ -use std::{error::Error, fs::File, path::Path}; - -use ethers::{ - abi::AbiEncode, - types::{Bytes, U256}, -}; -use serde::{Deserialize, Serialize}; - -use crate::contracts::generated::summa_contract::{AddressOwnershipProof, Asset}; - -#[derive(Debug, Deserialize, Serialize)] -pub struct SignatureRecord { - chain: String, - address: String, - signature: String, - message: String, -} - -impl SignatureRecord { - pub fn new(chain: String, address: String, signature: String, message: String) -> Self { - Self { - chain, - address, - signature, - message, - } - } -} - -pub fn parse_signature_csv>( - path: P, -) -> Result, Box> { - let file = File::open(path)?; - let mut rdr = csv::ReaderBuilder::new().delimiter(b';').from_reader(file); - - let mut address_ownership_proofs = Vec::::new(); - - for result in rdr.deserialize() { - let record: SignatureRecord = result?; - - address_ownership_proofs.push(AddressOwnershipProof { - cex_address: record.address.to_string(), - chain: record.chain.to_string(), - signature: record.signature.parse()?, - message: Bytes::from(record.message.encode()), - }); - } - - Ok(address_ownership_proofs) -} - -#[derive(Debug, Deserialize)] -struct AssetRecord { - chain: String, - asset_name: String, - amount: String, -} - -pub fn parse_asset_csv, const N_ASSETS: usize>( - path: P, -) -> Result<[Asset; N_ASSETS], Box> { - let file = File::open(path)?; - let mut rdr = csv::ReaderBuilder::new().delimiter(b';').from_reader(file); - - let mut assets_vec = Vec::with_capacity(N_ASSETS); - - for result in rdr.deserialize() { - let record: AssetRecord = result?; - - assets_vec.push(Asset { - asset_name: record.asset_name, - chain: record.chain, - amount: U256::from_dec_str(&record.amount)?, - }); - } - - let assets_array: [Asset; N_ASSETS] = assets_vec.try_into().map_err(|v: Vec| { - format!( - "The number of assets in CSV file does not match the expected count {:?}", - v - ) - })?; - - Ok(assets_array) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_parse_csv_to_signature() { - let path = "src/apis/csv/signatures.csv"; - let address_ownership = parse_signature_csv(path).unwrap(); - - let first_address_ownership = AddressOwnershipProof { - chain: "ETH".to_string(), - cex_address: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8".to_string(), - signature: - ("0x089b32327d332c295dc3b8873c205b72153211de6dc1c51235782b091cefb9d06d6df2661b86a7d441cd322f125b84901486b150e684221a7b7636eb8182af551b").parse().unwrap(), - message: "Summa proof of solvency for CryptoExchange".encode().into(), - }; - - assert_eq!(address_ownership[0], first_address_ownership); - } - - #[test] - fn test_parse_csv_to_assets() { - let path = "src/apis/csv/assets.csv"; - let assets = parse_asset_csv::<&str, 2>(path).unwrap(); - - assert_eq!( - assets[0], - Asset { - chain: "ETH".to_string(), - asset_name: "ETH".to_string(), - amount: U256::from(556863), - } - ); - assert_eq!( - assets[1], - Asset { - chain: "ETH".to_string(), - asset_name: "USDT".to_string(), - amount: U256::from(556863), - } - ); - } -} diff --git a/backend/src/apis/mod.rs b/backend/src/apis/mod.rs index 82fca001..66aa937e 100644 --- a/backend/src/apis/mod.rs +++ b/backend/src/apis/mod.rs @@ -1,3 +1,2 @@ pub mod address_ownership; -pub mod csv_parser; pub mod round; diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 88c85b69..d9bbd50f 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -3,3 +3,5 @@ pub mod apis; pub mod contracts; pub mod sample_data; pub mod tests; +pub use merkle_sum_tree::{Entry, MerkleSumTree}; +use summa_solvency::merkle_sum_tree; diff --git a/zk_prover/src/circuits/tests.rs b/zk_prover/src/circuits/tests.rs index 7ec559f3..80069a11 100644 --- a/zk_prover/src/circuits/tests.rs +++ b/zk_prover/src/circuits/tests.rs @@ -765,7 +765,7 @@ mod test { MerkleSumTree::::new("src/merkle_sum_tree/csv/entry_16.csv") .unwrap(); - let circuit = SolvencyCircuit::::init(merkle_sum_tree, asset_sums); + let circuit = SolvencyCircuit::::init(&merkle_sum_tree, asset_sums); let root = BitMapBackend::new("prints/solvency-layout.png", (2048, 32768)).into_drawing_area();