Skip to content

Commit

Permalink
Add ability to parse coldstorage with decompressed ec points
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Jan 25, 2023
1 parent 9582514 commit be8f838
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libzkbob-rs-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ console_error_panic_hook = { version = "0.1.6", optional = true }
wee_alloc = { version = "0.4.5", optional = true }

libzkbob-rs = { path = "../libzkbob-rs" }
libzeropool = { git = "https://github.com/zkBob/libzeropool", branch = "multicore-wasm", version = "0.5.6", default-features = false }
libzeropool = { path = "../../libzeropool", default-features = false }
getrandom = { version = "0.2.3", features = ["js"] }
fawkes-crypto = { git = "https://github.com/zkBob/fawkes-crypto", branch = "multicore-wasm", version = "4.2.4", features = ["wasm", "serde_support"] }
bs58 = "0.4.0"
Expand Down
1 change: 1 addition & 0 deletions libzkbob-rs-wasm/src/client/coldstorage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pub struct BulkData {
pub root_before: Num<Fr>,
pub root_after: Num<Fr>,
pub txs: Vec<TxInputData>,
pub ec_points_compressed: bool,
}
4 changes: 3 additions & 1 deletion libzkbob-rs-wasm/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ impl UserAccount {
let eta = &self.inner.borrow().keys.eta;
let params = &self.inner.borrow().params;
let range = from_index.unwrap_or(0)..to_index.unwrap_or(u64::MAX);
let compressed = bulk.ec_points_compressed;
let bulk_results: Vec<ParseResult> = vec_into_iter(bulk.txs)
.filter(|tx| range.contains(&tx.index))
.map(|tx| -> ParseResult {
Expand All @@ -390,7 +391,8 @@ impl UserAccount {
&tx.memo,
Some(&tx.tx_hash),
eta,
params
params,
compressed
)
})
.collect();
Expand Down
18 changes: 14 additions & 4 deletions libzkbob-rs-wasm/src/client/tx_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TxParser {
let memo = hex::decode(memo).unwrap();
let commitment = hex::decode(commitment).unwrap();

parse_tx(index, &commitment, &memo, None, &eta, params)
parse_tx(index, &commitment, &memo, None, &eta, params, true)
}).collect();

let parse_result = parse_results
Expand Down Expand Up @@ -109,15 +109,20 @@ pub fn parse_tx(
memo: &Vec<u8>,
tx_hash: Option<&Vec<u8>>,
eta: &Num<Fr>,
params: &PoolParams
params: &PoolParams,
compressed: bool,
) -> ParseResult {
let num_hashes = (&memo[0..4]).read_u32::<LittleEndian>().unwrap();
let hashes = (&memo[4..])
.chunks(32)
.take(num_hashes as usize)
.map(|bytes| Num::from_uint_reduced(NumRepr(Uint::from_little_endian(bytes))));

let pair = cipher::decrypt_out(*eta, &memo, params);
let pair = if compressed {
cipher::decrypt_out(*eta, &memo, params)
} else {
cipher::decrypt_out_decompressed(*eta, &memo, params)
};

match pair {
Some((account, notes)) => {
Expand Down Expand Up @@ -154,7 +159,12 @@ pub fn parse_tx(
}
},
None => {
let in_notes: Vec<(_, _)> = cipher::decrypt_in(*eta, &memo, params)
let in_notes = if compressed {
cipher::decrypt_in(*eta, &memo, params)
} else {
cipher::decrypt_in_decompressed(*eta, &memo, params)
};
let in_notes: Vec<(_, _)> = in_notes
.into_iter()
.enumerate()
.filter_map(|(i, note)| {
Expand Down
2 changes: 1 addition & 1 deletion libzkbob-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
edition = "2018"

[dependencies]
libzeropool = { git = "https://github.com/zkBob/libzeropool", branch = "multicore-wasm", version = "0.5.6", default-features = false, features = ["in3out127"] }
libzeropool = { path = "../../libzeropool", default-features = false, features = ["in3out127"] }
getrandom = { version = "0.2.3" }
bs58 = "0.4.0"
kvdb = "0.9.0"
Expand Down

0 comments on commit be8f838

Please sign in to comment.