Skip to content

Commit

Permalink
Merge pull request #2070 from AleoHQ/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
howardwu authored Oct 19, 2023
2 parents 6758aaf + 6aec633 commit c1af0b5
Show file tree
Hide file tree
Showing 229 changed files with 9,792 additions and 4,098 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,16 @@ jobs:
workspace_member: synthesizer/process
cache_key: snarkvm-synthesizer-process-cache

synthesizer-process-with-rocksdb:
docker:
- image: cimg/rust:1.71.1
resource_class: 2xlarge
steps:
- run_serial:
flags: --features=rocks
workspace_member: synthesizer/process
cache_key: snarkvm-synthesizer-process-cache

synthesizer-program:
docker:
- image: cimg/rust:1.71.1
Expand Down Expand Up @@ -862,6 +872,7 @@ workflows:
- synthesizer
- synthesizer-integration
- synthesizer-process
- synthesizer-process-with-rocksdb
- synthesizer-program
- synthesizer-program-integration-keccak
- synthesizer-program-integration-psd
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions algorithms/src/snark/varuna/ahp/indexer/constraint_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::{
use snarkvm_fields::Field;
use snarkvm_utilities::serialize::*;

use anyhow::Result;

/// Stores constraints during index generation.
pub(crate) struct ConstraintSystem<F: Field> {
pub(crate) a: Vec<Vec<(F, VarIndex)>>,
Expand All @@ -44,19 +46,19 @@ impl<F: Field> ConstraintSystem<F> {

#[inline]
/// Returns the sparse A matrix as Vec of rows, where each row is a Vec of assigned value and variable index
pub(crate) fn a_matrix(&self) -> Vec<Vec<(F, usize)>> {
pub(crate) fn a_matrix(&self) -> Result<Vec<Vec<(F, usize)>>> {
to_matrix_helper(&self.a, self.num_public_variables)
}

#[inline]
/// Returns the sparse B matrix as Vec of rows, where each row is a Vec of assigned value and variable index
pub(crate) fn b_matrix(&self) -> Vec<Vec<(F, usize)>> {
pub(crate) fn b_matrix(&self) -> Result<Vec<Vec<(F, usize)>>> {
to_matrix_helper(&self.b, self.num_public_variables)
}

#[inline]
/// Returns the sparse C matrix as Vec of rows, where each row is a Vec of assigned value and variable index
pub(crate) fn c_matrix(&self) -> Vec<Vec<(F, usize)>> {
pub(crate) fn c_matrix(&self) -> Result<Vec<Vec<(F, usize)>>> {
to_matrix_helper(&self.c, self.num_public_variables)
}

Expand Down
6 changes: 3 additions & 3 deletions algorithms/src/snark/varuna/ahp/indexer/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ impl<F: PrimeField, SM: SNARKMode> AHPForR1CS<F, SM> {

crate::snark::varuna::ahp::matrices::pad_input_for_indexer_and_prover(&mut ics);

let a = ics.a_matrix();
let b = ics.b_matrix();
let c = ics.c_matrix();
let a = ics.a_matrix()?;
let b = ics.b_matrix()?;
let c = ics.c_matrix()?;

end_timer!(padding_time);

Expand Down
24 changes: 13 additions & 11 deletions algorithms/src/snark/varuna/ahp/matrices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,22 @@ use rayon::prelude::*;

// This function converts a matrix output by Zexe's constraint infrastructure
// to the one used in this crate.
pub(crate) fn to_matrix_helper<F: Field>(matrix: &[Vec<(F, VarIndex)>], num_input_variables: usize) -> Matrix<F> {
pub(crate) fn to_matrix_helper<F: Field>(
matrix: &[Vec<(F, VarIndex)>],
num_input_variables: usize,
) -> Result<Matrix<F>> {
cfg_iter!(matrix)
.map(|row| {
let mut row_map = BTreeMap::new();
row.iter().for_each(|(val, column)| {
if !val.is_zero() {
let column = match column {
VarIndex::Public(i) => *i,
VarIndex::Private(i) => num_input_variables + i,
};
*row_map.entry(column).or_insert_with(F::zero) += *val;
}
});
row_map.into_iter().map(|(column, val)| (val, column)).collect()
for (val, column) in row.iter() {
ensure!(*val != F::zero(), "matrix entries should be non-zero");
let column = match column {
VarIndex::Public(i) => *i,
VarIndex::Private(i) => num_input_variables + i,
};
*row_map.entry(column).or_insert_with(F::zero) += *val;
}
Ok(row_map.into_iter().map(|(column, coeff)| (coeff, column)).collect())
})
.collect()
}
Expand Down
32 changes: 16 additions & 16 deletions circuit/account/src/compute_key/equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,28 @@ mod tests {
let mut rng = TestRng::default();

check_is_equal(Mode::Constant, Mode::Constant, 0, 0, 0, 0, &mut rng);
check_is_equal(Mode::Constant, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Constant, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Public, Mode::Constant, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Private, Mode::Constant, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Public, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Public, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Private, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Private, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_equal(Mode::Constant, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Constant, Mode::Private, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Public, Mode::Constant, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Private, Mode::Constant, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Public, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Public, Mode::Private, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Private, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_equal(Mode::Private, Mode::Private, 0, 0, 14, 14, &mut rng);
}

#[test]
fn test_is_not_equal() {
let mut rng = TestRng::default();

check_is_not_equal(Mode::Constant, Mode::Constant, 0, 0, 0, 0, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Public, Mode::Constant, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Private, Mode::Constant, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Public, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Public, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Private, Mode::Public, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Private, Mode::Private, 0, 0, 14, 19, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Private, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Public, Mode::Constant, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Private, Mode::Constant, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Public, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Public, Mode::Private, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Private, Mode::Public, 0, 0, 14, 14, &mut rng);
check_is_not_equal(Mode::Private, Mode::Private, 0, 0, 14, 14, &mut rng);
}
}
12 changes: 6 additions & 6 deletions circuit/account/src/compute_key/helpers/from_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,31 @@ mod tests {

#[test]
fn test_from_bits_le_constant() {
check_from_bits_le(Mode::Constant, 276, 0, 0, 0);
check_from_bits_le(Mode::Constant, 272, 0, 0, 0);
}

#[test]
fn test_from_bits_le_public() {
check_from_bits_le(Mode::Public, 9, 0, 1379, 1379);
check_from_bits_le(Mode::Public, 9, 0, 1375, 1379);
}

#[test]
fn test_from_bits_le_private() {
check_from_bits_le(Mode::Private, 9, 0, 1379, 1379);
check_from_bits_le(Mode::Private, 9, 0, 1375, 1379);
}

#[test]
fn test_from_bits_be_constant() {
check_from_bits_be(Mode::Constant, 276, 0, 0, 0);
check_from_bits_be(Mode::Constant, 272, 0, 0, 0);
}

#[test]
fn test_from_bits_be_public() {
check_from_bits_be(Mode::Public, 9, 0, 1379, 1379);
check_from_bits_be(Mode::Public, 9, 0, 1375, 1379);
}

#[test]
fn test_from_bits_be_private() {
check_from_bits_be(Mode::Private, 9, 0, 1379, 1379);
check_from_bits_be(Mode::Private, 9, 0, 1375, 1379);
}
}
2 changes: 1 addition & 1 deletion circuit/account/src/compute_key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub(crate) mod tests {

#[test]
fn test_compute_key_new_public() -> Result<()> {
check_new(Mode::Public, 9, 4, 873, 875)
check_new(Mode::Public, 9, 4, 869, 873)
}

#[test]
Expand Down
34 changes: 17 additions & 17 deletions circuit/account/src/signature/equal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<A: Aleo> Metrics<dyn Equal<Signature<A>, Output = Boolean<A>>> for Signatur
fn count(case: &Self::Case) -> Count {
match case.0.is_constant() && case.1.is_constant() {
true => Count::is(0, 0, 0, 0),
false => Count::is(0, 0, 20, 27),
false => Count::is(0, 0, 20, 20),
}
}
}
Expand Down Expand Up @@ -136,28 +136,28 @@ mod tests {
let mut rng = TestRng::default();

check_is_equal(Mode::Constant, Mode::Constant, 0, 0, 0, 0, &mut rng);
check_is_equal(Mode::Constant, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Constant, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Public, Mode::Constant, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Private, Mode::Constant, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Public, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Public, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Private, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Private, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_equal(Mode::Constant, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Constant, Mode::Private, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Public, Mode::Constant, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Private, Mode::Constant, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Public, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Public, Mode::Private, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Private, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_equal(Mode::Private, Mode::Private, 0, 0, 20, 20, &mut rng);
}

#[test]
fn test_is_not_equal() {
let mut rng = TestRng::default();

check_is_not_equal(Mode::Constant, Mode::Constant, 0, 0, 0, 0, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Public, Mode::Constant, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Private, Mode::Constant, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Public, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Public, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Private, Mode::Public, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Private, Mode::Private, 0, 0, 20, 27, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Constant, Mode::Private, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Public, Mode::Constant, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Private, Mode::Constant, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Public, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Public, Mode::Private, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Private, Mode::Public, 0, 0, 20, 20, &mut rng);
check_is_not_equal(Mode::Private, Mode::Private, 0, 0, 20, 20, &mut rng);
}
}
12 changes: 6 additions & 6 deletions circuit/account/src/signature/helpers/from_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,31 +118,31 @@ mod tests {

#[test]
fn test_from_bits_le_constant() {
check_from_bits_le(Mode::Constant, 276, 0, 0, 0);
check_from_bits_le(Mode::Constant, 272, 0, 0, 0);
}

#[test]
fn test_from_bits_le_public() {
check_from_bits_le(Mode::Public, 9, 0, 1879, 1881);
check_from_bits_le(Mode::Public, 9, 0, 1875, 1881);
}

#[test]
fn test_from_bits_le_private() {
check_from_bits_le(Mode::Private, 9, 0, 1879, 1881);
check_from_bits_le(Mode::Private, 9, 0, 1875, 1881);
}

#[test]
fn test_from_bits_be_constant() {
check_from_bits_be(Mode::Constant, 276, 0, 0, 0);
check_from_bits_be(Mode::Constant, 272, 0, 0, 0);
}

#[test]
fn test_from_bits_be_public() {
check_from_bits_be(Mode::Public, 9, 0, 1879, 1881);
check_from_bits_be(Mode::Public, 9, 0, 1875, 1881);
}

#[test]
fn test_from_bits_be_private() {
check_from_bits_be(Mode::Private, 9, 0, 1879, 1881);
check_from_bits_be(Mode::Private, 9, 0, 1875, 1881);
}
}
2 changes: 1 addition & 1 deletion circuit/account/src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod tests {

#[test]
fn test_signature_new_public() -> Result<()> {
check_new(Mode::Public, 9, 6, 873, 875)
check_new(Mode::Public, 9, 6, 869, 873)
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions circuit/account/src/signature/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ pub(crate) mod tests {

#[test]
fn test_verify_public() -> Result<()> {
check_verify(Mode::Public, 1757, 0, 7783, 7792)
check_verify(Mode::Public, 1757, 0, 7783, 7789)
}

#[test]
fn test_verify_private() -> Result<()> {
check_verify(Mode::Private, 1757, 0, 7783, 7792)
check_verify(Mode::Private, 1757, 0, 7783, 7789)
}

#[test]
Expand All @@ -148,11 +148,11 @@ pub(crate) mod tests {

#[test]
fn test_verify_large_public() -> Result<()> {
check_verify_large(Mode::Public, 1757, 0, 8308, 8317)
check_verify_large(Mode::Public, 1757, 0, 8308, 8314)
}

#[test]
fn test_verify_large_private() -> Result<()> {
check_verify_large(Mode::Private, 1757, 0, 8308, 8317)
check_verify_large(Mode::Private, 1757, 0, 8308, 8314)
}
}
10 changes: 5 additions & 5 deletions circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> HashUncompres
let lambda: Field<E> = witness!(|this_x, this_y, that_x, that_y| (that_y - this_y) / (that_x - this_x));

// Ensure `lambda` is correct by enforcing:
// `lambda * (that_x - this_x) == (that_y - this_y)`
E::enforce(|| (&lambda, that_x - this_x, that_y - this_y));
// `(that_x - this_x) * lambda == (that_y - this_y)`
E::enforce(|| (that_x - this_x, &lambda, that_y - this_y));

// Construct `sum_x` as a witness defined as:
// `sum_x := (B * lambda^2) - A - this_x - that_x`
Expand All @@ -78,8 +78,8 @@ impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> HashUncompres
let sum_y: Field<E> = witness!(|lambda, sum_x, this_x, this_y| -(this_y + (lambda * (sum_x - this_x))));

// Ensure `sum_y` is correct by enforcing:
// `(lambda * (this_x - sum_x)) == (this_y + sum_y)`
E::enforce(|| (&lambda, this_x - &sum_x, this_y + &sum_y));
// `(this_x - sum_x) * lambda == (this_y + sum_y)`
E::enforce(|| (this_x - &sum_x, &lambda, this_y + &sum_y));

(sum_x, sum_y)
};
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> HashUncompres
// which is equivalent to:
// if `bit_2 == 0`, then `montgomery_y = -1/2 * -2 * y = y`
// if `bit_2 == 1`, then `montgomery_y = 1/2 * -2 * y = -y`
E::enforce(|| (bit_2 - &one_half, -y.double(), &montgomery_y)); // 1 constraint
E::enforce(|| (-y.double(), bit_2 - &one_half, &montgomery_y)); // 1 constraint

montgomery_y
};
Expand Down
Loading

0 comments on commit c1af0b5

Please sign in to comment.