Skip to content

Commit

Permalink
Release 0.4.0
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
lander86 authored Feb 11, 2022
2 parents d8bf2b7 + c0f35a9 commit 1beb8c2
Show file tree
Hide file tree
Showing 187 changed files with 26,084 additions and 2,649 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Cargo.lock
*.orig
coeffs_*
msm_bases_*
*.py
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ script:

jobs:
include:
- name: bionic_rust-1.51.0_latest-STAGE1
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='000,001,003,005,006,008,009,011,012,013,014,015,016,018'
- name: bionic_rust-1.51.0_latest-STAGE2
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='017'
- name: bionic_rust-nightly-2021-04-25_latest
- name: bionic_rust-1.51.0_latest-CHECK
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='000,001,003,005,006,008,009,011,012,013,014,015,016,020'
- name: bionic_rust-1.51.0_latest-TEST
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='017,018'
- name: bionic_rust-1.51.0_latest-TEST_INTENSIVE
env: IMAGE_TAG=bionic_rust-1.51.0_latest TESTS='019'
- name: bionic_rust-nightly-2021-04-25_latest-CHECK
env: IMAGE_TAG=bionic_rust-nightly-2021-04-25_latest TESTS='002,004,007,010' CARGOARGS='+nightly-2021-04-25'
5 changes: 4 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ Pratyush Mishra
Howard Wu
Daniele Di Benedetto
Marcelo Kaihara
Ulrich Haboeck
Ulrich Haboeck
Luca Giussani
Daniele Di Tullio
Nicholas Mainardi
20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ debug-assertions = true
debug = true

# Uncomment these lines for local development paths
#
#[patch.'https://github.com/HorizenOfficial/ginger-lib']
#algebra = { path = './algebra' }
#r1cs-core = { path = "./r1cs/core" }
#
#[patch.'https://github.com/HorizenLabs/marlin']
#marlin = { path = '../marlin' }
#
#[patch.'https://github.com/HorizenLabs/poly-commit']
#poly-commit = { path = '../poly-commit' }

# [patch.'https://github.com/HorizenOfficial/ginger-lib']
# algebra = { path = './algebra' }
# r1cs-core = { path = "./r1cs/core" }

# [patch.'https://github.com/HorizenLabs/marlin']
# marlin = { path = '../marlin' }

# [patch.'https://github.com/HorizenLabs/poly-commit']
# poly-commit = { path = '../poly-commit' }
20 changes: 14 additions & 6 deletions algebra/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "algebra"
version = "0.3.1"
version = "0.4.0"
authors = [
"Sean Bowe",
"Alessandro Chiesa",
Expand All @@ -13,7 +13,10 @@ authors = [
"Ulrich Haboeck <ulrich@horizenlabs.io>",
"Maksym Vereshchak <phoinic@gmail.com>",
"Luigi Varriale <luigi@horizenlabs.io>",
"cronicc <cronic@horizenlabs.io>"
"cronicc <cronic@horizenlabs.io>",
"Luca Giussani <lucagiussani@horizenlabs.io>",
"Daniele Di Tullio <danieled@horizenlabs.io>",
"Nicholas Mainardi <nicholas@horizenlabs.io>"
]
description = "A library for finite fields, elliptic curves and FFTs evaluation over prime finite fields"
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
Expand All @@ -26,9 +29,10 @@ build = "build.rs"

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

bench-utils = { path = "../bench-utils", optional = true }
byteorder = { version = "1" }
byteorder = { version = "=1.4.3" }
rand = { version = "=0.8.4" }
derivative = { version = "=2.2.0", features = ["use_core"] }

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

[features]
parallel = [ "rayon" ]
Expand All @@ -55,7 +61,7 @@ llvm_asm = []
derive = ["algebra-derive"]

bls12_377 = []
bls12_381 = []
bls12_381 = ["jubjub"]
edwards_bls12 = ["bls12_377"]
edwards_sw6 = ["sw6"]
jubjub = []
Expand All @@ -65,8 +71,10 @@ mnt6_298 = []
mnt6_753 = ["mnt4_753"]
bn_382 = []
tweedle = []
secp256k1 = []
ed25519 = []

full = [ "bls12_377", "bls12_381", "sw6", "mnt4_753", "mnt6_298", "mnt6_753", "edwards_bls12", "edwards_sw6", "jubjub", "bn_382", "tweedle" ]
full = [ "bls12_377", "bls12_381", "sw6", "mnt4_753", "mnt6_298", "mnt6_753", "edwards_bls12", "edwards_sw6", "jubjub", "bn_382", "tweedle", "secp256k1", "ed25519" ]

[build-dependencies]
field-assembly = { path = "./field-assembly" }
Expand Down
1 change: 0 additions & 1 deletion algebra/algebra-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
clippy::assertions_on_constants
)]


