mirror of https://github.com/zcash/orchard.git
Add constants for short signed scalar mul
This commit is contained in:
parent
137ebf4a5a
commit
6cc957e998
|
@ -44,12 +44,16 @@ pub const MERKLE_CRH_PERSONALIZATION: &str = "z.cash:Orchard-MerkleCRH";
|
|||
/// Window size for fixed-base scalar multiplication
|
||||
pub const FIXED_BASE_WINDOW_SIZE: usize = 3;
|
||||
|
||||
/// 2^{FIXED_BASE_WINDOW_SIZE}
|
||||
/// $2^{`FIXED_BASE_WINDOW_SIZE`}$
|
||||
pub const H: usize = 1 << FIXED_BASE_WINDOW_SIZE;
|
||||
|
||||
/// Number of windows
|
||||
/// Number of windows for a full-width scalar
|
||||
pub const NUM_WINDOWS: usize = pallas::Base::NUM_BITS as usize / FIXED_BASE_WINDOW_SIZE;
|
||||
|
||||
/// Number of windows for a short signed scalar
|
||||
pub const NUM_WINDOWS_SHORT: usize =
|
||||
(L_VALUE + FIXED_BASE_WINDOW_SIZE - 1) / FIXED_BASE_WINDOW_SIZE;
|
||||
|
||||
/// Number of bits used in complete addition (for variable-base scalar mul)
|
||||
pub const NUM_COMPLETE_BITS: usize = 3;
|
||||
|
||||
|
@ -109,28 +113,27 @@ impl<C: CurveAffine> OrchardFixedBase<C> {
|
|||
|
||||
pub trait FixedBase<C: CurveAffine> {
|
||||
/// For each fixed base, we calculate its scalar multiples in three-bit windows.
|
||||
/// Each window will have 2^3 = 8 points.
|
||||
fn compute_window_table(&self) -> Vec<[C; H]>;
|
||||
/// Each window will have $2^3 = 8$ points.
|
||||
fn compute_window_table(&self, num_windows: usize) -> Vec<[C; H]>;
|
||||
|
||||
/// For each window, we interpolate the x-coordinate.
|
||||
/// For each window, we interpolate the $x$-coordinate.
|
||||
/// Here, we pre-compute and store the coefficients of the interpolation polynomial.
|
||||
fn compute_lagrange_coeffs(&self) -> Vec<[C::Base; H]>;
|
||||
fn compute_lagrange_coeffs(&self, num_windows: usize) -> Vec<[C::Base; H]>;
|
||||
|
||||
/// For each window, z is a field element
|
||||
/// such that for each point (x, y) in the window:
|
||||
/// - z + y = u^2 (some square in the field); and
|
||||
/// - z - y is not a square.
|
||||
fn find_zs(&self) -> Option<Vec<u64>>;
|
||||
/// For each window, $z$ is a field element such that for each point $(x, y)$ in the window:
|
||||
/// - $z + y = u^2$ (some square in the field); and
|
||||
/// - $z - y$ is not a square.
|
||||
fn find_zs(&self, num_windows: usize) -> Option<Vec<u64>>;
|
||||
}
|
||||
|
||||
impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
||||
fn compute_window_table(&self) -> Vec<[C; H]> {
|
||||
let mut window_table: Vec<[C; H]> = Vec::with_capacity(NUM_WINDOWS);
|
||||
fn compute_window_table(&self, num_windows: usize) -> Vec<[C; H]> {
|
||||
let mut window_table: Vec<[C; H]> = Vec::with_capacity(num_windows);
|
||||
|
||||
// Generate window table entries for all windows but the last.
|
||||
// For these first 84 windows, we compute the multiple [(k+1)*(8^w)]B.
|
||||
// Here, w ranges from [0..84)
|
||||
for w in 0..(NUM_WINDOWS - 1) {
|
||||
// For these first `num_windows - 1` windows, we compute the multiple $[(k+1)*(8^w)]B.
|
||||
// Here, w ranges from [0..`num_windows - 1`)
|
||||
for w in 0..(num_windows - 1) {
|
||||
window_table.push(
|
||||
(0..H)
|
||||
.map(|k| {
|
||||
|
@ -147,19 +150,19 @@ impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
|||
);
|
||||
}
|
||||
|
||||
// Generate window table entries for the last window, w = 84.
|
||||
// Generate window table entries for the last window, w = `num_windows - 1`.
|
||||
// For the last window, we compute [k * (8^w) - sum]B, where sum is defined
|
||||
// as sum = \sum_{j = 0}^{83} 8^j
|
||||
let sum = (0..(NUM_WINDOWS - 1)).fold(C::ScalarExt::zero(), |acc, w| {
|
||||
// as sum = \sum_{j = 0}^{`num_windows - 2`} 8^j
|
||||
let sum = (0..(num_windows - 1)).fold(C::ScalarExt::zero(), |acc, w| {
|
||||
acc + C::ScalarExt::from_u64(H as u64).pow(&[w as u64, 0, 0, 0])
|
||||
});
|
||||
window_table.push(
|
||||
(0..H)
|
||||
.map(|k| {
|
||||
// scalar = k * (8^w) - sum, where w = 84
|
||||
// scalar = k * (8^w) - sum, where w = `num_windows - 1`
|
||||
let scalar = C::ScalarExt::from_u64(k as u64)
|
||||
* C::ScalarExt::from_u64(H as u64).pow(&[
|
||||
(NUM_WINDOWS - 1) as u64,
|
||||
(num_windows - 1) as u64,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -177,11 +180,11 @@ impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
|||
window_table
|
||||
}
|
||||
|
||||
fn compute_lagrange_coeffs(&self) -> Vec<[C::Base; 8]> {
|
||||
fn compute_lagrange_coeffs(&self, num_windows: usize) -> Vec<[C::Base; 8]> {
|
||||
// We are interpolating over the 3-bit window, k \in [0..8)
|
||||
let points: Vec<_> = (0..H).map(|i| C::Base::from_u64(i as u64)).collect();
|
||||
|
||||
let window_table = self.compute_window_table();
|
||||
let window_table = self.compute_window_table(num_windows);
|
||||
|
||||
window_table
|
||||
.iter()
|
||||
|
@ -201,11 +204,10 @@ impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// For each window, z is a field element
|
||||
/// such that for each point (x, y) in the window:
|
||||
/// For each window, z is a field element such that for each point (x, y) in the window:
|
||||
/// - z + y = u^2 (some square in the field); and
|
||||
/// - z - y is not a square.
|
||||
fn find_zs(&self) -> Option<Vec<u64>> {
|
||||
fn find_zs(&self, num_windows: usize) -> Option<Vec<u64>> {
|
||||
// Closure to find z for one window
|
||||
let find_z = |window_points: &[C]| {
|
||||
assert_eq!(H, window_points.len());
|
||||
|
@ -229,8 +231,8 @@ impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
|||
None
|
||||
};
|
||||
|
||||
let window_table = self.compute_window_table();
|
||||
window_table
|
||||
let window_table = self.compute_window_table(num_windows);
|
||||
window_table[21..22]
|
||||
.iter()
|
||||
.map(|window_points| find_z(window_points))
|
||||
.collect()
|
||||
|
@ -238,27 +240,23 @@ impl<C: CurveAffine> FixedBase<C> for OrchardFixedBase<C> {
|
|||
}
|
||||
|
||||
pub trait TestFixedBase<C: CurveAffine> {
|
||||
fn test_lagrange_coeffs(&self);
|
||||
fn test_z(&self, z: &[u64]);
|
||||
fn test_lagrange_coeffs(&self, scalar: C::Scalar, scalar_num_bits: usize, num_windows: usize);
|
||||
fn test_z(&self, z: &[u64], num_windows: usize);
|
||||
}
|
||||
|
||||
impl<C: CurveAffine> TestFixedBase<C> for OrchardFixedBase<C> {
|
||||
fn test_lagrange_coeffs(&self) {
|
||||
let lagrange_coeffs = self.compute_lagrange_coeffs();
|
||||
let mut points = Vec::<C::CurveExt>::with_capacity(NUM_WINDOWS);
|
||||
fn test_lagrange_coeffs(&self, scalar: C::Scalar, scalar_num_bits: usize, num_windows: usize) {
|
||||
let lagrange_coeffs = self.compute_lagrange_coeffs(num_windows);
|
||||
let mut points = Vec::<C::CurveExt>::with_capacity(num_windows);
|
||||
|
||||
let scalar = C::Scalar::rand();
|
||||
let bits = util::decompose_scalar_fixed::<C>(
|
||||
scalar,
|
||||
C::Scalar::NUM_BITS as usize,
|
||||
FIXED_BASE_WINDOW_SIZE,
|
||||
);
|
||||
let bits =
|
||||
util::decompose_scalar_fixed::<C>(scalar, scalar_num_bits, FIXED_BASE_WINDOW_SIZE);
|
||||
|
||||
// Check first 84 windows, i.e. `k_0, k_1, ..., k_83`
|
||||
for ((idx, bits), coeffs) in bits[0..(NUM_WINDOWS - 1)]
|
||||
for ((idx, bits), coeffs) in bits[0..(num_windows - 1)]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.zip(lagrange_coeffs[0..(NUM_WINDOWS - 1)].iter())
|
||||
.zip(lagrange_coeffs[0..(num_windows - 1)].iter())
|
||||
{
|
||||
let interpolated_x = util::evaluate::<C>(*bits, coeffs);
|
||||
|
||||
|
@ -274,15 +272,15 @@ impl<C: CurveAffine> TestFixedBase<C> for OrchardFixedBase<C> {
|
|||
|
||||
// Check last window
|
||||
{
|
||||
let last_bits = bits[NUM_WINDOWS - 1];
|
||||
let interpolated_x = util::evaluate::<C>(last_bits, &lagrange_coeffs[NUM_WINDOWS - 1]);
|
||||
let last_bits = bits[num_windows - 1];
|
||||
let interpolated_x = util::evaluate::<C>(last_bits, &lagrange_coeffs[num_windows - 1]);
|
||||
|
||||
// [k * (8^w) - offset]B, where offset = \sum_{j = 0}^{83} 8^j
|
||||
let offset = (0..(NUM_WINDOWS - 1)).fold(C::Scalar::zero(), |acc, w| {
|
||||
let offset = (0..(num_windows - 1)).fold(C::Scalar::zero(), |acc, w| {
|
||||
acc + C::Scalar::from_u64(H as u64).pow(&[w as u64, 0, 0, 0])
|
||||
});
|
||||
let scalar = C::Scalar::from_u64(last_bits as u64)
|
||||
* C::Scalar::from_u64(H as u64).pow(&[(NUM_WINDOWS - 1) as u64, 0, 0, 0])
|
||||
* C::Scalar::from_u64(H as u64).pow(&[(num_windows - 1) as u64, 0, 0, 0])
|
||||
- offset;
|
||||
let point = self.0 * scalar;
|
||||
let x = point.to_affine().get_xy().unwrap().0;
|
||||
|
@ -299,8 +297,8 @@ impl<C: CurveAffine> TestFixedBase<C> for OrchardFixedBase<C> {
|
|||
assert_eq!(window_sum, multiple);
|
||||
}
|
||||
|
||||
fn test_z(&self, z: &[u64]) {
|
||||
let window_table = self.compute_window_table();
|
||||
fn test_z(&self, z: &[u64], num_windows: usize) {
|
||||
let window_table = self.compute_window_table(num_windows);
|
||||
|
||||
for (z, window_points) in z.iter().zip(window_table) {
|
||||
for point in window_points.iter() {
|
||||
|
|
|
@ -15,8 +15,8 @@ pub const GENERATOR: ([u8; 32], [u8; 32]) = (
|
|||
],
|
||||
);
|
||||
|
||||
/// z-values for GENERATOR
|
||||
pub const Z: [u64; 85] = [
|
||||
/// Full-width z-values for GENERATOR
|
||||
pub const Z: [u64; super::NUM_WINDOWS] = [
|
||||
1640, 16319, 75535, 213644, 22431, 77718, 73598, 44704, 58426, 90793, 51317, 35788, 62987,
|
||||
39128, 29961, 196204, 23144, 4960, 31792, 67688, 156889, 128199, 394678, 1391, 49801, 69085,
|
||||
177001, 27216, 17637, 12069, 8898, 134862, 137982, 35001, 261172, 3219, 171891, 6532, 93082,
|
||||
|
@ -26,6 +26,12 @@ pub const Z: [u64; 85] = [
|
|||
163259, 49391, 34561, 350373, 139177, 147760,
|
||||
];
|
||||
|
||||
/// Short signed z-values for GENERATOR
|
||||
pub const Z_SHORT: [u64; super::NUM_WINDOWS_SHORT] = [
|
||||
1640, 16319, 75535, 213644, 22431, 77718, 73598, 44704, 58426, 90793, 51317, 35788, 62987,
|
||||
39128, 29961, 196204, 23144, 4960, 31792, 67688, 156889, 11429,
|
||||
];
|
||||
|
||||
pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
||||
OrchardFixedBases::CommitIvkR(OrchardFixedBase::<C>::new(
|
||||
C::from_xy(
|
||||
|
@ -38,14 +44,16 @@ pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::TestFixedBase;
|
||||
use super::super::{TestFixedBase, L_VALUE, NUM_WINDOWS, NUM_WINDOWS_SHORT};
|
||||
use super::*;
|
||||
use crate::primitives::sinsemilla::CommitDomain;
|
||||
use ff::PrimeField;
|
||||
use group::Curve;
|
||||
use halo2::{
|
||||
arithmetic::{CurveAffine, FieldExt},
|
||||
pasta::pallas,
|
||||
};
|
||||
use rand;
|
||||
|
||||
#[test]
|
||||
fn generator() {
|
||||
|
@ -61,7 +69,23 @@ mod tests {
|
|||
fn lagrange_coeffs() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::CommitIvkR(inner) => inner.test_lagrange_coeffs(),
|
||||
OrchardFixedBases::CommitIvkR(inner) => inner.test_lagrange_coeffs(
|
||||
pallas::Scalar::rand(),
|
||||
pallas::Scalar::NUM_BITS as usize,
|
||||
NUM_WINDOWS,
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lagrange_coeffs_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::CommitIvkR(inner) => {
|
||||
let scalar = pallas::Scalar::from_u64(rand::random::<u64>());
|
||||
inner.test_lagrange_coeffs(scalar, L_VALUE, NUM_WINDOWS_SHORT)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +94,16 @@ mod tests {
|
|||
fn z() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::CommitIvkR(inner) => inner.test_z(&Z),
|
||||
OrchardFixedBases::CommitIvkR(inner) => inner.test_z(&Z, NUM_WINDOWS),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::CommitIvkR(inner) => inner.test_z(&Z_SHORT, NUM_WINDOWS_SHORT),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ pub const GENERATOR: ([u8; 32], [u8; 32]) = (
|
|||
],
|
||||
);
|
||||
|
||||
/// z-values for GENERATOR
|
||||
pub const Z: [u64; 85] = [
|
||||
/// Full-width z-values for GENERATOR
|
||||
pub const Z: [u64; super::NUM_WINDOWS] = [
|
||||
10213, 84688, 5015, 29076, 5250, 12480, 1589, 21978, 40626, 116200, 36680, 56513, 80295, 1371,
|
||||
36801, 26527, 11103, 61032, 199301, 33177, 49711, 167190, 1448, 51069, 40410, 171413, 82827,
|
||||
15451, 53663, 4202, 47840, 93100, 44310, 10271, 27499, 76928, 39695, 59189, 70288, 24401,
|
||||
|
@ -26,6 +26,12 @@ pub const Z: [u64; 85] = [
|
|||
149297, 10335, 32061, 214389,
|
||||
];
|
||||
|
||||
/// Short signed z-values for GENERATOR
|
||||
pub const Z_SHORT: [u64; super::NUM_WINDOWS_SHORT] = [
|
||||
10213, 84688, 5015, 29076, 5250, 12480, 1589, 21978, 40626, 116200, 36680, 56513, 80295, 1371,
|
||||
36801, 26527, 11103, 61032, 199301, 33177, 49711, 26839,
|
||||
];
|
||||
|
||||
pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
||||
OrchardFixedBases::NoteCommitR(OrchardFixedBase::<C>::new(
|
||||
C::from_xy(
|
||||
|
@ -38,14 +44,16 @@ pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::TestFixedBase;
|
||||
use super::super::{TestFixedBase, L_VALUE, NUM_WINDOWS, NUM_WINDOWS_SHORT};
|
||||
use super::*;
|
||||
use crate::primitives::sinsemilla::CommitDomain;
|
||||
use ff::PrimeField;
|
||||
use group::Curve;
|
||||
use halo2::{
|
||||
arithmetic::{CurveAffine, FieldExt},
|
||||
pasta::pallas,
|
||||
};
|
||||
use rand;
|
||||
|
||||
#[test]
|
||||
fn generator() {
|
||||
|
@ -61,7 +69,23 @@ mod tests {
|
|||
fn lagrange_coeffs() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NoteCommitR(inner) => inner.test_lagrange_coeffs(),
|
||||
OrchardFixedBases::NoteCommitR(inner) => inner.test_lagrange_coeffs(
|
||||
pallas::Scalar::rand(),
|
||||
pallas::Scalar::NUM_BITS as usize,
|
||||
NUM_WINDOWS,
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lagrange_coeffs_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NoteCommitR(inner) => {
|
||||
let scalar = pallas::Scalar::from_u64(rand::random::<u64>());
|
||||
inner.test_lagrange_coeffs(scalar, L_VALUE, NUM_WINDOWS_SHORT)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +94,16 @@ mod tests {
|
|||
fn z() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NoteCommitR(inner) => inner.test_z(&Z),
|
||||
OrchardFixedBases::NoteCommitR(inner) => inner.test_z(&Z, NUM_WINDOWS),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NoteCommitR(inner) => inner.test_z(&Z_SHORT, NUM_WINDOWS_SHORT),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ pub const GENERATOR: ([u8; 32], [u8; 32]) = (
|
|||
],
|
||||
);
|
||||
|
||||
/// z-values for GENERATOR
|
||||
pub const Z: [u64; 85] = [
|
||||
/// Full-width z-values for GENERATOR
|
||||
pub const Z: [u64; super::NUM_WINDOWS] = [
|
||||
32517, 3118, 55842, 5295, 2252, 43091, 193188, 73424, 27335, 55867, 11015, 46382, 29066, 69577,
|
||||
2838, 245429, 25519, 172913, 25762, 138009, 11170, 132216, 114997, 52870, 52313, 102066, 5989,
|
||||
365, 73950, 74675, 191463, 34356, 16506, 63389, 4652, 81717, 108428, 120446, 80918, 25398,
|
||||
|
@ -25,6 +25,12 @@ pub const Z: [u64; 85] = [
|
|||
89930, 69888, 193158, 105211, 27681, 32387,
|
||||
];
|
||||
|
||||
/// Short signed z-values for GENERATOR
|
||||
pub const Z_SHORT: [u64; super::NUM_WINDOWS_SHORT] = [
|
||||
32517, 3118, 55842, 5295, 2252, 43091, 193188, 73424, 27335, 55867, 11015, 46382, 29066, 69577,
|
||||
2838, 245429, 25519, 172913, 25762, 138009, 11170, 5770,
|
||||
];
|
||||
|
||||
pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
||||
OrchardFixedBases::NullifierK(OrchardFixedBase::<C>::new(
|
||||
C::from_xy(
|
||||
|
@ -37,13 +43,15 @@ pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::TestFixedBase;
|
||||
use super::super::{TestFixedBase, L_VALUE, NUM_WINDOWS, NUM_WINDOWS_SHORT};
|
||||
use super::*;
|
||||
use ff::PrimeField;
|
||||
use group::Curve;
|
||||
use halo2::{
|
||||
arithmetic::{CurveAffine, CurveExt, FieldExt},
|
||||
pasta::pallas,
|
||||
};
|
||||
use rand;
|
||||
|
||||
#[test]
|
||||
fn generator() {
|
||||
|
@ -59,7 +67,23 @@ mod tests {
|
|||
fn lagrange_coeffs() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NullifierK(inner) => inner.test_lagrange_coeffs(),
|
||||
OrchardFixedBases::NullifierK(inner) => inner.test_lagrange_coeffs(
|
||||
pallas::Scalar::rand(),
|
||||
pallas::Scalar::NUM_BITS as usize,
|
||||
NUM_WINDOWS,
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lagrange_coeffs_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NullifierK(inner) => {
|
||||
let scalar = pallas::Scalar::from_u64(rand::random::<u64>());
|
||||
inner.test_lagrange_coeffs(scalar, L_VALUE, NUM_WINDOWS_SHORT)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +92,16 @@ mod tests {
|
|||
fn z() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NullifierK(inner) => inner.test_z(&Z),
|
||||
OrchardFixedBases::NullifierK(inner) => inner.test_z(&Z, NUM_WINDOWS),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::NullifierK(inner) => inner.test_z(&Z_SHORT, NUM_WINDOWS_SHORT),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ pub const GENERATOR: ([u8; 32], [u8; 32]) = (
|
|||
],
|
||||
);
|
||||
|
||||
/// z-values for GENERATOR
|
||||
pub const Z: [u64; 85] = [
|
||||
/// Full-width z-values for GENERATOR
|
||||
pub const Z: [u64; super::NUM_WINDOWS] = [
|
||||
287008, 5261, 10541, 67788, 1084, 31201, 1662, 32921, 2652, 52006, 3486, 82692, 7295, 40007,
|
||||
37754, 44773, 3021, 171863, 33315, 8829, 67034, 50428, 40391, 6615, 40340, 238, 199437, 50234,
|
||||
899, 27825, 139735, 36053, 194684, 28229, 31719, 66166, 100600, 59796, 52804, 10221, 159298,
|
||||
|
@ -27,6 +27,12 @@ pub const Z: [u64; 85] = [
|
|||
132537, 189703, 29967, 9941,
|
||||
];
|
||||
|
||||
/// Short signed z-values for GENERATOR
|
||||
pub const Z_SHORT: [u64; super::NUM_WINDOWS_SHORT] = [
|
||||
287008, 5261, 10541, 67788, 1084, 31201, 1662, 32921, 2652, 52006, 3486, 82692, 7295, 40007,
|
||||
37754, 44773, 3021, 171863, 33315, 8829, 67034, 16641,
|
||||
];
|
||||
|
||||
pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
||||
OrchardFixedBases::ValueCommitR(OrchardFixedBase::<C>::new(
|
||||
C::from_xy(
|
||||
|
@ -39,13 +45,15 @@ pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::TestFixedBase;
|
||||
use super::super::{TestFixedBase, L_VALUE, NUM_WINDOWS, NUM_WINDOWS_SHORT};
|
||||
use super::*;
|
||||
use ff::PrimeField;
|
||||
use group::Curve;
|
||||
use halo2::{
|
||||
arithmetic::{CurveAffine, CurveExt, FieldExt},
|
||||
pasta::pallas,
|
||||
};
|
||||
use rand;
|
||||
|
||||
#[test]
|
||||
fn generator() {
|
||||
|
@ -61,7 +69,23 @@ mod tests {
|
|||
fn lagrange_coeffs() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitR(inner) => inner.test_lagrange_coeffs(),
|
||||
OrchardFixedBases::ValueCommitR(inner) => inner.test_lagrange_coeffs(
|
||||
pallas::Scalar::rand(),
|
||||
pallas::Scalar::NUM_BITS as usize,
|
||||
NUM_WINDOWS,
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lagrange_coeffs_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitR(inner) => {
|
||||
let scalar = pallas::Scalar::from_u64(rand::random::<u64>());
|
||||
inner.test_lagrange_coeffs(scalar, L_VALUE, NUM_WINDOWS_SHORT)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +94,16 @@ mod tests {
|
|||
fn z() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitR(inner) => inner.test_z(&Z),
|
||||
OrchardFixedBases::ValueCommitR(inner) => inner.test_z(&Z, NUM_WINDOWS),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitR(inner) => inner.test_z(&Z_SHORT, NUM_WINDOWS_SHORT),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ pub const GENERATOR: ([u8; 32], [u8; 32]) = (
|
|||
],
|
||||
);
|
||||
|
||||
/// z-values for GENERATOR
|
||||
pub const Z: [u64; 85] = [
|
||||
/// Full-width z-values for GENERATOR
|
||||
pub const Z: [u64; super::NUM_WINDOWS] = [
|
||||
12093, 20558, 3369, 22650, 43666, 81863, 2960, 131095, 84, 117033, 7349, 122998, 47884, 43451,
|
||||
22237, 3461, 71521, 147314, 31021, 70554, 47822, 44159, 45362, 7756, 19977, 41666, 82714,
|
||||
21407, 16731, 48013, 173284, 356652, 3027, 9756, 10560, 1554, 40272, 131726, 32724, 6152,
|
||||
|
@ -27,6 +27,12 @@ pub const Z: [u64; 85] = [
|
|||
33976, 106405, 11043, 44897, 98652,
|
||||
];
|
||||
|
||||
/// Short signed z-values for GENERATOR
|
||||
pub const Z_SHORT: [u64; super::NUM_WINDOWS_SHORT] = [
|
||||
12093, 20558, 3369, 22650, 43666, 81863, 2960, 131095, 84, 117033, 7349, 122998, 47884, 43451,
|
||||
22237, 3461, 71521, 147314, 31021, 70554, 47822, 108204,
|
||||
];
|
||||
|
||||
pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
||||
OrchardFixedBases::ValueCommitV(OrchardFixedBase::<C>::new(
|
||||
C::from_xy(
|
||||
|
@ -39,13 +45,15 @@ pub fn generator<C: CurveAffine>() -> OrchardFixedBases<C> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::TestFixedBase;
|
||||
use super::super::{TestFixedBase, L_VALUE, NUM_WINDOWS, NUM_WINDOWS_SHORT};
|
||||
use super::*;
|
||||
use ff::PrimeField;
|
||||
use group::Curve;
|
||||
use halo2::{
|
||||
arithmetic::{CurveAffine, CurveExt, FieldExt},
|
||||
pasta::pallas,
|
||||
};
|
||||
use rand;
|
||||
|
||||
#[test]
|
||||
fn generator() {
|
||||
|
@ -64,7 +72,23 @@ mod tests {
|
|||
fn lagrange_coeffs() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitV(inner) => inner.test_lagrange_coeffs(),
|
||||
OrchardFixedBases::ValueCommitV(inner) => inner.test_lagrange_coeffs(
|
||||
pallas::Scalar::rand(),
|
||||
pallas::Scalar::NUM_BITS as usize,
|
||||
NUM_WINDOWS,
|
||||
),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lagrange_coeffs_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitV(inner) => {
|
||||
let scalar = pallas::Scalar::from_u64(rand::random::<u64>());
|
||||
inner.test_lagrange_coeffs(scalar, L_VALUE, NUM_WINDOWS_SHORT)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +97,16 @@ mod tests {
|
|||
fn z() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitV(inner) => inner.test_z(&Z),
|
||||
OrchardFixedBases::ValueCommitV(inner) => inner.test_z(&Z, NUM_WINDOWS),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn z_short() {
|
||||
let base = super::generator::<pallas::Affine>();
|
||||
match base {
|
||||
OrchardFixedBases::ValueCommitV(inner) => inner.test_z(&Z_SHORT, NUM_WINDOWS_SHORT),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue