mirror of https://github.com/zcash/orchard.git
Store anchors as pallas::Base instead of [u8; 32]
This matches what we store in `MerklePath`, and better enforces the required type.
This commit is contained in:
parent
769be6c080
commit
de78186503
|
@ -594,6 +594,7 @@ pub mod testing {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use pasta_curves::pallas;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
|
|
||||||
use super::Builder;
|
use super::Builder;
|
||||||
|
@ -601,7 +602,6 @@ mod tests {
|
||||||
bundle::{Authorized, Bundle, Flags},
|
bundle::{Authorized, Bundle, Flags},
|
||||||
circuit::ProvingKey,
|
circuit::ProvingKey,
|
||||||
keys::{FullViewingKey, SpendingKey},
|
keys::{FullViewingKey, SpendingKey},
|
||||||
tree::Anchor,
|
|
||||||
value::NoteValue,
|
value::NoteValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -614,7 +614,7 @@ mod tests {
|
||||||
let fvk = FullViewingKey::from(&sk);
|
let fvk = FullViewingKey::from(&sk);
|
||||||
let recipient = fvk.default_address();
|
let recipient = fvk.default_address();
|
||||||
|
|
||||||
let mut builder = Builder::new(Flags::from_parts(true, true), Anchor([0; 32]));
|
let mut builder = Builder::new(Flags::from_parts(true, true), pallas::Base::zero().into());
|
||||||
builder
|
builder
|
||||||
.add_recipient(None, recipient, NoteValue::from_raw(5000), None)
|
.add_recipient(None, recipient, NoteValue::from_raw(5000), None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -355,6 +355,7 @@ pub struct BundleAuthorizingCommitment;
|
||||||
#[cfg(any(test, feature = "test-dependencies"))]
|
#[cfg(any(test, feature = "test-dependencies"))]
|
||||||
pub mod testing {
|
pub mod testing {
|
||||||
use nonempty::NonEmpty;
|
use nonempty::NonEmpty;
|
||||||
|
use pasta_curves::{arithmetic::FieldExt, pallas};
|
||||||
use rand::{rngs::StdRng, SeedableRng};
|
use rand::{rngs::StdRng, SeedableRng};
|
||||||
use reddsa::orchard::SpendAuth;
|
use reddsa::orchard::SpendAuth;
|
||||||
|
|
||||||
|
@ -511,6 +512,15 @@ pub mod testing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prop_compose! {
|
||||||
|
fn arb_base()(bytes in prop::array::uniform32(0u8..)) -> pallas::Base {
|
||||||
|
// Instead of rejecting out-of-range bytes, let's reduce them.
|
||||||
|
let mut buf = [0; 64];
|
||||||
|
buf[..32].copy_from_slice(&bytes);
|
||||||
|
pallas::Base::from_bytes_wide(&buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
prop_compose! {
|
prop_compose! {
|
||||||
/// Generate an arbitrary unauthorized bundle. This bundle does not
|
/// Generate an arbitrary unauthorized bundle. This bundle does not
|
||||||
/// necessarily respect consensus rules; for that use
|
/// necessarily respect consensus rules; for that use
|
||||||
|
@ -522,7 +532,7 @@ pub mod testing {
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
acts in vec(arb_unauthorized_action_n(n_actions, flags), n_actions),
|
acts in vec(arb_unauthorized_action_n(n_actions, flags), n_actions),
|
||||||
anchor in prop::array::uniform32(prop::num::u8::ANY).prop_map(Anchor),
|
anchor in arb_base().prop_map(Anchor::from),
|
||||||
flags in Just(flags)
|
flags in Just(flags)
|
||||||
) -> Bundle<Unauthorized, ValueSum> {
|
) -> Bundle<Unauthorized, ValueSum> {
|
||||||
let (balances, actions): (Vec<ValueSum>, Vec<Action<_>>) = acts.into_iter().unzip();
|
let (balances, actions): (Vec<ValueSum>, Vec<Action<_>>) = acts.into_iter().unzip();
|
||||||
|
@ -548,7 +558,7 @@ pub mod testing {
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
acts in vec(arb_action_n(n_actions, flags), n_actions),
|
acts in vec(arb_action_n(n_actions, flags), n_actions),
|
||||||
anchor in prop::array::uniform32(prop::num::u8::ANY).prop_map(Anchor),
|
anchor in arb_base().prop_map(Anchor::from),
|
||||||
sk in arb_binding_signing_key(),
|
sk in arb_binding_signing_key(),
|
||||||
rng_seed in prop::array::uniform32(prop::num::u8::ANY),
|
rng_seed in prop::array::uniform32(prop::num::u8::ANY),
|
||||||
fake_proof in vec(prop::num::u8::ANY, 1973),
|
fake_proof in vec(prop::num::u8::ANY, 1973),
|
||||||
|
|
|
@ -182,7 +182,6 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
keys::SpendValidatingKey,
|
keys::SpendValidatingKey,
|
||||||
note::Note,
|
note::Note,
|
||||||
tree::Anchor,
|
|
||||||
value::{ValueCommitTrapdoor, ValueCommitment},
|
value::{ValueCommitTrapdoor, ValueCommitment},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -208,7 +207,7 @@ mod tests {
|
||||||
(
|
(
|
||||||
Circuit {},
|
Circuit {},
|
||||||
Instance {
|
Instance {
|
||||||
anchor: Anchor([0; 32]),
|
anchor: pallas::Base::zero().into(),
|
||||||
cv_net,
|
cv_net,
|
||||||
nf_old,
|
nf_old,
|
||||||
rk,
|
rk,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
note::commitment::ExtractedNoteCommitment,
|
note::commitment::ExtractedNoteCommitment,
|
||||||
primitives::sinsemilla::{i2lebsp_k, HashDomain},
|
primitives::sinsemilla::{i2lebsp_k, HashDomain},
|
||||||
};
|
};
|
||||||
use pasta_curves::{arithmetic::FieldExt, pallas};
|
use pasta_curves::pallas;
|
||||||
|
|
||||||
use ff::{Field, PrimeFieldBits};
|
use ff::{Field, PrimeFieldBits};
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
|
@ -13,11 +13,11 @@ use std::iter;
|
||||||
|
|
||||||
/// The root of an Orchard commitment tree.
|
/// The root of an Orchard commitment tree.
|
||||||
#[derive(Eq, PartialEq, Clone, Debug)]
|
#[derive(Eq, PartialEq, Clone, Debug)]
|
||||||
pub struct Anchor(pub [u8; 32]);
|
pub struct Anchor(pallas::Base);
|
||||||
|
|
||||||
impl From<pallas::Base> for Anchor {
|
impl From<pallas::Base> for Anchor {
|
||||||
fn from(anchor_field: pallas::Base) -> Anchor {
|
fn from(anchor_field: pallas::Base) -> Anchor {
|
||||||
Anchor(anchor_field.to_bytes())
|
Anchor(anchor_field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ impl MerklePath {
|
||||||
let swap = self.position & (1 << l_star) != 0;
|
let swap = self.position & (1 << l_star) != 0;
|
||||||
hash_layer(l_star, cond_swap(swap, node, *sibling))
|
hash_layer(l_star, cond_swap(swap, node, *sibling))
|
||||||
});
|
});
|
||||||
Anchor(node.to_bytes())
|
Anchor(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the position of the leaf using this Merkle path.
|
/// Returns the position of the leaf using this Merkle path.
|
||||||
|
|
Loading…
Reference in New Issue