Skip to content

Commit 1beb8c2

Browse files
authored
Release 0.4.0
Release 0.4.0
2 parents d8bf2b7 + c0f35a9 commit 1beb8c2

File tree

187 files changed

+26084
-2649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+26084
-2649
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Cargo.lock
77
*.orig
88
coeffs_*
99
msm_bases_*
10+
*.py

.travis.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ script:
3434

3535
jobs:
3636
include:
37-
- name: bionic_rust-1.51.0_latest-STAGE1
38-
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='000,001,003,005,006,008,009,011,012,013,014,015,016,018'
39-
- name: bionic_rust-1.51.0_latest-STAGE2
40-
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='017'
41-
- name: bionic_rust-nightly-2021-04-25_latest
37+
- name: bionic_rust-1.51.0_latest-CHECK
38+
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='000,001,003,005,006,008,009,011,012,013,014,015,016,020'
39+
- name: bionic_rust-1.51.0_latest-TEST
40+
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='017,018'
41+
- name: bionic_rust-1.51.0_latest-TEST_INTENSIVE
42+
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='019'
43+
- name: bionic_rust-nightly-2021-04-25_latest-CHECK
4244
env: IMAGE_TAG=bionic_rust-nightly-2021-04-25_latest TESTS='002,004,007,010' CARGOARGS='+nightly-2021-04-25'

AUTHORS

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ Pratyush Mishra
66
Howard Wu
77
Daniele Di Benedetto
88
Marcelo Kaihara
9-
Ulrich Haboeck
9+
Ulrich Haboeck
10+
Luca Giussani
11+
Daniele Di Tullio
12+
Nicholas Mainardi

Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ debug-assertions = true
3434
debug = true
3535

3636
# Uncomment these lines for local development paths
37-
#
38-
#[patch.'https://github.com/HorizenOfficial/ginger-lib']
39-
#algebra = { path = './algebra' }
40-
#r1cs-core = { path = "./r1cs/core" }
41-
#
42-
#[patch.'https://github.com/HorizenLabs/marlin']
43-
#marlin = { path = '../marlin' }
44-
#
45-
#[patch.'https://github.com/HorizenLabs/poly-commit']
46-
#poly-commit = { path = '../poly-commit' }
37+
38+
# [patch.'https://github.com/HorizenOfficial/ginger-lib']
39+
# algebra = { path = './algebra' }
40+
# r1cs-core = { path = "./r1cs/core" }
41+
42+
# [patch.'https://github.com/HorizenLabs/marlin']
43+
# marlin = { path = '../marlin' }
44+
45+
# [patch.'https://github.com/HorizenLabs/poly-commit']
46+
# poly-commit = { path = '../poly-commit' }

algebra/Cargo.toml

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "algebra"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
authors = [
55
"Sean Bowe",
66
"Alessandro Chiesa",
@@ -13,7 +13,10 @@ authors = [
1313
"Ulrich Haboeck <ulrich@horizenlabs.io>",
1414
"Maksym Vereshchak <phoinic@gmail.com>",
1515
"Luigi Varriale <luigi@horizenlabs.io>",
16-
"cronicc <cronic@horizenlabs.io>"
16+
"cronicc <cronic@horizenlabs.io>",
17+
"Luca Giussani <lucagiussani@horizenlabs.io>",
18+
"Daniele Di Tullio <danieled@horizenlabs.io>",
19+
"Nicholas Mainardi <nicholas@horizenlabs.io>"
1720
]
1821
description = "A library for finite fields, elliptic curves and FFTs evaluation over prime finite fields"
1922
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
@@ -26,9 +29,10 @@ build = "build.rs"
2629

2730
[dependencies]
2831
algebra-derive = { path = "algebra-derive", optional = true }
32+
num-bigint = { version = "=0.4.3", default-features = false }
2933

3034
bench-utils = { path = "../bench-utils", optional = true }
31-
byteorder = { version = "1" }
35+
byteorder = { version = "=1.4.3" }
3236
rand = { version = "=0.8.4" }
3337
derivative = { version = "=2.2.0", features = ["use_core"] }
3438

@@ -45,7 +49,9 @@ blake2 = "=0.8.1"
4549
rand_xorshift = { version = "=0.3.0" }
4650
paste = "=1.0.6"
4751
criterion = "=0.3.5"
48-
algebra = { path = "../algebra", features = ["full"] }
52+
hex-literal = "=0.3.4"
53+
num-traits = { version = "=0.2.14", default-features = false }
54+
num-bigint = { version = "=0.4.3", features = ["rand"] }
4955

5056
[features]
5157
parallel = [ "rayon" ]
@@ -55,7 +61,7 @@ llvm_asm = []
5561
derive = ["algebra-derive"]
5662

5763
bls12_377 = []
58-
bls12_381 = []
64+
bls12_381 = ["jubjub"]
5965
edwards_bls12 = ["bls12_377"]
6066
edwards_sw6 = ["sw6"]
6167
jubjub = []
@@ -65,8 +71,10 @@ mnt6_298 = []
6571
mnt6_753 = ["mnt4_753"]
6672
bn_382 = []
6773
tweedle = []
74+
secp256k1 = []
75+
ed25519 = []
6876

69-
full = [ "bls12_377", "bls12_381", "sw6", "mnt4_753", "mnt6_298", "mnt6_753", "edwards_bls12", "edwards_sw6", "jubjub", "bn_382", "tweedle" ]
77+
full = [ "bls12_377", "bls12_381", "sw6", "mnt4_753", "mnt6_298", "mnt6_753", "edwards_bls12", "edwards_sw6", "jubjub", "bn_382", "tweedle", "secp256k1", "ed25519" ]
7078

7179
[build-dependencies]
7280
field-assembly = { path = "./field-assembly" }

algebra/algebra-derive/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
clippy::assertions_on_constants
1313
)]
1414

