mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-02 13:53:07 +00:00
Fix no-std tests and add corresponding jobs in the CI (#1501)
This commit is contained in:
parent
06444eaaf3
commit
1a08e783da
@ -69,8 +69,8 @@ jobs:
|
||||
CARGO_INCREMENTAL: 1
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
wasm32:
|
||||
name: wasm32 compatibility
|
||||
wasm:
|
||||
name: Check wasm32 compatibility
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
|
||||
@ -89,7 +89,7 @@ jobs:
|
||||
with:
|
||||
cache-on-failure: true
|
||||
|
||||
- name: Check in plonky2 subdirectory
|
||||
- name: Check in plonky2 subdirectory for wasm targets
|
||||
run: cargo check --manifest-path plonky2/Cargo.toml --target wasm32-unknown-unknown --no-default-features
|
||||
env:
|
||||
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
|
||||
@ -97,7 +97,7 @@ jobs:
|
||||
CARGO_INCREMENTAL: 1
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
- name: Check in starky subdirectory
|
||||
- name: Check in starky subdirectory for wasm targets
|
||||
run: cargo check --manifest-path starky/Cargo.toml --target wasm32-unknown-unknown --no-default-features
|
||||
env:
|
||||
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
|
||||
@ -105,6 +105,41 @@ jobs:
|
||||
CARGO_INCREMENTAL: 1
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
no_std:
|
||||
name: Test Suite in no-std
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install nightly toolchain
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
toolchain: nightly-2024-02-01
|
||||
|
||||
- name: Set up rust cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
cache-on-failure: true
|
||||
|
||||
- name: Run cargo test in plonky2 subdirectory (no-std)
|
||||
run: cargo test --manifest-path plonky2/Cargo.toml --no-default-features --lib
|
||||
env:
|
||||
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
|
||||
RUST_LOG: 1
|
||||
CARGO_INCREMENTAL: 1
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
- name: Run cargo test in starky subdirectory (no-std)
|
||||
run: cargo test --manifest-path starky/Cargo.toml --no-default-features --lib
|
||||
env:
|
||||
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
|
||||
RUST_LOG: 1
|
||||
CARGO_INCREMENTAL: 1
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
lints:
|
||||
name: Formatting and Clippy
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
@ -38,6 +38,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::extension::FieldExtension;
|
||||
|
||||
@ -532,6 +532,9 @@ impl<F: RichField + Extendable<D> + Poseidon, const D: usize> SimpleGenerator<F,
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
|
||||
@ -148,12 +148,15 @@ mod tests {
|
||||
|
||||
assert_eq!(proofs, decompressed_proofs);
|
||||
|
||||
let compressed_proof_bytes = serde_cbor::to_vec(&compressed_proofs).unwrap();
|
||||
println!(
|
||||
"Compressed proof length: {} bytes",
|
||||
compressed_proof_bytes.len()
|
||||
);
|
||||
let proof_bytes = serde_cbor::to_vec(&proofs).unwrap();
|
||||
println!("Proof length: {} bytes", proof_bytes.len());
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
let compressed_proof_bytes = serde_cbor::to_vec(&compressed_proofs).unwrap();
|
||||
println!(
|
||||
"Compressed proof length: {} bytes",
|
||||
compressed_proof_bytes.len()
|
||||
);
|
||||
let proof_bytes = serde_cbor::to_vec(&proofs).unwrap();
|
||||
println!("Proof length: {} bytes", proof_bytes.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -753,6 +753,9 @@ impl<F: RichField> AlgebraicHasher<F> for PoseidonHash {
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test_helpers {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::field::types::Field;
|
||||
use crate::hash::poseidon::{Poseidon, SPONGE_WIDTH};
|
||||
|
||||
|
||||
@ -444,6 +444,9 @@ mod poseidon12_mds {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{vec, vec::Vec};
|
||||
|
||||
use crate::field::goldilocks_field::GoldilocksField as F;
|
||||
use crate::field::types::{Field, PrimeField64};
|
||||
use crate::hash::poseidon::test_helpers::{check_consistency, check_test_vectors};
|
||||
|
||||
@ -293,6 +293,9 @@ impl<F: RichField + Extendable<D>, H: AlgebraicHasher<F>, const D: usize>
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::field::types::Sample;
|
||||
use crate::iop::challenger::{Challenger, RecursiveChallenger};
|
||||
use crate::iop::generator::generate_partial_witness;
|
||||
|
||||
@ -1,28 +1,34 @@
|
||||
static LOGGER_INITIALIZED: Once = Once::new();
|
||||
|
||||
use alloc::sync::Arc;
|
||||
use std::sync::Once;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{sync::Arc, vec, vec::Vec};
|
||||
#[cfg(feature = "std")]
|
||||
use std::sync::{Arc, Once};
|
||||
|
||||
use itertools::Itertools;
|
||||
use log::{Level, LevelFilter};
|
||||
use log::Level;
|
||||
|
||||
use crate::field::types::Field;
|
||||
use crate::gadgets::lookup::{OTHER_TABLE, SMALLER_TABLE, TIP5_TABLE};
|
||||
use crate::gates::lookup_table::LookupTable;
|
||||
use crate::gates::noop::NoopGate;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
use crate::plonk::prover::prove;
|
||||
use crate::util::timing::TimingTree;
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
const LUT_SIZE: usize = u16::MAX as usize + 1;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
static LOGGER_INITIALIZED: Once = Once::new();
|
||||
|
||||
#[test]
|
||||
fn test_no_lookup() -> anyhow::Result<()> {
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
use crate::iop::witness::PartialWitness;
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
init_logger();
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
@ -41,14 +47,7 @@ fn test_no_lookup() -> anyhow::Result<()> {
|
||||
#[should_panic]
|
||||
#[test]
|
||||
fn test_lookup_table_not_used() {
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
init_logger();
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
@ -63,14 +62,7 @@ fn test_lookup_table_not_used() {
|
||||
#[should_panic]
|
||||
#[test]
|
||||
fn test_lookup_without_table() {
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
init_logger();
|
||||
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
@ -84,17 +76,8 @@ fn test_lookup_without_table() {
|
||||
// Tests two lookups in one lookup table.
|
||||
#[test]
|
||||
fn test_one_lookup() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let tip5_table = TIP5_TABLE.to_vec();
|
||||
let table: LookupTable = Arc::new((0..256).zip_eq(tip5_table).collect());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
@ -145,18 +128,9 @@ fn test_one_lookup() -> anyhow::Result<()> {
|
||||
|
||||
// Tests one lookup in two different lookup tables.
|
||||
#[test]
|
||||
pub fn test_two_luts() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
fn test_two_luts() -> anyhow::Result<()> {
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
@ -229,17 +203,9 @@ pub fn test_two_luts() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_different_inputs() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
fn test_different_inputs() -> anyhow::Result<()> {
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
@ -314,17 +280,9 @@ pub fn test_different_inputs() -> anyhow::Result<()> {
|
||||
|
||||
// This test looks up over 514 values for one LookupTableGate, which means that several LookupGates are created.
|
||||
#[test]
|
||||
pub fn test_many_lookups() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
fn test_many_lookups() -> anyhow::Result<()> {
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
@ -404,18 +362,9 @@ pub fn test_many_lookups() -> anyhow::Result<()> {
|
||||
|
||||
// Tests whether, when adding the same LUT to the circuit, the circuit only adds one copy, with the same index.
|
||||
#[test]
|
||||
pub fn test_same_luts() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
fn test_same_luts() -> anyhow::Result<()> {
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
@ -469,21 +418,11 @@ pub fn test_same_luts() -> anyhow::Result<()> {
|
||||
|
||||
#[test]
|
||||
fn test_big_lut() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
const LUT_SIZE: usize = u16::MAX as usize + 1;
|
||||
let inputs: [u16; LUT_SIZE] = core::array::from_fn(|i| i as u16);
|
||||
let lut_fn = |inp: u16| inp / 10;
|
||||
let lut_index = builder.add_lookup_table_from_fn(lut_fn, &inputs);
|
||||
@ -522,21 +461,11 @@ fn test_big_lut() -> anyhow::Result<()> {
|
||||
|
||||
#[test]
|
||||
fn test_many_lookups_on_big_lut() -> anyhow::Result<()> {
|
||||
use crate::field::types::Field;
|
||||
use crate::iop::witness::{PartialWitness, WitnessWrite};
|
||||
use crate::plonk::circuit_builder::CircuitBuilder;
|
||||
use crate::plonk::circuit_data::CircuitConfig;
|
||||
use crate::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};
|
||||
init_logger();
|
||||
|
||||
const D: usize = 2;
|
||||
type C = PoseidonGoldilocksConfig;
|
||||
type F = <C as GenericConfig<D>>::F;
|
||||
|
||||
LOGGER_INITIALIZED.call_once(|| init_logger().unwrap());
|
||||
let config = CircuitConfig::standard_recursion_config();
|
||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||
|
||||
const LUT_SIZE: usize = u16::MAX as usize + 1;
|
||||
let inputs: [u16; LUT_SIZE] = core::array::from_fn(|i| i as u16);
|
||||
let lut_fn = |inp: u16| inp / 10;
|
||||
let lut_index = builder.add_lookup_table_from_fn(lut_fn, &inputs);
|
||||
@ -581,11 +510,15 @@ fn test_many_lookups_on_big_lut() -> anyhow::Result<()> {
|
||||
data.verify(proof)
|
||||
}
|
||||
|
||||
fn init_logger() -> anyhow::Result<()> {
|
||||
let mut builder = env_logger::Builder::from_default_env();
|
||||
builder.format_timestamp(None);
|
||||
builder.filter_level(LevelFilter::Debug);
|
||||
fn init_logger() {
|
||||
#[cfg(feature = "std")]
|
||||
{
|
||||
LOGGER_INITIALIZED.call_once(|| {
|
||||
let mut builder = env_logger::Builder::from_default_env();
|
||||
builder.format_timestamp(None);
|
||||
builder.filter_level(log::LevelFilter::Debug);
|
||||
|
||||
builder.try_init()?;
|
||||
Ok(())
|
||||
builder.try_init().unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -451,7 +451,10 @@ impl<const D: usize> OpeningSetTarget<D> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::sync::Arc;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{sync::Arc, vec};
|
||||
#[cfg(feature = "std")]
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
@ -336,6 +336,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec;
|
||||
|
||||
use anyhow::Result;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
|
||||
@ -198,6 +198,9 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec;
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::field::extension::Extendable;
|
||||
|
||||
@ -191,7 +191,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloc::sync::Arc;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::{sync::Arc, vec};
|
||||
#[cfg(feature = "std")]
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
@ -690,12 +693,17 @@ mod tests {
|
||||
let proof_from_bytes = ProofWithPublicInputs::from_bytes(proof_bytes, common_data)?;
|
||||
assert_eq!(proof, &proof_from_bytes);
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
let now = std::time::Instant::now();
|
||||
|
||||
let compressed_proof = proof.clone().compress(&vd.circuit_digest, common_data)?;
|
||||
let decompressed_compressed_proof = compressed_proof
|
||||
.clone()
|
||||
.decompress(&vd.circuit_digest, common_data)?;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
info!("{:.4}s to compress proof", now.elapsed().as_secs_f64());
|
||||
|
||||
assert_eq!(proof, &decompressed_compressed_proof);
|
||||
|
||||
let compressed_proof_bytes = compressed_proof.to_bytes();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
//! Utility module for helper methods and plonky2 serialization logic.
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use plonky2_maybe_rayon::*;
|
||||
@ -41,6 +42,10 @@ pub(crate) const fn reverse_bits(n: usize, num_bits: usize) -> usize {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@ -108,6 +108,9 @@ pub(crate) fn check_partial_products_circuit<F: RichField + Extendable<D>, const
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec;
|
||||
|
||||
use super::*;
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user