diff --git a/evm/tests/basic_smart_contract.rs b/evm/tests/basic_smart_contract.rs index 89aacd2c..28b5be0b 100644 --- a/evm/tests/basic_smart_contract.rs +++ b/evm/tests/basic_smart_contract.rs @@ -27,7 +27,7 @@ type C = KeccakGoldilocksConfig; /// Test a simple token transfer to a new address. #[test] -#[ignore] // Too slow to run on CI. +// #[ignore] // Too slow to run on CI. fn test_basic_smart_contract() -> anyhow::Result<()> { init_logger(); diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index c5de1e63..367b99d0 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -16,6 +16,7 @@ gate_testing = [] parallel = ["hashbrown/rayon", "plonky2_maybe_rayon/parallel"] std = ["anyhow/std", "rand/std", "itertools/use_std"] timing = ["std"] +mock = [] [dependencies] ahash = { version = "0.8.3", default-features = false, features = ["compile-time-rng"] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`. diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index dca3202a..a7182e15 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -36,9 +36,32 @@ pub struct PolynomialBatch, C: GenericConfig, C: GenericConfig, const D: usize> Default + for PolynomialBatch +{ + fn default() -> Self { + PolynomialBatch { + polynomials: Vec::new(), + merkle_tree: MerkleTree::default(), + degree_log: 0, + rate_bits: 0, + blinding: false, + } + } +} + impl, C: GenericConfig, const D: usize> PolynomialBatch { + pub fn default() -> Self { + Self { + polynomials: Vec::new(), + merkle_tree: MerkleTree::default(), + degree_log: 0, + rate_bits: 0, + blinding: false, + } + } /// Creates a list polynomial commitment for the polynomials interpolating the values in `values`. pub fn from_values( values: Vec>, diff --git a/plonky2/src/hash/merkle_tree.rs b/plonky2/src/hash/merkle_tree.rs index b3b0e0cb..ab7e3958 100644 --- a/plonky2/src/hash/merkle_tree.rs +++ b/plonky2/src/hash/merkle_tree.rs @@ -17,6 +17,12 @@ use crate::util::log2_strict; // TODO: Change H to GenericHashOut, since this only cares about the hash, not the hasher. pub struct MerkleCap>(pub Vec); +impl> Default for MerkleCap { + fn default() -> Self { + Self(Vec::new()) + } +} + impl> MerkleCap { pub fn len(&self) -> usize { self.0.len() @@ -54,6 +60,16 @@ pub struct MerkleTree> { pub cap: MerkleCap, } +impl> Default for MerkleTree { + fn default() -> Self { + Self { + leaves: Vec::new(), + digests: Vec::new(), + cap: MerkleCap::default(), + } + } +} + fn capacity_up_to_mut(v: &mut Vec, len: usize) -> &mut [MaybeUninit] { assert!(v.capacity() >= len); let v_ptr = v.as_mut_ptr().cast::>(); diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 478c5ff5..10293339 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -16,7 +16,7 @@ use crate::util::serialization::{Buffer, IoResult, Read, Write}; /// Given a `PartitionWitness` that has only inputs set, populates the rest of the witness using the /// given set of generators. -pub(crate) fn generate_partial_witness< +pub fn generate_partial_witness< 'a, F: RichField + Extendable, C: GenericConfig, diff --git a/plonky2/src/lookup_test.rs b/plonky2/src/lookup_test.rs index c575417e..c8b084cc 100644 --- a/plonky2/src/lookup_test.rs +++ b/plonky2/src/lookup_test.rs @@ -469,6 +469,51 @@ mod tests { Ok(()) } + #[cfg(feature = "mock")] + #[test] + fn test_circuit_build_mock() { + // This code is taken from examples/fibonacci.rs + use crate::field::types::Field; + use crate::iop::generator::generate_partial_witness; + use crate::iop::witness::{PartialWitness, Witness, WitnessWrite}; + 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 = >::F; + + let config = CircuitConfig::standard_recursion_config(); + let mut builder = CircuitBuilder::::new(config); + + // The arithmetic circuit. + let initial_a = builder.add_virtual_target(); + let initial_b = builder.add_virtual_target(); + let mut prev_target = initial_a; + let mut cur_target = initial_b; + for _ in 0..99 { + let temp = builder.add(prev_target, cur_target); + prev_target = cur_target; + cur_target = temp; + } + + // Public inputs are the two initial values (provided below) and the result (which is generated). + builder.register_public_input(initial_a); + builder.register_public_input(initial_b); + builder.register_public_input(cur_target); + + // Provide initial values. + let mut pw = PartialWitness::new(); + pw.set_target(initial_a, F::ZERO); + pw.set_target(initial_b, F::ONE); + + let data = builder.build::(); + let partition_witness = generate_partial_witness(pw, &data.prover_only, &data.common); + let result = partition_witness.try_get_target(cur_target).unwrap(); + assert_eq!(result, F::from_canonical_u64(3736710860384812976)); + } + fn init_logger() -> anyhow::Result<()> { let mut builder = env_logger::Builder::from_default_env(); builder.format_timestamp(None); diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 82d4ee89..89ec0903 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -1023,15 +1023,19 @@ impl, const D: usize> CircuitBuilder { let max_fft_points = 1 << (degree_bits + max(rate_bits, log2_ceil(quotient_degree_factor))); let fft_root_table = fft_root_table(max_fft_points); - let constants_sigmas_vecs = [constant_vecs, sigma_vecs.clone()].concat(); - let constants_sigmas_commitment = PolynomialBatch::::from_values( - constants_sigmas_vecs, - rate_bits, - PlonkOracle::CONSTANTS_SIGMAS.blinding, - cap_height, - &mut timing, - Some(&fft_root_table), - ); + let mut constants_sigmas_commitment = PolynomialBatch::::default(); + #[cfg(not(feature = "mock"))] + { + let constants_sigmas_vecs = [constant_vecs, sigma_vecs.clone()].concat(); + constants_sigmas_commitment = PolynomialBatch::::from_values( + constants_sigmas_vecs, + rate_bits, + PlonkOracle::CONSTANTS_SIGMAS.blinding, + cap_height, + &mut timing, + Some(&fft_root_table), + ); + } // Map between gates where not all generators are used and the gate's number of used generators. let incomplete_gates = self