diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index b686bf181..60ae616da 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -62,7 +62,7 @@ jobs: cache-suffix: bench - name: Build benchmarks - run: cargo bench --workspace --all-features --locked --bench arithmetic --bench circuits --bench pcd --bench primitives --no-run + run: cargo bench --workspace --locked --bench arithmetic --bench circuits --bench pcd --bench primitives --no-run # Push-to-main: full run + save baseline for future comparisons # Manual dispatch: full run + regression summary against a chosen baseline @@ -109,7 +109,7 @@ jobs: find target/gungraun -name 'summary.json' -delete - name: Run benchmarks - run: cargo bench --workspace --all-features --locked --bench arithmetic --bench circuits --bench pcd --bench primitives -- --save-summary=json + run: cargo bench --workspace --locked --bench arithmetic --bench circuits --bench pcd --bench primitives -- --save-summary=json - name: Summarize benchmark regressions if: github.event_name == 'workflow_dispatch' diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml index 46317d289..af72304cd 100644 --- a/.github/workflows/debug.yml +++ b/.github/workflows/debug.yml @@ -25,4 +25,4 @@ jobs: - name: Setup Rust uses: ./.github/actions/rust-setup - name: Run debug tests - run: cargo test --all --locked --all-features --verbose + run: cargo test --all --locked --verbose diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 456ab3359..005d28dab 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -80,7 +80,25 @@ jobs: with: components: clippy - name: Run clippy - run: cargo clippy --workspace --lib --tests --benches --locked --all-features -- -D warnings + run: cargo clippy --workspace --lib --tests --benches --locked -- -D warnings + + legacy-check: + name: legacy dependency check + needs: changes + if: needs.changes.outputs.rust == 'true' || github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + with: + persist-credentials: false + - name: Setup Rust + uses: ./.github/actions/rust-setup + with: + cache-suffix: legacy-deps + - name: Check runtime crates with legacy dependencies + run: cargo check -p ragu_arithmetic -p ragu_pasta -p ragu_core -p ragu_primitives -p ragu_circuits -p ragu_pcd --lib --locked --no-default-features --features "alloc legacy-deps" + - name: Check root crate with legacy dependencies + run: cargo check -p ragu --lib --locked --no-default-features --features legacy-deps proptests-fast: name: proptests (fast) @@ -96,7 +114,7 @@ jobs: with: cache-suffix: proptests-fast - name: Run fast proptests - run: cargo test --release -p ragu_arithmetic -p ragu_core --locked --all-features proptest + run: cargo test --release -p ragu_arithmetic -p ragu_core --locked proptest env: PROPTEST_CASES: "64" @@ -118,7 +136,7 @@ jobs: with: cache-suffix: release - name: Run tests - run: cargo test --release --all --locked --all-features + run: cargo test --release --all --locked test-32-bit: name: test (i686-unknown-linux-gnu) @@ -136,7 +154,7 @@ jobs: apt-packages: gcc-multilib cache-suffix: release - name: Run 32-bit tests - run: cargo test --release --all --locked --all-features --target i686-unknown-linux-gnu + run: cargo test --release --all --locked --target i686-unknown-linux-gnu bitrot: name: bitrot check @@ -150,9 +168,9 @@ jobs: - name: Setup Rust uses: ./.github/actions/rust-setup with: - cache-suffix: all-features + cache-suffix: default-features - name: Build benchmarks and examples - run: cargo build --benches --examples --all-features + run: cargo build --benches --examples fuzz-check: name: fuzz harness check (nightly) diff --git a/Cargo.lock b/Cargo.lock index e812f411f..127dd109a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -382,9 +382,20 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "ff" -version = "0.14.0-pre.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d1fa20678d31fcd57b1e146f5ca2c24282428601f45a1002a0d2a54136ef681" +checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393" +dependencies = [ + "bitvec", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "ff" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f686ab92a9fb0eaf188f6c6c87b89490baa6fdb0db4544ba4dc47f7942489f" dependencies = [ "bitvec", "ff_derive", @@ -394,9 +405,9 @@ dependencies = [ [[package]] name = "ff_derive" -version = "0.14.0-pre.1" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc58d7ca5bc500948e3ef5837fbbe707a4a9475e24346121ab8f793a14fd0eaf" +checksum = "241afe8c15ffa21933eaefe8a563af36fd9fc98a3e8a044e8f7db52eb1fae3d8" dependencies = [ "addchain", "num-bigint", @@ -425,6 +436,17 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -453,11 +475,22 @@ dependencies = [ [[package]] name = "group" -version = "0.14.0-pre.1" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff 0.13.1", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "group" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d2d58f7caba35039967de2de47857f38cba03e6b173d32fef14412282d49ac9" +checksum = "7fd1a1c7a5206c5b7a3f5a0d7ccd3ff85d0c8f5133d62a02680255b0004af5f4" dependencies = [ - "ff", + "ff 0.14.0", "rand_core 0.10.0", "subtle", ] @@ -601,8 +634,8 @@ name = "lean_extraction" version = "0.0.0" dependencies = [ "clap", - "ff", - "group", + "ff 0.14.0", + "group 0.14.0", "ragu_arithmetic", "ragu_core", "ragu_pasta", @@ -698,13 +731,28 @@ checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "pasta_curves" version = "0.5.1" -source = "git+https://github.com/ebfull/pasta_curves?rev=4b2c768ec4b14b2c7fa0f6e527e453cde97805aa#4b2c768ec4b14b2c7fa0f6e527e453cde97805aa" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" +dependencies = [ + "blake2b_simd", + "ff 0.13.1", + "group 0.13.0", + "lazy_static", + "rand 0.8.6", + "static_assertions", + "subtle", +] + +[[package]] +name = "pasta_curves" +version = "0.5.1" +source = "git+https://github.com/ebfull/pasta_curves?rev=5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5#5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5" dependencies = [ "blake2b_simd", - "ff", - "group", + "ff 0.14.0", + "group 0.14.0", "lazy_static", - "rand 0.10.0", + "rand 0.10.1", "static_assertions", "subtle", ] @@ -779,7 +827,7 @@ dependencies = [ "bitflags", "num-traits", "rand 0.9.2", - "rand_chacha", + "rand_chacha 0.9.0", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -830,14 +878,19 @@ name = "ragu_arithmetic" version = "0.0.0" dependencies = [ "criterion", - "ff", + "ff 0.13.1", + "ff 0.14.0", + "group 0.13.0", + "group 0.14.0", "gungraun", "maybe-rayon", - "pasta_curves", + "pasta_curves 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "pasta_curves 0.5.1 (git+https://github.com/ebfull/pasta_curves?rev=5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5)", "proptest", "ragu_macros", "ragu_testing", - "rand 0.10.0", + "rand 0.10.1", + "rand 0.8.6", ] [[package]] @@ -846,32 +899,32 @@ version = "0.0.0" dependencies = [ "blake2b_simd", "criterion", - "ff", - "group", + "ff 0.14.0", + "group 0.14.0", "gungraun", "maybe-rayon", - "pasta_curves", + "pasta_curves 0.5.1 (git+https://github.com/ebfull/pasta_curves?rev=5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5)", "proptest", "ragu_arithmetic", "ragu_core", "ragu_pasta", "ragu_primitives", "ragu_testing", - "rand 0.10.0", + "rand 0.10.1", ] [[package]] name = "ragu_core" version = "0.0.0" dependencies = [ - "ff", - "group", + "ff 0.14.0", + "group 0.14.0", "proptest", "ragu_arithmetic", "ragu_macros", "ragu_pasta", "ragu_testing", - "rand 0.10.0", + "rand 0.10.1", "thiserror", ] @@ -898,10 +951,7 @@ dependencies = [ name = "ragu_pasta" version = "0.0.0" dependencies = [ - "ff", - "group", "lazy_static", - "pasta_curves", "ragu_arithmetic", ] @@ -910,10 +960,10 @@ name = "ragu_pcd" version = "0.0.0" dependencies = [ "criterion", - "ff", + "ff 0.14.0", "gungraun", "maybe-rayon", - "pasta_curves", + "pasta_curves 0.5.1 (git+https://github.com/ebfull/pasta_curves?rev=5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5)", "proptest", "ragu_arithmetic", "ragu_circuits", @@ -921,15 +971,15 @@ dependencies = [ "ragu_pasta", "ragu_primitives", "ragu_testing", - "rand 0.10.0", + "rand 0.10.1", ] [[package]] name = "ragu_primitives" version = "0.0.0" dependencies = [ - "ff", - "group", + "ff 0.14.0", + "group 0.14.0", "gungraun", "proptest", "ragu_arithmetic", @@ -937,7 +987,7 @@ dependencies = [ "ragu_macros", "ragu_pasta", "ragu_testing", - "rand 0.10.0", + "rand 0.10.1", "thiserror", ] @@ -945,14 +995,25 @@ dependencies = [ name = "ragu_testing" version = "0.0.0" dependencies = [ - "ff", + "ff 0.14.0", "proptest", "ragu_arithmetic", "ragu_circuits", "ragu_core", "ragu_pcd", "ragu_primitives", - "rand 0.10.0", + "rand 0.10.1", +] + +[[package]] +name = "rand" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", ] [[package]] @@ -961,21 +1022,31 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ - "rand_chacha", + "rand_chacha 0.9.0", "rand_core 0.9.5", ] [[package]] name = "rand" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", "getrandom 0.4.1", "rand_core 0.10.0", ] +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + [[package]] name = "rand_chacha" version = "0.9.0" @@ -986,6 +1057,15 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + [[package]] name = "rand_core" version = "0.9.5" @@ -1308,6 +1388,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.2+wasi-0.2.9" @@ -1492,18 +1578,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.38" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57cf3aa6855b23711ee9852dfc97dfaa51c45feaba5b645d0c777414d494a961" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.38" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a616990af1a287837c4fe6596ad77ef57948f787e46ce28e166facc0cc1cb75" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index bcb200a6f..eefb54b8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,10 +17,25 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["modern-deps", "multicore"] [features] -default = ["multicore"] +default = ["modern-deps", "multicore"] +modern-deps = [ + "ragu_arithmetic/modern-deps", + "ragu_circuits/modern-deps", + "ragu_core/modern-deps", + "ragu_primitives/modern-deps", + "ragu_pcd/modern-deps", +] +legacy-deps = [ + "ragu_arithmetic/legacy-deps", + "ragu_circuits/legacy-deps", + "ragu_core/legacy-deps", + "ragu_primitives/legacy-deps", + "ragu_pcd/legacy-deps", +] multicore = [ "ragu_arithmetic/multicore", "ragu_circuits/multicore", @@ -32,11 +47,11 @@ std = [] bench = false [dependencies] -ragu_core = { path = "crates/ragu_core", version = "0.0.0" } -ragu_circuits = { path = "crates/ragu_circuits", version = "0.0.0" } -ragu_arithmetic = { path = "crates/ragu_arithmetic", version = "0.0.0" } -ragu_primitives = { path = "crates/ragu_primitives", version = "0.0.0" } -ragu_pcd = { path = "crates/ragu_pcd", version = "0.0.0" } +ragu_core = { path = "crates/ragu_core", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_circuits = { path = "crates/ragu_circuits", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_arithmetic = { path = "crates/ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_primitives = { path = "crates/ragu_primitives", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_pcd = { path = "crates/ragu_pcd", version = "0.0.0", default-features = false, features = ["alloc"] } [workspace] members = [ @@ -67,26 +82,24 @@ rust-version = "1.90" repository = "https://github.com/tachyon-zcash/ragu" [workspace.dependencies] -ff = { version = "0.14.0-pre.1", default-features = false } -group = { version = "0.14.0-pre.1", default-features = false } -pasta_curves = { version = "0.5.1", features = ["deferred"] } +# Keep the unaliased modern ff/group/pasta_curves/rand entries in sync with +# qa/fuzz/Cargo.toml. The cargo-fuzz workspace is intentionally isolated and +# cannot inherit these workspace dependencies. +ff = { version = "0.14", default-features = false } +group = { version = "0.14", default-features = false } +pasta_curves = { git = "https://github.com/ebfull/pasta_curves", rev = "5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5", features = ["deferred"] } rand = "0.10" +ff_modern = { package = "ff", version = "0.14", default-features = false } +group_modern = { package = "group", version = "0.14", default-features = false } +pasta_curves_modern = { package = "pasta_curves", git = "https://github.com/ebfull/pasta_curves", rev = "5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5", features = ["deferred"] } +rand_modern = { package = "rand", version = "0.10" } +ff_legacy = { package = "ff", version = "0.13", default-features = false } +group_legacy = { package = "group", version = "0.13", default-features = false } +pasta_curves_legacy = { package = "pasta_curves", version = "0.5.1" } +rand_legacy = { package = "rand", version = "0.8" } lazy_static = "1.5.0" proptest = "1.11.0" gungraun = "0.17.0" blake2b_simd = "1.0" maybe-rayon = { version = "0.1.1", default-features = false } criterion = { version = "0.5", default-features = false } - -# NOTE: `qa/fuzz/Cargo.toml` is its own workspace root -# (cargo-fuzz convention) and `[patch.crates-io]` does not propagate into -# nested workspaces. If you add, remove, or change any patch below, mirror -# the change in that file or fuzz builds will resolve different versions -# than the rest of the workspace. -[patch.crates-io] -# `ebfull/pasta_curves` branch `ff-0.14-for-ragu` HEAD as of 2026-05-21. -# Stacks on the prior `ff-0.14-with-rand-0.10-and-deferred-redux` work -# (ff/group 0.14.0-pre.0, rand 0.10, deferred reduction, try_random rename) -# and adds adaptation for the new `CurveAffine` API from upstream `group` -# release-0.14.0 (PR #48). -pasta_curves = { git = "https://github.com/ebfull/pasta_curves", rev = "4b2c768ec4b14b2c7fa0f6e527e453cde97805aa" } diff --git a/crates/ragu_arithmetic/Cargo.toml b/crates/ragu_arithmetic/Cargo.toml index ce8e8a6f3..2491c0eb1 100644 --- a/crates/ragu_arithmetic/Cargo.toml +++ b/crates/ragu_arithmetic/Cargo.toml @@ -17,11 +17,24 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = [ + "dep:ff_legacy", + "dep:group_legacy", + "dep:pasta_curves_legacy", + "dep:rand_legacy", +] +modern-deps = [ + "dep:ff_modern", + "dep:group_modern", + "dep:pasta_curves_modern", + "dep:rand_modern", +] multicore = ["maybe-rayon/threads", "std"] std = [] @@ -29,10 +42,15 @@ std = [] bench = false [dependencies] -ff = { workspace = true } -pasta_curves = { workspace = true } +ff_modern = { workspace = true, optional = true } +group_modern = { workspace = true, optional = true } +pasta_curves_modern = { workspace = true, optional = true } +rand_modern = { workspace = true, optional = true } +ff_legacy = { workspace = true, optional = true } +group_legacy = { workspace = true, optional = true } +pasta_curves_legacy = { workspace = true, optional = true } +rand_legacy = { workspace = true, optional = true } ragu_macros = { path = "../ragu_macros", version = "0.0.0" } -rand = { workspace = true } maybe-rayon = { workspace = true } [dev-dependencies] diff --git a/crates/ragu_arithmetic/benches/arithmetic.rs b/crates/ragu_arithmetic/benches/arithmetic.rs index 828d5e175..7684aef5d 100644 --- a/crates/ragu_arithmetic/benches/arithmetic.rs +++ b/crates/ragu_arithmetic/benches/arithmetic.rs @@ -3,8 +3,11 @@ mod setup; use std::hint::black_box; use gungraun::{library_benchmark, library_benchmark_group, main}; -use pasta_curves::{EpAffine, Fp, Fq}; -use ragu_arithmetic::{Domain, dot, eval, factor, geosum, mul, poly_with_roots}; +use ragu_arithmetic::{ + Domain, dot, eval, factor, geosum, mul, + pasta_curves::{EpAffine, Fp, Fq}, + poly_with_roots, +}; use setup::{f, setup_domain_ell, setup_domain_fft, setup_rng, setup_with_rng, vec_affine, vec_f}; #[library_benchmark(setup = setup_rng)] diff --git a/crates/ragu_arithmetic/benches/criterion/fft.rs b/crates/ragu_arithmetic/benches/criterion/fft.rs index 3537d1063..6f797af2d 100644 --- a/crates/ragu_arithmetic/benches/criterion/fft.rs +++ b/crates/ragu_arithmetic/benches/criterion/fft.rs @@ -1,8 +1,10 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use ff::Field; -use pasta_curves::Fp; -use ragu_arithmetic::Domain; -use rand::{SeedableRng, rngs::StdRng}; +use ragu_arithmetic::{ + Domain, + ff::Field, + pasta_curves::Fp, + rand::{SeedableRng, rngs::StdRng}, +}; fn fft_bench(c: &mut Criterion) { let mut group = c.benchmark_group("fft"); diff --git a/crates/ragu_arithmetic/benches/criterion/msm.rs b/crates/ragu_arithmetic/benches/criterion/msm.rs index 27161355f..eb17b051b 100644 --- a/crates/ragu_arithmetic/benches/criterion/msm.rs +++ b/crates/ragu_arithmetic/benches/criterion/msm.rs @@ -1,8 +1,10 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main}; -use ff::Field; -use pasta_curves::{EpAffine, Fq, group::CurveAffine}; -use ragu_arithmetic::mul; -use rand::{SeedableRng, rngs::StdRng}; +use ragu_arithmetic::{ + ff::Field, + mul, + pasta_curves::{EpAffine, Fq, group::CurveAffine}, + rand::{SeedableRng, rngs::StdRng}, +}; fn msm_bench(c: &mut Criterion) { let mut group = c.benchmark_group("msm"); diff --git a/crates/ragu_arithmetic/benches/setup/mod.rs b/crates/ragu_arithmetic/benches/setup/mod.rs index e764a7a4a..fc8d285af 100644 --- a/crates/ragu_arithmetic/benches/setup/mod.rs +++ b/crates/ragu_arithmetic/benches/setup/mod.rs @@ -1,7 +1,9 @@ -use ff::Field; -use pasta_curves::{EpAffine, Fp, Fq, group::CurveAffine}; -use ragu_arithmetic::Domain; -use rand::{SeedableRng, rngs::StdRng}; +use ragu_arithmetic::{ + Domain, + ff::Field, + pasta_curves::{EpAffine, Fp, Fq, group::CurveAffine}, + rand::{SeedableRng, rngs::StdRng}, +}; pub trait SetupRng { fn setup(self, rng: &mut StdRng) -> Out; diff --git a/crates/ragu_arithmetic/src/coeff.rs b/crates/ragu_arithmetic/src/coeff.rs index 85bac4735..9cc6e2383 100644 --- a/crates/ragu_arithmetic/src/coeff.rs +++ b/crates/ragu_arithmetic/src/coeff.rs @@ -1,6 +1,6 @@ use core::ops::{Add, Mul}; -use ff::Field; +use crate::ff::Field; /// Represents a field element (typically a coefficient) that may have a special /// value. By representing these cases explicitly, `Coeff` maintains context @@ -118,10 +118,11 @@ impl Add for Coeff { #[cfg(test)] mod proptests { - use pasta_curves::Fp as F; use proptest::prelude::*; use ragu_testing::strategies; + use crate::pasta_curves::Fp as F; + proptest! { #[test] fn proptest_coeff_mul(coeff1 in strategies::coeff::(), coeff2 in strategies::coeff::()) { @@ -141,7 +142,7 @@ mod proptests { #[test] fn proptest_coeff_is_zero(coeff in strategies::coeff::()) { - use ff::Field; + use crate::ff::Field; prop_assert_eq!(coeff.is_zero(), bool::from(coeff.value().is_zero())); } } diff --git a/crates/ragu_arithmetic/src/deferred.rs b/crates/ragu_arithmetic/src/deferred.rs new file mode 100644 index 000000000..17709562e --- /dev/null +++ b/crates/ragu_arithmetic/src/deferred.rs @@ -0,0 +1,82 @@ +use core::fmt; + +use crate::ff::Field; + +/// A field that can accumulate products before reducing to a canonical element. +/// +/// Implementations may defer reduction across many products for efficiency; call +/// [`reduce`](DeferredField::reduce) to obtain the canonical field element. +pub trait DeferredField: Field { + /// The accumulator used for unreduced or eagerly-reduced products. + type Accumulator: Copy + Clone + fmt::Debug + Default; + + /// Multiplies `a` by `b` and adds the product into `acc`. + fn mul_accumulate(acc: &mut Self::Accumulator, a: &Self, b: &Self); + + /// Squares `a` and adds the product into `acc`. + fn square_accumulate(acc: &mut Self::Accumulator, a: &Self); + + /// Reduces the accumulator to a canonical field element. + fn reduce(acc: Self::Accumulator) -> Self; +} + +// In modern dependency mode this delegates to `pasta_curves` deferred reduction. +#[cfg(feature = "modern-deps")] +impl DeferredField for F +where + F: crate::pasta_curves::deferred::DeferredField, +{ + type Accumulator = ::Accumulator; + + fn mul_accumulate(acc: &mut Self::Accumulator, a: &Self, b: &Self) { + ::mul_accumulate(acc, a, b); + } + + fn square_accumulate(acc: &mut Self::Accumulator, a: &Self) { + ::square_accumulate(acc, a); + } + + fn reduce(acc: Self::Accumulator) -> Self { + ::reduce(acc) + } +} + +/// Eager accumulator used when legacy dependencies do not provide deferred reduction. +/// +/// Must be `pub`: it is the value of [`DeferredField::Accumulator`], a public +/// associated type, even though the `deferred` module itself is private. +#[cfg(feature = "legacy-deps")] +#[derive(Clone, Copy)] +pub struct EagerAccumulator(F); + +#[cfg(feature = "legacy-deps")] +impl Default for EagerAccumulator { + fn default() -> Self { + Self(F::ZERO) + } +} + +#[cfg(feature = "legacy-deps")] +impl fmt::Debug for EagerAccumulator { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_tuple("EagerAccumulator").finish() + } +} + +// In legacy dependency mode this falls back to ordinary eager field arithmetic. +#[cfg(feature = "legacy-deps")] +impl DeferredField for F { + type Accumulator = EagerAccumulator; + + fn mul_accumulate(acc: &mut Self::Accumulator, a: &Self, b: &Self) { + acc.0 += *a * *b; + } + + fn square_accumulate(acc: &mut Self::Accumulator, a: &Self) { + acc.0 += a.square(); + } + + fn reduce(acc: Self::Accumulator) -> Self { + acc.0 + } +} diff --git a/crates/ragu_arithmetic/src/domain.rs b/crates/ragu_arithmetic/src/domain.rs index 6dd0fa8de..c036c88a0 100644 --- a/crates/ragu_arithmetic/src/domain.rs +++ b/crates/ragu_arithmetic/src/domain.rs @@ -1,6 +1,6 @@ use alloc::{vec, vec::Vec}; -use ff::PrimeField; +use crate::ff::PrimeField; /// Radix-2 evaluation domain of size $n = 2^k$ generated by powers of a /// primitive $n$-th root of unity $\omega$, consisting of the set @@ -194,7 +194,7 @@ impl Domain { .collect(); { let mut scratch = vec![F::ZERO; denominators.len()]; - ff::BatchInverter::invert_with_external_scratch(&mut denominators, &mut scratch); + crate::ff::BatchInverter::invert_with_external_scratch(&mut denominators, &mut scratch); } Some( @@ -213,10 +213,7 @@ impl Domain { #[test] fn test_fft() { - use ff::Field; - use pasta_curves::Fp as F; - - use crate::eval; + use crate::{eval, ff::Field, pasta_curves::Fp as F}; for log2_n in 1..=8 { let params = Domain::::new(log2_n); @@ -246,10 +243,7 @@ fn test_fft() { fn test_ell() { use alloc::vec; - use ff::Field; - use pasta_curves::Fp as F; - - use crate::eval; + use crate::{eval, ff::Field, pasta_curves::Fp as F}; let params = Domain::::new(5); @@ -278,8 +272,7 @@ fn test_ell() { #[test] fn test_contains() { - use ff::Field; - use pasta_curves::Fp as F; + use crate::{ff::Field, pasta_curves::Fp as F}; let domain = Domain::::new(5); @@ -298,10 +291,10 @@ fn test_contains() { #[cfg(test)] mod proptests { - use pasta_curves::Fp as F; use proptest::prelude::*; use super::*; + use crate::pasta_curves::Fp as F; fn arb_fe() -> impl Strategy { (any::(), any::()) @@ -326,7 +319,7 @@ mod proptests { #[test] #[should_panic] fn test_domain_exceeds_max_boundary_panics() { - use pasta_curves::Fp as F; + use crate::pasta_curves::Fp as F; let over_max = F::S + 1; let _domain = Domain::::new(over_max); diff --git a/crates/ragu_arithmetic/src/fft.rs b/crates/ragu_arithmetic/src/fft.rs index a06527320..1c5405b3c 100644 --- a/crates/ragu_arithmetic/src/fft.rs +++ b/crates/ragu_arithmetic/src/fft.rs @@ -1,6 +1,7 @@ -use ff::{Field, PrimeField}; - -use crate::multicore; +use crate::{ + ff::{Field, PrimeField}, + multicore, +}; /// A ring that can be used for FFTs. pub trait Ring { @@ -159,10 +160,8 @@ fn log2_floor(num: usize) -> u32 { mod tests { use alloc::{vec, vec::Vec}; - use pasta_curves::Fp; - use super::*; - use crate::domain::Domain; + use crate::{domain::Domain, pasta_curves::Fp}; fn naive_dft(input: &[F], omega: F) -> Vec { let n = input.len(); diff --git a/crates/ragu_arithmetic/src/lib.rs b/crates/ragu_arithmetic/src/lib.rs index 142e3925e..c889a6392 100644 --- a/crates/ragu_arithmetic/src/lib.rs +++ b/crates/ragu_arithmetic/src/lib.rs @@ -70,32 +70,79 @@ #[cfg(not(feature = "alloc"))] compile_error!("`ragu_arithmetic` requires the `alloc` feature to be enabled."); +#[cfg(all(feature = "modern-deps", feature = "legacy-deps"))] +compile_error!("`modern-deps` and `legacy-deps` are mutually exclusive."); +#[cfg(not(any(feature = "modern-deps", feature = "legacy-deps")))] +compile_error!("`ragu_arithmetic` requires either `modern-deps` or `legacy-deps`."); extern crate alloc; mod coeff; +mod deferred; mod domain; mod fft; mod multicore; mod util; +/// The selected `ff` crate. +#[cfg(feature = "legacy-deps")] +pub extern crate ff_legacy as ff; +/// The selected `ff` crate. +#[cfg(feature = "modern-deps")] +pub extern crate ff_modern as ff; +/// The selected `group` crate. +#[cfg(feature = "legacy-deps")] +pub extern crate group_legacy as group; +/// The selected `group` crate. +#[cfg(feature = "modern-deps")] +pub extern crate group_modern as group; +/// The selected `pasta_curves` crate. +#[cfg(feature = "legacy-deps")] +pub extern crate pasta_curves_legacy as pasta_curves; +/// The selected `pasta_curves` crate. +#[cfg(feature = "modern-deps")] +pub extern crate pasta_curves_modern as pasta_curves; +/// The selected `rand` crate. +#[cfg(feature = "legacy-deps")] +pub extern crate rand_legacy as rand; +/// The selected `rand` crate. +#[cfg(feature = "modern-deps")] +pub extern crate rand_modern as rand; + pub use coeff::Coeff; +pub use deferred::DeferredField; pub use domain::Domain; -use ff::{Field, FromUniformBytes, WithSmallOrderMulGroup}; pub use fft::{Ring, bitreverse}; -pub use pasta_curves::{ - arithmetic::{Coordinates, CurveAffine, CurveExt}, - deferred::DeferredField, -}; /// Converts a 256-bit integer literal into the little endian `[u64; 4]` -/// representation that e.g. [`Fp::from_raw`](pasta_curves::Fp::from_raw) or -/// [`Fp::pow`](pasta_curves::Fp::pow) need as input. This makes constants -/// slightly more readable, but is not intended for use in other contexts. +/// representation that e.g. [`Fp::from_raw`](crate::pasta_curves::Fp::from_raw) or +/// [`Fp::pow`](crate::pasta_curves::Fp::pow) need as input. This makes constants +/// more readable, but is not intended for use in other contexts. pub use ragu_macros::repr256; pub use util::{ batch_to_affine, decomp_product_poly, dot, eval, factor, factor_iter, geosum, low_u64, mul, poly_mul, poly_with_roots, }; +use crate::ff::{Field, FromUniformBytes, WithSmallOrderMulGroup}; +pub use crate::pasta_curves::arithmetic::{Coordinates, CurveAffine, CurveExt}; + +/// A random number generator suitable for cryptographic field sampling, +/// blanket-implemented for any [`CryptoRng`](crate::rand::CryptoRng) that is also +/// an [`Rng`](crate::rand::Rng). +#[cfg(feature = "modern-deps")] +pub trait CryptoRngCore: crate::rand::CryptoRng + crate::rand::Rng {} + +#[cfg(feature = "modern-deps")] +impl CryptoRngCore for RNG {} + +/// A random number generator suitable for cryptographic field sampling, +/// blanket-implemented for any [`CryptoRng`](crate::rand::CryptoRng) that is also +/// an [`RngCore`](crate::rand::RngCore). +#[cfg(feature = "legacy-deps")] +pub trait CryptoRngCore: crate::rand::CryptoRng + crate::rand::RngCore {} + +#[cfg(feature = "legacy-deps")] +impl CryptoRngCore for RNG {} + /// Represents a "cycle" of elliptic curves where the scalar field of one curve /// is the base field of the other, and vice-versa. /// diff --git a/crates/ragu_arithmetic/src/util.rs b/crates/ragu_arithmetic/src/util.rs index d10537daf..909376c81 100644 --- a/crates/ragu_arithmetic/src/util.rs +++ b/crates/ragu_arithmetic/src/util.rs @@ -1,13 +1,15 @@ use alloc::{boxed::Box, vec, vec::Vec}; -use ff::{Field, PrimeField}; -use pasta_curves::{ - arithmetic::CurveAffine, - group::{Curve, Group}, +use crate::{ + domain::Domain, + ff::{Field, PrimeField}, + multicore::*, + pasta_curves::{ + arithmetic::CurveAffine, + group::{Curve, Group}, + }, }; -use crate::{domain::Domain, multicore::*}; - /// Returns the low 64 bits of a [`PrimeField`] element's canonical /// little-endian representation. /// @@ -478,12 +480,11 @@ pub fn poly_with_roots(roots: &[F]) -> Vec { #[cfg(test)] mod poly_with_roots_tests { - use ff::Field; - use pasta_curves::Fp as F; use proptest::prelude::*; use ragu_testing::strategies; use super::*; + use crate::{ff::Field, pasta_curves::Fp as F}; fn check(roots: &[F]) -> Result<(), TestCaseError> { let poly = poly_with_roots(roots); @@ -523,7 +524,7 @@ mod poly_with_roots_tests { #[test] fn test_poly_with_roots() { - use pasta_curves::Fp as F; + use crate::pasta_curves::Fp as F; let roots = vec![F::from(1), F::from(2), F::from(3)]; let poly = poly_with_roots(&roots); @@ -545,11 +546,13 @@ fn test_poly_with_roots() { #[cfg(test)] mod proptests { - use ff::{Field, PrimeField}; - use pasta_curves::Fp as F; use proptest::prelude::*; use super::*; + use crate::{ + ff::{Field, PrimeField}, + pasta_curves::Fp as F, + }; fn arb_fe() -> impl Strategy { (any::(), any::()) @@ -740,31 +743,34 @@ mod proptests { #[test] fn test_mul() { - use pasta_curves::group::{Curve, CurveAffine}; + use crate::pasta_curves::group::{Curve, CurveAffine}; let mut coeffs = vec![]; for i in 0..1000 { - coeffs.push(pasta_curves::Fp::from(i) * pasta_curves::Fp::MULTIPLICATIVE_GENERATOR); + coeffs.push( + crate::pasta_curves::Fp::from(i) * crate::pasta_curves::Fp::MULTIPLICATIVE_GENERATOR, + ); } let mut bases = vec![]; for i in 0..1000 { - bases.push((pasta_curves::EqAffine::generator() * pasta_curves::Fp::from(i)).to_affine()); + bases.push( + (crate::pasta_curves::EqAffine::generator() * crate::pasta_curves::Fp::from(i)) + .to_affine(), + ); } - let expected = coeffs - .iter() - .zip(bases.iter()) - .fold(pasta_curves::Eq::identity(), |acc, (scalar, point)| { - acc + point * scalar - }); + let expected = coeffs.iter().zip(bases.iter()).fold( + crate::pasta_curves::Eq::identity(), + |acc, (scalar, point)| acc + point * scalar, + ); assert_eq!(mul(coeffs.iter(), bases.iter()), expected); } #[test] fn test_dot() { - use pasta_curves::Fp as F; + use crate::pasta_curves::Fp as F; let powers = [ F::ONE, @@ -783,7 +789,7 @@ fn test_dot() { #[test] fn test_factor() { - use pasta_curves::Fp as F; + use crate::pasta_curves::Fp as F; let poly = vec![ F::DELTA, @@ -803,7 +809,7 @@ fn test_factor() { #[test] fn test_geosum() { - use pasta_curves::Fp as F; + use crate::pasta_curves::Fp as F; fn geosum_slow(r: F, m: usize) -> F { let mut sum = F::ZERO; @@ -825,8 +831,7 @@ fn test_geosum() { #[test] fn test_batched_quotient_streaming() { - use ff::Field; - use pasta_curves::Fp as F; + use crate::{ff::Field, pasta_curves::Fp as F}; let polys: Vec> = vec![ vec![F::from(1), F::from(2), F::from(3), F::from(4)], diff --git a/crates/ragu_circuits/Cargo.toml b/crates/ragu_circuits/Cargo.toml index f6ce3816a..74034abf3 100644 --- a/crates/ragu_circuits/Cargo.toml +++ b/crates/ragu_circuits/Cargo.toml @@ -17,11 +17,22 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = [ + "ragu_arithmetic/legacy-deps", + "ragu_core/legacy-deps", + "ragu_primitives/legacy-deps", +] +modern-deps = [ + "ragu_arithmetic/modern-deps", + "ragu_core/modern-deps", + "ragu_primitives/modern-deps", +] multicore = ["maybe-rayon/threads", "ragu_arithmetic/multicore", "std"] std = [] @@ -29,17 +40,17 @@ std = [] bench = false [dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } blake2b_simd = { workspace = true } +ragu_core = { path = "../ragu_core", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_primitives = { path = "../ragu_primitives", version = "0.0.0", default-features = false, features = ["alloc"] } +maybe-rayon = { workspace = true } + +[dev-dependencies] ff = { workspace = true } group = { workspace = true } pasta_curves = { workspace = true } -ragu_core = { path = "../ragu_core", version = "0.0.0" } -ragu_primitives = { path = "../ragu_primitives", version = "0.0.0" } rand = { workspace = true } -maybe-rayon = { workspace = true } - -[dev-dependencies] proptest = { workspace = true } gungraun = { workspace = true } criterion = { workspace = true } diff --git a/crates/ragu_circuits/src/ky.rs b/crates/ragu_circuits/src/ky.rs index f805905d9..e2560d429 100644 --- a/crates/ragu_circuits/src/ky.rs +++ b/crates/ragu_circuits/src/ky.rs @@ -4,7 +4,7 @@ //! particular [`Circuit`], arranging it into the low-degree coefficient vector //! for the circuit's $k(Y)$ instance polynomial. -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::emulator::Emulator, @@ -38,7 +38,7 @@ mod tests { fn test_ky() { let circuit = SquareCircuit { times: 10 }; let instance: Fp = Fp::from(3); - let y = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // k(Y) = 1 + 3Y for this circuit, so k(y) = 1 + 3y. let expected = Fp::ONE + Fp::from(3) * y; diff --git a/crates/ragu_circuits/src/lib.rs b/crates/ragu_circuits/src/lib.rs index 0a0febdbb..98c005568 100644 --- a/crates/ragu_circuits/src/lib.rs +++ b/crates/ragu_circuits/src/lib.rs @@ -40,8 +40,8 @@ mod tests; use alloc::boxed::Box; -use ff::{Field, FromUniformBytes}; use polynomials::{Rank, sparse}; +use ragu_arithmetic::ff::{Field, FromUniformBytes}; use ragu_core::{ Error, Result, drivers::{Driver, DriverValue}, diff --git a/crates/ragu_circuits/src/metrics.rs b/crates/ragu_circuits/src/metrics.rs index e0e9d47c3..4e117946b 100644 --- a/crates/ragu_circuits/src/metrics.rs +++ b/crates/ragu_circuits/src/metrics.rs @@ -36,8 +36,10 @@ use alloc::vec::Vec; use core::any::TypeId; -use ff::{FromUniformBytes, PrimeField}; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{ + Coeff, + ff::{FromUniformBytes, PrimeField}, +}; use ragu_core::{ Result, convert::WireMap, diff --git a/crates/ragu_circuits/src/polynomials/mod.rs b/crates/ragu_circuits/src/polynomials/mod.rs index d26b26ff1..0f9beab75 100644 --- a/crates/ragu_circuits/src/polynomials/mod.rs +++ b/crates/ragu_circuits/src/polynomials/mod.rs @@ -3,7 +3,7 @@ pub mod sparse; pub mod txz; -use ff::Field; +use ragu_arithmetic::ff::Field; mod private { pub trait Sealed {} @@ -158,7 +158,7 @@ fn test_tz() { view.b.push(Fp::ONE); } let mut poly = view.build(); - let z = Fp::random(&mut rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); poly.dilate(z); poly.negate(); let poly_dense = poly.to_dense(); @@ -180,8 +180,8 @@ fn test_tz() { fn test_txz_consistency() { use ragu_pasta::Fp; type DemoR = TestRank; - let z = Fp::random(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); let txz = DemoR::txz(x, z); let tx0 = DemoR::txz(x, Fp::ZERO); let t0z: Fp = DemoR::txz(Fp::ZERO, z); diff --git a/crates/ragu_circuits/src/polynomials/sparse/mod.rs b/crates/ragu_circuits/src/polynomials/sparse/mod.rs index 1e79eb31d..60c103e76 100644 --- a/crates/ragu_circuits/src/polynomials/sparse/mod.rs +++ b/crates/ragu_circuits/src/polynomials/sparse/mod.rs @@ -49,9 +49,7 @@ mod tests; use alloc::vec::Vec; use core::{borrow::Borrow, marker::PhantomData}; -use ff::Field; -use ragu_arithmetic::{CurveAffine, DeferredField}; -use rand::CryptoRng; +use ragu_arithmetic::{CryptoRngCore, CurveAffine, DeferredField, ff::Field}; use super::Rank; @@ -183,7 +181,7 @@ impl Polynomial { } /// Creates a polynomial with random coefficients filling all `4n` slots. - pub fn random(rng: &mut RNG) -> Self { + pub fn random(rng: &mut RNG) -> Self { assert!(R::num_coeffs() > 0, "num_coeffs must be positive"); let coeffs: Vec = (0..R::num_coeffs()).map(|_| F::random(&mut *rng)).collect(); Self::from_blocks(alloc::vec![(0, coeffs)]) diff --git a/crates/ragu_circuits/src/polynomials/sparse/tests.rs b/crates/ragu_circuits/src/polynomials/sparse/tests.rs index 10b37ed3e..f543a6a3e 100644 --- a/crates/ragu_circuits/src/polynomials/sparse/tests.rs +++ b/crates/ragu_circuits/src/polynomials/sparse/tests.rs @@ -1,7 +1,7 @@ use alloc::{vec, vec::Vec}; -use ff::Field; use proptest::prelude::*; +use ragu_arithmetic::ff::Field; use ragu_pasta::Fp; use super::{Polynomial, View}; @@ -480,7 +480,7 @@ proptest! { fn sub_self_is_zero(poly in arb_any_poly()) { let mut result = poly.clone(); result.sub_assign(&poly); - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); prop_assert_eq!(result.eval(x), Fp::ZERO, "sub_assign(self) should yield zero"); } @@ -490,7 +490,7 @@ proptest! { negated.negate(); let mut result = poly; result.add_assign(&negated); - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); prop_assert_eq!(result.eval(x), Fp::ZERO, "add_assign(-self) should yield zero"); } } @@ -544,7 +544,9 @@ fn single_coefficient_at_degree_boundaries() { fn only_a_wire_data() { let n = R::n(); let mut view = View::<_, R, _>::trace(); - let a_vals: Vec = (0..n).map(|_| Fp::random(&mut rand::rng())).collect(); + let a_vals: Vec = (0..n) + .map(|_| Fp::random(&mut ragu_arithmetic::rand::rng())) + .collect(); view.a = a_vals.clone(); let poly = view.build(); @@ -554,7 +556,7 @@ fn only_a_wire_data() { for (i, val) in a_vals.iter().enumerate() { expected[2 * n - 1 - i] = *val; } - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); assert_eq!(poly.eval(x), ragu_arithmetic::eval(&expected, x)); } @@ -562,7 +564,9 @@ fn only_a_wire_data() { fn only_d_wire_data() { let n = R::n(); let mut view = View::<_, R, _>::trace(); - let d_vals: Vec = (0..n).map(|_| Fp::random(&mut rand::rng())).collect(); + let d_vals: Vec = (0..n) + .map(|_| Fp::random(&mut ragu_arithmetic::rand::rng())) + .collect(); view.d = d_vals.clone(); let poly = view.build(); @@ -571,7 +575,7 @@ fn only_d_wire_data() { for (i, val) in d_vals.iter().enumerate() { expected[4 * n - 1 - i] = *val; } - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); assert_eq!(poly.eval(x), ragu_arithmetic::eval(&expected, x)); } @@ -584,14 +588,14 @@ fn alloc_optimization_pattern() { for i in 0..n { if i % 10 == 0 { // Alloc gate: a is non-zero, b=c=0, d is non-zero. - view.a.push(Fp::random(&mut rand::rng())); + view.a.push(Fp::random(&mut ragu_arithmetic::rand::rng())); view.b.push(Fp::ZERO); view.c.push(Fp::ZERO); - view.d.push(Fp::random(&mut rand::rng())); + view.d.push(Fp::random(&mut ragu_arithmetic::rand::rng())); } else { // Mul gate: a,b,c non-zero, d=0. - let a = Fp::random(&mut rand::rng()); - let b = Fp::random(&mut rand::rng()); + let a = Fp::random(&mut ragu_arithmetic::rand::rng()); + let b = Fp::random(&mut ragu_arithmetic::rand::rng()); view.a.push(a); view.b.push(b); view.c.push(a * b); @@ -602,7 +606,7 @@ fn alloc_optimization_pattern() { // Verify eval consistency. let dense = poly.to_dense(); - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); assert_eq!(poly.eval(x), ragu_arithmetic::eval(&dense, x)); // The d-wire region should be sparse (few non-zero entries). @@ -672,8 +676,8 @@ fn iter_coeffs_fully_drain_both_ends() { fn product_identity() { let mut view = View::<_, R, _>::trace(); for _ in 0..R::n() { - let a = Fp::random(&mut rand::rng()); - let b = Fp::random(&mut rand::rng()); + let a = Fp::random(&mut ragu_arithmetic::rand::rng()); + let b = Fp::random(&mut ragu_arithmetic::rand::rng()); view.a.push(a); view.b.push(b); view.c.push(a * b); @@ -681,7 +685,7 @@ fn product_identity() { let rx = view.build(); let mut rzx = rx.clone(); - let z = Fp::random(&mut rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); rzx.dilate(z); rzx.add_assign(&R::tz::(z)); @@ -692,7 +696,7 @@ fn product_identity() { /// followed by IFFT, equals the polynomial of diagonal revdot products. #[test] fn ring_convolution() { - let rand_poly = || Polynomial::::random(&mut rand::rng()); + let rand_poly = || Polynomial::::random(&mut ragu_arithmetic::rand::rng()); let little = ragu_arithmetic::Domain::::new(2); let big = ragu_arithmetic::Domain::::new(3); @@ -723,7 +727,7 @@ fn ring_convolution() { big.ifft(&mut big_c); - let x = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); let mut cur = Fp::ONE; let mut a = Polynomial::::new(); diff --git a/crates/ragu_circuits/src/polynomials/sparse/view.rs b/crates/ragu_circuits/src/polynomials/sparse/view.rs index 62242e812..1fbe2628a 100644 --- a/crates/ragu_circuits/src/polynomials/sparse/view.rs +++ b/crates/ragu_circuits/src/polynomials/sparse/view.rs @@ -34,7 +34,7 @@ use alloc::vec::Vec; use core::marker::PhantomData; -use ff::Field; +use ragu_arithmetic::ff::Field; use super::{Polynomial, Rank, extend_runs}; diff --git a/crates/ragu_circuits/src/polynomials/txz.rs b/crates/ragu_circuits/src/polynomials/txz.rs index ca8dbfc7c..4b34d11ad 100644 --- a/crates/ragu_circuits/src/polynomials/txz.rs +++ b/crates/ragu_circuits/src/polynomials/txz.rs @@ -4,8 +4,7 @@ use core::marker::PhantomData; -use ff::Field; -use ragu_arithmetic::geosum; +use ragu_arithmetic::{ff::Field, geosum}; use ragu_core::{ Result, drivers::{Driver, DriverValue}, @@ -129,8 +128,8 @@ mod tests { // ProductionRank (R<13>) has log2_n = 11 type TestRank = ProductionRank; - let x = Fp::random(&mut rand::rng()); - let z = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); let evaluator = Evaluate::::new(); Simulator::simulate((x, z), |dr, witness| { diff --git a/crates/ragu_circuits/src/raw.rs b/crates/ragu_circuits/src/raw.rs index e6f523102..2d0d411b1 100644 --- a/crates/ragu_circuits/src/raw.rs +++ b/crates/ragu_circuits/src/raw.rs @@ -33,8 +33,7 @@ use alloc::vec::Vec; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression}, diff --git a/crates/ragu_circuits/src/registry.rs b/crates/ragu_circuits/src/registry.rs index 038413442..a07bbcaef 100644 --- a/crates/ragu_circuits/src/registry.rs +++ b/crates/ragu_circuits/src/registry.rs @@ -18,8 +18,10 @@ use alloc::{boxed::Box, collections::btree_map::BTreeMap, vec::Vec}; use blake2b_simd::Params; -use ff::{Field, FromUniformBytes, PrimeField}; -use ragu_arithmetic::{Domain, bitreverse}; +use ragu_arithmetic::{ + Domain, bitreverse, + ff::{Field, FromUniformBytes, PrimeField}, +}; use ragu_core::{Error, Result}; use crate::{ @@ -358,7 +360,7 @@ impl Registry<'_, F, R> { &self, trace: &crate::trace::Trace, circuit: CircuitIndex, - rng: &mut impl rand::CryptoRng, + rng: &mut impl ragu_arithmetic::CryptoRngCore, ) -> Result> { self.assemble_with_alpha(trace, circuit, F::random(rng)) } @@ -698,8 +700,10 @@ impl, R: Rank> Registry<'_, F, R> { mod tests { use alloc::collections::{BTreeSet, btree_map::BTreeMap}; - use ff::{Field, PrimeField}; - use ragu_arithmetic::{Domain, bitreverse}; + use ragu_arithmetic::{ + Domain, bitreverse, + ff::{Field, PrimeField}, + }; use ragu_core::Result; use ragu_pasta::Fp; @@ -743,9 +747,9 @@ mod tests { .register_circuit(SquareCircuit { times: 19 })? .finalize()?; - let w = Fp::random(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let w = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let xy_poly = registry.xy(x, y); let wy_poly = registry.wy(w, y); @@ -784,10 +788,10 @@ mod tests { .register_circuit(SquareCircuit { times: 11 })? .finalize()?; - let w = Fp::random(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); - let eval_point = Fp::random(&mut rand::rng()); + let w = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); + let eval_point = Fp::random(&mut ragu_arithmetic::rand::rng()); let registry_at_w = registry.at(w); @@ -965,9 +969,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(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let w = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let wxy = registry.wxy(w, x, y); let xy = registry.xy(x, y); @@ -1105,9 +1109,9 @@ mod tests { assert_eq!(registry.num_circuits(), 5); // Verify evaluation consistency - let w = Fp::random(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let w = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let wxy = registry.wxy(w, x, y); let xy = registry.xy(x, y); diff --git a/crates/ragu_circuits/src/staging/bonding.rs b/crates/ragu_circuits/src/staging/bonding.rs index 8027cb336..af1392f7b 100644 --- a/crates/ragu_circuits/src/staging/bonding.rs +++ b/crates/ragu_circuits/src/staging/bonding.rs @@ -21,8 +21,10 @@ use alloc::boxed::Box; -use ff::{Field, FromUniformBytes}; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{ + Coeff, + ff::{Field, FromUniformBytes}, +}; use ragu_core::{ Result, drivers::{Driver, DriverTypes, LinearExpression}, @@ -269,7 +271,7 @@ impl WiringObject for Stripped<'_, F, R> { mod tests { use core::marker::PhantomData; - use ff::Field; + use ragu_arithmetic::ff::Field; use ragu_core::{ drivers::DriverValue, gadgets::{Bound, Gadget}, @@ -590,8 +592,8 @@ mod tests { let obj = bonding_obj(); let floor_plan = floor_planner::floor_plan(obj.segment_records()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // s(0, y) = 0: no constraint on d_0 wires. assert_eq!(obj.sxy(Fp::ZERO, y, &floor_plan), Fp::ZERO); @@ -605,8 +607,8 @@ mod tests { let obj = bonding_obj(); let floor_plan = floor_planner::floor_plan(obj.segment_records()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let sxy = obj.sxy(x, y, &floor_plan); assert_eq!(sxy, obj.sx(x, &floor_plan).eval(y)); @@ -638,11 +640,11 @@ mod tests { let obj = bonding_obj(); let floor_plan = floor_planner::floor_plan(obj.segment_records()); - let y = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let sy = obj.sy(y, &floor_plan); - let v = Fp::random(&mut rand::rng()); - let w = Fp::random(&mut rand::rng()); + let v = Fp::random(&mut ragu_arithmetic::rand::rng()); + let w = Fp::random(&mut ragu_arithmetic::rand::rng()); let rx_equal = build_trace(&[(v, v)]); assert_eq!(rx_equal.revdot(&sy), Fp::ZERO); @@ -660,8 +662,8 @@ mod tests { .unwrap() .into_inner(); let floor_plan = floor_planner::floor_plan(obj.segment_records()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); assert_eq!(obj.sxy(Fp::ZERO, y, &floor_plan), Fp::ZERO); assert_eq!(obj.sxy(x, Fp::ZERO, &floor_plan), Fp::ZERO); @@ -670,7 +672,10 @@ mod tests { assert_eq!(sxy, obj.sx(x, &floor_plan).eval(y)); assert_eq!(sxy, obj.sy(y, &floor_plan).eval(x)); - let rx = build_trace(&[(Fp::random(&mut rand::rng()), Fp::random(&mut rand::rng()))]); + let rx = build_trace(&[( + Fp::random(&mut ragu_arithmetic::rand::rng()), + Fp::random(&mut ragu_arithmetic::rand::rng()), + )]); assert_eq!(rx.revdot(&obj.sy(y, &floor_plan)), Fp::ZERO); } } diff --git a/crates/ragu_circuits/src/staging/mask.rs b/crates/ragu_circuits/src/staging/mask.rs index 80756277c..7f1a45b32 100644 --- a/crates/ragu_circuits/src/staging/mask.rs +++ b/crates/ragu_circuits/src/staging/mask.rs @@ -1,5 +1,4 @@ -use ff::Field; -use ragu_arithmetic::geosum; +use ragu_arithmetic::{ff::Field, geosum}; use ragu_core::Result; use crate::{ @@ -237,10 +236,13 @@ impl WiringObject for StageMask { mod tests { use core::marker::PhantomData; - use ff::Field; - use group::{Curve, CurveAffine as _}; use proptest::prelude::*; - use ragu_arithmetic::{CurveAffine, Cycle, FixedGenerators}; + use ragu_arithmetic::{ + CurveAffine, Cycle, FixedGenerators, + ff::Field, + group::{Curve, CurveAffine as _}, + rand::RngExt, + }; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression, emulator::Emulator}, @@ -250,7 +252,6 @@ mod tests { }; use ragu_pasta::{EpAffine, EqAffine, Fp, Fq, Pasta}; use ragu_primitives::{Element, Endoscalar, Point, consistent::Consistent, io::Write}; - use rand::RngExt; use super::{ super::{Stage, StageExt}, @@ -448,10 +449,10 @@ mod tests { } } - let endoscalar_a: u128 = rand::rng().random(); - let endoscalar_b: u128 = rand::rng().random(); - let p1 = (EpAffine::generator() * Fq::random(&mut rand::rng())).into(); - let p2 = (EpAffine::generator() * Fq::random(&mut rand::rng())).into(); + let endoscalar_a: u128 = ragu_arithmetic::rand::rng().random(); + let endoscalar_b: u128 = ragu_arithmetic::rand::rng().random(); + let p1 = (EpAffine::generator() * Fq::random(&mut ragu_arithmetic::rand::rng())).into(); + let p2 = (EpAffine::generator() * Fq::random(&mut ragu_arithmetic::rand::rng())).into(); let rx1_a = MyStage1::rx(Fp::ZERO, endoscalar_a)?; let rx1_b = MyStage1::rx(Fp::ZERO, endoscalar_b)?; @@ -460,8 +461,8 @@ mod tests { let circ1 = MyStage1::mask()?.into_inner(); let circ2 = MyStage2::mask()?.into_inner(); - let z = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // sy() now returns -notch; add global_project to recover the full mask. let full_sy = |circ: &dyn WiringObject, y| { @@ -497,8 +498,8 @@ mod tests { fn test_skip_gates_one() { let stage_mask = StageMask::::new(1, 5).unwrap(); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // All three return -notch (the global term is factored out by Registry). let sxy = stage_mask.sxy(x, y, &[]); @@ -519,8 +520,8 @@ mod tests { fn test_stage_mask_all_gates() { // Edge case: skip = 1, num = R::n() - 1, reserved = 0. let stage = StageMask::::new(1, R::n() - 1).unwrap(); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let generic = mask_wiring_object(stage.clone()); let plan = floor_planner::floor_plan(generic.segment_records()); @@ -563,8 +564,8 @@ mod tests { // When reserved = 0, all gates except the SYSTEM gate are active. let stage = StageMask::::new(1, R::n() - 1).expect("valid stage mask"); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // All three return -notch (the global term is factored out by Registry). let sxy = stage.sxy(x, y, &[]); @@ -630,8 +631,8 @@ mod tests { Ok(()) }; - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); check(x, y)?; check(Fp::ZERO, y)?; check(x, Fp::ZERO)?; @@ -647,12 +648,12 @@ mod tests { let mask_a = StageMask::::new(1, split - 1).unwrap(); let mask_b = StageMask::::new(split, R::n() - split).unwrap(); - let p = Fp::random(&mut rand::rng()); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let p = Fp::random(&mut ragu_arithmetic::rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // Polynomial-level: (-notch_a(p) + -notch_b(p)).eval(q) == -global_project(p).eval(q) - let q = Fp::random(&mut rand::rng()); + let q = Fp::random(&mut ragu_arithmetic::rand::rng()); let mut sum_poly = mask_a.notch_project(p); sum_poly += &mask_b.notch_project(p); let mut neg_global = super::global_project::(p); @@ -742,7 +743,7 @@ mod tests { let stage_mask = ConstrainedStage::mask::<'_>().unwrap().into_inner(); // sy() returns -notch; add global_project to recover the full mask. - let y = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let mut sy = super::global_project::(y); sy += &stage_mask.sy(y, &[]); @@ -847,8 +848,8 @@ mod tests { "MulOnlyRoutine should have 0 constraints" ); - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // None of these must panic — previously sy would underflow on `- 1`. let sxy = circuit.sxy(x, y, &floor_plan); diff --git a/crates/ragu_circuits/src/staging/mod.rs b/crates/ragu_circuits/src/staging/mod.rs index 085a889b5..cd51e427a 100644 --- a/crates/ragu_circuits/src/staging/mod.rs +++ b/crates/ragu_circuits/src/staging/mod.rs @@ -70,7 +70,7 @@ //! let mask_handle = builder.register_bonding(MyStage::mask()?); //! let registry = builder.finalize()?; //! -//! let y = Fp::random(&mut rand::rng()); +//! let y = Fp::random(&mut ragu_arithmetic::rand::rng()); //! assert_eq!(a.revdot(®istry.y(mask_handle, y)), Fp::ZERO); //! ``` //! @@ -82,7 +82,7 @@ //! let b = MyStage::rx(alpha_b, my_stage_witness)?; //! //! // Sample random challenge z after committing to `a` and `b` -//! let z = Fp::random(&mut rand::rng()); +//! let z = Fp::random(&mut ragu_arithmetic::rand::rng()); //! //! let mut combined = a.clone(); //! combined.scale(z); @@ -91,7 +91,7 @@ //! let mask_handle = builder.register_bonding(MyStage::mask()?); //! let registry = builder.finalize()?; //! -//! let y = Fp::random(&mut rand::rng()); +//! let y = Fp::random(&mut ragu_arithmetic::rand::rng()); //! assert_eq!(combined.revdot(®istry.y(mask_handle, y)), Fp::ZERO); //! ``` //! @@ -151,8 +151,7 @@ mod rx_driver; use alloc::boxed::Box; pub use builder::{StageBuilder, StageGuard}; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Result, drivers::{Driver, DriverValue, emulator::Emulator}, diff --git a/crates/ragu_circuits/src/staging/rx_driver.rs b/crates/ragu_circuits/src/staging/rx_driver.rs index f3873aaf2..d5463f266 100644 --- a/crates/ragu_circuits/src/staging/rx_driver.rs +++ b/crates/ragu_circuits/src/staging/rx_driver.rs @@ -1,7 +1,6 @@ //! [`Driver`] that records gate placements into a [`sparse::View`]. -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Result, drivers::{Driver, DriverTypes}, diff --git a/crates/ragu_circuits/src/tests/identity.rs b/crates/ragu_circuits/src/tests/identity.rs index 29b268314..296dd070f 100644 --- a/crates/ragu_circuits/src/tests/identity.rs +++ b/crates/ragu_circuits/src/tests/identity.rs @@ -1,4 +1,4 @@ -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression}, diff --git a/crates/ragu_circuits/src/tests/mod.rs b/crates/ragu_circuits/src/tests/mod.rs index 062338191..16032633a 100644 --- a/crates/ragu_circuits/src/tests/mod.rs +++ b/crates/ragu_circuits/src/tests/mod.rs @@ -3,7 +3,7 @@ mod identity; mod segment_order; -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression}, @@ -56,8 +56,8 @@ impl Circuit for SquareCircuit { } fn consistency_checks(obj: &dyn WiringObject) { - let x = Fp::random(&mut rand::rng()); - let y = Fp::random(&mut rand::rng()); + let x = Fp::random(&mut ragu_arithmetic::rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let plan = floor_planner::floor_plan(obj.segment_records()); let sxy_eval = obj.sxy(x, y, &plan); @@ -155,8 +155,8 @@ fn test_simple_circuit() { consistency_checks::(&*obj); - let y = Fp::random(&mut rand::rng()); - let z = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); + let z = Fp::random(&mut ragu_arithmetic::rand::rng()); let a = assignment.clone(); let mut b = assignment.clone(); diff --git a/crates/ragu_circuits/src/trace.rs b/crates/ragu_circuits/src/trace.rs index c2b223d23..2c5b48484 100644 --- a/crates/ragu_circuits/src/trace.rs +++ b/crates/ragu_circuits/src/trace.rs @@ -9,8 +9,7 @@ use alloc::{vec, vec::Vec}; #[cfg(feature = "multicore")] use std::sync::mpsc; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, convert::{CloneWires, StripWires, WireMap}, @@ -443,7 +442,7 @@ mod tests { element: Element<'dr, D>, } - impl ragu_primitives::io::Write for Kind![F; @MulOnWrite<'_, _>] { + impl ragu_primitives::io::Write for Kind![F; @MulOnWrite<'_, _>] { fn write_gadget<'dr, D: Driver<'dr, F = F>, B: ragu_primitives::io::Buffer<'dr, D>>( _this: &MulOnWrite<'dr, D>, dr: &mut D, diff --git a/crates/ragu_circuits/src/trivial.rs b/crates/ragu_circuits/src/trivial.rs index 6ad371a37..a9f8abee4 100644 --- a/crates/ragu_circuits/src/trivial.rs +++ b/crates/ragu_circuits/src/trivial.rs @@ -3,7 +3,7 @@ //! Provides an implementation of [`Circuit`] for the unit type `()`, //! which creates zero constraints. Useful for testing and placeholders. -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::{Driver, DriverValue}, diff --git a/crates/ragu_circuits/src/wiring/sx.rs b/crates/ragu_circuits/src/wiring/sx.rs index fec922b3b..524ee9ebb 100644 --- a/crates/ragu_circuits/src/wiring/sx.rs +++ b/crates/ragu_circuits/src/wiring/sx.rs @@ -76,8 +76,7 @@ use alloc::{vec, vec::Vec}; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, drivers::{DirectSum, Driver, DriverTypes, emulator::Emulator}, diff --git a/crates/ragu_circuits/src/wiring/sxy.rs b/crates/ragu_circuits/src/wiring/sxy.rs index 850eb82f4..3a8144eee 100644 --- a/crates/ragu_circuits/src/wiring/sxy.rs +++ b/crates/ragu_circuits/src/wiring/sxy.rs @@ -47,8 +47,7 @@ //! [`sx`]: super::sx //! [`Driver::enforce_zero`]: ragu_core::drivers::Driver::enforce_zero -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, drivers::{DirectSum, Driver, DriverTypes, emulator::Emulator}, diff --git a/crates/ragu_circuits/src/wiring/sy.rs b/crates/ragu_circuits/src/wiring/sy.rs index aa6a4cdab..2caf4d6b6 100644 --- a/crates/ragu_circuits/src/wiring/sy.rs +++ b/crates/ragu_circuits/src/wiring/sy.rs @@ -62,8 +62,7 @@ use alloc::{vec, vec::Vec}; use core::cell::{RefCell, RefMut}; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, drivers::{Driver, DriverTypes, LinearExpression, emulator::Emulator}, diff --git a/crates/ragu_core/Cargo.toml b/crates/ragu_core/Cargo.toml index d50ca6501..3196b1f7e 100644 --- a/crates/ragu_core/Cargo.toml +++ b/crates/ragu_core/Cargo.toml @@ -23,23 +23,26 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = ["ragu_arithmetic/legacy-deps"] +modern-deps = ["ragu_arithmetic/modern-deps"] std = [] [lib] bench = false [dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } -ff = { workspace = true } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } ragu_macros = { path = "../ragu_macros", version = "0.0.0" } thiserror = "2.0.12" [dev-dependencies] +ff = { workspace = true } rand = { workspace = true } group = { workspace = true } ragu_pasta = { path = "../ragu_pasta", version = "0.0.0", features = ["baked"] } diff --git a/crates/ragu_core/src/convert.rs b/crates/ragu_core/src/convert.rs index e774f56f4..dc79f0f1e 100644 --- a/crates/ragu_core/src/convert.rs +++ b/crates/ragu_core/src/convert.rs @@ -25,7 +25,7 @@ use core::marker::PhantomData; -use ff::Field; +use ragu_arithmetic::ff::Field; use crate::{ Result, @@ -148,8 +148,7 @@ impl> WireMap for StripWires { #[cfg(test)] mod tests { - use ff::Field; - use ragu_arithmetic::Coeff; + use ragu_arithmetic::{Coeff, ff::Field}; use ragu_pasta::Fp; use crate::{ diff --git a/crates/ragu_core/src/drivers.rs b/crates/ragu_core/src/drivers.rs index 1a74f27b2..c94a1d405 100644 --- a/crates/ragu_core/src/drivers.rs +++ b/crates/ragu_core/src/drivers.rs @@ -50,9 +50,8 @@ pub mod emulator; mod linexp; mod phantom; -use ff::Field; pub use linexp::{DirectSum, LinearExpression}; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use crate::{ Result, diff --git a/crates/ragu_core/src/drivers/emulator.rs b/crates/ragu_core/src/drivers/emulator.rs index efefeecd9..79f5da48e 100644 --- a/crates/ragu_core/src/drivers/emulator.rs +++ b/crates/ragu_core/src/drivers/emulator.rs @@ -65,7 +65,7 @@ use alloc::vec::Vec; use core::marker::PhantomData; -use ff::Field; +use ragu_arithmetic::ff::Field; use crate::{ Result, @@ -370,7 +370,7 @@ fn short_circuit_routine<'dr, D: Driver<'dr, Wire = ()>, R: Routine + 'dr> #[cfg(test)] mod tests { - use ff::Field; + use ragu_arithmetic::ff::Field; use ragu_pasta::Fp; use super::*; diff --git a/crates/ragu_core/src/drivers/linexp.rs b/crates/ragu_core/src/drivers/linexp.rs index cd289d23c..3fdcb746c 100644 --- a/crates/ragu_core/src/drivers/linexp.rs +++ b/crates/ragu_core/src/drivers/linexp.rs @@ -1,4 +1,4 @@ -use ff::Field; +use ragu_arithmetic::ff::Field; use super::Coeff; diff --git a/crates/ragu_core/src/gadgets.rs b/crates/ragu_core/src/gadgets.rs index 116063f30..e5b7571dd 100644 --- a/crates/ragu_core/src/gadgets.rs +++ b/crates/ragu_core/src/gadgets.rs @@ -83,7 +83,7 @@ mod foreign; -use ff::Field; +use ragu_arithmetic::ff::Field; use super::{ Result, @@ -358,7 +358,7 @@ pub use ragu_macros::Gadget; /// expected you can use `'_` instead. /// /// ```rust -/// # use ff::Field; +/// # use ragu_arithmetic::ff::Field; /// # use ragu_core::{drivers::{Driver, DriverValue}, gadgets::Kind}; /// # #[derive(ragu_core::gadgets::Gadget)] /// # struct Boolean<'my_dr, #[ragu(driver)] MyD: Driver<'my_dr>> { @@ -379,7 +379,7 @@ pub use ragu_macros::Gadget; /// In this example, the `Kind!` macro expands to the type /// /// ```rust -/// # use ff::Field; +/// # use ragu_arithmetic::ff::Field; /// # use ragu_core::{drivers::{Driver, DriverValue}, gadgets::{Kind, Gadget}}; /// # use core::marker::PhantomData; /// # #[derive(ragu_core::gadgets::Gadget)] diff --git a/crates/ragu_core/src/gadgets/foreign.rs b/crates/ragu_core/src/gadgets/foreign.rs index e2d2302db..ca67ca069 100644 --- a/crates/ragu_core/src/gadgets/foreign.rs +++ b/crates/ragu_core/src/gadgets/foreign.rs @@ -3,7 +3,7 @@ use alloc::{boxed::Box, vec::Vec}; use core::marker::PhantomData; -use ff::Field; +use ragu_arithmetic::ff::Field; use crate::{ Result, diff --git a/crates/ragu_core/src/routines.rs b/crates/ragu_core/src/routines.rs index 6f012f5a9..c9507e1cf 100644 --- a/crates/ragu_core/src/routines.rs +++ b/crates/ragu_core/src/routines.rs @@ -10,7 +10,7 @@ //! //! [book]: https://tachyon.z.cash/ragu/guide/routines.html -use ff::Field; +use ragu_arithmetic::ff::Field; use crate::{ Result, diff --git a/crates/ragu_gadgets/Cargo.toml b/crates/ragu_gadgets/Cargo.toml index 8557f5383..ba34d83d0 100644 --- a/crates/ragu_gadgets/Cargo.toml +++ b/crates/ragu_gadgets/Cargo.toml @@ -17,7 +17,6 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true [features] default = [] diff --git a/crates/ragu_macros/src/derive/gadget.rs b/crates/ragu_macros/src/derive/gadget.rs index f7bb6ed07..dbc0defde 100644 --- a/crates/ragu_macros/src/derive/gadget.rs +++ b/crates/ragu_macros/src/derive/gadget.rs @@ -7,7 +7,7 @@ use syn::{ use crate::{ helpers::{GenericDriver, attr_is}, - path_resolution::RaguCorePath, + path_resolution::{RaguArithmeticPath, RaguCorePath}, substitution::replace_driver_field_in_generic_param, }; @@ -56,7 +56,11 @@ impl GenericDriver { } } -pub fn derive(input: DeriveInput, ragu_core_path: RaguCorePath) -> Result { +pub fn derive( + input: DeriveInput, + ragu_arithmetic_path: RaguArithmeticPath, + ragu_core_path: RaguCorePath, +) -> Result { let DeriveInput { ident: struct_ident, generics, @@ -213,7 +217,7 @@ pub fn derive(input: DeriveInput, ragu_core_path: RaguCorePath) -> Result) }; @@ -297,7 +301,12 @@ fn test_fail_enum() { }; assert!( - derive(input, RaguCorePath::default()).is_err(), + derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default() + ) + .is_err(), "Expected error for enum usage" ); } @@ -317,7 +326,12 @@ fn test_fail_where_clause() { }; assert!( - derive(input, RaguCorePath::default()).is_err(), + derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default() + ) + .is_err(), "Expected error for where clause" ); } @@ -336,7 +350,12 @@ fn test_fail_multi_annotations() { }; assert!( - derive(input, RaguCorePath::default()).is_err(), + derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default() + ) + .is_err(), "Expected error for multiple annotations on field" ); } @@ -353,7 +372,12 @@ fn test_fail_unnamed_struct() { }; assert!( - derive(input, RaguCorePath::default()).is_err(), + derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default() + ) + .is_err(), "Expected error for unnamed struct fields" ); } @@ -373,7 +397,7 @@ fn test_gadget_derive_boolean_customdriver() { } }; - let result = derive(input, RaguCorePath::default()).unwrap(); + let result = derive(input, RaguArithmeticPath::default(), RaguCorePath::default()).unwrap(); assert_eq!( result.to_string(), @@ -398,7 +422,7 @@ fn test_gadget_derive_boolean_customdriver() { Boolean<'static, ::core::marker::PhantomData< >::F> >; } #[automatically_derived] - unsafe impl ::ragu_core::gadgets::GadgetKind + unsafe impl ::ragu_core::gadgets::GadgetKind for Boolean<'static, ::core::marker::PhantomData > { type Rebind<'my_dr, MyD: ::ragu_core::drivers::Driver<'my_dr, F = DriverField>> = @@ -464,7 +488,7 @@ fn test_gadget_derive() { } }; - let result = derive(input, RaguCorePath::default()).unwrap(); + let result = derive(input, RaguArithmeticPath::default(), RaguCorePath::default()).unwrap(); assert_eq!( result.to_string(), @@ -490,7 +514,7 @@ fn test_gadget_derive() { } #[automatically_derived] - unsafe impl, const N: usize, DriverField: ::ff::Field> ::ragu_core::gadgets::GadgetKind + unsafe impl, const N: usize, DriverField: ::ragu_arithmetic::ff::Field> ::ragu_core::gadgets::GadgetKind for MyGadget<'static, ::core::marker::PhantomData< DriverField >, C, N> { type Rebind<'mydr, MyD: ::ragu_core::drivers::Driver<'mydr, F = DriverField>> = MyGadget<'mydr, MyD, C, N>; @@ -562,7 +586,7 @@ fn test_gadget_derive_default_gadget() { } }; - let result = derive(input, RaguCorePath::default()).unwrap(); + let result = derive(input, RaguArithmeticPath::default(), RaguCorePath::default()).unwrap(); // Verify both field_a (no annotation) and field_b (explicit annotation) are treated as gadgets let result_str = result.to_string(); diff --git a/crates/ragu_macros/src/derive/gadgetequals.rs b/crates/ragu_macros/src/derive/gadgetequals.rs index 0bd967471..c4f6a951b 100644 --- a/crates/ragu_macros/src/derive/gadgetequals.rs +++ b/crates/ragu_macros/src/derive/gadgetequals.rs @@ -7,12 +7,13 @@ use syn::{ use crate::{ helpers::{GenericDriver, attr_is}, - path_resolution::{RaguCorePath, RaguPrimitivesPath}, + path_resolution::{RaguArithmeticPath, RaguCorePath, RaguPrimitivesPath}, substitution::replace_driver_field_in_generic_param, }; pub fn derive( input: DeriveInput, + ragu_arithmetic_path: RaguArithmeticPath, ragu_core_path: RaguCorePath, ragu_primitives_path: RaguPrimitivesPath, ) -> Result { @@ -121,7 +122,7 @@ pub fn derive( for param in &mut params { replace_driver_field_in_generic_param(param, &driver.ident, &driverfield_ident); } - params.push(parse_quote!( #driverfield_ident: ::ff::Field )); + params.push(parse_quote!( #driverfield_ident: #ragu_arithmetic_path::ff::Field )); parse_quote!( < #( #params ),* >) }; @@ -184,13 +185,19 @@ fn test_gadgetequals_derive() { } }; - let result = derive(input, RaguCorePath::default(), RaguPrimitivesPath::default()).unwrap(); + let result = derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default(), + RaguPrimitivesPath::default(), + ) + .unwrap(); assert_eq!( result.to_string(), quote!( #[automatically_derived] - impl ::ragu_primitives::comparison::GadgetEquals + impl ::ragu_primitives::comparison::GadgetEquals for MyGadget<'static, ::core::marker::PhantomData > { fn enforce_equal_gadget< @@ -233,6 +240,7 @@ fn test_gadgetequals_derive_rejects_where_clause() { assert!( derive( input, + RaguArithmeticPath::default(), RaguCorePath::default(), RaguPrimitivesPath::default() ) diff --git a/crates/ragu_macros/src/derive/gadgetwrite.rs b/crates/ragu_macros/src/derive/gadgetwrite.rs index 84a4095bf..d803d655d 100644 --- a/crates/ragu_macros/src/derive/gadgetwrite.rs +++ b/crates/ragu_macros/src/derive/gadgetwrite.rs @@ -7,12 +7,13 @@ use syn::{ use crate::{ helpers::{GenericDriver, attr_is}, - path_resolution::{RaguCorePath, RaguPrimitivesPath}, + path_resolution::{RaguArithmeticPath, RaguCorePath, RaguPrimitivesPath}, substitution::replace_driver_field_in_generic_param, }; pub fn derive( input: DeriveInput, + ragu_arithmetic_path: RaguArithmeticPath, ragu_core_path: RaguCorePath, ragu_primitives_path: RaguPrimitivesPath, ) -> Result { @@ -105,7 +106,7 @@ pub fn derive( for param in &mut params { replace_driver_field_in_generic_param(param, &driver.ident, &driverfield_ident); } - params.push(parse_quote!( #driverfield_ident: ::ff::Field )); + params.push(parse_quote!( #driverfield_ident: #ragu_arithmetic_path::ff::Field )); parse_quote!( < #( #params ),* >) }; @@ -157,13 +158,19 @@ fn test_gadget_serialize_derive() { } }; - let result = derive(input, RaguCorePath::default(), RaguPrimitivesPath::default()).unwrap(); + let result = derive( + input, + RaguArithmeticPath::default(), + RaguCorePath::default(), + RaguPrimitivesPath::default(), + ) + .unwrap(); assert_eq!( result.to_string(), quote!( #[automatically_derived] - impl ::ragu_primitives::io::Write + impl ::ragu_primitives::io::Write for MyGadget<'static, ::core::marker::PhantomData< DriverField >, C, N> { fn write_gadget<'my_dr, MyD: ::ragu_core::drivers::Driver<'my_dr, F = DriverField>, B: ::ragu_primitives::io::Buffer<'my_dr, MyD> >( diff --git a/crates/ragu_macros/src/lib.rs b/crates/ragu_macros/src/lib.rs index f45b4bf3c..2a0779048 100644 --- a/crates/ragu_macros/src/lib.rs +++ b/crates/ragu_macros/src/lib.rs @@ -56,8 +56,9 @@ use ragu_core::gadgets::Gadget as _; pub fn derive_gadget(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); macro_body(|| { + let ragu_arithmetic_path = path_resolution::RaguArithmeticPath::resolve()?; let ragu_core_path = path_resolution::RaguCorePath::resolve()?; - derive::gadget::derive(input, ragu_core_path) + derive::gadget::derive(input, ragu_arithmetic_path, ragu_core_path) }) } @@ -71,9 +72,15 @@ use ragu_primitives::io::Write as _; pub fn derive_write(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); macro_body(|| { + let ragu_arithmetic_path = path_resolution::RaguArithmeticPath::resolve()?; let ragu_core_path = path_resolution::RaguCorePath::resolve()?; let ragu_primitives_path = path_resolution::RaguPrimitivesPath::resolve()?; - derive::gadgetwrite::derive(input, ragu_core_path, ragu_primitives_path) + derive::gadgetwrite::derive( + input, + ragu_arithmetic_path, + ragu_core_path, + ragu_primitives_path, + ) }) } @@ -103,9 +110,15 @@ use ragu_primitives::comparison::GadgetEquals as _; pub fn derive_gadget_equals(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); macro_body(|| { + let ragu_arithmetic_path = path_resolution::RaguArithmeticPath::resolve()?; let ragu_core_path = path_resolution::RaguCorePath::resolve()?; let ragu_primitives_path = path_resolution::RaguPrimitivesPath::resolve()?; - derive::gadgetequals::derive(input, ragu_core_path, ragu_primitives_path) + derive::gadgetequals::derive( + input, + ragu_arithmetic_path, + ragu_core_path, + ragu_primitives_path, + ) }) } diff --git a/crates/ragu_macros/src/path_resolution.rs b/crates/ragu_macros/src/path_resolution.rs index b60b0c507..f17a67585 100644 --- a/crates/ragu_macros/src/path_resolution.rs +++ b/crates/ragu_macros/src/path_resolution.rs @@ -1,21 +1,34 @@ -//! Resolving paths for `ragu_core` and `ragu_primitives`. +//! Resolving paths for `ragu_arithmetic`, `ragu_core`, and `ragu_primitives`. //! //! If the end-user invoking the procedural macro is using the `ragu` crate and //! not importing `ragu_core`, we need to identify the path inside `ragu` that //! corresponds to where `ragu_core` traits are re-exported. Also, the end-user //! might have renamed the crates, so we must use `proc-macro-crate`. +//! +//! Only `ragu_core` and `ragu_primitives` support that `ragu` umbrella-crate +//! fallback. `ragu_arithmetic` must be present as a direct dependency of the +//! caller, possibly renamed; its resolution does not fall back to `ragu`. use proc_macro_crate::{FoundCrate, crate_name}; use proc_macro2::Span; use quote::{ToTokens, format_ident}; use syn::{Error, Ident, Path, Result, parse_quote}; +#[derive(Clone)] +pub struct RaguArithmeticPath(Path); + #[derive(Clone)] pub struct RaguCorePath(Path); #[derive(Clone)] pub struct RaguPrimitivesPath(Path); +impl ToTokens for RaguArithmeticPath { + fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { + self.0.to_tokens(tokens) + } +} + impl ToTokens for RaguCorePath { fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { self.0.to_tokens(tokens) @@ -28,6 +41,12 @@ impl ToTokens for RaguPrimitivesPath { } } +impl Default for RaguArithmeticPath { + fn default() -> Self { + Self(parse_quote! { ::ragu_arithmetic }) + } +} + impl Default for RaguCorePath { fn default() -> Self { Self(parse_quote! { ::ragu_core }) @@ -40,6 +59,22 @@ impl Default for RaguPrimitivesPath { } } +fn ragu_arithmetic_path() -> Result { + Ok(match crate_name("ragu_arithmetic") { + Ok(FoundCrate::Itself) => parse_quote! { ::ragu_arithmetic }, + Ok(FoundCrate::Name(name)) => { + let name: Ident = format_ident!("{}", name); + parse_quote! { ::#name } + } + Err(_) => { + return Err(Error::new( + Span::call_site(), + "Failed to find ragu_arithmetic crate. Ensure it is included in your Cargo.toml.", + )); + } + }) +} + fn ragu_core_path() -> Result { Ok(match (crate_name("ragu_core"), crate_name("ragu")) { (Ok(FoundCrate::Itself), _) => parse_quote! { ::ragu_core }, @@ -78,6 +113,12 @@ fn ragu_primitives_path() -> Result { }) } +impl RaguArithmeticPath { + pub fn resolve() -> Result { + ragu_arithmetic_path().map(Self) + } +} + impl RaguCorePath { pub fn resolve() -> Result { ragu_core_path().map(Self) diff --git a/crates/ragu_pasta/Cargo.toml b/crates/ragu_pasta/Cargo.toml index 2b582c942..8d89ccf94 100644 --- a/crates/ragu_pasta/Cargo.toml +++ b/crates/ragu_pasta/Cargo.toml @@ -17,27 +17,24 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "baked", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = ["ragu_arithmetic/legacy-deps"] +modern-deps = ["ragu_arithmetic/modern-deps"] baked = ["lazy_static"] std = [] [build-dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } -ff = { workspace = true } -group = { workspace = true } -pasta_curves = { workspace = true } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } [lib] bench = false [dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } -ff = { workspace = true } -group = { workspace = true } -pasta_curves = { workspace = true } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } lazy_static = { workspace = true, optional = true } diff --git a/crates/ragu_pasta/build.rs b/crates/ragu_pasta/build.rs index 7e5cf93d6..ba6003f9b 100644 --- a/crates/ragu_pasta/build.rs +++ b/crates/ragu_pasta/build.rs @@ -7,8 +7,7 @@ use std::{ path::Path, }; -use ff::PrimeField; -use pasta_curves::arithmetic::CurveAffine; +use ragu_arithmetic::{ff::PrimeField, pasta_curves::arithmetic::CurveAffine}; mod common { include!("pasta_common.rs"); diff --git a/crates/ragu_pasta/pasta_common.rs b/crates/ragu_pasta/pasta_common.rs index 25ee318d2..483ac5d2f 100644 --- a/crates/ragu_pasta/pasta_common.rs +++ b/crates/ragu_pasta/pasta_common.rs @@ -1,6 +1,6 @@ use ragu_arithmetic::CurveExt; -use group::{Curve, CurveAffine}; -use pasta_curves::{ +use ragu_arithmetic::group::Curve; +use ragu_arithmetic::pasta_curves::{ EpAffine, EqAffine, Ep, @@ -44,7 +44,8 @@ fn params_for_curve(n: usize) -> (Vec, C::AffineExt) } g }; - let mut g = vec![C::AffineExt::identity(); n]; + // Placeholder values; every slot is overwritten by `batch_normalize` below. + let mut g = vec![C::AffineExt::default(); n]; Curve::batch_normalize(&g_projective[..], &mut g); let h: C::AffineExt = C::hash_to_curve(DOMAIN_PREFIX)(&[1]).into(); diff --git a/crates/ragu_pasta/src/lib.rs b/crates/ragu_pasta/src/lib.rs index ba675c970..46f4a9b57 100644 --- a/crates/ragu_pasta/src/lib.rs +++ b/crates/ragu_pasta/src/lib.rs @@ -43,9 +43,9 @@ mod poseidon_fp; mod poseidon_fq; pub use common::{PallasGenerators, PastaParams, VestaGenerators}; -pub use pasta_curves::{Ep, EpAffine, Eq, EqAffine, Fp, Fq}; pub use poseidon_fp::PoseidonFp; pub use poseidon_fq::PoseidonFq; +pub use ragu_arithmetic::pasta_curves::{Ep, EpAffine, Eq, EqAffine, Fp, Fq}; use ragu_arithmetic::{Cycle, FixedGenerators}; /// Zero-sized marker type for the [Pasta @@ -59,10 +59,10 @@ use ragu_arithmetic::{Cycle, FixedGenerators}; pub struct Pasta; impl Cycle for Pasta { - type CircuitField = pasta_curves::Fp; - type ScalarField = pasta_curves::Fq; - type NestedCurve = pasta_curves::EpAffine; - type HostCurve = pasta_curves::EqAffine; + type CircuitField = ragu_arithmetic::pasta_curves::Fp; + type ScalarField = ragu_arithmetic::pasta_curves::Fq; + type NestedCurve = ragu_arithmetic::pasta_curves::EpAffine; + type HostCurve = ragu_arithmetic::pasta_curves::EqAffine; type HostGenerators = VestaGenerators; type NestedGenerators = PallasGenerators; @@ -93,22 +93,22 @@ impl Cycle for Pasta { } } -impl FixedGenerators for PallasGenerators { - fn g(&self) -> &[pasta_curves::EpAffine] { +impl FixedGenerators for PallasGenerators { + fn g(&self) -> &[ragu_arithmetic::pasta_curves::EpAffine] { &self.g } - fn h(&self) -> &pasta_curves::EpAffine { + fn h(&self) -> &ragu_arithmetic::pasta_curves::EpAffine { &self.h } } -impl FixedGenerators for VestaGenerators { - fn g(&self) -> &[pasta_curves::EqAffine] { +impl FixedGenerators for VestaGenerators { + fn g(&self) -> &[ragu_arithmetic::pasta_curves::EqAffine] { &self.g } - fn h(&self) -> &pasta_curves::EqAffine { + fn h(&self) -> &ragu_arithmetic::pasta_curves::EqAffine { &self.h } } @@ -117,9 +117,8 @@ impl FixedGenerators for VestaGenerators { mod baked { use alloc::vec::Vec; - use ff::PrimeField; use lazy_static::lazy_static; - use pasta_curves::arithmetic::CurveAffine; + use ragu_arithmetic::{ff::PrimeField, pasta_curves::arithmetic::CurveAffine}; use super::{PallasGenerators, Pasta, PastaParams, VestaGenerators}; diff --git a/crates/ragu_pasta/src/macros.rs b/crates/ragu_pasta/src/macros.rs index 1d87ade32..4b53a50a7 100644 --- a/crates/ragu_pasta/src/macros.rs +++ b/crates/ragu_pasta/src/macros.rs @@ -1,5 +1,5 @@ -/// Creates an [`Fp`](pasta_curves::Fp) element from a `0x`-prefixed hex -/// literal via [`Fp::from_raw`](pasta_curves::Fp::from_raw) (non-Montgomery +/// Creates an [`Fp`](ragu_arithmetic::pasta_curves::Fp) element from a `0x`-prefixed hex +/// literal via [`Fp::from_raw`](ragu_arithmetic::pasta_curves::Fp::from_raw) (non-Montgomery /// representation). #[macro_export] macro_rules! fp { @@ -8,8 +8,8 @@ macro_rules! fp { }; } -/// Creates an [`Fq`](pasta_curves::Fq) element from a `0x`-prefixed hex -/// literal via [`Fq::from_raw`](pasta_curves::Fq::from_raw) (non-Montgomery +/// Creates an [`Fq`](ragu_arithmetic::pasta_curves::Fq) element from a `0x`-prefixed hex +/// literal via [`Fq::from_raw`](ragu_arithmetic::pasta_curves::Fq::from_raw) (non-Montgomery /// representation). #[macro_export] macro_rules! fq { diff --git a/crates/ragu_pasta/src/poseidon_fp.rs b/crates/ragu_pasta/src/poseidon_fp.rs index e5d547698..55a3371fe 100644 --- a/crates/ragu_pasta/src/poseidon_fp.rs +++ b/crates/ragu_pasta/src/poseidon_fp.rs @@ -1,5 +1,5 @@ /// Poseidon permutation parameters for Pallas's base field -/// ([`Fp`](pasta_curves::Fp), the [`CircuitField`](ragu_arithmetic::Cycle::CircuitField) +/// ([`Fp`](ragu_arithmetic::pasta_curves::Fp), the [`CircuitField`](ragu_arithmetic::Cycle::CircuitField) /// in the Pasta cycle). /// /// Constants generated using the [Hades/Poseidon reference @@ -8,22 +8,22 @@ /// 8 full rounds, and 56 partial rounds. #[derive(Clone, PartialEq, Eq, Debug)] pub struct PoseidonFp; -impl ragu_arithmetic::PoseidonPermutation for PoseidonFp { +impl ragu_arithmetic::PoseidonPermutation for PoseidonFp { const T: usize = 5; const RATE: usize = 4; const FULL_ROUNDS: usize = 8; const PARTIAL_ROUNDS: usize = 56; const ALPHA: isize = 5; - fn round_constants(&self) -> impl Iterator { + fn round_constants(&self) -> impl Iterator { ROUND_CONSTANTS.iter().copied() } - fn mds_matrix(&self) -> impl ExactSizeIterator { + fn mds_matrix(&self) -> impl ExactSizeIterator { MDS_MATRIX.iter().copied() } } -const ROUND_CONSTANTS: &[&[pasta_curves::Fp]] = &[ +const ROUND_CONSTANTS: &[&[ragu_arithmetic::pasta_curves::Fp]] = &[ &[ fp!(0x2c44402b93c5ac82bc8bb58e947fca107e865d85b1cb0f1f32f0c05cdaf439f8), fp!(0x023eb54d53e89505d0c9258bee0de17bb0a11e451b48d22d88549e05e2018403), @@ -473,7 +473,7 @@ const ROUND_CONSTANTS: &[&[pasta_curves::Fp]] = &[ fp!(0x03de34a7d5476efdedbadbc3888aaabe655e3a2ef1b9808d445abafb6b223a14), ], ]; -const MDS_MATRIX: &[&[pasta_curves::Fp]] = &[ +const MDS_MATRIX: &[&[ragu_arithmetic::pasta_curves::Fp]] = &[ &[ fp!(0x0e4b3540d4d73fa420f1851a6740eddbd600c9ab0ad8d5b4dcf64f04ffb374c6), fp!(0x3fe7ecb7e78834870cdce4b908a2fb807b03af17cded80294c0c030880410ed4), diff --git a/crates/ragu_pasta/src/poseidon_fq.rs b/crates/ragu_pasta/src/poseidon_fq.rs index b15daa022..5a1b63db2 100644 --- a/crates/ragu_pasta/src/poseidon_fq.rs +++ b/crates/ragu_pasta/src/poseidon_fq.rs @@ -1,5 +1,5 @@ /// Poseidon permutation parameters for Vesta's base field -/// ([`Fq`](pasta_curves::Fq), the [`ScalarField`](ragu_arithmetic::Cycle::ScalarField) +/// ([`Fq`](ragu_arithmetic::pasta_curves::Fq), the [`ScalarField`](ragu_arithmetic::Cycle::ScalarField) /// in the Pasta cycle). /// /// Constants generated using the [Hades/Poseidon reference @@ -8,22 +8,22 @@ /// 8 full rounds, and 56 partial rounds. #[derive(Clone, PartialEq, Eq, Debug)] pub struct PoseidonFq; -impl ragu_arithmetic::PoseidonPermutation for PoseidonFq { +impl ragu_arithmetic::PoseidonPermutation for PoseidonFq { const T: usize = 5; const RATE: usize = 4; const FULL_ROUNDS: usize = 8; const PARTIAL_ROUNDS: usize = 56; const ALPHA: isize = 5; - fn round_constants(&self) -> impl Iterator { + fn round_constants(&self) -> impl Iterator { ROUND_CONSTANTS.iter().copied() } - fn mds_matrix(&self) -> impl ExactSizeIterator { + fn mds_matrix(&self) -> impl ExactSizeIterator { MDS_MATRIX.iter().copied() } } -const ROUND_CONSTANTS: &[&[pasta_curves::Fq]] = &[ +const ROUND_CONSTANTS: &[&[ragu_arithmetic::pasta_curves::Fq]] = &[ &[ fq!(0x2c44402b93c5ac82bc8bb58e947fca107e865d85b1cb0f1f32f0c05cdaf439f8), fq!(0x023eb54d53e89505d0c9258bee0de17bb0a11e451b48d22d88549e05e2018403), @@ -473,7 +473,7 @@ const ROUND_CONSTANTS: &[&[pasta_curves::Fq]] = &[ fq!(0x03de34a7d5476efdedbadbc3888aaabe655e3a2ef1b9808d445abafb6b223a14), ], ]; -const MDS_MATRIX: &[&[pasta_curves::Fq]] = &[ +const MDS_MATRIX: &[&[ragu_arithmetic::pasta_curves::Fq]] = &[ &[ fq!(0x387bc299da4a3b231b844c30f9174070413e32d7aa79c431defa67f50590b3fc), fq!(0x1e87a100c43d815e10c2ac64cced79e08be5aff53c309f96d649640308ff4ebf), diff --git a/crates/ragu_pcd/Cargo.toml b/crates/ragu_pcd/Cargo.toml index f2678b178..80296c8c0 100644 --- a/crates/ragu_pcd/Cargo.toml +++ b/crates/ragu_pcd/Cargo.toml @@ -23,11 +23,24 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = [ + "ragu_arithmetic/legacy-deps", + "ragu_circuits/legacy-deps", + "ragu_core/legacy-deps", + "ragu_primitives/legacy-deps", +] +modern-deps = [ + "ragu_arithmetic/modern-deps", + "ragu_circuits/modern-deps", + "ragu_core/modern-deps", + "ragu_primitives/modern-deps", +] multicore = ["maybe-rayon/threads", "ragu_arithmetic/multicore", "ragu_circuits/multicore", "std"] std = [] # Exposes the `fuzz_utils` module, which provides proof-corruption helpers @@ -38,16 +51,16 @@ unstable-fuzzing = [] bench = false [dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } -ff = { workspace = true } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } maybe-rayon = { workspace = true } -pasta_curves = { workspace = true } -ragu_circuits = { path = "../ragu_circuits", version = "0.0.0" } -ragu_core = { path = "../ragu_core", version = "0.0.0" } -ragu_primitives = { path = "../ragu_primitives", version = "0.0.0" } -rand = { workspace = true } +ragu_circuits = { path = "../ragu_circuits", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_core = { path = "../ragu_core", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_primitives = { path = "../ragu_primitives", version = "0.0.0", default-features = false, features = ["alloc"] } [dev-dependencies] +ff = { workspace = true } +pasta_curves = { workspace = true } +rand = { workspace = true } criterion = { workspace = true } ragu_pasta = { path = "../ragu_pasta", version = "0.0.0", features = ["baked"] } gungraun = { workspace = true } diff --git a/crates/ragu_pcd/src/fuse/_01_application.rs b/crates/ragu_pcd/src/fuse/_01_application.rs index 7ef619e4a..1f6f83ca2 100644 --- a/crates/ragu_pcd/src/fuse/_01_application.rs +++ b/crates/ragu_pcd/src/fuse/_01_application.rs @@ -4,10 +4,9 @@ //! the step witness. This sets the application fields on the [`ProofBuilder`] //! and returns the child proofs along with the output data from the step circuit. -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle}; use ragu_circuits::{CircuitExt, polynomials::Rank}; use ragu_core::Result; -use rand::CryptoRng; use crate::{ Application, Header, Pcd, Proof, @@ -16,7 +15,7 @@ use crate::{ }; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_application_proof<'source, RNG: CryptoRng, S: Step>( + pub(super) fn compute_application_proof<'source, RNG: CryptoRngCore, S: Step>( &self, rng: &mut RNG, step: S, diff --git a/crates/ragu_pcd/src/fuse/_02_preamble.rs b/crates/ragu_pcd/src/fuse/_02_preamble.rs index 08c688c08..ce9e353f7 100644 --- a/crates/ragu_pcd/src/fuse/_02_preamble.rs +++ b/crates/ragu_pcd/src/fuse/_02_preamble.rs @@ -3,11 +3,9 @@ //! This sets the preamble fields on the [`ProofBuilder`], which commits to the //! instance and trace polynomials used in the fuse step. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{polynomials::Rank, staging::StageExt}; use ragu_core::Result; -use rand::CryptoRng; use crate::{ Application, Proof, @@ -16,7 +14,7 @@ use crate::{ }; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_preamble<'a, RNG: CryptoRng>( + pub(super) fn compute_preamble<'a, RNG: CryptoRngCore>( &self, rng: &mut RNG, left: &'a Proof, @@ -28,7 +26,7 @@ impl Application<'_, C, R, HEADER_S Ok(preamble_witness) } - fn compute_native_preamble<'a, RNG: CryptoRng>( + fn compute_native_preamble<'a, RNG: CryptoRngCore>( &self, rng: &mut RNG, left: &'a Proof, @@ -52,7 +50,7 @@ impl Application<'_, C, R, HEADER_S Ok(preamble_witness) } - fn compute_bridge_preamble( + fn compute_bridge_preamble( &self, rng: &mut RNG, left: &Proof, diff --git a/crates/ragu_pcd/src/fuse/_03_s_prime.rs b/crates/ragu_pcd/src/fuse/_03_s_prime.rs index 548264f6b..69ad48546 100644 --- a/crates/ragu_pcd/src/fuse/_03_s_prime.rs +++ b/crates/ragu_pcd/src/fuse/_03_s_prime.rs @@ -3,17 +3,15 @@ //! This sets the s-prime fields on the [`ProofBuilder`], which commits to the //! $m(w, x_i, Y)$ polynomials for the $i$th child proof's $x$ challenge. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{polynomials::Rank, registry::RegistryAt, staging::StageExt}; use ragu_core::Result; -use rand::CryptoRng; use super::NativeSPrime; use crate::{Application, Proof, internal::nested, proof::ProofBuilder}; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_s_prime( + pub(super) fn compute_s_prime( &self, rng: &mut RNG, native_registry: &RegistryAt<'_, C::CircuitField, R>, @@ -26,7 +24,7 @@ impl Application<'_, C, R, HEADER_S Ok(native) } - fn compute_bridge_s_prime( + fn compute_bridge_s_prime( &self, rng: &mut RNG, native: &NativeSPrime, diff --git a/crates/ragu_pcd/src/fuse/_04_inner_error.rs b/crates/ragu_pcd/src/fuse/_04_inner_error.rs index b63f1e8a5..6b10a7947 100644 --- a/crates/ragu_pcd/src/fuse/_04_inner_error.rs +++ b/crates/ragu_pcd/src/fuse/_04_inner_error.rs @@ -7,12 +7,10 @@ //! This phase of the fuse operation is also used to commit to the $m(w, X, y)$ //! restriction. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{polynomials::Rank, registry::RegistryAt, staging::StageExt}; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::Element; -use rand::CryptoRng; use super::{ RegistryWy, @@ -25,7 +23,7 @@ use crate::{ }; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn inner_error_terms<'dr, 'rx, D, RNG: CryptoRng>( + pub(super) fn inner_error_terms<'dr, 'rx, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, native_registry: &RegistryAt<'_, C::CircuitField, R>, @@ -47,7 +45,7 @@ impl Application<'_, C, R, HEADER_S Ok((inner_error_witness, claims_builder, registry_wy)) } - fn compute_bridge_inner_error( + fn compute_bridge_inner_error( &self, rng: &mut RNG, registry_wy: &RegistryWy, @@ -65,7 +63,7 @@ impl Application<'_, C, R, HEADER_S Ok(()) } - fn compute_native_inner_error<'dr, 'rx, D, RNG: CryptoRng>( + fn compute_native_inner_error<'dr, 'rx, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, native_registry: &RegistryAt<'_, C::CircuitField, R>, diff --git a/crates/ragu_pcd/src/fuse/_05_outer_error.rs b/crates/ragu_pcd/src/fuse/_05_outer_error.rs index 8933b7d3b..c1bd1398f 100644 --- a/crates/ragu_pcd/src/fuse/_05_outer_error.rs +++ b/crates/ragu_pcd/src/fuse/_05_outer_error.rs @@ -6,8 +6,7 @@ //! the $k(Y)$ evaluations for the child proofs, as well as the temporary sponge //! state used to split the hashing operations across two circuits. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{ polynomials::{Rank, sparse}, staging::{Stage as StageTrait, StageExt}, @@ -18,7 +17,6 @@ use ragu_core::{ maybe::Maybe, }; use ragu_primitives::{Element, vec::FixedVec}; -use rand::CryptoRng; use super::claims::{FoldKey, FuseBuilder, TrackedPoly}; use crate::{ @@ -33,7 +31,7 @@ use crate::{ type NativeNumGroups = ::NumGroups; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn outer_error_terms<'dr, 'rx, D, RNG: CryptoRng>( + pub(super) fn outer_error_terms<'dr, 'rx, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, preamble_witness: &native::stages::preamble::Witness<'_, C, R, HEADER_SIZE>, @@ -153,7 +151,7 @@ impl Application<'_, C, R, HEADER_S Ok((outer_error_witness, a, b)) } - fn compute_native_outer_error( + fn compute_native_outer_error( &self, rng: &mut RNG, outer_error_witness: &native::stages::outer_error::Witness, diff --git a/crates/ragu_pcd/src/fuse/_06_ab.rs b/crates/ragu_pcd/src/fuse/_06_ab.rs index 30cdbfe30..47bef7aeb 100644 --- a/crates/ragu_pcd/src/fuse/_06_ab.rs +++ b/crates/ragu_pcd/src/fuse/_06_ab.rs @@ -29,8 +29,7 @@ use alloc::vec::Vec; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::polynomials::{Rank, sparse}; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::{Element, vec::FixedVec}; diff --git a/crates/ragu_pcd/src/fuse/_07_query.rs b/crates/ragu_pcd/src/fuse/_07_query.rs index 7c6a41c09..b2d2c3c7c 100644 --- a/crates/ragu_pcd/src/fuse/_07_query.rs +++ b/crates/ragu_pcd/src/fuse/_07_query.rs @@ -8,18 +8,16 @@ //! This phase of the fuse operation is also used to commit to the $m(W, x, y)$ //! restriction. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{polynomials::Rank, staging::StageExt}; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::Element; -use rand::CryptoRng; use super::RegistryWy; use crate::{Application, Proof, internal::native, proof::ProofBuilder}; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_query<'dr, D, RNG: CryptoRng>( + pub(super) fn compute_query<'dr, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, w: &Element<'dr, D>, diff --git a/crates/ragu_pcd/src/fuse/_08_f.rs b/crates/ragu_pcd/src/fuse/_08_f.rs index 20056b28b..a02bd6513 100644 --- a/crates/ragu_pcd/src/fuse/_08_f.rs +++ b/crates/ragu_pcd/src/fuse/_08_f.rs @@ -10,15 +10,13 @@ use alloc::{vec, vec::Vec}; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{ polynomials::{Rank, sparse}, staging::StageExt, }; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::Element; -use rand::CryptoRng; use super::{NativeF, NativeSPrime, RegistryWy}; use crate::{ @@ -32,7 +30,7 @@ use crate::{ }; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_f<'dr, D, RNG: CryptoRng>( + pub(super) fn compute_f<'dr, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, w: &Element<'dr, D>, @@ -69,7 +67,7 @@ impl Application<'_, C, R, HEADER_S /// [`ProofBuilder`] retain the native copy that derives it, since the `f` /// polynomial is not retained after the fuse step and so does not appear in /// the proof. - fn compute_bridge_f( + fn compute_bridge_f( &self, rng: &mut RNG, native: &NativeF, diff --git a/crates/ragu_pcd/src/fuse/_09_eval.rs b/crates/ragu_pcd/src/fuse/_09_eval.rs index 17a535e59..3162515b2 100644 --- a/crates/ragu_pcd/src/fuse/_09_eval.rs +++ b/crates/ragu_pcd/src/fuse/_09_eval.rs @@ -4,18 +4,16 @@ //! of every element that was also queried in the `query` stage. The evaluation //! $f(u)$ is derived from the aforementioned evaluations. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{polynomials::Rank, staging::StageExt}; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::Element; -use rand::CryptoRng; use super::{NativeSPrime, RegistryWy}; use crate::{Application, Proof, internal::native, proof::ProofBuilder}; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_eval<'dr, D, RNG: CryptoRng>( + pub(super) fn compute_eval<'dr, D, RNG: CryptoRngCore>( &self, rng: &mut RNG, u: &Element<'dr, D>, diff --git a/crates/ragu_pcd/src/fuse/_10_p.rs b/crates/ragu_pcd/src/fuse/_10_p.rs index 7df46a12a..16bf56a98 100644 --- a/crates/ragu_pcd/src/fuse/_10_p.rs +++ b/crates/ragu_pcd/src/fuse/_10_p.rs @@ -14,8 +14,7 @@ use alloc::vec::Vec; use core::ops::AddAssign; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::polynomials::{Rank, sparse}; use ragu_core::{Result, drivers::Driver, maybe::Maybe}; use ragu_primitives::{Element, extract_endoscalar, lift_endoscalar}; @@ -49,7 +48,7 @@ impl Accumulator<'_, C, R> { } impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_p<'dr, D, RNG: rand::CryptoRng>( + pub(super) fn compute_p<'dr, D, RNG: ragu_arithmetic::CryptoRngCore>( &self, rng: &mut RNG, pre_beta: &Element<'dr, D>, diff --git a/crates/ragu_pcd/src/fuse/_11_circuits.rs b/crates/ragu_pcd/src/fuse/_11_circuits.rs index f924257b5..85599acef 100644 --- a/crates/ragu_pcd/src/fuse/_11_circuits.rs +++ b/crates/ragu_pcd/src/fuse/_11_circuits.rs @@ -1,7 +1,6 @@ -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle}; use ragu_circuits::{CircuitExt, polynomials::Rank}; use ragu_core::Result; -use rand::CryptoRng; use crate::{ Application, @@ -10,7 +9,7 @@ use crate::{ }; impl Application<'_, C, R, HEADER_SIZE> { - pub(super) fn compute_internal_circuits( + pub(super) fn compute_internal_circuits( &self, rng: &mut RNG, preamble_witness: &native::stages::preamble::Witness<'_, C, R, HEADER_SIZE>, diff --git a/crates/ragu_pcd/src/fuse/claims.rs b/crates/ragu_pcd/src/fuse/claims.rs index 9f2f66a97..8c0642e19 100644 --- a/crates/ragu_pcd/src/fuse/claims.rs +++ b/crates/ragu_pcd/src/fuse/claims.rs @@ -14,8 +14,10 @@ use alloc::{borrow::Cow, vec::Vec}; use core::borrow::Borrow; -use ff::{Field, PrimeField}; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{ + Cycle, + ff::{Field, PrimeField}, +}; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::CircuitIndex, diff --git a/crates/ragu_pcd/src/fuse/mod.rs b/crates/ragu_pcd/src/fuse/mod.rs index 280df794d..7f0447993 100644 --- a/crates/ragu_pcd/src/fuse/mod.rs +++ b/crates/ragu_pcd/src/fuse/mod.rs @@ -17,12 +17,10 @@ mod _11_circuits; pub(crate) mod claims; use claims::FuseProofSource; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::polynomials::{Rank, sparse}; use ragu_core::{Result, drivers::emulator::Emulator, maybe::Maybe}; use ragu_primitives::{GadgetExt, Point, vec::CollectFixed}; -use rand::CryptoRng; use crate::{ Application, Pcd, RAGU_TAG, internal::transcript::Transcript, proof::ProofBuilder, step::Step, @@ -68,7 +66,7 @@ impl Application<'_, C, R, HEADER_S /// [`Step::Left`] header. /// * `right`: the right [`Pcd`] to fuse in this step; must correspond to /// the [`Step::Right`] header. - pub fn fuse<'source, RNG: CryptoRng, S: Step>( + pub fn fuse<'source, RNG: CryptoRngCore, S: Step>( &self, rng: &mut RNG, step: S, diff --git a/crates/ragu_pcd/src/fuzz_utils.rs b/crates/ragu_pcd/src/fuzz_utils.rs index 3a99ceba9..488224a29 100644 --- a/crates/ragu_pcd/src/fuzz_utils.rs +++ b/crates/ragu_pcd/src/fuzz_utils.rs @@ -1,7 +1,6 @@ //! Proof corruption utilities for fuzz-testing the verifier. -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::CircuitIndex, diff --git a/crates/ragu_pcd/src/header.rs b/crates/ragu_pcd/src/header.rs index 6346be4ee..82844b527 100644 --- a/crates/ragu_pcd/src/header.rs +++ b/crates/ragu_pcd/src/header.rs @@ -3,7 +3,7 @@ use core::any::Any; -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::{Driver, DriverValue}, diff --git a/crates/ragu_pcd/src/internal/claims.rs b/crates/ragu_pcd/src/internal/claims.rs index 0ba39e74d..d3a7779c6 100644 --- a/crates/ragu_pcd/src/internal/claims.rs +++ b/crates/ragu_pcd/src/internal/claims.rs @@ -19,7 +19,7 @@ use alloc::{borrow::Cow, vec::Vec}; use core::borrow::Borrow; -use ff::{Field, PrimeField}; +use ragu_arithmetic::ff::{Field, PrimeField}; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::{CircuitIndex, Registry}, diff --git a/crates/ragu_pcd/src/internal/endoscalar.rs b/crates/ragu_pcd/src/internal/endoscalar.rs index ad95dad54..872345206 100644 --- a/crates/ragu_pcd/src/internal/endoscalar.rs +++ b/crates/ragu_pcd/src/internal/endoscalar.rs @@ -18,9 +18,11 @@ use alloc::vec; -use ff::{Field, WithSmallOrderMulGroup}; -use pasta_curves::group::{Curve, WnafBase, WnafScalar}; -use ragu_arithmetic::CurveAffine; +use ragu_arithmetic::{ + CurveAffine, + ff::{Field, WithSmallOrderMulGroup}, + pasta_curves::group::{Curve, WnafBase, WnafScalar}, +}; use ragu_circuits::{ WithAux, polynomials::Rank, @@ -326,8 +328,11 @@ impl MultiStageCircuit::len(); // Generate random endoscalar and base input points. - let endoscalar: u128 = rand::rng().random(); + let endoscalar: u128 = ragu_arithmetic::rand::rng().random(); let base_inputs: [EpAffine; NUM_POINTS] = core::array::from_fn(|_| { - (Ep::generator() * ::Scalar::random(&mut rand::rng())).to_affine() + (Ep::generator() * ::Scalar::random(&mut ragu_arithmetic::rand::rng())) + .to_affine() }); // Compute expected final result via Horner over all base inputs. @@ -460,7 +465,7 @@ mod tests { .into_output(); let final_rx = registry.assemble(&final_trace, staged_h, Fp::ZERO)?; - let y = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); // Verify revdot identities for each stage. assert_eq!(endoscalar_rx.revdot(®istry.y(endo_mask_h, y)), Fp::ZERO); @@ -493,9 +498,10 @@ mod tests { assert_eq!(InputsLen::::len(), 10); // Generate random endoscalar and base input points. - let endoscalar: u128 = rand::rng().random(); + let endoscalar: u128 = ragu_arithmetic::rand::rng().random(); let base_inputs: [EpAffine; NUM_POINTS] = core::array::from_fn(|_| { - (Ep::generator() * ::Scalar::random(&mut rand::rng())).to_affine() + (Ep::generator() * ::Scalar::random(&mut ragu_arithmetic::rand::rng())) + .to_affine() }); // Compute expected final result via Horner over all base inputs. @@ -527,7 +533,7 @@ mod tests { .into_output(); let final_rx = registry.assemble(&final_trace, staged_h, Fp::ZERO)?; - let y = Fp::random(&mut rand::rng()); + let y = Fp::random(&mut ragu_arithmetic::rand::rng()); let endoscalar_rx = >::rx(Fp::ZERO, endoscalar)?; let points_rx = @@ -635,9 +641,10 @@ mod tests { fn test_points_witness_new() { /// Verifies PointsWitness::new produces identical results to manual construction. fn check() { - let endoscalar: u128 = rand::rng().random(); + let endoscalar: u128 = ragu_arithmetic::rand::rng().random(); let base_inputs: [EpAffine; NUM_POINTS] = core::array::from_fn(|_| { - (Ep::generator() * ::Scalar::random(&mut rand::rng())).to_affine() + (Ep::generator() * ::Scalar::random(&mut ragu_arithmetic::rand::rng())) + .to_affine() }); // Compute via PointsWitness::new diff --git a/crates/ragu_pcd/src/internal/fold_revdot.rs b/crates/ragu_pcd/src/internal/fold_revdot.rs index 7c9d71aba..d01fb117f 100644 --- a/crates/ragu_pcd/src/internal/fold_revdot.rs +++ b/crates/ragu_pcd/src/internal/fold_revdot.rs @@ -6,8 +6,7 @@ use core::{borrow::Borrow, iter, marker::PhantomData}; -use ff::Field; -use ragu_arithmetic::DeferredField; +use ragu_arithmetic::{DeferredField, ff::Field}; use ragu_circuits::{ horner::Horner, polynomials::{Rank, sparse}, @@ -292,12 +291,11 @@ pub fn fold_two_layer<'dr, D: Driver<'dr>, P: Parameters>( mod tests { use alloc::{vec, vec::Vec}; - use ff::Field; + use ragu_arithmetic::{ff::Field, rand::SeedableRng}; use ragu_circuits::polynomials::{TestRank, sparse}; use ragu_core::{drivers::emulator::Emulator, maybe::Maybe}; use ragu_pasta::Fp; use ragu_primitives::{Simulator, allocator::Standard, vec::CollectFixed}; - use rand::SeedableRng; use super::*; use crate::internal::native::RevdotParameters; @@ -315,7 +313,7 @@ mod tests { type P = TestParams<3, 3>; let n =

