Skip to content
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

Calldata V2 #80

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libzkbob-rs-node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libzkbob-rs-node"
version = "1.1.0"
version = "1.2.0"
authors = ["Dmitry Vdovin <[email protected]>"]
repository = "https://github.com/zkBob/libzkbob-rs/"
license = "MIT OR Apache-2.0"
Expand All @@ -23,5 +23,5 @@ hex = "0.4.3"
git = "https://github.com/zkbob/fawkes-crypto"
branch = "master"
package = "fawkes-crypto-zkbob"
version = "4.6.0"
version = "4.7.0"
features = ["multicore"]
2 changes: 1 addition & 1 deletion libzkbob-rs-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libzkbob-rs-node",
"version": "1.1.0",
"version": "1.2.0",
"description": "Neon version of libzkbob-rs",
"main": "index.js",
"types": "index.d.ts",
Expand Down
23 changes: 12 additions & 11 deletions libzkbob-rs-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "libzkbob-rs-wasm"
description = "A higher level zkBob API for Wasm"
version = "1.6.0"
version = "1.7.0"
authors = ["Dmitry Vdovin <[email protected]>"]
repository = "https://github.com/zkBob/libzkbob-rs/"
license = "MIT OR Apache-2.0"
Expand All @@ -18,7 +18,7 @@ nodejs = ["libzkbob-rs/node"]
multicore = ["fawkes-crypto/multicore", "wasm-bindgen-rayon"]

[dependencies]
wasm-bindgen = { version = "0.2.74" }
wasm-bindgen = { version = "0.2.90" }

# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
Expand All @@ -40,33 +40,34 @@ kvdb-web = { version = "0.9.0", path = "../libs/kvdb-web"}
kvdb = "0.9.0"
kvdb-memorydb = "0.9.0"
byteorder = "1.4.3"
wasm-bindgen-futures = "0.4.24"
serde = "1.0.126"
wasm-bindgen-futures = "0.4.40"
serde = "1.0.195"
serde_bytes = "0.11.14"
sha3 = "0.9.1"
thiserror = "1.0.26"
serde-wasm-bindgen = "0.3.0"
serde-wasm-bindgen = "0.6.3"
lazy_static = "1.4.0"
hex = { version = "0.4.3", features = ["serde"] }
js-sys = "0.3.55"
wasm-bindgen-rayon = { version = "1.0", optional = true }
rayon = "1.5.1"
wasm-bindgen-rayon = { version = "1.2.1", optional = true }
rayon = "1.8.1"
bincode = "1.3.3"
web-sys = "0.3.61"

[dependencies.fawkes-crypto]
git = "https://github.com/zkBob/fawkes-crypto"
branch = "master"
package = "fawkes-crypto-zkbob"
version = "4.6.0"
version = "4.7.0"
features = ["wasm", "serde_support"]


[dev-dependencies]
wasm-bindgen-test = "0.3.24"
wasm-bindgen-test = "0.3.40"
test-case = "1.2.0"
rand = "0.8.4"
serde_json = "1.0.64"
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"] }
serde_json = "1.0.111"
wasm-bindgen = { version = "0.2.90", features = ["serde-serialize"] }

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
5 changes: 5 additions & 0 deletions libzkbob-rs-wasm/scripts/publish-beta
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

TAG=beta
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
$SCRIPT_DIR/publish
6 changes: 2 additions & 4 deletions libzkbob-rs-wasm/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;
use std::rc::Rc;
use std::{cell::RefCell, convert::TryInto};
use std::str::FromStr;

#[cfg(feature = "multicore")]
use rayon::prelude::*;

Expand Down Expand Up @@ -63,13 +62,12 @@ pub struct UserAccount {
impl UserAccount {
#[wasm_bindgen(constructor)]
/// Initializes UserAccount with a spending key that has to be an element of the prime field Fs (p = 6554484396890773809930967563523245729705921265872317281365359162392183254199).
pub fn new(sk: &[u8], pool_id: u32, state: UserState) -> Result<UserAccount, JsValue> {
pub fn new(sk: &[u8], pool_id: u32, is_obsolete_pool: bool, state: UserState) -> Result<UserAccount, JsValue> {
crate::utils::set_panic_hook();

let sk = Num::<Fs>::from_uint(NumRepr(Uint::from_little_endian(sk)))
.ok_or_else(|| js_err!("Invalid spending key"))?;

let account = NativeUserAccount::new(sk, pool_id, state.inner, POOL_PARAMS.clone());
let account = NativeUserAccount::new(sk, pool_id, is_obsolete_pool, state.inner, POOL_PARAMS.clone());

Ok(UserAccount {
inner: Rc::new(RefCell::new(account)),
Expand Down
88 changes: 46 additions & 42 deletions libzkbob-rs-wasm/src/client/tx_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libzkbob_rs::libzeropool::{
self,
symcipher_decryption_keys,
decrypt_account_no_validate,
decrypt_note_no_validate, Version
decrypt_note_no_validate, MessageEncryptionType
},
key::{
self,derive_key_p_d
Expand Down Expand Up @@ -48,7 +48,7 @@ pub enum ParseError {
}

impl ParseError {
pub fn index(&self) -> u64 {
pub fn _index(&self) -> u64 {
match *self {
ParseError::NoPrefix(idx) => idx,
ParseError::IncorrectPrefix(idx, _, _) => idx,
Expand Down Expand Up @@ -131,48 +131,52 @@ impl TxParser {

let txs: Vec<IndexedTx> = serde_wasm_bindgen::from_value(txs.to_owned()).map_err(|err| js_err!(&err.to_string()))?;

let (parse_results, parse_errors): (Vec<_>, Vec<_>) = vec_into_iter(txs)
.map(|tx| -> Result<ParseResult, ParseError> {
let parse_results: Vec<_> = vec_into_iter(txs)
.map(|tx| -> ParseResult {
let IndexedTx{index, memo, commitment} = tx;
let memo = hex::decode(memo).unwrap();
let commitment = hex::decode(commitment).unwrap();

parse_tx(index, &commitment, &memo, None, &eta, kappa, params)
})
.partition(Result::is_ok);

if parse_errors.is_empty() {
let parse_result = parse_results
.into_iter()
.map(Result::unwrap)
.fold(Default::default(), |acc: ParseResult, parse_result| {
ParseResult {
decrypted_memos: vec![acc.decrypted_memos, parse_result.decrypted_memos].concat(),
state_update: StateUpdate {
new_leafs: vec![acc.state_update.new_leafs, parse_result.state_update.new_leafs].concat(),
new_commitments: vec![acc.state_update.new_commitments, parse_result.state_update.new_commitments].concat(),
new_accounts: vec![acc.state_update.new_accounts, parse_result.state_update.new_accounts].concat(),
new_notes: vec![acc.state_update.new_notes, parse_result.state_update.new_notes].concat()
match parse_tx(index, &commitment, &memo, None, &eta, kappa, params) {
Ok(res) => res,
Err(err) => {
console::log_1(&format!("[WASM TxParser] ERROR: {}", err.to_string()).into());
// Skip transaction in case of parsing errors (assume it doesn't belongs to the our account)
ParseResult {
state_update: StateUpdate {
new_commitments: vec![(
index,
Num::from_uint_reduced(NumRepr(Uint::from_big_endian(
&commitment,
))),
)],
..Default::default()
},
..Default::default()
}
}
});
}
})
.collect();

let parse_result = parse_results
.into_iter()
.fold(Default::default(), |acc: ParseResult, parse_result| {
ParseResult {
decrypted_memos: vec![acc.decrypted_memos, parse_result.decrypted_memos].concat(),
state_update: StateUpdate {
new_leafs: vec![acc.state_update.new_leafs, parse_result.state_update.new_leafs].concat(),
new_commitments: vec![acc.state_update.new_commitments, parse_result.state_update.new_commitments].concat(),
new_accounts: vec![acc.state_update.new_accounts, parse_result.state_update.new_accounts].concat(),
new_notes: vec![acc.state_update.new_notes, parse_result.state_update.new_notes].concat()
}
}
});

let parse_result = serde_wasm_bindgen::to_value(&parse_result)
.unwrap()
.unchecked_into::<ParseTxsResult>();
Ok(parse_result)
} else {
let errors: Vec<_> = parse_errors
.into_iter()
.map(|err| -> ParseError {
let err = err.unwrap_err();
console::log_1(&format!("[WASM TxParser] ERROR: {}", err.to_string()).into());
err
})
.collect();
let all_errs: Vec<u64> = errors.into_iter().map(|err| err.index()).collect();
Err(js_err!("The following txs cannot be processed: {:?}", all_errs))
}
let parse_result = serde_wasm_bindgen::to_value(&parse_result)
.unwrap()
.unchecked_into::<ParseTxsResult>();
Ok(parse_result)
}

#[wasm_bindgen(js_name = "extractDecryptKeys")]
Expand Down Expand Up @@ -241,8 +245,8 @@ pub fn parse_tx(
return Err(ParseError::NoPrefix(index));
}

let (num_items, version) =
cipher::parse_memo_header(&mut memo.as_slice()).ok_or(ParseError::NoPrefix(0))?;
let (num_items, enc_type) =
cipher::parse_memo_header(&mut memo.as_slice()).ok_or(ParseError::NoPrefix(index))?;

if num_items > constants::OUT + 1 {
return Err(ParseError::IncorrectPrefix(
Expand All @@ -252,9 +256,9 @@ pub fn parse_tx(
));
}

match version {
match enc_type {

Version::DelegatedDeposit => {// Special case: transaction contains delegated deposits
MessageEncryptionType::Plain => {// Special case: transaction contains delegated deposits
let num_deposits = num_items as usize;

let delegated_deposits = memo[4..]
Expand Down Expand Up @@ -326,7 +330,7 @@ pub fn parse_tx(

return Ok(parse_result);
}
Version::SymmetricEncryption | Version::Original => {// regular case: simple transaction memo
MessageEncryptionType::Symmetric | MessageEncryptionType::ECDH => {// regular case: simple transaction memo
let num_hashes = num_items;
let hashes = (&memo[4..])
.chunks(32)
Expand Down
Loading
Loading