Skip to content

Commit

Permalink
Merge pull request #1264 from nuttycom/orchard_rho
Browse files Browse the repository at this point in the history
zcash_client_sqlite: Update to make use of `orchard::note::Rho`
  • Loading branch information
nuttycom authored Mar 13, 2024
2 parents 3dcac7a + 0c5a365 commit a788fc9
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions zcash_client_backend/src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ where
self.orchard.add_outputs(
block_hash,
txid,
|action| OrchardDomain::for_nullifier(action.nullifier()),
|action| OrchardDomain::for_compact_action(action),
&tx.actions
.iter()
.enumerate()
Expand Down Expand Up @@ -888,7 +888,7 @@ where
index: i,
}
})?;
Ok((OrchardDomain::for_nullifier(action.nullifier()), action))
Ok((OrchardDomain::for_compact_action(&action), action))
})
.collect::<Result<Vec<_>, _>>()?,
batch_runners
Expand Down
37 changes: 12 additions & 25 deletions zcash_client_sqlite/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
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,
);

(
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(),
},
note,
)
Expand Down
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};

Expand Down Expand Up @@ -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))
.ok_or_else(|| SqliteClientError::CorruptedData("Invalid rho.".to_string()))
}?;

Expand Down

0 comments on commit a788fc9

Please sign in to comment.