mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-31 07:42:15 +00:00
Adopt new versions of pairing and bellman.
This commit is contained in:
parent
57687cf70f
commit
51c35a9bcf
@ -9,14 +9,14 @@ repository = "https://github.com/zcash-hackworks/sapling"
|
||||
version = "0.0.1"
|
||||
|
||||
[dependencies.pairing]
|
||||
version = "~0.13.2"
|
||||
version = "0.14"
|
||||
features = ["expose-arith"]
|
||||
|
||||
[dependencies]
|
||||
rand = "0.3"
|
||||
rand = "0.4"
|
||||
blake2 = "0.7"
|
||||
digest = "0.7"
|
||||
bellman = "0.0.8"
|
||||
bellman = "0.0.9"
|
||||
|
||||
byteorder = "1"
|
||||
|
||||
|
@ -118,7 +118,7 @@ impl PrimeFieldRepr for FsRepr {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn divn(&mut self, mut n: u32) {
|
||||
fn shr(&mut self, mut n: u32) {
|
||||
if n >= 64 * 4 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
@ -166,7 +166,7 @@ impl PrimeFieldRepr for FsRepr {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn muln(&mut self, mut n: u32) {
|
||||
fn shl(&mut self, mut n: u32) {
|
||||
if n >= 64 * 4 {
|
||||
*self = Self::from(0);
|
||||
return;
|
||||
@ -206,25 +206,21 @@ impl PrimeFieldRepr for FsRepr {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn add_nocarry(&mut self, other: &FsRepr) -> bool {
|
||||
fn add_nocarry(&mut self, other: &FsRepr) {
|
||||
let mut carry = 0;
|
||||
|
||||
for (a, b) in self.0.iter_mut().zip(other.0.iter()) {
|
||||
*a = adc(*a, *b, &mut carry);
|
||||
}
|
||||
|
||||
carry != 0
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn sub_noborrow(&mut self, other: &FsRepr) -> bool {
|
||||
fn sub_noborrow(&mut self, other: &FsRepr) {
|
||||
let mut borrow = 0;
|
||||
|
||||
for (a, b) in self.0.iter_mut().zip(other.0.iter()) {
|
||||
*a = sbb(*a, *b, &mut borrow);
|
||||
}
|
||||
|
||||
borrow != 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -668,29 +664,29 @@ fn test_fs_repr_div2() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fs_repr_divn() {
|
||||
fn test_fs_repr_shr() {
|
||||
let mut a = FsRepr([0xb33fbaec482a283f, 0x997de0d3a88cb3df, 0x9af62d2a9a0e5525, 0x36003ab08de70da1]);
|
||||
a.divn(0);
|
||||
a.shr(0);
|
||||
assert_eq!(
|
||||
a,
|
||||
FsRepr([0xb33fbaec482a283f, 0x997de0d3a88cb3df, 0x9af62d2a9a0e5525, 0x36003ab08de70da1])
|
||||
);
|
||||
a.divn(1);
|
||||
a.shr(1);
|
||||
assert_eq!(
|
||||
a,
|
||||
FsRepr([0xd99fdd762415141f, 0xccbef069d44659ef, 0xcd7b16954d072a92, 0x1b001d5846f386d0])
|
||||
);
|
||||
a.divn(50);
|
||||
a.shr(50);
|
||||
assert_eq!(
|
||||
a,
|
||||
FsRepr([0xbc1a7511967bf667, 0xc5a55341caa4b32f, 0x75611bce1b4335e, 0x6c0])
|
||||
);
|
||||
a.divn(130);
|
||||
a.shr(130);
|
||||
assert_eq!(
|
||||
a,
|
||||
FsRepr([0x1d5846f386d0cd7, 0x1b0, 0x0, 0x0])
|
||||
);
|
||||
a.divn(64);
|
||||
a.shr(64);
|
||||
assert_eq!(
|
||||
a,
|
||||
FsRepr([0x1b0, 0x0, 0x0, 0x0])
|
||||
@ -765,14 +761,6 @@ fn test_fs_repr_sub_noborrow() {
|
||||
|
||||
assert_eq!(csub_ab, csub_ba);
|
||||
}
|
||||
|
||||
// Subtracting r+1 from r should produce a borrow
|
||||
let mut qplusone = FsRepr([0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48]);
|
||||
assert!(qplusone.sub_noborrow(&FsRepr([0xffffffff00000002, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48])));
|
||||
|
||||
// Subtracting x from x should produce no borrow
|
||||
let mut x = FsRepr([0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48]);
|
||||
assert!(!x.sub_noborrow(&FsRepr([0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48])))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -835,14 +823,6 @@ fn test_fr_repr_add_nocarry() {
|
||||
assert_eq!(abc, cab);
|
||||
assert_eq!(abc, cba);
|
||||
}
|
||||
|
||||
// Adding 1 to (2^256 - 1) should produce a carry
|
||||
let mut x = FsRepr([0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff]);
|
||||
assert!(x.add_nocarry(&FsRepr::from(1)));
|
||||
|
||||
// Adding 1 to r should not produce a carry
|
||||
let mut x = FsRepr([0xffffffff00000001, 0x53bda402fffe5bfe, 0x3339d80809a1d805, 0x73eda753299d7d48]);
|
||||
assert!(!x.add_nocarry(&FsRepr::from(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -390,8 +390,8 @@ fn test_jubjub_params<E: JubjubEngine>(params: &E::Params) {
|
||||
tmp.mul2();
|
||||
tmp.mul2();
|
||||
|
||||
assert_eq!(pacc.add_nocarry(&tmp), false);
|
||||
assert_eq!(nacc.sub_noborrow(&tmp), false);
|
||||
pacc.add_nocarry(&tmp);
|
||||
nacc.sub_noborrow(&tmp);
|
||||
|
||||
assert!(pacc < max);
|
||||
assert!(pacc < nacc);
|
||||
|
Loading…
Reference in New Issue
Block a user