diff --git a/Cargo.toml b/Cargo.toml index 0aa2610..f1f5e71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ default-members = [ ] [patch."https://github.com/zkbob/libzeropool-zkbob"] -libzeropool = { git = "https://github.com/zkbob//libzeropool-zkbob", branch = "devel", package = "libzeropool-zkbob" } +libzeropool = { git = "https://github.com/zkbob//libzeropool-zkbob", branch = "enc-memo-message-tune", package = "libzeropool-zkbob" } [patch.crates-io] -libzeropool = { git = "https://github.com/zkbob//libzeropool-zkbob", branch = "devel", package = "libzeropool-zkbob" } \ No newline at end of file +libzeropool = { git = "https://github.com/zkbob//libzeropool-zkbob", branch = "enc-memo-message-tune", package = "libzeropool-zkbob" } \ No newline at end of file diff --git a/libzkbob-rs-wasm/src/client/tx_parser.rs b/libzkbob-rs-wasm/src/client/tx_parser.rs index 65e5ab1..a9f1d80 100644 --- a/libzkbob-rs-wasm/src/client/tx_parser.rs +++ b/libzkbob-rs-wasm/src/client/tx_parser.rs @@ -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 @@ -241,7 +241,7 @@ pub fn parse_tx( return Err(ParseError::NoPrefix(index)); } - let (num_items, version) = + let (num_items, enc_type) = cipher::parse_memo_header(&mut memo.as_slice()).ok_or(ParseError::NoPrefix(0))?; if num_items > constants::OUT + 1 { @@ -252,9 +252,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..] @@ -326,7 +326,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) diff --git a/libzkbob-rs-wasm/src/client/tx_types.rs b/libzkbob-rs-wasm/src/client/tx_types.rs index 2d59e3f..cadd7ef 100644 --- a/libzkbob-rs-wasm/src/client/tx_types.rs +++ b/libzkbob-rs-wasm/src/client/tx_types.rs @@ -1,5 +1,5 @@ use crate::{Fr, IDepositData, IDepositPermittableData, ITransferData, IWithdrawData, IMultiTransferData, IMultiWithdrawData}; -use libzkbob_rs::client::{TokenAmount, TxOutput, TxType as NativeTxType}; +use libzkbob_rs::client::{TokenAmount, TxOutput, TxType as NativeTxType, ExtraItem, TxOperator}; use serde::Deserialize; use wasm_bindgen::prelude::*; @@ -23,8 +23,10 @@ pub trait JsMultiTxType { #[wasm_bindgen] #[derive(Deserialize)] pub struct TxBaseFields { - fee: TokenAmount, - data: Option>, + proxy: Vec, + proxy_fee: TokenAmount, + prover_fee: TokenAmount, + data: Vec, } #[wasm_bindgen] @@ -42,9 +44,15 @@ impl JsTxType for IDepositData { amount, } = serde_wasm_bindgen::from_value(self.into())?; + let operator = TxOperator { + proxy_address: base_fields.proxy, + proxy_fee: base_fields.proxy_fee, + prover_fee: base_fields.prover_fee, + }; + Ok(NativeTxType::Deposit( - base_fields.fee, - base_fields.data.unwrap_or_default(), + operator, + base_fields.data, amount, )) } @@ -69,9 +77,15 @@ impl JsTxType for IDepositPermittableData { holder, } = serde_wasm_bindgen::from_value(self.into())?; + let operator = TxOperator { + proxy_address: base_fields.proxy, + proxy_fee: base_fields.proxy_fee, + prover_fee: base_fields.prover_fee, + }; + Ok(NativeTxType::DepositPermittable( - base_fields.fee, - base_fields.data.unwrap_or_default(), + operator, + base_fields.data, amount, deadline.parse::().unwrap_or(0), holder @@ -107,10 +121,16 @@ impl JsTxType for ITransferData { amount: out.amount, }) .collect::>(); + + let operator = TxOperator { + proxy_address: base_fields.proxy, + proxy_fee: base_fields.proxy_fee, + prover_fee: base_fields.prover_fee, + }; Ok(NativeTxType::Transfer( - base_fields.fee, - base_fields.data.unwrap_or_default(), + operator, + base_fields.data, outputs, )) } @@ -129,9 +149,15 @@ impl JsMultiTxType for IMultiTransferData { }) .collect::>(); + let operator = TxOperator { + proxy_address: tx.base_fields.proxy, + proxy_fee: tx.base_fields.proxy_fee, + prover_fee: tx.base_fields.prover_fee, + }; + NativeTxType::Transfer( - tx.base_fields.fee, - tx.base_fields.data.unwrap_or_default(), + operator, + tx.base_fields.data, outputs, ) }).collect(); @@ -161,9 +187,15 @@ impl JsTxType for IWithdrawData { energy_amount, } = serde_wasm_bindgen::from_value(self.into())?; + let operator = TxOperator { + proxy_address: base_fields.proxy, + proxy_fee: base_fields.proxy_fee, + prover_fee: base_fields.prover_fee, + }; + Ok(NativeTxType::Withdraw( - base_fields.fee, - base_fields.data.unwrap_or_default(), + operator, + base_fields.data, amount, to, native_amount, @@ -177,9 +209,15 @@ impl JsMultiTxType for IMultiWithdrawData { let array: Vec = serde_wasm_bindgen::from_value(self.into())?; let tx_array = array.into_iter().map(|tx| { + let operator = TxOperator { + proxy_address: tx.base_fields.proxy, + proxy_fee: tx.base_fields.proxy_fee, + prover_fee: tx.base_fields.prover_fee, + }; + NativeTxType::Withdraw( - tx.base_fields.fee, - tx.base_fields.data.unwrap_or_default(), + operator, + tx.base_fields.data, tx.amount, tx.to, tx.native_amount, diff --git a/libzkbob-rs-wasm/src/ts_types.rs b/libzkbob-rs-wasm/src/ts_types.rs index 175f4c3..1ace85c 100644 --- a/libzkbob-rs-wasm/src/ts_types.rs +++ b/libzkbob-rs-wasm/src/ts_types.rs @@ -119,9 +119,18 @@ export interface IAddressComponents { is_pool_valid: boolean; } +export interface IExtraItem { + leaf_index: number; + pad_length: number; + need_encrypt: boolean; + data: Uint8Array; +} + export interface ITxBaseFields { - fee: string; - data?: Uint8Array; + proxy: Uint8Array; + proxy_fee: string; + prover_fee: string; + data: IExtraItem[]; } export interface IDepositData extends ITxBaseFields { diff --git a/libzkbob-rs/Cargo.toml b/libzkbob-rs/Cargo.toml index d611443..1bd809b 100644 --- a/libzkbob-rs/Cargo.toml +++ b/libzkbob-rs/Cargo.toml @@ -24,9 +24,9 @@ hex = { version = "0.4.3", features = ["serde"] } [dependencies.libzeropool] git = "https://github.com/zkbob/libzeropool-zkbob" -branch = "master" +branch = "enc-memo-message-tune" package = "libzeropool-zkbob" -version = "1.3.0" +version = "1.4.0" default-features = false features = ["in3out127"] diff --git a/libzkbob-rs/src/address.rs b/libzkbob-rs/src/address.rs index e66279d..ea0a1e7 100644 --- a/libzkbob-rs/src/address.rs +++ b/libzkbob-rs/src/address.rs @@ -8,7 +8,7 @@ use libzeropool::{ constants, fawkes_crypto::{ borsh::{BorshDeserialize, BorshSerialize}, - ff_uint::{Num, Uint, NumRepr}, + ff_uint::Num, native::ecc::EdwardsPoint, }, native::boundednum::BoundedNum, diff --git a/libzkbob-rs/src/client/mod.rs b/libzkbob-rs/src/client/mod.rs index d16497c..77270a4 100644 --- a/libzkbob-rs/src/client/mod.rs +++ b/libzkbob-rs/src/client/mod.rs @@ -590,8 +590,9 @@ where #[allow(clippy::redundant_clone)] memo_data.append(&mut tx_data.clone()); + memo_data.extend((ciphertext.len() as u16).to_be_bytes()); memo_data.extend(&ciphertext); - memo_data.append(&mut user_data.clone()); + // TODO: append extra data here let memo_hash = keccak256(&memo_data); let memo = Num::from_uint_reduced(NumRepr(Uint::from_big_endian(&memo_hash)));