Skip to content

Commit

Permalink
Merge pull request #413 from zcash/zcash_spec-0.1
Browse files Browse the repository at this point in the history
Migrate to `zcash_spec 0.1`
  • Loading branch information
str4d authored Jan 11, 2024
2 parents 9a85034 + 4b09ef6 commit d5fa3e1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 87 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ serde = { version = "1.0", features = ["derive"] }
subtle = "2.3"
zcash_note_encryption = "0.4"
incrementalmerkletree = "0.5"
zcash_spec = "0.1"

# Logging
tracing = "0.1"
Expand Down
10 changes: 5 additions & 5 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct SpendAuthorizingKey(redpallas::SigningKey<SpendAuth>);
impl SpendAuthorizingKey {
/// Derives ask from sk. Internal use only, does not enforce all constraints.
fn derive_inner(sk: &SpendingKey) -> pallas::Scalar {
to_scalar(PrfExpand::OrchardAsk.expand(&sk.0))
to_scalar(PrfExpand::ORCHARD_ASK.with(&sk.0))
}

/// Randomizes this spend authorizing key with the given `randomizer`.
Expand Down Expand Up @@ -222,7 +222,7 @@ impl NullifierDerivingKey {

impl From<&SpendingKey> for NullifierDerivingKey {
fn from(sk: &SpendingKey) -> Self {
NullifierDerivingKey(to_base(PrfExpand::OrchardNk.expand(&sk.0)))
NullifierDerivingKey(to_base(PrfExpand::ORCHARD_NK.with(&sk.0)))
}
}

Expand Down Expand Up @@ -257,7 +257,7 @@ pub(crate) struct CommitIvkRandomness(pallas::Scalar);

impl From<&SpendingKey> for CommitIvkRandomness {
fn from(sk: &SpendingKey) -> Self {
CommitIvkRandomness(to_scalar(PrfExpand::OrchardRivk.expand(&sk.0)))
CommitIvkRandomness(to_scalar(PrfExpand::ORCHARD_RIVK.with(&sk.0)))
}
}

Expand Down Expand Up @@ -351,7 +351,7 @@ impl FullViewingKey {
let ak = self.ak.to_bytes();
let nk = self.nk.to_bytes();
CommitIvkRandomness(to_scalar(
PrfExpand::OrchardRivkInternal.with_ad_slices(&k, &[&ak, &nk]),
PrfExpand::ORCHARD_RIVK_INTERNAL.with(&k, &ak, &nk),
))
}
}
Expand All @@ -363,7 +363,7 @@ impl FullViewingKey {
fn derive_dk_ovk(&self) -> (DiversifierKey, OutgoingViewingKey) {
let k = self.rivk.0.to_repr();
let b = [(&self.ak.0).into(), self.nk.0.to_repr()];
let r = PrfExpand::OrchardDkOvk.with_ad_slices(&k, &[&b[0][..], &b[1][..]]);
let r = PrfExpand::ORCHARD_DK_OVK.with(&k, &b[0], &b[1]);
(
DiversifierKey(r[..32].try_into().unwrap()),
OutgoingViewingKey(r[32..].try_into().unwrap()),
Expand Down
6 changes: 3 additions & 3 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ impl RandomSeed {
///
/// [orchardsend]: https://zips.z.cash/protocol/nu5.pdf#orchardsend
pub(crate) fn psi(&self, rho: &Nullifier) -> pallas::Base {
to_base(PrfExpand::Psi.with_ad(&self.0, &rho.to_bytes()[..]))
to_base(PrfExpand::PSI.with(&self.0, &rho.to_bytes()))
}

/// Defined in [Zcash Protocol Spec § 4.7.3: Sending Notes (Orchard)][orchardsend].
///
/// [orchardsend]: https://zips.z.cash/protocol/nu5.pdf#orchardsend
fn esk_inner(&self, rho: &Nullifier) -> CtOption<NonZeroPallasScalar> {
NonZeroPallasScalar::from_scalar(to_scalar(
PrfExpand::Esk.with_ad(&self.0, &rho.to_bytes()[..]),
PrfExpand::ORCHARD_ESK.with(&self.0, &rho.to_bytes()),
))
}

Expand All @@ -78,7 +78,7 @@ impl RandomSeed {
/// [orchardsend]: https://zips.z.cash/protocol/nu5.pdf#orchardsend
pub(crate) fn rcm(&self, rho: &Nullifier) -> commitment::NoteCommitTrapdoor {
commitment::NoteCommitTrapdoor(to_scalar(
PrfExpand::Rcm.with_ad(&self.0, &rho.to_bytes()[..]),
PrfExpand::ORCHARD_RCM.with(&self.0, &rho.to_bytes()),
))
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use crate::constants::{
KEY_DIVERSIFICATION_PERSONALIZATION, L_ORCHARD_BASE,
};

mod prf_expand;
pub(crate) use prf_expand::PrfExpand;
pub(crate) use zcash_spec::PrfExpand;

/// A Pallas point that is guaranteed to not be the identity.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
75 changes: 0 additions & 75 deletions src/spec/prf_expand.rs

This file was deleted.

5 changes: 3 additions & 2 deletions src/zip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ impl ExtendedSpendingKey {
/// Discards index if it results in an invalid sk
fn derive_child(&self, index: ChildIndex) -> Result<Self, Error> {
// I := PRF^Expand(c_par, [0x81] || sk_par || I2LEOSP(i))
let I: [u8; 64] = PrfExpand::OrchardZip32Child.with_ad_slices(
let I: [u8; 64] = PrfExpand::ORCHARD_ZIP32_CHILD.with(
&self.chain_code.0,
&[self.sk.to_bytes(), &index.0.to_le_bytes()],
self.sk.to_bytes(),
&index.0.to_le_bytes(),
);

// I_L is used as the child spending key sk_i.
Expand Down

0 comments on commit d5fa3e1

Please sign in to comment.