15-
1615
use proc_macro2::TokenStream;
1716
use syn::{parse_macro_input, Data, DeriveInput, Index, Type};
1817

algebra/src/biginteger/macros.rs

+53
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ macro_rules! bigint_impl {
88
pub fn new(value: [u64; $num_limbs]) -> Self {
99
$name(value)
1010
}
11+
12+
#[inline]
13+
fn to_bytes_le(&self) -> Vec<u8> {
14+
let array_map = self.0.iter().map(|limb| limb.to_le_bytes());
15+
let mut res = Vec::<u8>::with_capacity($num_limbs * 8);
16+
for limb in array_map {
17+
res.extend_from_slice(&limb);
18+
}
19+
res
20+
}
1121
}
1222

1323
impl BigInteger for $name {
@@ -147,14 +157,18 @@ macro_rules! bigint_impl {
147157
}
148158
}
149159

160+
// Defines a BigInt from a slice of big endian booleans.
150161
#[inline]
151162
fn from_bits(bits: &[bool]) -> Self {
152163
let mut res = Self::default();
153164
let mut acc: u64 = 0;
154165

166+
// convert to little endian as the limbs are in
167+
// little endian order
155168
let mut bits = bits.to_vec();
156169
bits.reverse();
157170
for (i, bits64) in bits.chunks(64).enumerate() {
171+
// each chunk is again arranged big endian
158172
for bit in bits64.iter().rev() {
159173
acc <<= 1;
160174
acc += *bit as u64;
@@ -165,6 +179,7 @@ macro_rules! bigint_impl {
165179
res
166180
}
167181

182+
// Note: Does not skip leading zeroes
168183
#[inline]
169184
fn to_bits(&self) -> Vec<bool> {
170185
let mut res = Vec::with_capacity(256);
@@ -293,5 +308,43 @@ macro_rules! bigint_impl {
293308
repr
294309
}
295310
}
311+
312+
impl TryFrom<BigUint> for $name {
313+
type Error = Box<dyn std::error::Error>;
314+
315+
#[inline]
316+
fn try_from(val: BigUint) -> Result<$name, Self::Error> {
317+
let bytes = val.to_bytes_le();
318+
319+
if bytes.len() > $num_limbs * 8 {
320+
Err(format!(
321+
"A BigUint of {} bytes cannot fit into a BigInt of {} bytes.",
322+
bytes.len(),
323+
$num_limbs * 8
324+
))?
325+
} else {
326+
let mut limbs = [0u64; $num_limbs];
327+
328+
bytes
329+
.chunks(8)
330+
.into_iter()
331+
.enumerate()
332+
.for_each(|(i, chunk)| {
333+
let mut chunk_padded = [0u8; 8];
334+
chunk_padded[..chunk.len()].copy_from_slice(chunk);
335+
limbs[i] = u64::from_le_bytes(chunk_padded)
336+
});
337+
338+
Ok(Self(limbs))
339+
}
340+
}
341+
}
342+
343+
impl From<$name> for BigUint {
344+
#[inline]
345+
fn from(val: $name) -> BigUint {
346+
BigUint::from_bytes_le(&val.to_bytes_le())
347+
}
348+
}
296349
};
297350
}

algebra/src/biginteger/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ use crate::{
33
fields::BitIterator,
44
CanonicalDeserialize, CanonicalSerialize, SerializationError, UniformRand,
55
};
6+
use num_bigint::BigUint;
67
use rand::{
78
distributions::{Distribution, Standard},
89
Rng,
910
};
1011
use serde::{Deserialize, Serialize};
1112
use std::{
13+
convert::TryFrom,
1214
fmt::{Debug, Display},
1315
io::{Read, Result as IoResult, Write},
1416
};
@@ -51,6 +53,8 @@ pub trait BigInteger:
5153
+ AsMut<[u64]>
5254
+ AsRef<[u64]>
5355
+ From<u64>
56+
+ TryFrom<BigUint>
57+
+ Into<BigUint>
5458
{
5559
/// Add another representation to this one, returning the carry bit.
5660
fn add_nocarry(&mut self, other: &Self) -> bool;
@@ -94,6 +98,8 @@ pub trait BigInteger:
9498

9599
/// Returns the bit representation in a big endian boolean array, without
96100
/// leading zeros.
101+
// TODO: the current implementation does not seem to skip leading zeroes.
102+
// Let us check its usage and determine if a change is reasonable.
97103
fn to_bits(&self) -> Vec<bool>;
98104

99105
/// Returns a vector for wnaf.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
echo "################ CHECKING ALL CURVE PARAMETERS##################"
2+
echo "################################################################"
3+
echo #
4+
echo "###############Checking bls12_377 curve parameters:"
5+
sage check_curve_parameters.sage bls12_377/g1.rs ../fields/bls12_377/fq.rs ../fields/bls12_377/fr.rs #
6+
echo #
7+
echo "################Checking bls12_381 curve parameters:"
8+
sage check_curve_parameters.sage bls12_381/g1.rs ../fields/bls12_381/fq.rs ../fields/jubjub/fq.rs #
9+
echo #
10+
echo "###############Checking bn_382 curve parameters:"
11+
echo "########### curve g1:"
12+
sage check_curve_parameters.sage bn_382/g1.rs ../fields/bn_382/fq.rs ../fields/bn_382/fr.rs #
13+
echo "########### curve g:"
14+
sage check_curve_parameters.sage bn_382/g.rs ../fields/bn_382/fr.rs ../fields/bn_382/fq.rs #
15+
echo #
16+
echo "################Checking ed25519 curve parameters:"
17+
sage check_curve_parameters.sage ed25519/mod.rs ../fields/ed25519/fq.rs ../fields/ed25519/fr.rs #
18+
echo #
19+
echo "###############Checking mnt6 curve parameters:"
20+
sage check_curve_parameters.sage mnt6/g1.rs ../fields/mnt6/fq.rs ../fields/mnt6/fr.rs #
21+
echo #
22+
echo "###############Checking mnt4753 curve parameters:"
23+
sage check_curve_parameters.sage mnt4753/g1.rs ../fields/mnt4753/fq.rs ../fields/mnt6753/fq.rs #
24+
echo #
25+
echo "###############Checking mnt6753 curve parameters:"
26+
sage check_curve_parameters.sage mnt6753/g1.rs ../fields/mnt6753/fq.rs ../fields/mnt4753/fq.rs #
27+
echo #
28+
echo "###############Checking secp256k1 curve parameters:"
29+
sage check_curve_parameters.sage secp256k1/mod.rs ../fields/secp256k1/fq.rs ../fields/secp256k1/fr.rs #
30+
echo #
31+
echo "###############Checking sw6 curve parameters:" # Very long computation.
32+
sage check_curve_parameters.sage sw6/g1.rs ../fields/sw6/fq.rs ../fields/bls12_377/fq.rs #
33+
echo #
34+
echo "###############Checking tweedle curve parameters:"
35+
echo "############ dee:"
36+
sage check_curve_parameters.sage tweedle/dee.rs ../fields/tweedle/fq.rs ../fields/tweedle/fr.rs #
37+
echo "############ dum:"
38+
sage check_curve_parameters.sage tweedle/dum.rs ../fields/tweedle/fr.rs ../fields/tweedle/fq.rs #

algebra/src/curves/bls12_377/g1.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use crate::field_new;
22
use crate::{
33
biginteger::{BigInteger256, BigInteger384},
44
curves::models::{ModelParameters, SWModelParameters},
5-
fields::{
6-
bls12_377::{Fq, Fr},
7-
Field,
8-
},
5+
fields::{bls12_377::*, Field},
96
};
107

118
#[derive(Copy, Clone, Default, PartialEq, Eq)]

algebra/src/curves/bls12_377/g2.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use crate::field_new;
33
use crate::{
44
biginteger::{BigInteger256, BigInteger384},
55
curves::models::{ModelParameters, SWModelParameters},
6-
fields::{
7-
bls12_377::{Fq, Fq2, Fr},
8-
Field,
9-
},
6+
fields::{bls12_377::*, Field},
107
};
118

129
#[derive(Copy, Clone, Default, PartialEq, Eq)]

algebra/src/curves/bls12_381/g1.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use crate::{
66
bls12_381::Bls12_381Parameters,
77
models::{ModelParameters, SWModelParameters},
88
},
9-
fields::{
10-
bls12_381::{Fq, Fr},
11-
Field,
12-
},
9+
fields::{bls12_381::*, Field},
1310
};
1411

1512
pub type G1Affine = Bls12G1Affine<Bls12_381Parameters>;

algebra/src/curves/bls12_381/g2.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use crate::{
66
bls12_381::{g1::Bls12_381G1Parameters, Bls12_381Parameters},
77
models::{ModelParameters, SWModelParameters},
88
},
9-
fields::{
10-
bls12_381::{Fq, Fq2, Fr},
11-
Field,
12-
},
9+
fields::{bls12_381::*, Field},
1310
};
1411

1512
pub type G2Affine = Bls12G2Affine<Bls12_381Parameters>;

0 commit comments

Comments
 (0)