diff --git a/core/Cargo.toml b/core/Cargo.toml index 3102baa54..fc14e0738 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -79,6 +79,7 @@ neon = ["p3-blake3/neon"] programs = [] serial = [] avx512 = ["p3-baby-bear/nightly-features"] +enable-all-chips = [] [[bench]] harness = false diff --git a/core/src/stark/air.rs b/core/src/stark/air.rs index 9c764691d..ad0cb7da1 100644 --- a/core/src/stark/air.rs +++ b/core/src/stark/air.rs @@ -109,11 +109,11 @@ pub enum RiscvAir { Bls12381Fp2Op(QuadFieldChip), /// A precompile for decompressing a point on the BLS12-381 curve. Bls12381G1Decompress(Bls12381G1DecompressChip), - // A precompile for computing round function of Blake2s algorithm + /// A precompile for computing round function of Blake2s algorithm Blake2sRound(Blake2sRoundChip), /// A precompile for sha512 extend. Sha512Extend(Sha512ExtendChip), - /// A precompile for sha256 compress. + /// A precompile for sha512 compress. Sha512Compress(Sha512CompressChip), } @@ -140,27 +140,29 @@ impl RiscvAir { chips.push(RiscvAir::Sha256Extend(sha_extend)); let sha_compress = ShaCompressChip; chips.push(RiscvAir::Sha256Compress(sha_compress)); - let sha512_extend = Sha512ExtendChip; - chips.push(RiscvAir::Sha512Extend(sha512_extend)); - let sha512_compress = Sha512CompressChip; - chips.push(RiscvAir::Sha512Compress(sha512_compress)); - let ed_add_assign = EdAddAssignChip::>::new(); - chips.push(RiscvAir::Ed25519Add(ed_add_assign)); - let ed_decompress = EdDecompressChip::::default(); - chips.push(RiscvAir::Ed25519Decompress(ed_decompress)); - let k256_decompress = Secp256k1DecompressChip::new(); - chips.push(RiscvAir::Secp256k1Decompress(k256_decompress)); - let secp256k1_add_assign = WeierstrassAddAssignChip::>::new(); - chips.push(RiscvAir::Secp256k1Add(secp256k1_add_assign)); - let secp256k1_double_assign = - WeierstrassDoubleAssignChip::>::new(); - chips.push(RiscvAir::Secp256k1Double(secp256k1_double_assign)); let keccak_permute = KeccakPermuteChip::new(); chips.push(RiscvAir::KeccakP(keccak_permute)); - let bn254_add_assign = WeierstrassAddAssignChip::>::new(); - chips.push(RiscvAir::Bn254Add(bn254_add_assign)); - let bn254_double_assign = WeierstrassDoubleAssignChip::>::new(); - chips.push(RiscvAir::Bn254Double(bn254_double_assign)); + // NOTE: See issue #188 for more context. Enabling too many chips leads to errors in the recursive verifier. + // These chips below are disabled by default to work around this issue. + cfg_if::cfg_if! { + if #[cfg(feature = "enable-all-chips")] { + let bn254_add_assign = WeierstrassAddAssignChip::>::new(); + chips.push(RiscvAir::Bn254Add(bn254_add_assign)); + let bn254_double_assign = WeierstrassDoubleAssignChip::>::new(); + chips.push(RiscvAir::Bn254Double(bn254_double_assign)); + let secp256k1_add_assign = WeierstrassAddAssignChip::>::new(); + chips.push(RiscvAir::Secp256k1Add(secp256k1_add_assign)); + let secp256k1_double_assign = + WeierstrassDoubleAssignChip::>::new(); + chips.push(RiscvAir::Secp256k1Double(secp256k1_double_assign)); + let ed_add_assign = EdAddAssignChip::>::new(); + chips.push(RiscvAir::Ed25519Add(ed_add_assign)); + let ed_decompress = EdDecompressChip::::default(); + chips.push(RiscvAir::Ed25519Decompress(ed_decompress)); + let k256_decompress = Secp256k1DecompressChip::new(); + chips.push(RiscvAir::Secp256k1Decompress(k256_decompress)); + } + } let bls12381_g1_add = WeierstrassAddAssignChip::>::new(); chips.push(RiscvAir::Bls12381Add(bls12381_g1_add)); let bls12381_g1_double = WeierstrassDoubleAssignChip::>::new(); @@ -173,6 +175,10 @@ impl RiscvAir { chips.push(RiscvAir::Bls12381G1Decompress(bls12381_g1_decompress)); let blake_2s_round = Blake2sRoundChip::new(); chips.push(RiscvAir::Blake2sRound(blake_2s_round)); + let sha512_extend = Sha512ExtendChip; + chips.push(RiscvAir::Sha512Extend(sha512_extend)); + let sha512_compress = Sha512CompressChip; + chips.push(RiscvAir::Sha512Compress(sha512_compress)); let div_rem = DivRemChip; chips.push(RiscvAir::DivRem(div_rem)); diff --git a/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs b/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs index 6cb14abf6..daf646d3e 100644 --- a/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs +++ b/core/src/syscall/precompiles/weierstrass/weierstrass_add.rs @@ -496,7 +496,7 @@ mod tests { run_test, setup_logger, tests::{ BLS12381_G1_ADD_ELF, BLS12381_G1_DOUBLE_ELF, BLS12381_G1_SCALARMUL_ELF, - BN254_ADD_ELF, BN254_MUL_ELF, SECP256K1_ADD_ELF, SECP256K1_MUL_ELF, + SECP256K1_ADD_ELF, SECP256K1_MUL_ELF, }, }, }; @@ -509,14 +509,20 @@ mod tests { } #[test] + #[cfg(feature = "enable-all-chips")] fn test_bn254_add_simple() { + use crate::utils::tests::BN254_ADD_ELF; + setup_logger(); let program = Program::from(BN254_ADD_ELF); run_test::>(program).unwrap(); } #[test] + #[cfg(feature = "enable-all-chips")] fn test_bn254_mul_simple() { + use crate::utils::tests::BN254_MUL_ELF; + setup_logger(); let program = Program::from(BN254_MUL_ELF); run_test::>(program).unwrap(); diff --git a/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs b/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs index 4e03677a9..1bcdf34ab 100644 --- a/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs +++ b/core/src/syscall/precompiles/weierstrass/weierstrass_double.rs @@ -531,7 +531,7 @@ pub mod tests { stark::DefaultProver, utils::{ run_test, setup_logger, - tests::{BLS12381_G1_DOUBLE_ELF, BN254_DOUBLE_ELF, SECP256K1_DOUBLE_ELF}, + tests::{BLS12381_G1_DOUBLE_ELF, SECP256K1_DOUBLE_ELF}, }, }; @@ -543,7 +543,10 @@ pub mod tests { } #[test] + #[cfg(feature = "enable-all-chips")] fn test_bn254_double_simple() { + use crate::utils::tests::BN254_DOUBLE_ELF; + setup_logger(); let program = Program::from(BN254_DOUBLE_ELF); run_test::>(program).unwrap(); diff --git a/tests/hint-io/Cargo.lock b/tests/hint-io/Cargo.lock index f4b4d5b1c..095917052 100644 --- a/tests/hint-io/Cargo.lock +++ b/tests/hint-io/Cargo.lock @@ -104,12 +104,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.155"