Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 138 additions & 211 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,27 @@ rust-version = "1.90"
repository = "https://github.com/tachyon-zcash/ragu"

[workspace.dependencies]
ff = { version = "0.13", default-features = false }
group = { version = "0.13", default-features = false }
ff = { version = "0.14.0-pre.0", default-features = false }
group = { version = "0.14.0-pre.0", default-features = false }
pasta_curves = "0.5.1"
rand = "0.8.5"
rand = "0.9"
lazy_static = "1.5.0"
proptest = "1.7.0"
gungraun = "0.17.0"

[patch.crates-io]
# `ebfull/addchain` branch `bump-num-bigint` is a replica of
# https://github.com/str4d/addchain/pull/3
# that updates `addchain` to use `num_bigint 0.4`
addchain = { git = "https://github.com/ebfull/addchain", rev = "da4099a81bc29c895f3ca0ebcaae21c860494c12" }

# `ebfull/ff` branch `release-0.14.0` is a fork of
# https://github.com/zkcrypto/ff/pull/130
# which updates `ff` to bump `num-bigint` and `syn`
# dependencies to align with our local usage in `ragu_macros`
ff = { git = "https://github.com/ebfull/ff", rev = "e46e1d268bc026708c8ddeb2d49766ea49f9e70e" }

# `ebfull/pasta_curves` branch `ff-0.14` is a replica of
# https://github.com/zcash/pasta_curves/pull/86
# that updates `pasta_curves` to use `ff`/`group` `0.14.0-pre.0`
pasta_curves = { git = "https://github.com/ebfull/pasta_curves", rev = "32152d552b1c39fb3ffab8f0d8646f946c4adecc" }
4 changes: 2 additions & 2 deletions crates/ragu_arithmetic/src/uendo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ pub struct Uendo {
limbs: [u64; LIMBS],
}