::NumGroups::len(); - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); // Create N random polynomial pairs let lhs: Vec> = (0..n) @@ -382,7 +380,7 @@ mod tests { let n =

::NumGroups::len(); fn verify(count: usize, m: usize, n: usize) -> Result<()> { - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); // Create `count` random polynomial pairs let lhs: Vec> = (0..count) @@ -455,12 +453,14 @@ mod tests { fn test_fold_products_constraints() -> Result<()> { fn measure() -> Result { let sim = Simulator::simulate((), |dr, _| { - let mu = Element::constant(dr, Fp::random(&mut rand::rng())); - let nu = Element::constant(dr, Fp::random(&mut rand::rng())); - let error_terms = - FixedVec::from_fn(|_| Element::constant(dr, Fp::random(&mut rand::rng()))); - let ky_values = - FixedVec::from_fn(|_| Element::constant(dr, Fp::random(&mut rand::rng()))); + let mu = Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())); + let nu = Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())); + let error_terms = FixedVec::from_fn(|_| { + Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())) + }); + let ky_values = FixedVec::from_fn(|_| { + Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())) + }); let fold_products = ClaimFolder::new(dr, &mu, &nu)?; fold_products.fold_outer::

(dr, &error_terms, &ky_values)?; @@ -483,7 +483,7 @@ mod tests { fn test_multireduce() -> Result<()> { /// Verify two-layer folding correctness with actual polynomials. fn verify() -> Result<()> { - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); let n = P::NumGroups::len(); let m = P::GroupSize::len(); let count = n * m; @@ -608,7 +608,7 @@ mod tests { /// Verify fold_two_layer on evaluations matches evaluating folded polynomials /// for both lhs and rhs polynomial sets with their respective scale factors. fn verify(count: usize) -> Result<()> { - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); // Create `count` random polynomial pairs (up to m*n) let lhs: Vec> = (0..count) @@ -740,7 +740,8 @@ mod tests { #[test] fn test_cost_formulas() -> Result<()> { fn verify() -> Result<()> { - let rng = rand::rngs::StdRng::from_rng(&mut rand::rng()); + let rng = + ragu_arithmetic::rand::rngs::StdRng::from_rng(&mut ragu_arithmetic::rand::rng()); let sim = Simulator::simulate(rng, |dr, mut rng| { let allocator = &mut Standard::new(); let mu = Element::alloc(dr, allocator, rng.as_mut().map(Fp::random))?; @@ -848,7 +849,7 @@ mod tests { #[test] fn test_error_term_ordering() { - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); // Create 3 distinct polynomial pairs let a: Vec> = (0..3) @@ -878,12 +879,15 @@ mod tests { // Verify layer 1 constraint count formula: 2M^2 + 1 per group fn measure_m() -> Result { let sim = Simulator::simulate((), |dr, _| { - let mu = Element::constant(dr, Fp::random(&mut rand::rng())); - let nu = Element::constant(dr, Fp::random(&mut rand::rng())); + let mu = Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())); + let nu = Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())); let error_terms: FixedVec<_, NumErrorTerms>> = - FixedVec::from_fn(|_| Element::constant(dr, Fp::random(&mut rand::rng()))); - let ky_values: FixedVec<_, ConstLen> = - FixedVec::from_fn(|_| Element::constant(dr, Fp::random(&mut rand::rng()))); + FixedVec::from_fn(|_| { + Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())) + }); + let ky_values: FixedVec<_, ConstLen> = FixedVec::from_fn(|_| { + Element::constant(dr, Fp::random(&mut ragu_arithmetic::rand::rng())) + }); let fold_products = ClaimFolder::new(dr, &mu, &nu)?; fold_products.fold_inner::>(dr, &error_terms, &ky_values)?; @@ -905,7 +909,7 @@ mod tests { fn test_native_parameters_correctness() -> Result<()> { // Test with actual RevdotParameters (M=6, N=18) - let mut rng = rand::rng(); + let mut rng = ragu_arithmetic::rand::rng(); let m = ::GroupSize::len(); let _n = ::NumGroups::len(); diff --git a/crates/ragu_pcd/src/internal/native/circuits/compute_v.rs b/crates/ragu_pcd/src/internal/native/circuits/compute_v.rs index 137ed5520..8638ab224 100644 --- a/crates/ragu_pcd/src/internal/native/circuits/compute_v.rs +++ b/crates/ragu_pcd/src/internal/native/circuits/compute_v.rs @@ -46,8 +46,7 @@ use alloc::{vec, vec::Vec}; use core::marker::PhantomData; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::{ WithAux, horner::Horner, @@ -294,7 +293,7 @@ impl<'dr, D: Driver<'dr>> Denominators<'dr, D> { preamble: &native_preamble::Output<'dr, D, C, HEADER_SIZE>, ) -> Result where - D::F: ff::PrimeField, + D::F: ragu_arithmetic::ff::PrimeField, { let xz = x.mul(dr, z)?; @@ -638,7 +637,7 @@ struct Inverter<'dr, D: Driver<'dr>> { differences: Vec>, } -impl<'dr, D: Driver<'dr, F: ff::PrimeField>> Inverter<'dr, D> { +impl<'dr, D: Driver<'dr, F: ragu_arithmetic::ff::PrimeField>> Inverter<'dr, D> { /// Creates a batch inverter with the provided base [`Element`]. /// /// The base represents a fixed evaluation point (e.g., $u$ or $y$ @@ -707,7 +706,10 @@ impl<'dr, D: Driver<'dr, F: ff::PrimeField>> Inverter<'dr, D> { .collect::>(); let mut scratch = vec![D::F::ZERO; differences.len()]; - ff::BatchInverter::invert_with_external_scratch(&mut differences, &mut scratch); + ragu_arithmetic::ff::BatchInverter::invert_with_external_scratch( + &mut differences, + &mut scratch, + ); differences.into_iter() }); diff --git a/crates/ragu_pcd/src/internal/native/claims.rs b/crates/ragu_pcd/src/internal/native/claims.rs index 3ae9c3f53..a8f568b60 100644 --- a/crates/ragu_pcd/src/internal/native/claims.rs +++ b/crates/ragu_pcd/src/internal/native/claims.rs @@ -13,7 +13,7 @@ use alloc::borrow::Cow; use core::iter::{once, repeat_n}; -use ff::PrimeField; +use ragu_arithmetic::ff::PrimeField; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::CircuitIndex, diff --git a/crates/ragu_pcd/src/internal/native/stages/eval.rs b/crates/ragu_pcd/src/internal/native/stages/eval.rs index f80b900f9..f3452dc18 100644 --- a/crates/ragu_pcd/src/internal/native/stages/eval.rs +++ b/crates/ragu_pcd/src/internal/native/stages/eval.rs @@ -18,8 +18,7 @@ use core::marker::PhantomData; -use ff::PrimeField; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::PrimeField}; use ragu_circuits::{polynomials::Rank, staging}; use ragu_core::{ Result, diff --git a/crates/ragu_pcd/src/internal/native/stages/query.rs b/crates/ragu_pcd/src/internal/native/stages/query.rs index 1c9411980..cc45bd7dd 100644 --- a/crates/ragu_pcd/src/internal/native/stages/query.rs +++ b/crates/ragu_pcd/src/internal/native/stages/query.rs @@ -16,8 +16,7 @@ use core::marker::PhantomData; -use ff::PrimeField; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::PrimeField}; use ragu_circuits::{ polynomials::{Rank, sparse}, staging, @@ -109,7 +108,7 @@ impl<'dr, D: Driver<'dr>> Gadget<'dr, D> for InternalCircuitValues ragu_core::gadgets::GadgetKind +unsafe impl ragu_core::gadgets::GadgetKind for InternalCircuitValues>> { type Rebind<'dr, D: Driver<'dr, F = F>> = InternalCircuitValues>; @@ -147,7 +146,7 @@ impl<'dr, D: Driver<'dr>> Gadget<'dr, D> for RxValues> { // SAFETY: `Element` is `Send` when `D::Wire: Send`, and `RxValues` // is a plain product of `Element`s, so the same implication holds. -unsafe impl ragu_core::gadgets::GadgetKind +unsafe impl ragu_core::gadgets::GadgetKind for RxValues>> { type Rebind<'dr, D: Driver<'dr, F = F>> = RxValues>; @@ -179,7 +178,9 @@ unsafe impl ragu_core::gadgets::GadgetKind } } -impl ragu_primitives::io::Write for RxValues>> { +impl ragu_primitives::io::Write + for RxValues>> +{ fn write_gadget<'dr, D: Driver<'dr, F = F>, B: ragu_primitives::io::Buffer<'dr, D>>( this: &Bound<'dr, D, Self>, dr: &mut D, diff --git a/crates/ragu_pcd/src/internal/native/unified.rs b/crates/ragu_pcd/src/internal/native/unified.rs index 83626c874..5dac9afab 100644 --- a/crates/ragu_pcd/src/internal/native/unified.rs +++ b/crates/ragu_pcd/src/internal/native/unified.rs @@ -600,13 +600,14 @@ mod tests { ); } - type Dr = Emulator>; + type Dr = + Emulator>; type Sl = Slot< 'static, Dr, ragu_primitives::allocator::Standard<()>, Element<'static, Dr>, - pasta_curves::Fp, + ragu_arithmetic::pasta_curves::Fp, >; /// Helper: creates two independent element slots and a fresh emulator. diff --git a/crates/ragu_pcd/src/internal/nested/claims.rs b/crates/ragu_pcd/src/internal/nested/claims.rs index 259d3776c..1c798a3e9 100644 --- a/crates/ragu_pcd/src/internal/nested/claims.rs +++ b/crates/ragu_pcd/src/internal/nested/claims.rs @@ -11,7 +11,7 @@ use alloc::borrow::Cow; -use ff::PrimeField; +use ragu_arithmetic::ff::PrimeField; use ragu_circuits::polynomials::{Rank, sparse}; use ragu_core::Result; diff --git a/crates/ragu_pcd/src/internal/tests.rs b/crates/ragu_pcd/src/internal/tests.rs index 3d9386ffd..129311696 100644 --- a/crates/ragu_pcd/src/internal/tests.rs +++ b/crates/ragu_pcd/src/internal/tests.rs @@ -9,7 +9,7 @@ use super::*; use crate::*; pub type R = ragu_circuits::polynomials::ProductionRank; -use ff::PrimeField; +use ragu_arithmetic::ff::PrimeField; use ragu_circuits::polynomials::Rank; use ragu_core::{ drivers::emulator::{Emulator, Wireless}, @@ -237,7 +237,7 @@ fn print_registry_digests() { use alloc::{format, string::String, vec::Vec}; use std::println; - use ff::PrimeField; + use ragu_arithmetic::ff::PrimeField; let pasta = Pasta::baked(); diff --git a/crates/ragu_pcd/src/internal/transcript.rs b/crates/ragu_pcd/src/internal/transcript.rs index 22ea8b6f1..426cbf0ea 100644 --- a/crates/ragu_pcd/src/internal/transcript.rs +++ b/crates/ragu_pcd/src/internal/transcript.rs @@ -36,8 +36,7 @@ //! Transcripts of protocols with different interaction sequences are //! domain-separated by protocol tags during construction [`Transcript::new`]. -use ff::PrimeField; -use ragu_arithmetic::PoseidonPermutation; +use ragu_arithmetic::{PoseidonPermutation, ff::PrimeField}; use ragu_core::{Result, drivers::Driver}; use ragu_primitives::{ Element, @@ -184,9 +183,8 @@ impl<'dr, D: Driver<'dr>, P: PoseidonPermutation> Buffer<'dr, D> for Trans mod tests { use alloc::vec::Vec; - use ff::Field; use proptest::prelude::*; - use ragu_arithmetic::Cycle; + use ragu_arithmetic::{Cycle, ff::Field}; use ragu_core::maybe::Maybe; use ragu_pasta::{Fp, Pasta}; use ragu_primitives::{GadgetExt, Simulator}; diff --git a/crates/ragu_pcd/src/lib.rs b/crates/ragu_pcd/src/lib.rs index faa9f7429..b9190ba7f 100644 --- a/crates/ragu_pcd/src/lib.rs +++ b/crates/ragu_pcd/src/lib.rs @@ -38,13 +38,12 @@ use core::{any::TypeId, cell::OnceCell, marker::PhantomData}; use header::Header; pub use proof::{Pcd, Proof}; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle}; use ragu_circuits::{ polynomials::Rank, registry::{Registry, RegistryBuilder}, }; use ragu_core::{Error, Result}; -use rand::CryptoRng; use step::{Step, internal::adapter::Adapter}; /// Domain separation tag for Ragu PCD protocol. @@ -217,7 +216,7 @@ impl Application<'_, C, R, HEADER_S /// This is the entry point for creating leaf nodes in a PCD tree. /// Internally creates minimal trivial proofs with `()` headers and fuses /// them with the provided step to produce a valid proof. - pub fn seed<'source, RNG: CryptoRng, S: Step>( + pub fn seed<'source, RNG: CryptoRngCore, S: Step>( &self, rng: &mut RNG, step: S, @@ -234,7 +233,7 @@ impl Application<'_, C, R, HEADER_S /// /// The proof is lazily created on first use and cached; subsequent calls /// return the same (non-random) proof. - fn seeded_trivial_pcd(&self, rng: &mut RNG) -> Pcd { + fn seeded_trivial_pcd(&self, rng: &mut RNG) -> Pcd { self.seeded_trivial .get_or_init(|| { self.seed(rng, step::internal::trivial::Trivial::new(), ()) @@ -254,7 +253,7 @@ impl Application<'_, C, R, HEADER_S /// is valid for the same [`Header`] but reveals nothing else about the /// original proof. As a result, [`Application::verify`] should produce the /// same result on the provided `pcd` as it would the output of this method. - pub fn rerandomize>( + pub fn rerandomize>( &self, pcd: Pcd, rng: &mut RNG, diff --git a/crates/ragu_pcd/src/proof/builder.rs b/crates/ragu_pcd/src/proof/builder.rs index a6584b8c1..bc0a9ed33 100644 --- a/crates/ragu_pcd/src/proof/builder.rs +++ b/crates/ragu_pcd/src/proof/builder.rs @@ -9,8 +9,7 @@ use alloc::vec::Vec; use core::cell::OnceCell; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::CircuitIndex, diff --git a/crates/ragu_pcd/src/proof/mod.rs b/crates/ragu_pcd/src/proof/mod.rs index e7eb8544d..4558dcddb 100644 --- a/crates/ragu_pcd/src/proof/mod.rs +++ b/crates/ragu_pcd/src/proof/mod.rs @@ -14,8 +14,7 @@ pub(crate) mod builder; use alloc::{vec, vec::Vec}; pub(crate) use builder::ProofBuilder; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{Cycle, ff::Field}; use ragu_circuits::{ CircuitExt, polynomials::{Rank, sparse}, @@ -83,7 +82,7 @@ impl> Clone for Pcd { /// Stage rx polynomials from a child proof, stored so the verifier can /// check copying circuit claims. #[derive(Clone)] -pub(crate) struct ChildStageRx { +pub(crate) struct ChildStageRx { pub points_stage: sparse::Polynomial, pub bridge_s_prime: sparse::Polynomial, pub bridge_inner_error: sparse::Polynomial, @@ -93,7 +92,7 @@ pub(crate) struct ChildStageRx { pub bridge_eval: sparse::Polynomial, } -impl ChildStageRx { +impl ChildStageRx { /// Dispatch to the bridge-stage rx polynomial named by `kind`. pub(crate) fn bridge_at(&self, kind: ChildBridgeKind) -> &sparse::Polynomial { match kind { @@ -460,7 +459,7 @@ impl crate::Application<'_, C, R, H /// Shared by `compute_p` (in `fuse/_10_p.rs`) and by /// [`trivial_proof`](Self::trivial_proof), so the nested /// endoscaling setup lives in one place. - pub(crate) fn compute_endoscaling( + pub(crate) fn compute_endoscaling( &self, rng: &mut RNG, beta_endo: u128, @@ -633,7 +632,7 @@ impl crate::Application<'_, C, R, H points.push(host_commitment); // b points.push(registry_xy_commitment); // native_registry_xy - let mut trivial_rng = ::from_seed([0u8; 32]); + let mut trivial_rng = ::from_seed([0u8; 32]); self.compute_endoscaling( &mut trivial_rng, beta_endo, diff --git a/crates/ragu_pcd/src/step/encoder.rs b/crates/ragu_pcd/src/step/encoder.rs index 33115e5f4..c835ac3fe 100644 --- a/crates/ragu_pcd/src/step/encoder.rs +++ b/crates/ragu_pcd/src/step/encoder.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; -use ff::PrimeField; +use ragu_arithmetic::ff::PrimeField; use ragu_core::{ Result, drivers::{ diff --git a/crates/ragu_pcd/src/step/internal/padded.rs b/crates/ragu_pcd/src/step/internal/padded.rs index 28b592f7f..8a58925d1 100644 --- a/crates/ragu_pcd/src/step/internal/padded.rs +++ b/crates/ragu_pcd/src/step/internal/padded.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use ff::{Field, PrimeField}; +use ragu_arithmetic::ff::{Field, PrimeField}; use ragu_core::{ Result, drivers::Driver, diff --git a/crates/ragu_pcd/src/verify.rs b/crates/ragu_pcd/src/verify.rs index e614e2648..987f11993 100644 --- a/crates/ragu_pcd/src/verify.rs +++ b/crates/ragu_pcd/src/verify.rs @@ -2,15 +2,13 @@ use core::iter::once; -use ff::Field; -use ragu_arithmetic::Cycle; +use ragu_arithmetic::{CryptoRngCore, Cycle, ff::Field}; use ragu_circuits::{ polynomials::{Rank, sparse}, registry::CircuitIndex, }; use ragu_core::{Result, drivers::emulator::Emulator, maybe::Maybe}; use ragu_primitives::Element; -use rand::CryptoRng; use crate::{ Application, Pcd, Proof, @@ -29,7 +27,7 @@ impl Application<'_, C, R, HEADER_S /// any check fails (e.g., invalid circuit ID, header size mismatch, /// corrupted commitments or evaluations), or `Err` if an internal /// computation error occurs. - pub fn verify>( + pub fn verify>( &self, pcd: &Pcd, mut rng: RNG, @@ -239,10 +237,12 @@ mod nested { #[cfg(test)] mod tests { - use ff::Field; + use ragu_arithmetic::{ + ff::Field, + rand::{SeedableRng, rngs::StdRng}, + }; use ragu_circuits::{polynomials::ProductionRank, registry::CircuitIndex}; use ragu_pasta::Pasta; - use rand::{SeedableRng, rngs::StdRng}; use super::*; use crate::ApplicationBuilder; diff --git a/crates/ragu_primitives/Cargo.toml b/crates/ragu_primitives/Cargo.toml index cbd4b6918..dca4697fd 100644 --- a/crates/ragu_primitives/Cargo.toml +++ b/crates/ragu_primitives/Cargo.toml @@ -23,26 +23,29 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true +no-default-features = true +features = ["alloc", "modern-deps"] [features] alloc = [] -default = ["alloc"] +default = ["alloc", "modern-deps"] +legacy-deps = ["ragu_arithmetic/legacy-deps", "ragu_core/legacy-deps"] +modern-deps = ["ragu_arithmetic/modern-deps", "ragu_core/modern-deps"] std = [] [lib] bench = false [dependencies] -ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0" } -ff = { workspace = true } -ragu_core = { path = "../ragu_core", version = "0.0.0" } +ragu_arithmetic = { path = "../ragu_arithmetic", version = "0.0.0", default-features = false, features = ["alloc"] } +ragu_core = { path = "../ragu_core", version = "0.0.0", default-features = false, features = ["alloc"] } thiserror = "2.0.12" # Needed for the `Write` derive macro. ragu_macros = { path = "../ragu_macros", version = "0.0.0" } [dev-dependencies] +ff = { workspace = true } rand = { workspace = true } group = { workspace = true } ragu_pasta = { path = "../ragu_pasta", version = "0.0.0", features = ["baked"] } diff --git a/crates/ragu_primitives/src/boolean.rs b/crates/ragu_primitives/src/boolean.rs index 468770928..5ae9d6b29 100644 --- a/crates/ragu_primitives/src/boolean.rs +++ b/crates/ragu_primitives/src/boolean.rs @@ -5,8 +5,10 @@ use alloc::vec::Vec; -use ff::{Field, PrimeField}; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{ + Coeff, + ff::{Field, PrimeField}, +}; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression}, @@ -243,7 +245,7 @@ impl Promotion for Kind![F; @Boolean<'_, _>] { /// Packs boolean slices into field elements using little-endian bit order. /// /// The first bit in each chunk is the least significant bit. -pub fn multipack<'dr, D: Driver<'dr, F: ff::PrimeField>>( +pub fn multipack<'dr, D: Driver<'dr, F: ragu_arithmetic::ff::PrimeField>>( dr: &mut D, bits: &[Boolean<'dr, D>], ) -> Result>> { diff --git a/crates/ragu_primitives/src/comparison.rs b/crates/ragu_primitives/src/comparison.rs index 4885ac054..70f67ffc0 100644 --- a/crates/ragu_primitives/src/comparison.rs +++ b/crates/ragu_primitives/src/comparison.rs @@ -1,6 +1,6 @@ //! Invariant-aware gadget equality. -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::Driver, diff --git a/crates/ragu_primitives/src/element.rs b/crates/ragu_primitives/src/element.rs index 82e0e17e1..b9704595d 100644 --- a/crates/ragu_primitives/src/element.rs +++ b/crates/ragu_primitives/src/element.rs @@ -6,8 +6,7 @@ use alloc::vec::Vec; use core::borrow::Borrow; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, drivers::{Driver, DriverValue, LinearExpression}, @@ -490,7 +489,7 @@ pub fn multiadd<'dr, D: Driver<'dr>>( mod root_of_unity_tests { use alloc::{vec, vec::Vec}; - use ff::Field; + use ragu_arithmetic::ff::Field; use ragu_pasta::{Fp, fp}; use super::*; diff --git a/crates/ragu_primitives/src/endoscalar.rs b/crates/ragu_primitives/src/endoscalar.rs index 0133dbb20..fdee80f86 100644 --- a/crates/ragu_primitives/src/endoscalar.rs +++ b/crates/ragu_primitives/src/endoscalar.rs @@ -15,8 +15,10 @@ use alloc::vec::Vec; -use ff::{Field, PrimeField, WithSmallOrderMulGroup}; -use ragu_arithmetic::{Coeff, CurveAffine}; +use ragu_arithmetic::{ + Coeff, CurveAffine, + ff::{Field, PrimeField, WithSmallOrderMulGroup}, +}; use ragu_core::{ Result, drivers::{Driver, DriverValue, LinearExpression, emulator::Emulator}, @@ -265,12 +267,14 @@ pub fn extract_endoscalar>(value: F) - #[cfg(test)] mod tests { - use ff::{Field, PrimeField, WithSmallOrderMulGroup}; - use group::{CurveAffine as _, Group}; - use ragu_arithmetic::{CurveAffine, CurveExt}; + use ragu_arithmetic::{ + CurveAffine, CurveExt, + ff::{Field, PrimeField, WithSmallOrderMulGroup}, + group::{CurveAffine as _, Group}, + rand::RngExt, + }; use ragu_core::Result; use ragu_pasta::{EpAffine, Fp}; - use rand::RngExt; use super::{Element, Endoscalar, Maybe, Point}; use crate::{Simulator, allocator::Standard}; @@ -313,7 +317,7 @@ mod tests { #[test] #[allow(clippy::useless_conversion)] fn test_endoscaling_consistency() { - use group::CurveAffine as _; + use ragu_arithmetic::group::CurveAffine as _; use ragu_pasta::{EpAffine, Fq}; let p = EpAffine::generator(); @@ -329,7 +333,7 @@ mod tests { #[test] fn test_extract() -> Result<()> { let p = EpAffine::generator(); - let r = Fp::random(&mut rand::rng()); + let r = Fp::random(&mut ragu_arithmetic::rand::rng()); let extracted = extract(r).value; Simulator::::simulate((r, extracted, p), |dr, witness| { @@ -355,7 +359,7 @@ mod tests { #[test] fn test_endoscaling() -> Result<()> { let p = EpAffine::generator(); - let r: u128 = rand::rng().random(); + let r: u128 = ragu_arithmetic::rand::rng().random(); let expected = EndoscalarTest { value: r }.scale(&p); Simulator::simulate((p, r), |dr, witness| { @@ -375,7 +379,7 @@ mod tests { #[test] fn test_endoscalar_lift() -> Result<()> { - let r: u128 = rand::rng().random(); + let r: u128 = ragu_arithmetic::rand::rng().random(); let expected: Fp = EndoscalarTest { value: r }.lift(); Simulator::::simulate(r, |dr, witness| { diff --git a/crates/ragu_primitives/src/foreign.rs b/crates/ragu_primitives/src/foreign.rs index ae342034c..c8902d92f 100644 --- a/crates/ragu_primitives/src/foreign.rs +++ b/crates/ragu_primitives/src/foreign.rs @@ -7,7 +7,7 @@ use alloc::boxed::Box; use core::marker::PhantomData; -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{Result, drivers::Driver, gadgets::Bound}; use crate::{ diff --git a/crates/ragu_primitives/src/invertible.rs b/crates/ragu_primitives/src/invertible.rs index 7b032d620..104480894 100644 --- a/crates/ragu_primitives/src/invertible.rs +++ b/crates/ragu_primitives/src/invertible.rs @@ -1,5 +1,7 @@ -use ff::{Field, PrimeField}; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{ + Coeff, + ff::{Field, PrimeField}, +}; use ragu_core::{ Error, Result, drivers::{Driver, DriverValue}, @@ -313,7 +315,7 @@ impl<'dr, D: Driver<'dr>> NonzeroBank<'dr, D> { #[cfg(test)] mod tests { - use ff::Field; + use ragu_arithmetic::ff::Field; use super::*; use crate::{Simulator, allocator::Standard}; diff --git a/crates/ragu_primitives/src/io.rs b/crates/ragu_primitives/src/io.rs index 9c1dec25b..a469d2168 100644 --- a/crates/ragu_primitives/src/io.rs +++ b/crates/ragu_primitives/src/io.rs @@ -14,8 +14,8 @@ mod pipe; -use ff::Field; pub use pipe::Pipe; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::Driver, diff --git a/crates/ragu_primitives/src/point.rs b/crates/ragu_primitives/src/point.rs index ca30f8cdb..d81c64445 100644 --- a/crates/ragu_primitives/src/point.rs +++ b/crates/ragu_primitives/src/point.rs @@ -6,8 +6,7 @@ use core::marker::PhantomData; -use ff::WithSmallOrderMulGroup; -use ragu_arithmetic::{Coeff, CurveAffine}; +use ragu_arithmetic::{Coeff, CurveAffine, ff::WithSmallOrderMulGroup}; use ragu_core::{ Error, Result, drivers::{Driver, DriverValue, LinearExpression}, @@ -248,7 +247,7 @@ impl<'dr, D: Driver<'dr, F = C::Base>, C: CurveAffine> Consistent<'dr, D> for Po #[test] fn test_point_alloc() -> Result<()> { - use group::CurveAffine; + use ragu_arithmetic::group::CurveAffine; type F = ragu_pasta::Fp; type C = ragu_pasta::EpAffine; @@ -270,7 +269,7 @@ fn test_point_alloc() -> Result<()> { #[test] fn test_point_double() -> Result<()> { - use group::{CurveAffine, Group}; + use ragu_arithmetic::group::{CurveAffine, Group}; type F = ragu_pasta::Fp; type C = ragu_pasta::EpAffine; @@ -304,8 +303,10 @@ fn test_point_double() -> Result<()> { fn test_add_incomplete() -> Result<()> { use alloc::vec; - use group::{CurveAffine, Group}; - use ragu_arithmetic::CurveExt; + use ragu_arithmetic::{ + CurveExt, + group::{CurveAffine, Group}, + }; type F = ragu_pasta::Fp; type C = ragu_pasta::EpAffine; @@ -356,8 +357,10 @@ fn test_add_incomplete() -> Result<()> { fn test_double_and_add_incomplete() -> Result<()> { use alloc::{vec, vec::Vec}; - use group::{CurveAffine, Group}; - use ragu_arithmetic::CurveExt; + use ragu_arithmetic::{ + CurveExt, + group::{CurveAffine, Group}, + }; type F = ragu_pasta::Fp; type C = ragu_pasta::EpAffine; diff --git a/crates/ragu_primitives/src/poseidon.rs b/crates/ragu_primitives/src/poseidon.rs index 72aa14e61..9bc0a4799 100644 --- a/crates/ragu_primitives/src/poseidon.rs +++ b/crates/ragu_primitives/src/poseidon.rs @@ -7,8 +7,7 @@ use alloc::{vec, vec::Vec}; use core::{marker::PhantomData, panic}; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Result, drivers::{Driver, DriverValue}, diff --git a/crates/ragu_primitives/src/promotion.rs b/crates/ragu_primitives/src/promotion.rs index b68ecd6be..913f95883 100644 --- a/crates/ragu_primitives/src/promotion.rs +++ b/crates/ragu_primitives/src/promotion.rs @@ -3,8 +3,7 @@ use core::ops::Deref; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Result, convert::{CloneWires, WireMap}, diff --git a/crates/ragu_primitives/src/simulator.rs b/crates/ragu_primitives/src/simulator.rs index a4a99f7a7..66ddf2f22 100644 --- a/crates/ragu_primitives/src/simulator.rs +++ b/crates/ragu_primitives/src/simulator.rs @@ -3,8 +3,7 @@ //! Provides a [`Simulator`] driver that fully executes circuit synthesis, //! tracking constraint counts and enforcing constraint satisfaction. -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::{ Error, Result, drivers::{DirectSum, Driver, DriverTypes, emulator::Emulator}, diff --git a/crates/ragu_primitives/src/suffix.rs b/crates/ragu_primitives/src/suffix.rs index 80cbfcb60..edea58179 100644 --- a/crates/ragu_primitives/src/suffix.rs +++ b/crates/ragu_primitives/src/suffix.rs @@ -1,6 +1,6 @@ //! Compositional gadget that appends an extra element during serialization. -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Result, drivers::Driver, diff --git a/crates/ragu_primitives/src/util.rs b/crates/ragu_primitives/src/util.rs index 3d81da10f..b6e80a4c4 100644 --- a/crates/ragu_primitives/src/util.rs +++ b/crates/ragu_primitives/src/util.rs @@ -3,8 +3,7 @@ use core::borrow::Borrow; -use ff::Field; -use ragu_arithmetic::Coeff; +use ragu_arithmetic::{Coeff, ff::Field}; use ragu_core::maybe::{Maybe, Perhaps}; /// Extension trait for `Maybe` that provides helper methods kept internal to diff --git a/crates/ragu_primitives/src/vec.rs b/crates/ragu_primitives/src/vec.rs index 4a9d5bac4..ba2a84f76 100644 --- a/crates/ragu_primitives/src/vec.rs +++ b/crates/ragu_primitives/src/vec.rs @@ -19,7 +19,7 @@ use core::{ ops::{Deref, DerefMut}, }; -use ff::Field; +use ragu_arithmetic::ff::Field; use ragu_core::{ Error, Result, convert::WireMap, diff --git a/crates/ragu_testing/Cargo.toml b/crates/ragu_testing/Cargo.toml index 993ff4c8a..d3afc2b07 100644 --- a/crates/ragu_testing/Cargo.toml +++ b/crates/ragu_testing/Cargo.toml @@ -22,7 +22,6 @@ keywords = [] [package.metadata.docs.rs] rustdoc-args = ["--html-in-header", "katex-header.html"] -all-features = true [features] default = [] diff --git a/justfile b/justfile index c224817d6..b20ed7946 100644 --- a/justfile +++ b/justfile @@ -13,15 +13,15 @@ build_release *ARGS: _nightly := "nightly-2026-04-11" lint: _typos_setup _book_setup - cargo clippy --workspace --lib --tests --benches --all-features -- -D warnings + cargo clippy --workspace --lib --tests --benches -- -D warnings cargo +{{_nightly}} fmt --all -- --config-path rustfmt.nightly.toml --check typos mdbook build ./book fix: _typos_setup cargo +{{_nightly}} fmt --all -- --config-path rustfmt.nightly.toml - cargo fix --allow-dirty --allow-staged --all-features - cargo clippy --fix --allow-dirty --allow-staged --all-features + cargo fix --allow-dirty --allow-staged + cargo clippy --fix --allow-dirty --allow-staged typos -w _install_binstall: @@ -45,15 +45,20 @@ book COMMAND: _book_setup # run all tests test *ARGS: - cargo test --workspace --all-features {{ARGS}} + cargo test --workspace {{ARGS}} + +# check the temporary legacy dependency surface for external consumers +check_legacy *ARGS: + cargo check -p ragu_arithmetic -p ragu_pasta -p ragu_core -p ragu_primitives -p ragu_circuits -p ragu_pcd --lib --no-default-features --features "alloc legacy-deps" {{ARGS}} + cargo check -p ragu --lib --no-default-features --features legacy-deps {{ARGS}} # run quicker proptests used for routine local/CI coverage proptests_fast *ARGS: - PROPTEST_CASES="${PROPTEST_CASES:-64}" cargo test --release -p ragu_arithmetic -p ragu_core --all-features proptest {{ARGS}} + PROPTEST_CASES="${PROPTEST_CASES:-64}" cargo test --release -p ragu_arithmetic -p ragu_core proptest {{ARGS}} # run slower proptests with higher default case counts proptests_heavy *ARGS: - PROPTEST_CASES="${PROPTEST_CASES:-256}" cargo test --release -p ragu_circuits --all-features proptest {{ARGS}} + PROPTEST_CASES="${PROPTEST_CASES:-256}" cargo test --release -p ragu_circuits proptest {{ARGS}} # run benchmarks (auto-detects platform) bench *ARGS: @@ -77,7 +82,7 @@ _bench_macos *ARGS: docker attach --no-stdin $container _bench_linux *ARGS: _gungraun_setup - cargo bench --workspace --all-features --bench arithmetic --bench circuits --bench pcd --bench primitives {{ARGS}} + cargo bench --workspace --bench arithmetic --bench circuits --bench pcd --bench primitives {{ARGS}} # generate flamegraph in target/*.svg flamegraph PACKAGE GROUP TARGET *ARGS: @@ -131,11 +136,13 @@ ci_local: _book_setup @echo "Running formatting check..." cargo +{{_nightly}} fmt --all -- --config-path rustfmt.nightly.toml --check @echo "Running clippy..." - cargo clippy --workspace --lib --tests --benches --locked --all-features -- -D warnings + cargo clippy --workspace --lib --tests --benches --locked -- -D warnings @echo "Running tests..." - cargo test --release --all --locked --all-features + cargo test --release --all --locked + @echo "Checking legacy dependency surface..." + @just check_legacy --locked @echo "Building benchmarks and examples..." - cargo build --benches --examples --all-features + cargo build --benches --examples @echo "Checking documentation..." RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all --locked --document-private-items @echo "Building book..." diff --git a/qa/fuzz/Cargo.toml b/qa/fuzz/Cargo.toml index 29e599c09..067add665 100644 --- a/qa/fuzz/Cargo.toml +++ b/qa/fuzz/Cargo.toml @@ -26,9 +26,12 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" arbitrary = { version = "1", features = ["derive"] } -ff = { version = "0.14.0-pre.1", default-features = false } -group = { version = "0.14.0-pre.1", default-features = false } -pasta_curves = "0.5.1" +# This workspace cannot inherit repo-root [workspace.dependencies]. Fuzzing is +# intentionally modern-only, so keep these direct ff/group/pasta_curves/rand +# entries in sync with the repo-root modern dependency set. +ff = { version = "0.14", default-features = false } +group = { version = "0.14", default-features = false } +pasta_curves = { git = "https://github.com/ebfull/pasta_curves", rev = "5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5", features = ["deferred"] } ragu_testing = { path = "../../crates/ragu_testing" } ragu_arithmetic = { path = "../../crates/ragu_arithmetic" } ragu_primitives = { path = "../../crates/ragu_primitives" } @@ -38,12 +41,6 @@ ragu_circuits = { path = "../../crates/ragu_circuits" } ragu_pcd = { path = "../../crates/ragu_pcd", features = ["unstable-fuzzing"] } rand = "0.10" -# Mirror of the repo-root `[patch.crates-io]`. Patches don't propagate into -# nested workspaces, so the same overrides must be repeated here to keep -# fuzz builds resolving the same forks the rest of the workspace uses. -[patch.crates-io] -pasta_curves = { git = "https://github.com/ebfull/pasta_curves", rev = "4b2c768ec4b14b2c7fa0f6e527e453cde97805aa" } - # Poseidon sponge: absorb/squeeze mode transitions + save/resume consistency [[bin]] name = "fuzz_poseidon_sponge" diff --git a/qa/supply-chain/audits.toml b/qa/supply-chain/audits.toml index cd097880a..de34b32e8 100644 --- a/qa/supply-chain/audits.toml +++ b/qa/supply-chain/audits.toml @@ -9,7 +9,7 @@ delta = "0.4.1 -> 0.3.4" [[audits.pasta_curves]] who = "Sean Bowe " criteria = "safe-to-deploy" -delta = "0.5.1 -> 0.5.1@git:4b2c768ec4b14b2c7fa0f6e527e453cde97805aa" +delta = "0.5.1 -> 0.5.1@git:5a84fc0d13f738f54c43fb1f9e28ecf1d358dcf5" importable = false [[trusted.addchain]] @@ -312,6 +312,12 @@ user-id = 189 # Andrew Gallant (BurntSushi) start = "2019-06-09" end = "2027-04-07" +[[trusted.wasi]] +criteria = "safe-to-deploy" +user-id = 1 # Alex Crichton (alexcrichton) +start = "2020-06-03" +end = "2027-06-01" + [[trusted.windows-sys]] criteria = "safe-to-deploy" user-id = 64539 # Kenny Kerr (kennykerr) diff --git a/qa/supply-chain/config.toml b/qa/supply-chain/config.toml index 3dd529cf8..b3e5f7d38 100644 --- a/qa/supply-chain/config.toml +++ b/qa/supply-chain/config.toml @@ -83,6 +83,10 @@ criteria = "safe-to-deploy" version = "2.0.0" criteria = "safe-to-deploy" +[[exemptions.getrandom]] +version = "0.2.17" +criteria = "safe-to-deploy" + [[exemptions.getrandom]] version = "0.4.1" criteria = "safe-to-deploy" @@ -107,6 +111,10 @@ criteria = "safe-to-run" version = "0.5.2" criteria = "safe-to-run" +[[exemptions.ppv-lite86]] +version = "0.2.21" +criteria = "safe-to-deploy" + [[exemptions.proc-macro-crate]] version = "3.4.0" criteria = "safe-to-deploy" @@ -140,9 +148,9 @@ version = "0.5.1" criteria = "safe-to-deploy" [[exemptions.zerocopy]] -version = "0.8.38" -criteria = "safe-to-run" +version = "0.8.48" +criteria = "safe-to-deploy" [[exemptions.zerocopy-derive]] -version = "0.8.38" -criteria = "safe-to-run" +version = "0.8.48" +criteria = "safe-to-deploy" diff --git a/qa/supply-chain/imports.lock b/qa/supply-chain/imports.lock index aa1545ee1..cab06e52b 100644 --- a/qa/supply-chain/imports.lock +++ b/qa/supply-chain/imports.lock @@ -100,22 +100,36 @@ user-login = "JelteF" user-name = "Jelte Fennema-Nio" [[publisher.ff]] -version = "0.14.0-pre.1" -when = "2026-05-21" +version = "0.13.1" +when = "2025-03-09" +user-id = 6289 +user-login = "str4d" +user-name = "Jack Grigg" + +[[publisher.ff]] +version = "0.14.0" +when = "2026-05-30" user-id = 1244 user-login = "ebfull" user-name = "Sean Bowe" [[publisher.ff_derive]] -version = "0.14.0-pre.1" -when = "2026-05-21" +version = "0.14.0" +when = "2026-05-30" user-id = 1244 user-login = "ebfull" user-name = "Sean Bowe" [[publisher.group]] -version = "0.14.0-pre.1" -when = "2026-05-21" +version = "0.13.0" +when = "2022-12-06" +user-id = 6289 +user-login = "str4d" +user-name = "Jack Grigg" + +[[publisher.group]] +version = "0.14.0" +when = "2026-06-01" user-id = 1244 user-login = "ebfull" user-name = "Sean Bowe" @@ -334,6 +348,13 @@ user-id = 189 user-login = "BurntSushi" user-name = "Andrew Gallant" +[[publisher.wasi]] +version = "0.11.1+wasi-snapshot-preview1" +when = "2025-06-10" +user-id = 1 +user-login = "alexcrichton" +user-name = "Alex Crichton" + [[publisher.wasip2]] version = "1.0.2+wasi-0.2.9" when = "2026-01-15" @@ -625,6 +646,12 @@ criteria = "safe-to-deploy" version = "0.2.19" notes = "As advertised: a numeric library. The only `unsafe` is from some float-to-int conversions, which seems expected." +[[audits.bytecode-alliance.audits.rand]] +who = "Alex Crichton " +criteria = "safe-to-deploy" +delta = "0.10.0 -> 0.10.1" +notes = "Minor logging-based updated fixing a recent advisory for the crate." + [[audits.bytecode-alliance.audits.rand_xorshift]] who = "Alex Crichton " criteria = "safe-to-deploy" @@ -943,36 +970,6 @@ criteria = "safe-to-run" version = "1.19.0" aggregated-from = "https://chromium.googlesource.com/chromiumos/third_party/rust_crates/+/refs/heads/main/cargo-vet/audits.toml?format=TEXT" -[[audits.google.audits.ppv-lite86]] -who = "danakj@chromium.org" -criteria = "safe-to-run" -version = "0.2.17" -notes = """ -Reviewed in https://crrev.com/c/5171063 - -Previously reviewed during security review and the audit is grandparented in. -""" -aggregated-from = "https://chromium.googlesource.com/chromium/src/+/main/third_party/rust/chromium_crates_io/supply-chain/audits.toml?format=TEXT" - -[[audits.google.audits.ppv-lite86]] -who = "danakj " -criteria = "safe-to-run" -delta = "0.2.17 -> 0.2.20" -notes = "Using zerocopy to reduce unsafe usage." -aggregated-from = "https://chromium.googlesource.com/chromium/src/+/main/third_party/rust/chromium_crates_io/supply-chain/audits.toml?format=TEXT" - -[[audits.google.audits.ppv-lite86]] -who = "Lukasz Anforowicz " -criteria = "safe-to-run" -delta = "0.2.20 -> 0.2.21" -notes = """ -The delta mostly corresponds to @joshlf's -https://github.com/cryptocorrosion/cryptocorrosion/pull/85 which started -using an undocumented API that `zerocopy` has provided specifically for -`ppv-lite86` in https://github.com/google/zerocopy/pull/2418. -""" -aggregated-from = "https://chromium.googlesource.com/chromium/src/+/main/third_party/rust/chromium_crates_io/supply-chain/audits.toml?format=TEXT" - [[audits.google.audits.quick-error]] who = "George Burgess IV " criteria = "safe-to-run" @@ -1698,6 +1695,16 @@ version = "2.0.1" notes = "No unsafe block with a lovely `#![forbid(unsafe_code)]`." aggregated-from = "https://hg.mozilla.org/mozilla-central/raw-file/tip/supply-chain/audits.toml" +[[audits.mozilla.audits.rand]] +who = "Henrik Skupin " +criteria = "safe-to-deploy" +delta = "0.8.5 -> 0.8.6" +notes = """ +Fixes RUSTSEC-2026-0097 by removing `log` dependency. Removes `simd_support` +feature. No new dependencies or unsafe code. +""" +aggregated-from = "https://hg.mozilla.org/mozilla-central/raw-file/tip/supply-chain/audits.toml" + [[audits.mozilla.audits.rayon]] who = "Josh Stone " criteria = "safe-to-deploy"