2021-03-05 15:25:45 -08:00
|
|
|
//! Constants used in the Orchard protocol.
|
2021-08-19 21:21:46 -07:00
|
|
|
pub mod fixed_bases;
|
|
|
|
pub mod sinsemilla;
|
|
|
|
pub mod util;
|
2021-03-18 08:38:31 -07:00
|
|
|
|
2021-08-19 21:21:46 -07:00
|
|
|
pub use fixed_bases::{NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV, H};
|
|
|
|
pub use sinsemilla::{OrchardCommitDomains, OrchardHashDomains};
|
2021-03-18 08:38:31 -07:00
|
|
|
|
2021-08-19 21:21:46 -07:00
|
|
|
/// $\mathsf{MerkleDepth^{Orchard}}$
|
2024-01-05 11:08:35 -08:00
|
|
|
pub const MERKLE_DEPTH_ORCHARD: usize = 32;
|
2021-03-05 15:25:45 -08:00
|
|
|
|
2021-06-04 23:17:43 -07:00
|
|
|
/// The Pallas scalar field modulus is $q = 2^{254} + \mathsf{t_q}$.
|
|
|
|
/// <https://github.com/zcash/pasta>
|
|
|
|
pub(crate) const T_Q: u128 = 45560315531506369815346746415080538113;
|
|
|
|
|
|
|
|
/// The Pallas base field modulus is $p = 2^{254} + \mathsf{t_p}$.
|
|
|
|
/// <https://github.com/zcash/pasta>
|
|
|
|
pub(crate) const T_P: u128 = 45560315531419706090280762371685220353;
|
|
|
|
|
2021-03-15 13:33:07 -07:00
|
|
|
/// $\ell^\mathsf{Orchard}_\mathsf{base}$
|
|
|
|
pub(crate) const L_ORCHARD_BASE: usize = 255;
|
2021-03-18 08:38:18 -07:00
|
|
|
|
2021-06-04 22:14:29 -07:00
|
|
|
/// $\ell^\mathsf{Orchard}_\mathsf{scalar}$
|
|
|
|
pub(crate) const L_ORCHARD_SCALAR: usize = 255;
|
|
|
|
|
2021-03-24 04:46:34 -07:00
|
|
|
/// $\ell_\mathsf{value}$
|
|
|
|
pub(crate) const L_VALUE: usize = 64;
|
|
|
|
|
2021-03-18 08:38:18 -07:00
|
|
|
/// SWU hash-to-curve personalization for the group hash for key diversification
|
|
|
|
pub const KEY_DIVERSIFICATION_PERSONALIZATION: &str = "z.cash:Orchard-gd";
|
|
|
|
|
2021-06-09 19:31:47 -07:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use ff::PrimeField;
|
2023-02-28 14:21:37 -08:00
|
|
|
use pasta_curves::pallas;
|
2021-06-09 19:31:47 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
// Orchard uses the Pallas base field as its base field.
|
|
|
|
fn l_orchard_base() {
|
|
|
|
assert_eq!(super::L_ORCHARD_BASE, pallas::Base::NUM_BITS as usize);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
// Orchard uses the Pallas base field as its base field.
|
|
|
|
fn l_orchard_scalar() {
|
|
|
|
assert_eq!(super::L_ORCHARD_SCALAR, pallas::Scalar::NUM_BITS as usize);
|
|
|
|
}
|
2021-06-14 22:37:12 -07:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn t_q() {
|
|
|
|
let t_q = pallas::Scalar::from_u128(super::T_Q);
|
|
|
|
let two_pow_254 = pallas::Scalar::from_u128(1 << 127).square();
|
|
|
|
assert_eq!(t_q + two_pow_254, pallas::Scalar::zero());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn t_p() {
|
|
|
|
let t_p = pallas::Base::from_u128(super::T_P);
|
|
|
|
let two_pow_254 = pallas::Base::from_u128(1 << 127).square();
|
|
|
|
assert_eq!(t_p + two_pow_254, pallas::Base::zero());
|
|
|
|
}
|
2021-06-09 19:31:47 -07:00
|
|
|
}
|