Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
1.7.13
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Jun 7, 2022
1 parent c1ba87d commit bddbad1
Show file tree
Hide file tree
Showing 24 changed files with 1,175 additions and 641 deletions.
726 changes: 499 additions & 227 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zecwallet-cli"
version = "1.7.12"
version = "1.7.13"
edition = "2018"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion cli/src/version.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const VERSION: &str = "1.7.12";
pub const VERSION: &str = "1.7.13";
25 changes: 14 additions & 11 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ arr_macro = "0.1.3"
base64 = "0.13.0"
bytes = "0.4"
log4rs = "1.0.0"
rand = "0.7.3"
rand = "0.8.5"
http = "0.2.4"
tonic = {version = "0.4.3", features = ["tls", "tls-roots"]}
prost = "0.7.0"
Expand All @@ -32,28 +32,31 @@ json = "0.12.4"
webpki-roots = "0.21.0"

lazy_static = "1.4.0"
secp256k1 = "=0.20.2"
secp256k1 = "=0.21.3"
ripemd160 = "0.9.1"
sha2 = "0.9.5"
base58 = "0.1.0"
tiny-bip39 = "0.8.0"
sodiumoxide = "0.2.5"
byteorder = "1"

pairing = "0.18.0"
ff = "0.8"
jubjub = "0.5.1"
bls12_381 = "0.3.1"
group = "0.8"
pairing = "0.22"
ff = "0.12"
jubjub = "0.9.0"
bls12_381 = "0.7"
group = "0.12"

rust-embed = { version = "5.1.0", features = ["debug-embed"] }

zcash_primitives = { git = "https://github.com/adityapk00/librustzcash", rev = "b70edf39e26e4c687b5087daf2ffd40f99fffd67", features = ["transparent-inputs"] }
zcash_client_backend = { git = "https://github.com/adityapk00/librustzcash", rev = "b70edf39e26e4c687b5087daf2ffd40f99fffd67"}
zcash_proofs = { git = "https://github.com/adityapk00/librustzcash", rev = "b70edf39e26e4c687b5087daf2ffd40f99fffd67", features = ["multicore"]}
zcash_primitives = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["transparent-inputs"] }
# zcash_primitives = { path = "../../librustzcash/zcash_primitives", features = ["transparent-inputs"] }
zcash_client_backend = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
zcash_proofs = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["multicore"]}
zcash_encoding = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
zcash_note_encryption = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["pre-zip-212"]}

[dev-dependencies]
portpicker = "0.1.0"
portpicker = "0.1.1"
tempdir = "0.3.7"