impl rand::distributions::Distribution<Uendo> for rand::distributions::Standard {
impl rand::distr::Distribution<Uendo> for rand::distr::StandardUniform {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Uendo {
let mut limbs = [0; LIMBS];
for limb in &mut limbs {
*limb = rng.r#gen();
*limb = rng.random();
}
Uendo { limbs }.normalized()
}
Expand Down
1 change: 0 additions & 1 deletion crates/ragu_arithmetic/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ pub fn poly_with_roots<F: PrimeField>(roots: &[F]) -> Vec<F> {
#[cfg(test)]
mod poly_with_roots_tests {
use super::*;
use alloc::format;
use ff::Field;
use pasta_curves::Fp as F;
use proptest::prelude::*;
Expand Down
8 changes: 3 additions & 5 deletions crates/ragu_circuits/src/polynomials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ impl_rank_for_R! {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,2
#[test]
fn test_tz() {
use ragu_pasta::Fp;
use rand::thread_rng;

type DemoR = R<7>;

Expand All @@ -131,7 +130,7 @@ fn test_tz() {
poly.u.push(Fp::ONE);
poly.v.push(Fp::ONE);
}
let z = Fp::random(thread_rng());
let z = Fp::random(&mut rand::rng());
poly.dilate(z);
poly.negate();

Expand All @@ -151,10 +150,9 @@ fn test_tz() {
#[test]
fn test_txz_consistency() {
use ragu_pasta::Fp;
use rand::thread_rng;
type DemoR = R<10>;
let z = Fp::random(thread_rng());
let x = Fp::random(thread_rng());
let z = Fp::random(&mut rand::rng());
let x = Fp::random(&mut rand::rng());
let txz = DemoR::txz(x, z);
let tx0 = DemoR::txz(x, Fp::ZERO);
let t0z: Fp = DemoR::txz(Fp::ZERO, z);
Expand Down
76 changes: 34 additions & 42 deletions crates/ragu_circuits/src/polynomials/structured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,19 @@ impl<F: Field, R: Rank> Polynomial<F, R> {
#[test]
fn test_eval() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<6>;

for insertions in 0..R::n() {
let mut poly = Polynomial::<Fp, R>::new();
for _ in 0..insertions {
poly.u.push(Fp::random(thread_rng()));
poly.v.push(Fp::random(thread_rng()));
poly.w.push(Fp::random(thread_rng()));
poly.d.push(Fp::random(thread_rng()));
poly.u.push(Fp::random(&mut rand::rng()));
poly.v.push(Fp::random(&mut rand::rng()));
poly.w.push(Fp::random(&mut rand::rng()));
poly.d.push(Fp::random(&mut rand::rng()));
}

let x = Fp::random(thread_rng());
let x = Fp::random(&mut rand::rng());

assert_eq!(
arithmetic::eval(&poly.unstructured().coeffs, x),
Expand Down Expand Up @@ -429,7 +428,6 @@ fn test_backward_forward() {
#[test]
fn test_dilate() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<5>;

Expand All @@ -439,19 +437,19 @@ fn test_dilate() {
for insertions_d in 0..R::n() {
let mut poly = Polynomial::<Fp, R>::new();
for _ in 0..insertions_a {
poly.u.push(Fp::random(thread_rng()));
poly.u.push(Fp::random(&mut rand::rng()));
}
for _ in 0..insertions_b {
poly.v.push(Fp::random(thread_rng()));
poly.v.push(Fp::random(&mut rand::rng()));
}
for _ in 0..insertions_c {
poly.w.push(Fp::random(thread_rng()));
poly.w.push(Fp::random(&mut rand::rng()));
}
for _ in 0..insertions_d {
poly.d.push(Fp::random(thread_rng()));
poly.d.push(Fp::random(&mut rand::rng()));
}
let x = Fp::random(thread_rng());
let z = Fp::random(thread_rng());
let x = Fp::random(&mut rand::rng());
let z = Fp::random(&mut rand::rng());
let upoly = poly.unstructured();
poly.dilate(z);
let vpoly = poly.unstructured();
Expand All @@ -468,17 +466,16 @@ fn test_dilate() {
#[test]
fn test_negate() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<6>;

for insertions in 0..R::n() {
let mut poly = Polynomial::<Fp, R>::new();
for _ in 0..insertions {
poly.u.push(Fp::random(thread_rng()));
poly.v.push(Fp::random(thread_rng()));
poly.w.push(Fp::random(thread_rng()));
poly.d.push(Fp::random(thread_rng()));
poly.u.push(Fp::random(&mut rand::rng()));
poly.v.push(Fp::random(&mut rand::rng()));
poly.w.push(Fp::random(&mut rand::rng()));
poly.d.push(Fp::random(&mut rand::rng()));
}

let original = poly.clone();
Expand All @@ -502,20 +499,19 @@ fn test_negate() {
assert_eq!(*negated, -*orig);
}

let x = Fp::random(thread_rng());
let x = Fp::random(&mut rand::rng());
assert_eq!(poly.eval(x), -original.eval(x));
}
}

#[test]
fn test_constant_term() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<6>;

let mut poly = Polynomial::<Fp, R>::new();
let random_value = Fp::random(thread_rng());
let random_value = Fp::random(&mut rand::rng());

*poly.constant_term() = random_value;

Expand All @@ -528,16 +524,15 @@ fn test_constant_term() {
#[test]
fn test_prod() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<7>;

let mut rx = Polynomial::<Fp, R>::new();
{
let rx = rx.forward();
for _ in 0..R::n() {
let a = Fp::random(thread_rng());
let b = Fp::random(thread_rng());
let a = Fp::random(&mut rand::rng());
let b = Fp::random(&mut rand::rng());

rx.a.push(a);
rx.b.push(b);
Expand All @@ -546,7 +541,7 @@ fn test_prod() {
}

let mut rzx = rx.clone();
let z = Fp::random(thread_rng());
let z = Fp::random(&mut rand::rng());
rzx.dilate(z);
rzx.add_assign(&R::tz::<Fp>(z));

Expand All @@ -561,28 +556,27 @@ fn test_prod() {
fn test_commit_consistency() {
use arithmetic::Cycle;
use ragu_pasta::{Fp, Pasta};
use rand::thread_rng;

type R = super::R<10>;

let pasta = Pasta::baked();
let generators = Pasta::host_generators(pasta);

let blind = Fp::random(thread_rng());
let blind = Fp::random(&mut rand::rng());

let mut poly = Polynomial::<Fp, R>::new();

for _ in 0..R::n() / 4 {
poly.u.push(Fp::random(thread_rng()));
poly.u.push(Fp::random(&mut rand::rng()));
}
for _ in 0..R::n() / 3 {
poly.v.push(Fp::random(thread_rng()));
poly.v.push(Fp::random(&mut rand::rng()));
}
for _ in 0..R::n() / 2 {
poly.w.push(Fp::random(thread_rng()));
poly.w.push(Fp::random(&mut rand::rng()));
}
for _ in 0..R::n() {
poly.d.push(Fp::random(thread_rng()));
poly.d.push(Fp::random(&mut rand::rng()));
}

let structured_commitment = poly.commit(generators, blind);
Expand All @@ -594,37 +588,36 @@ fn test_commit_consistency() {
#[test]
fn test_product_with_dot() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<5>;

let mut poly1 = Polynomial::<Fp, R>::new();
let mut poly2 = Polynomial::<Fp, R>::new();

for _ in 0..3 {
poly1.u.push(Fp::random(thread_rng()));
poly1.u.push(Fp::random(&mut rand::rng()));
}
for _ in 0..5 {
poly1.v.push(Fp::random(thread_rng()));
poly1.v.push(Fp::random(&mut rand::rng()));
}
for _ in 0..7 {
poly1.w.push(Fp::random(thread_rng()));
poly1.w.push(Fp::random(&mut rand::rng()));
}
for _ in 0..2 {
poly1.d.push(Fp::random(thread_rng()));
poly1.d.push(Fp::random(&mut rand::rng()));
}

for _ in 0..4 {
poly2.u.push(Fp::random(thread_rng()));
poly2.u.push(Fp::random(&mut rand::rng()));
}
for _ in 0..6 {
poly2.v.push(Fp::random(thread_rng()));
poly2.v.push(Fp::random(&mut rand::rng()));
}
for _ in 0..1 {
poly2.w.push(Fp::random(thread_rng()));
poly2.w.push(Fp::random(&mut rand::rng()));
}
for _ in 0..8 {
poly2.d.push(Fp::random(thread_rng()));
poly2.d.push(Fp::random(&mut rand::rng()));
}

assert_eq!(
Expand All @@ -639,11 +632,10 @@ fn test_product_with_dot() {
#[test]
fn ring_poly_test() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<5>;

let rand = || Fp::random(thread_rng());
let rand = || Fp::random(&mut rand::rng());

let little = arithmetic::Domain::<Fp>::new(2);
let big = arithmetic::Domain::<Fp>::new(3);
Expand Down
5 changes: 2 additions & 3 deletions crates/ragu_circuits/src/polynomials/txz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,14 @@ mod tests {
use crate::polynomials::R;
use ragu_pasta::Fp;
use ragu_primitives::Simulator;
use rand::thread_rng;

#[test]
fn simulate_txz() -> Result<()> {
// R<13> has log2_n = 11
type TestRank = R<13>;

let x = Fp::random(thread_rng());
let z = Fp::random(thread_rng());
let x = Fp::random(&mut rand::rng());
let z = Fp::random(&mut rand::rng());
let evaluator = Evaluate::<TestRank>::new();

Simulator::simulate((x, z), |dr, witness| {
Expand Down
11 changes: 5 additions & 6 deletions crates/ragu_circuits/src/polynomials/unstructured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,24 @@ impl<F: Field, R: Rank> AddAssign<&super::structured::Polynomial<F, R>> for Poly
#[test]
fn test_add_structured() {
use ragu_pasta::Fp;
use rand::thread_rng;

type R = super::R<13>;

let p = super::structured::Polynomial::<Fp, R>::random(&mut thread_rng());
let p = super::structured::Polynomial::<Fp, R>::random(&mut rand::rng());

let mut q = super::structured::Polynomial::<Fp, R>::new();
for i in 0..R::n() {
if i % 7 == 0 {
q.u.push(Fp::random(thread_rng()));
q.u.push(Fp::random(&mut rand::rng()));
}
if i % 5 == 0 {
q.v.push(Fp::random(thread_rng()));
q.v.push(Fp::random(&mut rand::rng()));
}
if i % 3 == 0 {
q.w.push(Fp::random(thread_rng()));
q.w.push(Fp::random(&mut rand::rng()));
}
if i % 2 == 0 {
q.d.push(Fp::random(thread_rng()));
q.d.push(Fp::random(&mut rand::rng()));
}
}

Expand Down
13 changes: 6 additions & 7 deletions crates/ragu_circuits/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ mod tests {
use ff::PrimeField;
use ragu_core::Result;
use ragu_pasta::{Fp, Pasta};
use rand::thread_rng;

type TestRank = R<8>;
type TestRegistryBuilder<'a> = RegistryBuilder<'a, Fp, TestRank>;
Expand Down Expand Up @@ -527,9 +526,9 @@ mod tests {
.register_circuit(SquareCircuit { times: 19 })?
.finalize(poseidon)?;

let w = Fp::random(thread_rng());
let x = Fp::random(thread_rng());
let y = Fp::random(thread_rng());
let w = Fp::random(&mut rand::rng());
let x = Fp::random(&mut rand::rng());
let y = Fp::random(&mut rand::rng());

let xy_poly = registry.xy(x, y);
let wy_poly = registry.wy(w, y);
Expand Down Expand Up @@ -661,9 +660,9 @@ mod tests {
let expected_domain_size = num_circuits.next_power_of_two();
assert_eq!(registry.domain.n(), expected_domain_size);

let w = Fp::random(thread_rng());
let x = Fp::random(thread_rng());
let y = Fp::random(thread_rng());
let w = Fp::random(&mut rand::rng());
let x = Fp::random(&mut rand::rng());
let y = Fp::random(&mut rand::rng());

let wxy = registry.wxy(w, x, y);
let xy = registry.xy(x, y);
Expand Down
Loading