Skip to content

Commit

Permalink
zcash_client_sqlite: Update to make use of orchard::note::Rho
Browse files Browse the repository at this point in the history
nuttycom committed Mar 12, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 3dcac7a commit 0c5a365
Showing 6 changed files with 21 additions and 32 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -120,3 +120,6 @@ zip32 = "0.1"
lto = true
panic = 'abort'
codegen-units = 1

[patch.crates-io]
orchard = { git = "https://github.com/zcash/orchard", rev = "e74879dd0ad0918f4ffe0826e03905cd819981bd" }
2 changes: 1 addition & 1 deletion zcash_client_backend/src/decrypt.rs
Original file line number Diff line number Diff line change
@@ -185,7 +185,7 @@ pub fn decrypt_transaction<'a, P: consensus::Parameters, AccountId: Copy>(
.iter()
.enumerate()
.flat_map(move |(index, action)| {
let domain = OrchardDomain::for_nullifier(*action.nullifier());
let domain = OrchardDomain::for_action(action);
let account = account;
try_note_decryption(&domain, &ivk_external, action)
.map(|ret| (ret, TransferType::Incoming))
4 changes: 2 additions & 2 deletions zcash_client_backend/src/scanning.rs
Original file line number Diff line number Diff line change
@@ -624,7 +624,7 @@ where
self.orchard.add_outputs(
block_hash,
txid,
|action| OrchardDomain::for_nullifier(action.nullifier()),
|action| OrchardDomain::for_compact_action(action),

Check warning on line 627 in zcash_client_backend/src/scanning.rs

Codecov / codecov/patch

zcash_client_backend/src/scanning.rs#L627

Added line #L627 was not covered by tests
&tx.actions
.iter()
.enumerate()
@@ -888,7 +888,7 @@ where
index: i,
}
})?;
Ok((OrchardDomain::for_nullifier(action.nullifier()), action))
Ok((OrchardDomain::for_compact_action(&action), action))

Check warning on line 891 in zcash_client_backend/src/scanning.rs

Codecov / codecov/patch

zcash_client_backend/src/scanning.rs#L891

Added line #L891 was not covered by tests
})
.collect::<Result<Vec<_>, _>>()?,
batch_runners
37 changes: 12 additions & 25 deletions zcash_client_sqlite/src/testing.rs
Original file line number Diff line number Diff line change
@@ -77,7 +77,6 @@ use super::BlockDb;
#[cfg(feature = "orchard")]
use {
group::ff::{Field, PrimeField},
orchard::note_encryption::{OrchardDomain, OrchardNoteEncryption},
pasta_curves::pallas,
zcash_client_backend::proto::compact_formats::CompactOrchardAction,
};
@@ -1095,40 +1094,28 @@ fn compact_sapling_output<P: consensus::Parameters, R: RngCore + CryptoRng>(
/// Returns the `CompactOrchardAction` and the new note.
#[cfg(feature = "orchard")]
fn compact_orchard_action<R: RngCore + CryptoRng>(
nullifier: orchard::note::Nullifier,
nf_old: orchard::note::Nullifier,
recipient: orchard::Address,
value: NonNegativeAmount,
ovk: Option<orchard::keys::OutgoingViewingKey>,
rng: &mut R,
) -> (CompactOrchardAction, orchard::Note) {
let rseed = {
loop {
let mut bytes = [0; 32];
rng.fill_bytes(&mut bytes);
let rseed = orchard::note::RandomSeed::from_bytes(bytes, &nullifier);
if rseed.is_some().into() {
break rseed.unwrap();
}
}
};
let note = orchard::Note::from_parts(
use zcash_note_encryption::ShieldedOutput;

let (compact_action, note) = orchard::note_encryption::testing::fake_compact_action(
rng,
nf_old,

Check warning on line 1107 in zcash_client_sqlite/src/testing.rs

Codecov / codecov/patch

zcash_client_sqlite/src/testing.rs#L1106-L1107

Added lines #L1106 - L1107 were not covered by tests
recipient,
orchard::value::NoteValue::from_raw(value.into_u64()),
nullifier,
rseed,
)
.unwrap();
let encryptor = OrchardNoteEncryption::new(ovk, note, *MemoBytes::empty().as_array());
let cmx = orchard::note::ExtractedNoteCommitment::from(note.commitment());
let ephemeral_key = OrchardDomain::epk_bytes(encryptor.epk()).0.to_vec();
let enc_ciphertext = encryptor.encrypt_note_plaintext();
ovk,

Check warning on line 1110 in zcash_client_sqlite/src/testing.rs

Codecov / codecov/patch

zcash_client_sqlite/src/testing.rs#L1110

Added line #L1110 was not covered by tests
);

(
CompactOrchardAction {
nullifier: nullifier.to_bytes().to_vec(),
cmx: cmx.to_bytes().to_vec(),
ephemeral_key,
ciphertext: enc_ciphertext.as_ref()[..52].to_vec(),
nullifier: compact_action.nullifier().to_bytes().to_vec(),
cmx: compact_action.cmx().to_bytes().to_vec(),
ephemeral_key: compact_action.ephemeral_key().0.to_vec(),
ciphertext: compact_action.enc_ciphertext().as_ref()[..52].to_vec(),

Check warning on line 1118 in zcash_client_sqlite/src/testing.rs

Codecov / codecov/patch

zcash_client_sqlite/src/testing.rs#L1115-L1118

Added lines #L1115 - L1118 were not covered by tests
},
note,
)
4 changes: 2 additions & 2 deletions zcash_client_sqlite/src/wallet/orchard.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use incrementalmerkletree::Position;
use orchard::{
keys::Diversifier,
note::{Note, Nullifier, RandomSeed},
note::{Note, Nullifier, RandomSeed, Rho},
};
use rusqlite::{named_params, params, Connection, Row};

@@ -121,7 +121,7 @@ fn to_spendable_note<P: consensus::Parameters>(

let rho = {
let rho_bytes: [u8; 32] = row.get(5)?;
Option::from(Nullifier::from_bytes(&rho_bytes))
Option::from(Rho::from_bytes(&rho_bytes))

Check warning on line 124 in zcash_client_sqlite/src/wallet/orchard.rs

Codecov / codecov/patch

zcash_client_sqlite/src/wallet/orchard.rs#L124

Added line #L124 was not covered by tests
.ok_or_else(|| SqliteClientError::CorruptedData("Invalid rho.".to_string()))
}?;

0 comments on commit 0c5a365

Please sign in to comment.