[build-dependencies]
Expand Down
3 changes: 1 addition & 2 deletions lib/src/blaze/block_witness_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use tokio::{
use zcash_primitives::{
consensus::BlockHeight,
merkle_tree::{CommitmentTree, IncrementalWitness},
primitives::Nullifier,
sapling::Node,
sapling::{Node, Nullifier},
transaction::TxId,
};

Expand Down
264 changes: 130 additions & 134 deletions lib/src/blaze/fetch_full_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use zcash_primitives::{
consensus::BlockHeight,
legacy::TransparentAddress,
memo::Memo,
note_encryption::{try_sapling_note_decryption, try_sapling_output_recovery},
sapling::note_encryption::{try_sapling_note_decryption, try_sapling_output_recovery},
transaction::{Transaction, TxId},
};

Expand Down Expand Up @@ -163,27 +163,29 @@ impl FetchFullTxns {
let taddrs_set: HashSet<_> = taddrs.iter().map(|t| t.clone()).collect();

// Step 1: Scan all transparent outputs to see if we recieved any money
for (n, vout) in tx.vout.iter().enumerate() {
match vout.script_pubkey.address() {
Some(TransparentAddress::PublicKey(hash)) => {
let output_taddr = hash.to_base58check(&config.base58_pubkey_address(), &[]);
if taddrs_set.contains(&output_taddr) {
// This is our address. Add this as an output to the txid
wallet_txns.write().await.add_new_taddr_output(
tx.txid(),
output_taddr.clone(),
height.into(),
unconfirmed,
block_time as u64,
&vout,
n as u32,
);

// Ensure that we add any new HD addresses
keys.write().await.ensure_hd_taddresses(&output_taddr);
if let Some(t_bundle) = tx.transparent_bundle() {
for (n, vout) in t_bundle.vout.iter().enumerate() {
match vout.script_pubkey.address() {
Some(TransparentAddress::PublicKey(hash)) => {
let output_taddr = hash.to_base58check(&config.base58_pubkey_address(), &[]);
if taddrs_set.contains(&output_taddr) {
// This is our address. Add this as an output to the txid
wallet_txns.write().await.add_new_taddr_output(
tx.txid(),
output_taddr.clone(),
height.into(),
unconfirmed,
block_time as u64,
&vout,
n as u32,
);

// Ensure that we add any new HD addresses
keys.write().await.ensure_hd_taddresses(&output_taddr);
}
}
_ => {}
}
_ => {}
}
}

Expand All @@ -198,21 +200,23 @@ impl FetchFullTxns {

{
let current = &wallet_txns.read().await.current;
for vin in tx.vin.iter() {
// Find the prev txid that was spent
let prev_txid = TxId { 0: *vin.prevout.hash() };
let prev_n = vin.prevout.n() as u64;

if let Some(wtx) = current.get(&prev_txid) {
// One of the tx outputs is a match
if let Some(spent_utxo) = wtx
.utxos
.iter()
.find(|u| u.txid == prev_txid && u.output_index == prev_n)
{
info!("Spent: utxo from {} was spent in {}", prev_txid, tx.txid());
total_transparent_value_spent += spent_utxo.value;
spent_utxos.push((prev_txid, prev_n as u32, tx.txid(), height));
if let Some(t_bundle) = tx.transparent_bundle() {
for vin in t_bundle.vin.iter() {
// Find the prev txid that was spent
let prev_txid = TxId::from_bytes(*vin.prevout.hash());
let prev_n = vin.prevout.n() as u64;

if let Some(wtx) = current.get(&prev_txid) {
// One of the tx outputs is a match
if let Some(spent_utxo) = wtx
.utxos
.iter()
.find(|u| u.txid == prev_txid && u.output_index == prev_n)
{
info!("Spent: utxo from {} was spent in {}", prev_txid, tx.txid());
total_transparent_value_spent += spent_utxo.value;
spent_utxos.push((prev_txid, prev_n as u32, tx.txid(), height));
}
}
}
}
Expand Down Expand Up @@ -246,17 +250,19 @@ impl FetchFullTxns {
// because for txns in the block, we will check the nullifiers from the blockdata
if unconfirmed {
let unspent_nullifiers = wallet_txns.read().await.get_unspent_nullifiers();
for s in tx.shielded_spends.iter() {
if let Some((nf, value, txid)) = unspent_nullifiers.iter().find(|(nf, _, _)| *nf == s.nullifier) {
wallet_txns.write().await.add_new_spent(
tx.txid(),
height,
unconfirmed,
block_time,
*nf,
*value,
*txid,
);
if let Some(s_bundle) = tx.sapling_bundle() {
for s in s_bundle.shielded_spends.iter() {
if let Some((nf, value, txid)) = unspent_nullifiers.iter().find(|(nf, _, _)| *nf == s.nullifier) {
wallet_txns.write().await.add_new_spent(
tx.txid(),
height,
unconfirmed,
block_time,
*nf,
*value,
*txid,
);
}
}
}
}
Expand All @@ -281,88 +287,76 @@ impl FetchFullTxns {
// a second time by the Full Tx Fetcher
let mut outgoing_metadatas = vec![];

for output in tx.shielded_outputs.iter() {
let cmu = output.cmu;
let ct = output.enc_ciphertext;

// Search all of our keys
for (i, ivk) in ivks.iter().enumerate() {
let epk_prime = output.ephemeral_key;

let (note, to, memo_bytes) =
match try_sapling_note_decryption(&config.get_params(), height, &ivk, &epk_prime, &cmu, &ct) {
Some(ret) => ret,
None => continue,
};
if let Some(s_bundle) = tx.sapling_bundle() {
for output in s_bundle.shielded_outputs.iter() {
// Search all of our keys
for (i, ivk) in ivks.iter().enumerate() {
let (note, to, memo_bytes) =
match try_sapling_note_decryption(&config.get_params(), height, &ivk, output) {
Some(ret) => ret,
None => continue,
};

// info!("A sapling note was received into the wallet in {}", tx.txid());
if unconfirmed {
wallet_txns.write().await.add_pending_note(
tx.txid(),
height,
block_time as u64,
note.clone(),
to,
&extfvks.get(i).unwrap(),
);
}

// info!("A sapling note was received into the wallet in {}", tx.txid());
if unconfirmed {
wallet_txns.write().await.add_pending_note(
tx.txid(),
height,
block_time as u64,
note.clone(),
to,
&extfvks.get(i).unwrap(),
);
let memo = memo_bytes.clone().try_into().unwrap_or(Memo::Future(memo_bytes));
wallet_txns.write().await.add_memo_to_note(&tx.txid(), note, memo);
}

let memo = memo_bytes.clone().try_into().unwrap_or(Memo::Future(memo_bytes));
wallet_txns.write().await.add_memo_to_note(&tx.txid(), note, memo);
}

// Also scan the output to see if it can be decoded with our OutgoingViewKey
// If it can, then we sent this transaction, so we should be able to get
// the memo and value for our records

// Search all ovks that we have
let omds = ovks
.iter()
.filter_map(|ovk| {
match try_sapling_output_recovery(
&config.get_params(),
height,
&ovk,
&output.cv,
&output.cmu,
&output.ephemeral_key,
&output.enc_ciphertext,
&output.out_ciphertext,
) {
Some((note, payment_address, memo_bytes)) => {
// Mark this tx as an outgoing tx, so we can grab all outgoing metadata
is_outgoing_tx = true;

let address = encode_payment_address(config.hrp_sapling_address(), &payment_address);

// Check if this is change, and if it also doesn't have a memo, don't add
// to the outgoing metadata.
// If this is change (i.e., funds sent to ourself) AND has a memo, then
// presumably the users is writing a memo to themself, so we will add it to
// the outgoing metadata, even though it might be confusing in the UI, but hopefully
// the user can make sense of it.
match Memo::try_from(memo_bytes) {
Err(_) => None,
Ok(memo) => {
if z_addresses.contains(&address) && memo == Memo::Empty {
None
} else {
Some(OutgoingTxMetadata {
address,
value: note.value,
memo,
})
// Also scan the output to see if it can be decoded with our OutgoingViewKey
// If it can, then we sent this transaction, so we should be able to get
// the memo and value for our records

// Search all ovks that we have
let omds = ovks
.iter()
.filter_map(|ovk| {
match try_sapling_output_recovery(&config.get_params(), height, &ovk, &output) {
Some((note, payment_address, memo_bytes)) => {
// Mark this tx as an outgoing tx, so we can grab all outgoing metadata
is_outgoing_tx = true;

let address = encode_payment_address(config.hrp_sapling_address(), &payment_address);

// Check if this is change, and if it also doesn't have a memo, don't add
// to the outgoing metadata.
// If this is change (i.e., funds sent to ourself) AND has a memo, then
// presumably the users is writing a memo to themself, so we will add it to
// the outgoing metadata, even though it might be confusing in the UI, but hopefully
// the user can make sense of it.
match Memo::try_from(memo_bytes) {
Err(_) => None,
Ok(memo) => {
if z_addresses.contains(&address) && memo == Memo::Empty {
None
} else {
Some(OutgoingTxMetadata {
address,
value: note.value,
memo,
})
}
}
}
}
None => None,
}
None => None,
}
})
.collect::<Vec<_>>();
})
.collect::<Vec<_>>();

// Add it to the overall outgoing metadatas
outgoing_metadatas.extend(omds);
// Add it to the overall outgoing metadatas
outgoing_metadatas.extend(omds);
}
}

// Step 5. Process t-address outputs
Expand All @@ -373,22 +367,24 @@ impl FetchFullTxns {
}

if is_outgoing_tx {
for vout in &tx.vout {
let taddr = keys.read().await.address_from_pubkeyhash(vout.script_pubkey.address());

if taddr.is_some() && !taddrs_set.contains(taddr.as_ref().unwrap()) {
outgoing_metadatas.push(OutgoingTxMetadata {
address: taddr.unwrap(),
value: vout.value.into(),
memo: Memo::Empty,
});
if let Some(t_bundle) = tx.transparent_bundle() {
for vout in &t_bundle.vout {
let taddr = keys.read().await.address_from_pubkeyhash(vout.script_pubkey.address());

if taddr.is_some() && !taddrs_set.contains(taddr.as_ref().unwrap()) {
outgoing_metadatas.push(OutgoingTxMetadata {
address: taddr.unwrap(),
value: vout.value.into(),
memo: Memo::Empty,
});
}
}
}

// Also, if this is an outgoing transaction, then mark all the *incoming* sapling notes to this Tx as change.
// Note that this is also done in `WalletTxns::add_new_spent`, but that doesn't take into account transparent spends,
// so we'll do it again here.
wallet_txns.write().await.check_notes_mark_change(&tx.txid());
// Also, if this is an outgoing transaction, then mark all the *incoming* sapling notes to this Tx as change.
// Note that this is also done in `WalletTxns::add_new_spent`, but that doesn't take into account transparent spends,
// so we'll do it again here.
wallet_txns.write().await.check_notes_mark_change(&tx.txid());
}
}

if !outgoing_metadatas.is_empty() {
Expand Down
Loading

0 comments on commit bddbad1

Please sign in to comment.