pairing: Remove BLS12-381 implementation
It is replaced by the bls12_381 crate.
This commit is contained in:
parent
200901d496
commit
459fa4a635
|
@ -24,6 +24,7 @@ byteorder = "1"
|
|||
subtle = "2.2.1"
|
||||
|
||||
[dev-dependencies]
|
||||
bls12_381 = { version = "0.1", path = "../bls12_381" }
|
||||
hex-literal = "0.2"
|
||||
rand = "0.7"
|
||||
rand_xorshift = "0.2"
|
||||
|
|
|
@ -375,7 +375,7 @@ fn parallel_fft<S: PrimeField, T: Group<S>>(
|
|||
#[cfg(feature = "pairing")]
|
||||
#[test]
|
||||
fn polynomial_arith() {
|
||||
use pairing::bls12_381::Fr;
|
||||
use bls12_381::Scalar as Fr;
|
||||
use rand_core::RngCore;
|
||||
|
||||
fn test_mul<S: PrimeField, R: RngCore>(rng: &mut R) {
|
||||
|
@ -422,7 +422,7 @@ fn polynomial_arith() {
|
|||
#[cfg(feature = "pairing")]
|
||||
#[test]
|
||||
fn fft_composition() {
|
||||
use pairing::bls12_381::Fr;
|
||||
use bls12_381::Scalar as Fr;
|
||||
use rand_core::RngCore;
|
||||
|
||||
fn test_comp<S: PrimeField, R: RngCore>(rng: &mut R) {
|
||||
|
@ -460,7 +460,7 @@ fn fft_composition() {
|
|||
#[cfg(feature = "pairing")]
|
||||
#[test]
|
||||
fn parallel_fft_consistency() {
|
||||
use pairing::bls12_381::Fr;
|
||||
use bls12_381::Scalar as Fr;
|
||||
use rand_core::RngCore;
|
||||
use std::cmp::min;
|
||||
|
||||
|
|
|
@ -408,8 +408,8 @@ pub fn blake2s<Scalar: PrimeField, CS: ConstraintSystem<Scalar>>(
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use blake2s_simd::Params as Blake2sParams;
|
||||
use bls12_381::Scalar;
|
||||
use hex_literal::hex;
|
||||
use pairing::bls12_381::Fr;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
|
@ -420,7 +420,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_blank_hash() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let input_bits = vec![];
|
||||
let out = blake2s(&mut cs, &input_bits, b"12345678").unwrap();
|
||||
assert!(cs.is_satisfied());
|
||||
|
@ -443,7 +443,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_blake2s_constraints() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let input_bits: Vec<_> = (0..512)
|
||||
.map(|i| {
|
||||
AllocatedBit::alloc(cs.namespace(|| format!("input bit {}", i)), Some(true))
|
||||
|
@ -461,7 +461,7 @@ mod test {
|
|||
// Test that 512 fixed leading bits (constants)
|
||||
// doesn't result in more constraints.
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
|
||||
0xbc, 0xe5,
|
||||
|
@ -481,7 +481,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_blake2s_constant_constraints() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let mut rng = XorShiftRng::from_seed([
|
||||
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
|
||||
0xbc, 0xe5,
|
||||
|
@ -512,7 +512,7 @@ mod test {
|
|||
|
||||
let hash_result = h.finalize();
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut input_bits = vec![];
|
||||
|
||||
|
@ -559,7 +559,7 @@ mod test {
|
|||
let data: Vec<u8> = hex!("be9f9c485e670acce8b1516a378176161b20583637b6f1c536fbc1158a0a3296831df2920e57a442d5738f4be4dd6be89dd7913fc8b4d1c0a815646a4d674b77f7caf313bd880bf759fcac27037c48c2b2a20acd2fd5248e3be426c84a341c0a3c63eaf36e0d537d10b8db5c6e4c801832c41eb1a3ed602177acded8b4b803bd34339d99a18b71df399641cc8dfae2ad193fcd74b5913e704551777160d14c78f2e8d5c32716a8599c1080cb89a40ccd6ba596694a8b4a065d9f2d0667ef423ed2e418093caff884540858b4f4b62acd47edcea880523e1b1cda8eb225c128c2e9e83f14f6e7448c5733a195cac7d79a53dde5083172462c45b2f799e42af1c9").to_vec();
|
||||
assert_eq!(data.len(), 256);
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut input_bits = vec![];
|
||||
|
||||
|
@ -596,7 +596,7 @@ mod test {
|
|||
let data: Vec<u8> = hex!("5dcfe8bab4c758d2eb1ddb7ef337583e0df3e2c358e1755b7cd303a658de9a1227eed1d1114179a5c3c38d692ff2cf2d4e5c92a9516de750106774bbf9f7d063f707f4c9b6a02c0a77e4feb99e036c3ccaee7d1a31cb144093aa074bc9da608f8ff30b39c3c60e4a243cc0bbd406d1262a7d6607b31c60275c6bcc8b0ac49a06a4b629a98693c5f7640f3bca45e4977cfabc5b17f52838af3433b1fd407dbbdc131e8e4bd58bcee85bbab4b57b656c6a2ec6cf852525bc8423675e2bf29159139cd5df99db94719f3f7167230e0d5bd76f6d7891b656732cef9c3c0d48a5fa3d7a879988157b39015a85451b25af0301ca5e759ac35fea79dca38c673ec6db9f3885d9103e2dcb3304bd3d59b0b1d01babc97ef8a74d91b6ab6bf50f29eb5adf7250a28fd85db37bff0133193635da69caeefc72979cf3bef1d2896d847eea7e8a81e0927893dbd010feb6fb845d0399007d9a148a0596d86cd8f4192631f975c560f4de8da5f712c161342063af3c11029d93d6df7ff46db48343499de9ec4786cac059c4025ef418c9fe40132428ff8b91259d71d1709ff066add84ae944b45a817f60b4c1bf719e39ae23e9b413469db2310793e9137cf38741e5dd2a3c138a566dbde1950c00071b20ac457b46ba9b0a7ebdddcc212bd228d2a4c4146a970e54158477247c27871af1564b176576e9fd43bf63740bf77434bc4ea3b1a4b430e1a11714bf43160145578a575c3f78ddeaa48de97f73460f26f8df2b5d63e31800100d16bc27160fea5ced5a977ef541cfe8dadc7b3991ed1c0d4f16a3076bbfed96ba3e155113e794987af8abb133f06feefabc2ac32eb4d4d4ba1541ca08b9e518d2e74b7f946b0cbd2663d58c689359b9a565821acc619011233d1011963fa302cde34fc9c5ba2e03eeb2512f547391e940d56218e22ae325f2dfa38d4bae35744ee707aa5dc9c17674025d15390a08f5c452343546ef6da0f7").to_vec();
|
||||
assert_eq!(data.len(), 700);
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut input_bits = vec![];
|
||||
|
||||
|
@ -651,7 +651,7 @@ mod test {
|
|||
|
||||
let hash_result = h.finalize();
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut input_bits = vec![];
|
||||
|
||||
|
|
|
@ -749,19 +749,19 @@ mod test {
|
|||
use super::{field_into_allocated_bits_le, u64_into_boolean_vec_le, AllocatedBit, Boolean};
|
||||
use crate::gadgets::test::*;
|
||||
use crate::ConstraintSystem;
|
||||
use bls12_381::Scalar;
|
||||
use ff::{Field, PrimeField};
|
||||
use pairing::bls12_381::Fr;
|
||||
|
||||
#[test]
|
||||
fn test_allocated_bit() {
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
AllocatedBit::alloc(&mut cs, Some(true)).unwrap();
|
||||
assert!(cs.get("boolean") == Fr::one());
|
||||
assert!(cs.get("boolean") == Scalar::one());
|
||||
assert!(cs.is_satisfied());
|
||||
cs.set("boolean", Fr::zero());
|
||||
cs.set("boolean", Scalar::zero());
|
||||
assert!(cs.is_satisfied());
|
||||
cs.set("boolean", Fr::from_str("2").unwrap());
|
||||
cs.set("boolean", Scalar::from_str("2").unwrap());
|
||||
assert!(!cs.is_satisfied());
|
||||
assert!(cs.which_is_unsatisfied() == Some("boolean constraint"));
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ mod test {
|
|||
fn test_xor() {
|
||||
for a_val in [false, true].iter() {
|
||||
for b_val in [false, true].iter() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let a = AllocatedBit::alloc(cs.namespace(|| "a"), Some(*a_val)).unwrap();
|
||||
let b = AllocatedBit::alloc(cs.namespace(|| "b"), Some(*b_val)).unwrap();
|
||||
let c = AllocatedBit::xor(&mut cs, &a, &b).unwrap();
|
||||
|
@ -806,7 +806,7 @@ mod test {
|
|||
fn test_and() {
|
||||
for a_val in [false, true].iter() {
|
||||
for b_val in [false, true].iter() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let a = AllocatedBit::alloc(cs.namespace(|| "a"), Some(*a_val)).unwrap();
|
||||
let b = AllocatedBit::alloc(cs.namespace(|| "b"), Some(*b_val)).unwrap();
|
||||
let c = AllocatedBit::and(&mut cs, &a, &b).unwrap();
|
||||
|
@ -842,7 +842,7 @@ mod test {
|
|||
fn test_and_not() {
|
||||
for a_val in [false, true].iter() {
|
||||
for b_val in [false, true].iter() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let a = AllocatedBit::alloc(cs.namespace(|| "a"), Some(*a_val)).unwrap();
|
||||
let b = AllocatedBit::alloc(cs.namespace(|| "b"), Some(*b_val)).unwrap();
|
||||
let c = AllocatedBit::and_not(&mut cs, &a, &b).unwrap();
|
||||
|
@ -878,7 +878,7 @@ mod test {
|
|||
fn test_nor() {
|
||||
for a_val in [false, true].iter() {
|
||||
for b_val in [false, true].iter() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let a = AllocatedBit::alloc(cs.namespace(|| "a"), Some(*a_val)).unwrap();
|
||||
let b = AllocatedBit::alloc(cs.namespace(|| "b"), Some(*b_val)).unwrap();
|
||||
let c = AllocatedBit::nor(&mut cs, &a, &b).unwrap();
|
||||
|
@ -917,7 +917,7 @@ mod test {
|
|||
for a_neg in [false, true].iter().cloned() {
|
||||
for b_neg in [false, true].iter().cloned() {
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut a = Boolean::from(
|
||||
AllocatedBit::alloc(cs.namespace(|| "a"), Some(a_bool)).unwrap(),
|
||||
|
@ -938,7 +938,7 @@ mod test {
|
|||
assert_eq!(cs.is_satisfied(), (a_bool ^ a_neg) == (b_bool ^ b_neg));
|
||||
}
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut a = Boolean::Constant(a_bool);
|
||||
let mut b = Boolean::from(
|
||||
|
@ -957,7 +957,7 @@ mod test {
|
|||
assert_eq!(cs.is_satisfied(), (a_bool ^ a_neg) == (b_bool ^ b_neg));
|
||||
}
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut a = Boolean::from(
|
||||
AllocatedBit::alloc(cs.namespace(|| "a"), Some(a_bool)).unwrap(),
|
||||
|
@ -976,7 +976,7 @@ mod test {
|
|||
assert_eq!(cs.is_satisfied(), (a_bool ^ a_neg) == (b_bool ^ b_neg));
|
||||
}
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut a = Boolean::Constant(a_bool);
|
||||
let mut b = Boolean::Constant(b_bool);
|
||||
|
@ -1005,7 +1005,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_boolean_negation() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let mut b = Boolean::from(AllocatedBit::alloc(&mut cs, Some(true)).unwrap());
|
||||
|
||||
|
@ -1097,7 +1097,7 @@ mod test {
|
|||
|
||||
for first_operand in variants.iter().cloned() {
|
||||
for second_operand in variants.iter().cloned() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a;
|
||||
let b;
|
||||
|
@ -1306,7 +1306,7 @@ mod test {
|
|||
|
||||
for first_operand in variants.iter().cloned() {
|
||||
for second_operand in variants.iter().cloned() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a;
|
||||
let b;
|
||||
|
@ -1527,7 +1527,7 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_u64_into_boolean_vec_le() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let bits = u64_into_boolean_vec_le(&mut cs, Some(17234652694787248421)).unwrap();
|
||||
|
||||
|
@ -1548,9 +1548,9 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_field_into_allocated_bits_le() {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let r = Fr::from_str(
|
||||
let r = Scalar::from_str(
|
||||
"9147677615426976802526883532204139322118074541891858454835346926874644257775",
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -1643,16 +1643,16 @@ mod test {
|
|||
} else {
|
||||
assert_eq!(cs.get("ch"), {
|
||||
if expected {
|
||||
Fr::one()
|
||||
Scalar::one()
|
||||
} else {
|
||||
Fr::zero()
|
||||
Scalar::zero()
|
||||
}
|
||||
});
|
||||
cs.set("ch", {
|
||||
if expected {
|
||||
Fr::zero()
|
||||
Scalar::zero()
|
||||
} else {
|
||||
Fr::one()
|
||||
Scalar::one()
|
||||
}
|
||||
});
|
||||
assert_eq!(cs.which_is_unsatisfied().unwrap(), "ch computation");
|
||||
|
@ -1735,16 +1735,16 @@ mod test {
|
|||
} else {
|
||||
assert_eq!(cs.get("maj"), {
|
||||
if expected {
|
||||
Fr::one()
|
||||
Scalar::one()
|
||||
} else {
|
||||
Fr::zero()
|
||||
Scalar::zero()
|
||||
}
|
||||
});
|
||||
cs.set("maj", {
|
||||
if expected {
|
||||
Fr::zero()
|
||||
Scalar::zero()
|
||||
} else {
|
||||
Fr::one()
|
||||
Scalar::one()
|
||||
}
|
||||
});
|
||||
assert_eq!(cs.which_is_unsatisfied().unwrap(), "maj computation");
|
||||
|
@ -1757,7 +1757,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_alloc_conditionally() {
|
||||
{
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let b = AllocatedBit::alloc(&mut cs, Some(false)).unwrap();
|
||||
|
||||
let value = None;
|
||||
|
@ -1773,7 +1773,7 @@ mod test {
|
|||
|
||||
{
|
||||
// since value is true, b must be false, so it should succeed
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let value = Some(true);
|
||||
let b = AllocatedBit::alloc(&mut cs, Some(false)).unwrap();
|
||||
|
@ -1790,7 +1790,7 @@ mod test {
|
|||
|
||||
{
|
||||
// since value is true, b must be false, so it should fail
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let value = Some(true);
|
||||
let b = AllocatedBit::alloc(&mut cs, Some(true)).unwrap();
|
||||
|
@ -1805,7 +1805,7 @@ mod test {
|
|||
|
||||
let value = Some(false);
|
||||
//check with false bit
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let b1 = AllocatedBit::alloc(&mut cs, Some(false)).unwrap();
|
||||
AllocatedBit::alloc_conditionally(cs.namespace(|| "alloc_conditionally"), value, &b1)
|
||||
.unwrap();
|
||||
|
@ -1813,7 +1813,7 @@ mod test {
|
|||
assert!(cs.is_satisfied());
|
||||
|
||||
//check with true bit
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let b2 = AllocatedBit::alloc(&mut cs, Some(true)).unwrap();
|
||||
AllocatedBit::alloc_conditionally(cs.namespace(|| "alloc_conditionally"), value, &b2)
|
||||
.unwrap();
|
||||
|
|
|
@ -191,8 +191,8 @@ mod test {
|
|||
use crate::gadgets::boolean::{AllocatedBit, Boolean};
|
||||
use crate::gadgets::test::*;
|
||||
|
||||
use bls12_381::Scalar;
|
||||
use ff::Field;
|
||||
use pairing::bls12_381::Fr;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::{AddAssign, Neg};
|
||||
|
@ -218,8 +218,8 @@ mod test {
|
|||
|
||||
let bits = vec![a, b, c];
|
||||
|
||||
let points: Vec<(Fr, Fr)> = (0..8)
|
||||
.map(|_| (Fr::random(&mut rng), Fr::random(&mut rng)))
|
||||
let points: Vec<(Scalar, Scalar)> = (0..8)
|
||||
.map(|_| (Scalar::random(&mut rng), Scalar::random(&mut rng)))
|
||||
.collect();
|
||||
|
||||
let res = lookup3_xy(&mut cs, &bits, &points).unwrap();
|
||||
|
@ -263,8 +263,8 @@ mod test {
|
|||
|
||||
let bits = vec![a, b, c];
|
||||
|
||||
let points: Vec<(Fr, Fr)> = (0..4)
|
||||
.map(|_| (Fr::random(&mut rng), Fr::random(&mut rng)))
|
||||
let points: Vec<(Scalar, Scalar)> = (0..4)
|
||||
.map(|_| (Scalar::random(&mut rng), Scalar::random(&mut rng)))
|
||||
.collect();
|
||||
|
||||
let res = lookup3_xy_with_conditional_negation(&mut cs, &bits, &points).unwrap();
|
||||
|
@ -297,15 +297,15 @@ mod test {
|
|||
|
||||
let window_size = 4;
|
||||
|
||||
let mut assignment = vec![Fr::zero(); 1 << window_size];
|
||||
let mut assignment = vec![Scalar::zero(); 1 << window_size];
|
||||
let constants: Vec<_> = (0..(1 << window_size))
|
||||
.map(|_| Fr::random(&mut rng))
|
||||
.map(|_| Scalar::random(&mut rng))
|
||||
.collect();
|
||||
|
||||
synth(window_size, &constants, &mut assignment);
|
||||
|
||||
for b in 0..(1 << window_size) {
|
||||
let mut acc = Fr::zero();
|
||||
let mut acc = Scalar::zero();
|
||||
|
||||
for j in 0..(1 << window_size) {
|
||||
if j & b == j {
|
||||
|
|
|
@ -74,7 +74,7 @@ pub fn compute_multipacking<Scalar: PrimeField>(bits: &[bool]) -> Vec<Scalar> {
|
|||
#[test]
|
||||
fn test_multipacking() {
|
||||
use crate::ConstraintSystem;
|
||||
use pairing::bls12_381::Fr;
|
||||
use bls12_381::Scalar;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
|
@ -87,7 +87,7 @@ fn test_multipacking() {
|
|||
]);
|
||||
|
||||
for num_bits in 0..1500 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let bits: Vec<bool> = (0..num_bits).map(|_| rng.next_u32() % 2 != 0).collect();
|
||||
|
||||
|
|
|
@ -410,8 +410,8 @@ impl<Scalar: PrimeField> Num<Scalar> {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::ConstraintSystem;
|
||||
use bls12_381::Scalar;
|
||||
use ff::{BitIterator, Field, PrimeField};
|
||||
use pairing::bls12_381::Fr;
|
||||
use rand_core::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use std::ops::{Neg, SubAssign};
|
||||
|
@ -423,22 +423,22 @@ mod test {
|
|||
fn test_allocated_num() {
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
AllocatedNum::alloc(&mut cs, || Ok(Fr::one())).unwrap();
|
||||
AllocatedNum::alloc(&mut cs, || Ok(Scalar::one())).unwrap();
|
||||
|
||||
assert!(cs.get("num") == Fr::one());
|
||||
assert!(cs.get("num") == Scalar::one());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_num_squaring() {
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Fr::from_str("3").unwrap())).unwrap();
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Scalar::from_str("3").unwrap())).unwrap();
|
||||
let n2 = n.square(&mut cs).unwrap();
|
||||
|
||||
assert!(cs.is_satisfied());
|
||||
assert!(cs.get("squared num") == Fr::from_str("9").unwrap());
|
||||
assert!(n2.value.unwrap() == Fr::from_str("9").unwrap());
|
||||
cs.set("squared num", Fr::from_str("10").unwrap());
|
||||
assert!(cs.get("squared num") == Scalar::from_str("9").unwrap());
|
||||
assert!(n2.value.unwrap() == Scalar::from_str("9").unwrap());
|
||||
cs.set("squared num", Scalar::from_str("10").unwrap());
|
||||
assert!(!cs.is_satisfied());
|
||||
}
|
||||
|
||||
|
@ -446,16 +446,16 @@ mod test {
|
|||
fn test_num_multiplication() {
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let n =
|
||||
AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Fr::from_str("12").unwrap())).unwrap();
|
||||
let n2 =
|
||||
AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Fr::from_str("10").unwrap())).unwrap();
|
||||
let n = AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Scalar::from_str("12").unwrap()))
|
||||
.unwrap();
|
||||
let n2 = AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Scalar::from_str("10").unwrap()))
|
||||
.unwrap();
|
||||
let n3 = n.mul(&mut cs, &n2).unwrap();
|
||||
|
||||
assert!(cs.is_satisfied());
|
||||
assert!(cs.get("product num") == Fr::from_str("120").unwrap());
|
||||
assert!(n3.value.unwrap() == Fr::from_str("120").unwrap());
|
||||
cs.set("product num", Fr::from_str("121").unwrap());
|
||||
assert!(cs.get("product num") == Scalar::from_str("120").unwrap());
|
||||
assert!(n3.value.unwrap() == Scalar::from_str("120").unwrap());
|
||||
cs.set("product num", Scalar::from_str("121").unwrap());
|
||||
assert!(!cs.is_satisfied());
|
||||
}
|
||||
|
||||
|
@ -468,8 +468,10 @@ mod test {
|
|||
{
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let a = AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Fr::random(&mut rng))).unwrap();
|
||||
let b = AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Fr::random(&mut rng))).unwrap();
|
||||
let a =
|
||||
AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Scalar::random(&mut rng))).unwrap();
|
||||
let b =
|
||||
AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Scalar::random(&mut rng))).unwrap();
|
||||
let condition = Boolean::constant(false);
|
||||
let (c, d) = AllocatedNum::conditionally_reverse(&mut cs, &a, &b, &condition).unwrap();
|
||||
|
||||
|
@ -482,8 +484,10 @@ mod test {
|
|||
{
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let a = AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Fr::random(&mut rng))).unwrap();
|
||||
let b = AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Fr::random(&mut rng))).unwrap();
|
||||
let a =
|
||||
AllocatedNum::alloc(cs.namespace(|| "a"), || Ok(Scalar::random(&mut rng))).unwrap();
|
||||
let b =
|
||||
AllocatedNum::alloc(cs.namespace(|| "b"), || Ok(Scalar::random(&mut rng))).unwrap();
|
||||
let condition = Boolean::constant(true);
|
||||
let (c, d) = AllocatedNum::conditionally_reverse(&mut cs, &a, &b, &condition).unwrap();
|
||||
|
||||
|
@ -499,24 +503,24 @@ mod test {
|
|||
{
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Fr::from_str("3").unwrap())).unwrap();
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Scalar::from_str("3").unwrap())).unwrap();
|
||||
n.assert_nonzero(&mut cs).unwrap();
|
||||
|
||||
assert!(cs.is_satisfied());
|
||||
cs.set("ephemeral inverse", Fr::from_str("3").unwrap());
|
||||
cs.set("ephemeral inverse", Scalar::from_str("3").unwrap());
|
||||
assert!(cs.which_is_unsatisfied() == Some("nonzero assertion constraint"));
|
||||
}
|
||||
{
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Fr::zero())).unwrap();
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(Scalar::zero())).unwrap();
|
||||
assert!(n.assert_nonzero(&mut cs).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_into_bits_strict() {
|
||||
let negone = Fr::one().neg();
|
||||
let negone = Scalar::one().neg();
|
||||
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
|
@ -526,7 +530,7 @@ mod test {
|
|||
assert!(cs.is_satisfied());
|
||||
|
||||
// make the bit representation the characteristic
|
||||
cs.set("bit 254/boolean", Fr::one());
|
||||
cs.set("bit 254/boolean", Scalar::one());
|
||||
|
||||
// this makes the conditional boolean constraint fail
|
||||
assert_eq!(
|
||||
|
@ -543,7 +547,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for i in 0..200 {
|
||||
let r = Fr::random(&mut rng);
|
||||
let r = Scalar::random(&mut rng);
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
|
||||
let n = AllocatedNum::alloc(&mut cs, || Ok(r)).unwrap();
|
||||
|
@ -567,15 +571,15 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
cs.set("num", Fr::random(&mut rng));
|
||||
cs.set("num", Scalar::random(&mut rng));
|
||||
assert!(!cs.is_satisfied());
|
||||
cs.set("num", r);
|
||||
assert!(cs.is_satisfied());
|
||||
|
||||
for i in 0..Fr::NUM_BITS {
|
||||
for i in 0..Scalar::NUM_BITS {
|
||||
let name = format!("bit {}/boolean", i);
|
||||
let cur = cs.get(&name);
|
||||
let mut tmp = Fr::one();
|
||||
let mut tmp = Scalar::one();
|
||||
tmp.sub_assign(&cur);
|
||||
cs.set(&name, tmp);
|
||||
assert!(!cs.is_satisfied());
|
||||
|
|
|
@ -273,8 +273,8 @@ mod test {
|
|||
use super::*;
|
||||
use crate::gadgets::boolean::AllocatedBit;
|
||||
use crate::gadgets::test::TestConstraintSystem;
|
||||
use bls12_381::Scalar;
|
||||
use hex_literal::hex;
|
||||
use pairing::bls12_381::Fr;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
|
@ -282,7 +282,7 @@ mod test {
|
|||
fn test_blank_hash() {
|
||||
let iv = get_sha256_iv();
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let mut input_bits: Vec<_> = (0..512).map(|_| Boolean::Constant(false)).collect();
|
||||
input_bits[0] = Boolean::Constant(true);
|
||||
let out = sha256_compression_function(&mut cs, &input_bits, &iv).unwrap();
|
||||
|
@ -312,7 +312,7 @@ mod test {
|
|||
|
||||
let iv = get_sha256_iv();
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let input_bits: Vec<_> = (0..512)
|
||||
.map(|i| {
|
||||
Boolean::from(
|
||||
|
@ -346,7 +346,7 @@ mod test {
|
|||
h.update(&data);
|
||||
let hash_result = h.finalize();
|
||||
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
let mut input_bits = vec![];
|
||||
|
||||
for (byte_i, input_byte) in data.into_iter().enumerate() {
|
||||
|
|
|
@ -418,46 +418,46 @@ impl<Scalar: PrimeField> ConstraintSystem<Scalar> for TestConstraintSystem<Scala
|
|||
|
||||
#[test]
|
||||
fn test_cs() {
|
||||
use ff::{Field, PrimeField};
|
||||
use pairing::bls12_381::Fr;
|
||||
use bls12_381::Scalar;
|
||||
use ff::PrimeField;
|
||||
|
||||
let mut cs = TestConstraintSystem::new();
|
||||
assert!(cs.is_satisfied());
|
||||
assert_eq!(cs.num_constraints(), 0);
|
||||
let a = cs
|
||||
.namespace(|| "a")
|
||||
.alloc(|| "var", || Ok(Fr::from_str("10").unwrap()))
|
||||
.alloc(|| "var", || Ok(Scalar::from_str("10").unwrap()))
|
||||
.unwrap();
|
||||
let b = cs
|
||||
.namespace(|| "b")
|
||||
.alloc(|| "var", || Ok(Fr::from_str("4").unwrap()))
|
||||
.alloc(|| "var", || Ok(Scalar::from_str("4").unwrap()))
|
||||
.unwrap();
|
||||
let c = cs
|
||||
.alloc(|| "product", || Ok(Fr::from_str("40").unwrap()))
|
||||
.alloc(|| "product", || Ok(Scalar::from_str("40").unwrap()))
|
||||
.unwrap();
|
||||
|
||||
cs.enforce(|| "mult", |lc| lc + a, |lc| lc + b, |lc| lc + c);
|
||||
assert!(cs.is_satisfied());
|
||||
assert_eq!(cs.num_constraints(), 1);
|
||||
|
||||
cs.set("a/var", Fr::from_str("4").unwrap());
|
||||
cs.set("a/var", Scalar::from_str("4").unwrap());
|
||||
|
||||
let one = TestConstraintSystem::<Fr>::one();
|
||||
let one = TestConstraintSystem::<Scalar>::one();
|
||||
cs.enforce(|| "eq", |lc| lc + a, |lc| lc + one, |lc| lc + b);
|
||||
|
||||
assert!(!cs.is_satisfied());
|
||||
assert!(cs.which_is_unsatisfied() == Some("mult"));
|
||||
|
||||
assert!(cs.get("product") == Fr::from_str("40").unwrap());
|
||||
assert!(cs.get("product") == Scalar::from_str("40").unwrap());
|
||||
|
||||
cs.set("product", Fr::from_str("16").unwrap());
|
||||
cs.set("product", Scalar::from_str("16").unwrap());
|
||||
assert!(cs.is_satisfied());
|
||||
|
||||
{
|
||||
let mut cs = cs.namespace(|| "test1");
|
||||
let mut cs = cs.namespace(|| "test2");
|
||||
cs.alloc(|| "hehe", || Ok(Fr::one())).unwrap();
|
||||
cs.alloc(|| "hehe", || Ok(Scalar::one())).unwrap();
|
||||
}
|
||||
|
||||
assert!(cs.get("test1/test2/hehe") == Fr::one());
|
||||
assert!(cs.get("test1/test2/hehe") == Scalar::one());
|
||||
}
|
||||
|
|
|
@ -399,8 +399,8 @@ mod test {
|
|||
use crate::gadgets::multieq::MultiEq;
|
||||
use crate::gadgets::test::*;
|
||||
use crate::ConstraintSystem;
|
||||
use bls12_381::Scalar;
|
||||
use ff::Field;
|
||||
use pairing::bls12_381::Fr;
|
||||
use rand_core::{RngCore, SeedableRng};
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
|
@ -482,7 +482,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a = rng.next_u32();
|
||||
let b = rng.next_u32();
|
||||
|
@ -527,7 +527,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a = rng.next_u32();
|
||||
let b = rng.next_u32();
|
||||
|
@ -570,7 +570,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a = rng.next_u32();
|
||||
let b = rng.next_u32();
|
||||
|
@ -683,7 +683,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a = rng.next_u32();
|
||||
let b = rng.next_u32();
|
||||
|
@ -727,7 +727,7 @@ mod test {
|
|||
]);
|
||||
|
||||
for _ in 0..1000 {
|
||||
let mut cs = TestConstraintSystem::<Fr>::new();
|
||||
let mut cs = TestConstraintSystem::<Scalar>::new();
|
||||
|
||||
let a = rng.next_u32();
|
||||
let b = rng.next_u32();
|
||||
|
|
|
@ -479,8 +479,8 @@ mod test_with_bls12_381 {
|
|||
use super::*;
|
||||
use crate::{Circuit, ConstraintSystem, SynthesisError};
|
||||
|
||||
use bls12_381::{Bls12, Scalar};
|
||||
use ff::{Field, PrimeField};
|
||||
use pairing::bls12_381::{Bls12, Fr};
|
||||
use rand::thread_rng;
|
||||
use std::ops::MulAssign;
|
||||
|
||||
|
@ -537,8 +537,8 @@ mod test_with_bls12_381 {
|
|||
let pvk = prepare_verifying_key::<Bls12>(¶ms.vk);
|
||||
|
||||
for _ in 0..100 {
|
||||
let a = Fr::random(rng);
|
||||
let b = Fr::random(rng);
|
||||
let a = Scalar::random(rng);
|
||||
let b = Scalar::random(rng);
|
||||
let mut c = a;
|
||||
c.mul_assign(&b);
|
||||
|
||||
|
|
|
@ -311,17 +311,19 @@ fn test_with_bls12() {
|
|||
acc
|
||||
}
|
||||
|
||||
use bls12_381::{Bls12, Scalar};
|
||||
use group::{Curve, Group};
|
||||
use pairing::{
|
||||
bls12_381::{Bls12, Fr},
|
||||
Engine,
|
||||
};
|
||||
use pairing::Engine;
|
||||
use rand;
|
||||
|
||||
const SAMPLES: usize = 1 << 14;
|
||||
|
||||
let rng = &mut rand::thread_rng();
|
||||
let v = Arc::new((0..SAMPLES).map(|_| Fr::random(rng)).collect::<Vec<_>>());
|
||||
let v = Arc::new(
|
||||
(0..SAMPLES)
|
||||
.map(|_| Scalar::random(rng))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
let g = Arc::new(
|
||||
(0..SAMPLES)
|
||||
.map(|_| <Bls12 as Engine>::G1::random(rng).to_affine())
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::time::{Duration, Instant};
|
|||
use ff::{Field, PrimeField};
|
||||
|
||||
// We're going to use the BLS12-381 pairing-friendly elliptic curve.
|
||||
use pairing::bls12_381::{Bls12, Fr};
|
||||
use bls12_381::{Bls12, Scalar};
|
||||
|
||||
// We'll use these interfaces to construct our circuit.
|
||||
use bellman::{Circuit, ConstraintSystem, SynthesisError};
|
||||
|
@ -151,7 +151,7 @@ fn test_mimc() {
|
|||
|
||||
// Generate the MiMC round constants
|
||||
let constants = (0..MIMC_ROUNDS)
|
||||
.map(|_| Fr::random(rng))
|
||||
.map(|_| Scalar::random(rng))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
println!("Creating parameters...");
|
||||
|
@ -183,8 +183,8 @@ fn test_mimc() {
|
|||
|
||||
for _ in 0..SAMPLES {
|
||||
// Generate a random preimage and compute the image
|
||||
let xl = Fr::random(rng);
|
||||
let xr = Fr::random(rng);
|
||||
let xl = Scalar::random(rng);
|
||||
let xr = Scalar::random(rng);
|
||||
let image = mimc(xl, xr, &constants);
|
||||
|
||||
proof_vec.truncate(0);
|
||||
|
|
Loading…
Reference in New Issue