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

Commit 6536876

Browse files
committed
v1.8.0-beta1
switch librustzcash to git directly Add orchard incoming support
1 parent 89a2bab commit 6536876

21 files changed

+1212
-338
lines changed

Cargo.lock

Lines changed: 143 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ members = [
55
]
66

77
[profile.release]
8-
debug = false
8+
debug = false
9+
10+
[patch.crates-io]
11+
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}
12+
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}
13+
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}
14+
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}
15+
zcash_encoding = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}
16+
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "09567fc280463f5797a77f1d764205be8ad8e64a"}

cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zecwallet-cli"
3-
version = "1.7.20"
3+
version = "1.8.0-beta1"
44
edition = "2018"
55

66
[dependencies]

cli/src/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub const VERSION: &str = "1.7.20";
1+
pub const VERSION: &str = "1.8.0-beta1";

lib/Cargo.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,20 @@ group = "0.12"
4848

4949
rust-embed = { version = "6.3.0", features = ["debug-embed"] }
5050

51-
zcash_primitives = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["transparent-inputs"] }
52-
# zcash_primitives = { path = "../../librustzcash/zcash_primitives", features = ["transparent-inputs"] }
53-
zcash_client_backend = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
54-
zcash_proofs = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["multicore"]}
55-
zcash_encoding = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
56-
zcash_note_encryption = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["pre-zip-212"]}
51+
orchard = "0.2.0"
52+
zcash_address = "0.1.0"
53+
zcash_primitives = { version = "0.7.0", features = ["transparent-inputs"] }
54+
zcash_client_backend = "0.5.0"
55+
zcash_proofs = { version = "0.7.1", features = ["multicore"] }
56+
zcash_encoding = "0.1.0"
57+
zcash_note_encryption = { version = "0.1.0", features = ["pre-zip-212"] }
58+
59+
60+
#zcash_primitives = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["transparent-inputs"] }
61+
#zcash_client_backend = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
62+
#zcash_proofs = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["multicore"]}
63+
#zcash_encoding = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481"}
64+
#zcash_note_encryption = { git = "https://github.com/adityapk00/librustzcash", rev = "7183acd2fe12ebf201cae5b871166e356273c481", features = ["pre-zip-212"]}
5765

5866
[dev-dependencies]
5967
portpicker = "0.1.1"

lib/proto/compact_formats.proto

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,30 @@ message CompactTx {
3737
// valueBalance + (sum(vPubNew) - sum(vPubOld) - sum(tOut))
3838
uint32 fee = 3;
3939

40-
repeated CompactSpend spends = 4; // inputs
41-
repeated CompactOutput outputs = 5; // outputs
40+
repeated CompactSaplingSpend spends = 4; // inputs
41+
repeated CompactSaplingOutput outputs = 5; // outputs
42+
repeated CompactOrchardAction actions = 6;
4243
}
4344

