Orchard: tidy
This commit is contained in:
parent
1c903cab0f
commit
f3501333b7
|
@ -74,7 +74,9 @@ fn prf_expand(sk: [u8; 32], t: Vec<&[u8]>) -> [u8; 64] {
|
||||||
|
|
||||||
state.update(&sk[..]);
|
state.update(&sk[..]);
|
||||||
|
|
||||||
t.iter().map(|t_i| state.update(t_i));
|
for t_i in t {
|
||||||
|
state.update(t_i);
|
||||||
|
}
|
||||||
|
|
||||||
*state.finalize().as_array()
|
*state.finalize().as_array()
|
||||||
}
|
}
|
||||||
|
@ -370,14 +372,6 @@ impl fmt::Debug for NullifierDerivingKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<[u8; 32]> for NullifierDerivingKey {
|
|
||||||
fn from(bytes: [u8; 32]) -> Self {
|
|
||||||
Self(pallas::Base::from_bytes(&bytes).unwrap())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for NullifierDerivingKey {}
|
|
||||||
|
|
||||||
impl From<NullifierDerivingKey> for [u8; 32] {
|
impl From<NullifierDerivingKey> for [u8; 32] {
|
||||||
fn from(nk: NullifierDerivingKey) -> [u8; 32] {
|
fn from(nk: NullifierDerivingKey) -> [u8; 32] {
|
||||||
nk.0.to_bytes()
|
nk.0.to_bytes()
|
||||||
|
@ -390,6 +384,18 @@ impl From<&NullifierDerivingKey> for [u8; 32] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<NullifierDerivingKey> for pallas::Base {
|
||||||
|
fn from(nk: NullifierDerivingKey) -> pallas::Base {
|
||||||
|
nk.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<[u8; 32]> for NullifierDerivingKey {
|
||||||
|
fn from(bytes: [u8; 32]) -> Self {
|
||||||
|
Self(pallas::Base::from_bytes(&bytes).unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<SpendingKey> for NullifierDerivingKey {
|
impl From<SpendingKey> for NullifierDerivingKey {
|
||||||
/// nk = ToBase^Orchard(PRF^expand_sk ([7]))
|
/// nk = ToBase^Orchard(PRF^expand_sk ([7]))
|
||||||
///
|
///
|
||||||
|
@ -402,6 +408,8 @@ impl From<SpendingKey> for NullifierDerivingKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Eq for NullifierDerivingKey {}
|
||||||
|
|
||||||
impl PartialEq<[u8; 32]> for NullifierDerivingKey {
|
impl PartialEq<[u8; 32]> for NullifierDerivingKey {
|
||||||
fn eq(&self, other: &[u8; 32]) -> bool {
|
fn eq(&self, other: &[u8; 32]) -> bool {
|
||||||
<[u8; 32]>::from(*self) == *other
|
<[u8; 32]>::from(*self) == *other
|
||||||
|
@ -501,7 +509,7 @@ impl fmt::Display for IncomingViewingKey {
|
||||||
|
|
||||||
impl From<[u8; 32]> for IncomingViewingKey {
|
impl From<[u8; 32]> for IncomingViewingKey {
|
||||||
/// Generate an _IncomingViewingKey_ from existing bytes.
|
/// Generate an _IncomingViewingKey_ from existing bytes.
|
||||||
fn from(mut bytes: [u8; 32]) -> Self {
|
fn from(bytes: [u8; 32]) -> Self {
|
||||||
Self {
|
Self {
|
||||||
// TODO: handle setting the Network better.
|
// TODO: handle setting the Network better.
|
||||||
network: Network::default(),
|
network: Network::default(),
|
||||||
|
@ -663,9 +671,13 @@ impl FullViewingKey {
|
||||||
// let K = I2LEBSP_l_sk(rivk)
|
// let K = I2LEBSP_l_sk(rivk)
|
||||||
let K: [u8; 32] = self.ivk_commit_randomness.into();
|
let K: [u8; 32] = self.ivk_commit_randomness.into();
|
||||||
|
|
||||||
let t: Vec<&[u8]> = vec![&[0x82u8]];
|
let mut t: Vec<&[u8]> = vec![&[0x82u8]];
|
||||||
t.push(&<[u8; 32]>::from(self.spend_validating_key));
|
|
||||||
t.push(&<[u8; 32]>::from(self.nullifier_deriving_key));
|
let ak_bytes = <[u8; 32]>::from(self.spend_validating_key);
|
||||||
|
t.push(&ak_bytes);
|
||||||
|
|
||||||
|
let nk_bytes = <[u8; 32]>::from(self.nullifier_deriving_key);
|
||||||
|
t.push(&nk_bytes);
|
||||||
|
|
||||||
// let R = PRF^expand_K( [0x82] || I2LEOSP256(ak) || I2LEOSP256(nk) )
|
// let R = PRF^expand_K( [0x82] || I2LEOSP256(ak) || I2LEOSP256(nk) )
|
||||||
prf_expand(K, t)
|
prf_expand(K, t)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use group::GroupEncoding;
|
use group::GroupEncoding;
|
||||||
use halo2::pasta::pallas;
|
use halo2::{arithmetic::FieldExt, pasta::pallas};
|
||||||
|
|
||||||
use super::super::{
|
use super::super::{
|
||||||
commitment::NoteCommitment, keys::NullifierDerivingKey, sinsemilla::*, tree::Position,
|
commitment::NoteCommitment, keys::NullifierDerivingKey, sinsemilla::*, tree::Position,
|
||||||
|
@ -28,7 +28,7 @@ pub fn mixing_pedersen_hash(P: pallas::Point, x: pallas::Scalar) -> pallas::Poin
|
||||||
/// PoseidonHash(x, y) = f([x, y, 0])_1 (using 1-based indexing).
|
/// PoseidonHash(x, y) = f([x, y, 0])_1 (using 1-based indexing).
|
||||||
///
|
///
|
||||||
/// [poseidonhash]: https://zips.z.cash/protocol/nu5.pdf#poseidonhash
|
/// [poseidonhash]: https://zips.z.cash/protocol/nu5.pdf#poseidonhash
|
||||||
fn poseidon_hash(x: pallas::Base, y: pallas::Base) -> pallas::Base {
|
fn poseidon_hash(_x: pallas::Base, _y: pallas::Base) -> pallas::Base {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,12 @@ fn poseidon_hash(x: pallas::Base, y: pallas::Base) -> pallas::Base {
|
||||||
///
|
///
|
||||||
/// [concreteprfs]: https://zips.z.cash/protocol/protocol.pdf#concreteprfs
|
/// [concreteprfs]: https://zips.z.cash/protocol/protocol.pdf#concreteprfs
|
||||||
/// [poseidonhash]: https://zips.z.cash/protocol/nu5.pdf#poseidonhash
|
/// [poseidonhash]: https://zips.z.cash/protocol/nu5.pdf#poseidonhash
|
||||||
fn prf_nf(nk: [u8; 32], rho: [u8; 32]) -> [u8; 32] {
|
fn prf_nf(nk_bytes: [u8; 32], rho_bytes: [u8; 32]) -> [u8; 32] {
|
||||||
poseidon_hash(nk.into(), rho.into()).into()
|
poseidon_hash(
|
||||||
|
pallas::Base::from_bytes(&nk_bytes).unwrap(),
|
||||||
|
pallas::Base::from_bytes(&rho_bytes).unwrap(),
|
||||||
|
)
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Nullifier for Orchard transactions
|
/// A Nullifier for Orchard transactions
|
||||||
|
|
Loading…
Reference in New Issue