use proc_macro2::TokenStream;
use syn::{parse_macro_input, Data, DeriveInput, Index, Type};

Expand Down
53 changes: 53 additions & 0 deletions algebra/src/biginteger/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ macro_rules! bigint_impl {
pub fn new(value: [u64; $num_limbs]) -> Self {
$name(value)
}

#[inline]
fn to_bytes_le(&self) -> Vec<u8> {
let array_map = self.0.iter().map(|limb| limb.to_le_bytes());
let mut res = Vec::<u8>::with_capacity($num_limbs * 8);
for limb in array_map {
res.extend_from_slice(&limb);
}
res
}
}

impl BigInteger for $name {
Expand Down Expand Up @@ -147,14 +157,18 @@ macro_rules! bigint_impl {
}
}

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

// convert to little endian as the limbs are in
// little endian order
let mut bits = bits.to_vec();
bits.reverse();
for (i, bits64) in bits.chunks(64).enumerate() {
// each chunk is again arranged big endian
for bit in bits64.iter().rev() {
acc <<= 1;
acc += *bit as u64;
Expand All @@ -165,6 +179,7 @@ macro_rules! bigint_impl {
res
}

// Note: Does not skip leading zeroes
#[inline]
fn to_bits(&self) -> Vec<bool> {
let mut res = Vec::with_capacity(256);
Expand Down Expand Up @@ -293,5 +308,43 @@ macro_rules! bigint_impl {
repr
}
}

impl TryFrom<BigUint> for $name {
type Error = Box<dyn std::error::Error>;

#[inline]
fn try_from(val: BigUint) -> Result<$name, Self::Error> {
let bytes = val.to_bytes_le();

if bytes.len() > $num_limbs * 8 {
Err(format!(
"A BigUint of {} bytes cannot fit into a BigInt of {} bytes.",
bytes.len(),
$num_limbs * 8
))?
} else {
let mut limbs = [0u64; $num_limbs];

bytes
.chunks(8)
.into_iter()
.enumerate()
.for_each(|(i, chunk)| {
let mut chunk_padded = [0u8; 8];
chunk_padded[..chunk.len()].copy_from_slice(chunk);
limbs[i] = u64::from_le_bytes(chunk_padded)
});

Ok(Self(limbs))
}
}
}

impl From<$name> for BigUint {
#[inline]
fn from(val: $name) -> BigUint {
BigUint::from_bytes_le(&val.to_bytes_le())
}
}
};
}
6 changes: 6 additions & 0 deletions algebra/src/biginteger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ use crate::{
fields::BitIterator,
CanonicalDeserialize, CanonicalSerialize, SerializationError, UniformRand,
};
use num_bigint::BigUint;
use rand::{
distributions::{Distribution, Standard},
Rng,
};
use serde::{Deserialize, Serialize};
use std::{
convert::TryFrom,
fmt::{Debug, Display},
io::{Read, Result as IoResult, Write},
};
Expand Down Expand Up @@ -51,6 +53,8 @@ pub trait BigInteger:
+ AsMut<[u64]>
+ AsRef<[u64]>
+ From<u64>
+ TryFrom<BigUint>
+ Into<BigUint>
{
/// Add another representation to this one, returning the carry bit.
fn add_nocarry(&mut self, other: &Self) -> bool;
Expand Down Expand Up @@ -94,6 +98,8 @@ pub trait BigInteger:

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

/// Returns a vector for wnaf.
Expand Down
38 changes: 38 additions & 0 deletions algebra/src/curves/all_curve_checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
echo "################ CHECKING ALL CURVE PARAMETERS##################"
echo "################################################################"
echo #
echo "###############Checking bls12_377 curve parameters:"
sage check_curve_parameters.sage bls12_377/g1.rs ../fields/bls12_377/fq.rs ../fields/bls12_377/fr.rs #
echo #
echo "################Checking bls12_381 curve parameters:"
sage check_curve_parameters.sage bls12_381/g1.rs ../fields/bls12_381/fq.rs ../fields/jubjub/fq.rs #
echo #
echo "###############Checking bn_382 curve parameters:"
echo "########### curve g1:"
sage check_curve_parameters.sage bn_382/g1.rs ../fields/bn_382/fq.rs ../fields/bn_382/fr.rs #
echo "########### curve g:"
sage check_curve_parameters.sage bn_382/g.rs ../fields/bn_382/fr.rs ../fields/bn_382/fq.rs #
echo #
echo "################Checking ed25519 curve parameters:"
sage check_curve_parameters.sage ed25519/mod.rs ../fields/ed25519/fq.rs ../fields/ed25519/fr.rs #
echo #
echo "###############Checking mnt6 curve parameters:"
sage check_curve_parameters.sage mnt6/g1.rs ../fields/mnt6/fq.rs ../fields/mnt6/fr.rs #
echo #
echo "###############Checking mnt4753 curve parameters:"
sage check_curve_parameters.sage mnt4753/g1.rs ../fields/mnt4753/fq.rs ../fields/mnt6753/fq.rs #
echo #
echo "###############Checking mnt6753 curve parameters:"
sage check_curve_parameters.sage mnt6753/g1.rs ../fields/mnt6753/fq.rs ../fields/mnt4753/fq.rs #
echo #
echo "###############Checking secp256k1 curve parameters:"
sage check_curve_parameters.sage secp256k1/mod.rs ../fields/secp256k1/fq.rs ../fields/secp256k1/fr.rs #
echo #
echo "###############Checking sw6 curve parameters:" # Very long computation.
sage check_curve_parameters.sage sw6/g1.rs ../fields/sw6/fq.rs ../fields/bls12_377/fq.rs #
echo #
echo "###############Checking tweedle curve parameters:"
echo "############ dee:"
sage check_curve_parameters.sage tweedle/dee.rs ../fields/tweedle/fq.rs ../fields/tweedle/fr.rs #
echo "############ dum:"
sage check_curve_parameters.sage tweedle/dum.rs ../fields/tweedle/fr.rs ../fields/tweedle/fq.rs #
5 changes: 1 addition & 4 deletions algebra/src/curves/bls12_377/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use crate::field_new;
use crate::{
biginteger::{BigInteger256, BigInteger384},
curves::models::{ModelParameters, SWModelParameters},
fields::{
bls12_377::{Fq, Fr},
Field,
},
fields::{bls12_377::*, Field},
};

#[derive(Copy, Clone, Default, PartialEq, Eq)]
Expand Down
5 changes: 1 addition & 4 deletions algebra/src/curves/bls12_377/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use crate::field_new;
use crate::{
biginteger::{BigInteger256, BigInteger384},
curves::models::{ModelParameters, SWModelParameters},
fields::{
bls12_377::{Fq, Fq2, Fr},
Field,
},
fields::{bls12_377::*, Field},
};

#[derive(Copy, Clone, Default, PartialEq, Eq)]
Expand Down
5 changes: 1 addition & 4 deletions algebra/src/curves/bls12_381/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::{
bls12_381::Bls12_381Parameters,
models::{ModelParameters, SWModelParameters},
},
fields::{
bls12_381::{Fq, Fr},
Field,
},
fields::{bls12_381::*, Field},
};

pub type G1Affine = Bls12G1Affine<Bls12_381Parameters>;
Expand Down
5 changes: 1 addition & 4 deletions algebra/src/curves/bls12_381/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::{
bls12_381::{g1::Bls12_381G1Parameters, Bls12_381Parameters},
models::{ModelParameters, SWModelParameters},
},
fields::{
bls12_381::{Fq, Fq2, Fr},
Field,
},
fields::{bls12_381::*, Field},
};

pub type G2Affine = Bls12G2Affine<Bls12_381Parameters>;
Expand Down
Loading

0 comments on commit 1beb8c2

Please sign in to comment.