44-
// CompactSpend is a Sapling Spend Description as described in 7.3 of the Zcash
45+
// CompactSaplingSpend is a Sapling Spend Description as described in 7.3 of the Zcash
4546
// protocol specification.
46-
message CompactSpend {
47+
message CompactSaplingSpend {
4748
bytes nf = 1; // nullifier (see the Zcash protocol specification)
4849
}
4950

5051
// output is a Sapling Output Description as described in section 7.4 of the
5152
// Zcash protocol spec. Total size is 948.
52-
message CompactOutput {
53+
message CompactSaplingOutput {
5354
bytes cmu = 1; // note commitment u-coordinate
5455
bytes epk = 2; // ephemeral public key
55-
bytes ciphertext = 3; // ciphertext and zkproof
56+
bytes ciphertext = 3; // first 52 bytes of ciphertext
57+
}
58+
59+
// https://github.com/zcash/zips/blob/main/zip-0225.rst#orchard-action-description-orchardaction
60+
// (but not all fields are needed)
61+
message CompactOrchardAction {
62+
bytes nullifier = 1; // [32] The nullifier of the input note
63+
bytes cmx = 2; // [32] The x-coordinate of the note commitment for the output note
64+
bytes ephemeralKey = 3; // [32] An encoding of an ephemeral Pallas public key
65+
bytes ciphertext = 4; // [52] The note plaintext component of the encCiphertext field
5666
}

lib/proto/service.proto

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ message TxFilter {
3232
}
3333

3434
// RawTransaction contains the complete transaction data. It also optionally includes
35-
// the block height in which the transaction was included.
35+
// the block height in which the transaction was included, or, when returned
36+
// by GetMempoolStream(), the latest block height.
3637
message RawTransaction {
3738
bytes data = 1; // exact data returned by Zcash 'getrawtransaction'
3839
uint64 height = 2; // height that the transaction was mined (or -1)
@@ -109,11 +110,12 @@ message Exclude {
109110

110111
// The TreeState is derived from the Zcash z_gettreestate rpc.
111112
message TreeState {
112-
string network = 1; // "main" or "test"
113-
uint64 height = 2;
114-
string hash = 3; // block id
115-
uint32 time = 4; // Unix epoch time when the block was mined
116-
string tree = 5; // sapling commitment tree state
113+
string network = 1; // "main" or "test"
114+
uint64 height = 2; // block height
115+
string hash = 3; // block id
116+
uint32 time = 4; // Unix epoch time when the block was mined
117+
string tree = 5; // sapling commitment tree state
118+
string orchardTree = 6; // orchard commitment tree state
117119
}
118120

119121
// Results are sorted by height, which makes it easy to issue another
@@ -163,7 +165,7 @@ service CompactTxStreamer {
163165
rpc GetBlock(BlockID) returns (CompactBlock) {}
164166
// Return a list of consecutive compact blocks
165167
rpc GetBlockRange(BlockRange) returns (stream CompactBlock) {}
166-
168+
167169
// Get the historical and current prices
168170
rpc GetZECPrice(PriceRequest) returns (PriceResponse) {}
169171
rpc GetCurrentZECPrice(Empty) returns (PriceResponse) {}
@@ -178,7 +180,7 @@ service CompactTxStreamer {
178180

179181
// Legacy API that is used as a fallback for t-Address support, if the server is running the old version (lwdv2)
180182
rpc GetAddressTxids(TransparentAddressBlockFilter) returns (stream RawTransaction) {}
181-
183+
182184
rpc GetTaddressBalance(AddressList) returns (Balance) {}
183185
rpc GetTaddressBalanceStream(stream Address) returns (Balance) {}
184186

@@ -193,6 +195,8 @@ service CompactTxStreamer {
193195
// in the exclude list that don't exist in the mempool are ignored.
194196
rpc GetMempoolTx(Exclude) returns (stream CompactTx) {}
195197

198+
// Return a stream of current Mempool transactions. This will keep the output stream open while
199+
// there are mempool transactions. It will close the returned stream when a new block is mined.
196200
rpc GetMempoolStream(Empty) returns (stream RawTransaction) {}
197201

198202
// GetTreeState returns the note commitment tree state corresponding to the given block.

lib/src/blaze/fetch_full_tx.rs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use crate::{
99

1010
use futures::{stream::FuturesUnordered, StreamExt};
1111
use log::info;
12+
use orchard::note_encryption::OrchardDomain;
13+
use zcash_note_encryption::try_note_decryption;
14+
1215
use std::{
1316
collections::HashSet,
1417
convert::{TryFrom, TryInto},
@@ -291,9 +294,9 @@ impl<P: consensus::Parameters + Send + Sync + 'static> FetchFullTxns<P> {
291294
.collect();
292295

293296
let extfvks = Arc::new(keys.read().await.get_all_extfvks());
294-
let ivks: Vec<_> = extfvks.iter().map(|k| k.fvk.vk.ivk()).collect();
297+
let s_ivks: Vec<_> = extfvks.iter().map(|k| k.fvk.vk.ivk()).collect();
295298

296-
// Step 4: Scan shielded sapling outputs to see if anyone of them is us, and if it is, extract the memo. Note that if this
299+
// Step 4a: Scan shielded sapling outputs to see if anyone of them is us, and if it is, extract the memo. Note that if this
297300
// is invoked by a transparent transaction, and we have not seen this Tx from the trial_decryptions processor, the Note
298301
// might not exist, and the memo updating might be a No-Op. That's Ok, the memo will get updated when this Tx is scanned
299302
// a second time by the Full Tx Fetcher
@@ -302,7 +305,7 @@ impl<P: consensus::Parameters + Send + Sync + 'static> FetchFullTxns<P> {
302305
if let Some(s_bundle) = tx.sapling_bundle() {
303306
for output in s_bundle.shielded_outputs.iter() {
304307
// Search all of our keys
305-
for (i, ivk) in ivks.iter().enumerate() {
308+
for (i, ivk) in s_ivks.iter().enumerate() {
306309
let (note, to, memo_bytes) =
307310
match try_sapling_note_decryption(&config.get_params(), height, &ivk, output) {
308311
Some(ret) => ret,
@@ -322,7 +325,7 @@ impl<P: consensus::Parameters + Send + Sync + 'static> FetchFullTxns<P> {
322325
}
323326

324327
let memo = memo_bytes.clone().try_into().unwrap_or(Memo::Future(memo_bytes));
325-
wallet_txns.write().await.add_memo_to_note(&tx.txid(), note, memo);
328+
wallet_txns.write().await.add_memo_to_s_note(&tx.txid(), note, memo);
326329
}
327330

328331
// Also scan the output to see if it can be decoded with our OutgoingViewKey
@@ -371,6 +374,34 @@ impl<P: consensus::Parameters + Send + Sync + 'static> FetchFullTxns<P> {
371374
}
372375
}
373376

377+
// Step 4b: Scan the orchard part of the bundle to see if there are any memos
378+
let o_ivks = keys.read().await.get_all_orchard_ivks();
379+
if let Some(o_bundle) = tx.orchard_bundle() {
380+
// let orchard_actions = o_bundle
381+
// .actions()
382+
// .into_iter()
383+
// .map(|oa| (OrchardDomain::for_action(oa), oa))
384+
// .collect::<Vec<_>>();
385+
386+
// let decrypts = try_note_decryption(o_ivks.as_ref(), orchard_actions.as_ref());
387+
for oa in o_bundle.actions() {
388+
for (ivk_num, ivk) in o_ivks.iter().enumerate() {
389+
if let Some((note, _address, memo_bytes)) =
390+
try_note_decryption(&OrchardDomain::for_action(oa), ivk, oa)
391+
{
392+
if let Ok(memo) = Memo::from_bytes(&memo_bytes) {
393+
wallet_txns.write().await.add_memo_to_o_note(
394+
&tx.txid(),
395+
&keys.read().await.okeys[ivk_num].fvk(),
396+
note,
397+
memo,
398+
);
399+
}
400+
}
401+
}
402+
}
403+
}
404+
374405
// Step 5. Process t-address outputs
375406
// If this Tx in outgoing, i.e., we recieved sent some money in this Tx, then we need to grab all transparent outputs
376407
// that don't belong to us as the outgoing metadata

lib/src/blaze/test_utils.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{convert::TryInto, sync::Arc};
22

33
use crate::{
4-
compact_formats::{CompactBlock, CompactOutput, CompactSpend, CompactTx},
4+
compact_formats::{CompactBlock, CompactSaplingOutput, CompactSaplingSpend, CompactTx},
55
lightclient::{
66
faketx::{clone_transactiondata, new_transactiondata},
77
test_server::TestServerData,
@@ -138,12 +138,12 @@ impl FakeTransaction {
138138
let enc_ciphertext = encryptor.encrypt_note_plaintext();
139139

140140
// Create a fake CompactBlock containing the note
141-
let mut cout = CompactOutput::default();
141+
let mut cout = CompactSaplingOutput::default();
142142
cout.cmu = cmu;
143143
cout.epk = epk;
144144
cout.ciphertext = enc_ciphertext[..52].to_vec();
145145

146-
let mut sapling_bundle = if self.td.sapling_bundle.is_some() {
146+
let mut sapling_bundle = if self.td.sapling_bundle().is_some() {
147147
self.td.sapling_bundle().unwrap().clone()
148148
} else {
149149
sapling::Bundle {
@@ -156,7 +156,17 @@ impl FakeTransaction {
156156
}
157157
};
158158
sapling_bundle.shielded_outputs.push(od);
159-
self.td.sapling_bundle = Some(sapling_bundle);
159+
160+
self.td = TransactionData::from_parts(
161+
self.td.version(),
162+
self.td.consensus_branch_id(),
163+
self.td.lock_time(),
164+
self.td.expiry_height(),
165+
self.td.transparent_bundle().cloned(),
166+
self.td.sprout_bundle().cloned(),
167+
Some(sapling_bundle),
168+
self.td.orchard_bundle().cloned(),
169+
);
160170

161171
self.ctx.outputs.push(cout);
162172

@@ -166,7 +176,7 @@ impl FakeTransaction {
166176
pub fn add_tx_spending(&mut self, nf: &Nullifier, value: u64, ovk: &OutgoingViewingKey, to: &PaymentAddress) {
167177
let _ = self.add_sapling_output(value, Some(ovk.clone()), to);
168178

169-
let mut cs = CompactSpend::default();
179+
let mut cs = CompactSaplingSpend::default();
170180
cs.nf = nf.to_vec();
171181
self.ctx.spends.push(cs);
172182

@@ -206,7 +216,17 @@ impl FakeTransaction {
206216
value: Amount::from_u64(value).unwrap(),
207217
script_pubkey: TransparentAddress::PublicKey(taddr_bytes.try_into().unwrap()).script(),
208218
});
209-
self.td.transparent_bundle = Some(t_bundle);
219+
220+
self.td = TransactionData::from_parts(
221+
self.td.version(),
222+
self.td.consensus_branch_id(),
223+
self.td.lock_time(),
224+
self.td.expiry_height(),
225+
Some(t_bundle),
226+
self.td.sprout_bundle().cloned(),
227+
self.td.sapling_bundle().cloned(),
228+
self.td.orchard_bundle().cloned(),
229+
);
210230

211231
self.taddrs_involved.push(taddr)
212232
}
@@ -228,7 +248,17 @@ impl FakeTransaction {
228248
script_sig: Script { 0: vec![] },
229249
sequence: 0,
230250
});
231-
self.td.transparent_bundle = Some(t_bundle);
251+
252+
self.td = TransactionData::from_parts(
253+
self.td.version(),
254+
self.td.consensus_branch_id(),
255+
self.td.lock_time(),
256+
self.td.expiry_height(),
257+
Some(t_bundle),
258+
self.td.sprout_bundle().cloned(),
259+
self.td.sapling_bundle().cloned(),
260+
self.td.orchard_bundle().cloned(),
261+
);
232262

233263
self.taddrs_involved.push(taddr);
234264
}
@@ -289,7 +319,7 @@ impl FakeCompactBlock {
289319
};
290320

291321
// Create a fake CompactBlock containing the note
292-
let mut cout = CompactOutput::default();
322+
let mut cout = CompactSaplingOutput::default();
293323
cout.cmu = note.cmu().to_bytes().to_vec();
294324
cout.epk = [0u8; 32].to_vec();
295325
cout.ciphertext = [0u8; 52].to_vec();
@@ -349,7 +379,7 @@ impl FakeCompactBlockList {
349379

350380
if let Some(s_bundle) = tx.sapling_bundle() {
351381
for out in &s_bundle.shielded_outputs {
352-
let mut cout = CompactOutput::default();
382+
let mut cout = CompactSaplingOutput::default();
353383
cout.cmu = out.cmu.to_repr().to_vec();
354384
cout.epk = out.ephemeral_key.0.to_vec();
355385
cout.ciphertext = out.enc_ciphertext[..52].to_vec();
@@ -358,7 +388,7 @@ impl FakeCompactBlockList {
358388
}
359389

360390
for spend in &s_bundle.shielded_spends {
361-
let mut cs = CompactSpend::default();
391+
let mut cs = CompactSaplingSpend::default();
362392
cs.nf = spend.nullifier.to_vec();
363393

364394
ctx.spends.push(cs);

0 commit comments

Comments
 (0)