This repository was archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 839
Integration tests for tx, copy and bytecode circuits #654
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0dd2747
Add tx circuit integation test
7acf7cd
use paste in macro function generation
d30d793
added bytecode integration test
5032cd6
refactor
a0682d4
Merge branch 'main' into feature/more-integration-tests
adria0 e8082af
fix merge
5f78af5
Fix @pinkiebell comments
6d9b938
Merge branch 'main' into feature/more-integration-tests
adria0 46e055d
make clippy happy
9cf262a
Merge branch 'feature/more-integration-tests' of github.com:privacy-s…
16e1646
Fix merge
c99ea9b
Prefix integration tests with serial_
c6163f6
Update integration-tests/tests/circuits.rs
adria0 dddd4c8
Merge branch 'main' of github.com:privacy-scaling-explorations/zkevm-…
1ea8a58
Address @ChihChengLiang comments
c955dbb
Merge branch 'feature/more-integration-tests' of github.com:privacy-s…
a817cb4
Merge branch 'main' into feature/more-integration-tests
adria0 44441e4
Merge branch 'main' into feature/more-integration-tests
CPerezz 50b97d4
fix clippy lint
CPerezz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,29 @@ | |
|
|
||
| use bus_mapping::circuit_input_builder::BuilderClient; | ||
| use bus_mapping::operation::OperationContainer; | ||
| use halo2_proofs::dev::MockProver; | ||
| use integration_tests::{get_client, log_init, GenDataOutput}; | ||
| use eth_types::geth_types; | ||
| use group::{Curve, Group}; | ||
| use halo2_proofs::arithmetic::BaseExt; | ||
| use halo2_proofs::{ | ||
| arithmetic::{CurveAffine, Field}, | ||
| dev::MockProver, | ||
| pairing::bn256::Fr, | ||
| }; | ||
| use integration_tests::{get_client, log_init, GenDataOutput, CHAIN_ID}; | ||
| use lazy_static::lazy_static; | ||
| use log::trace; | ||
| use paste::paste; | ||
| use rand_chacha::rand_core::SeedableRng; | ||
| use rand_chacha::ChaCha20Rng; | ||
| use std::marker::PhantomData; | ||
| use zkevm_circuits::bytecode_circuit::dev::test_bytecode_circuit; | ||
| use zkevm_circuits::copy_circuit::dev::test_copy_circuit; | ||
| use zkevm_circuits::evm_circuit::witness::RwMap; | ||
| use zkevm_circuits::evm_circuit::{test::run_test_circuit, witness::block_convert}; | ||
| use zkevm_circuits::state_circuit::StateCircuit; | ||
| use zkevm_circuits::tx_circuit::{ | ||
| sign_verify::SignVerifyChip, Secp256k1Affine, TxCircuit, POW_RAND_SIZE, VERIF_HEIGHT, | ||
| }; | ||
|
|
||
| lazy_static! { | ||
| pub static ref GEN_DATA: GenDataOutput = GenDataOutput::load(); | ||
|
|
@@ -18,19 +34,17 @@ async fn test_evm_circuit_block(block_num: u64) { | |
| log::info!("test evm circuit, block number: {}", block_num); | ||
| let cli = get_client(); | ||
| let cli = BuilderClient::new(cli).await.unwrap(); | ||
| let builder = cli.gen_inputs(block_num).await.unwrap(); | ||
| let (builder, _) = cli.gen_inputs(block_num).await.unwrap(); | ||
|
|
||
| let block = block_convert(&builder.block, &builder.code_db); | ||
| run_test_circuit(block).expect("evm_circuit verification failed"); | ||
| } | ||
|
|
||
| async fn test_state_circuit_block(block_num: u64) { | ||
| use halo2_proofs::pairing::bn256::Fr; | ||
|
|
||
| log::info!("test state circuit, block number: {}", block_num); | ||
| let cli = get_client(); | ||
| let cli = BuilderClient::new(cli).await.unwrap(); | ||
| let builder = cli.gen_inputs(block_num).await.unwrap(); | ||
| let (builder, _) = cli.gen_inputs(block_num).await.unwrap(); | ||
|
|
||
| // Generate state proof | ||
| let stack_ops = builder.block.container.sorted_stack(); | ||
|
|
@@ -58,20 +72,108 @@ async fn test_state_circuit_block(block_num: u64) { | |
| prover.verify().expect("state_circuit verification failed"); | ||
| } | ||
|
|
||
| async fn test_tx_circuit_block(block_num: u64) { | ||
| const DEGREE: u32 = 20; | ||
|
Comment on lines
+75
to
+76
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing this on each test, why don't we use a crate like: https://github.com/markhildreth/test-context to do test setup/teardown? |
||
|
|
||
| log::info!("test tx circuit, block number: {}", block_num); | ||
| let cli = get_client(); | ||
| let cli = BuilderClient::new(cli).await.unwrap(); | ||
|
|
||
| let (_, eth_block) = cli.gen_inputs(block_num).await.unwrap(); | ||
|
pinkiebell marked this conversation as resolved.
|
||
| let txs: Vec<_> = eth_block | ||
| .transactions | ||
| .iter() | ||
| .map(geth_types::Transaction::from_eth_tx) | ||
| .collect(); | ||
|
|
||
| let mut rng = ChaCha20Rng::seed_from_u64(2); | ||
| let aux_generator = <Secp256k1Affine as CurveAffine>::CurveExt::random(&mut rng).to_affine(); | ||
|
|
||
| let randomness = Fr::random(&mut rng); | ||
| let mut instance: Vec<Vec<Fr>> = (1..POW_RAND_SIZE + 1) | ||
| .map(|exp| vec![randomness.pow(&[exp as u64, 0, 0, 0]); txs.len() * VERIF_HEIGHT]) | ||
| .collect(); | ||
|
|
||
| instance.push(vec![]); | ||
| let circuit = TxCircuit::<Fr, 4, { 4 * (4 + 32 + 32) }> { | ||
| sign_verify: SignVerifyChip { | ||
| aux_generator, | ||
| window_size: 2, | ||
| _marker: PhantomData, | ||
| }, | ||
| randomness, | ||
| txs, | ||
| chain_id: CHAIN_ID, | ||
| }; | ||
|
|
||
| let prover = MockProver::run(DEGREE, &circuit, instance).unwrap(); | ||
|
|
||
| prover.verify().expect("tx_circuit verification failed"); | ||
| } | ||
|
|
||
| pub async fn test_bytecode_circuit_block(block_num: u64) { | ||
| const DEGREE: u32 = 16; | ||
| let randomness = Fr::from(123456); | ||
|
|
||
| log::info!("test bytecode circuit, block number: {}", block_num); | ||
| let cli = get_client(); | ||
| let cli = BuilderClient::new(cli).await.unwrap(); | ||
| let (builder, _) = cli.gen_inputs(block_num).await.unwrap(); | ||
| let bytecodes: Vec<Vec<u8>> = builder.code_db.0.values().cloned().collect(); | ||
|
|
||
| test_bytecode_circuit(DEGREE, bytecodes, randomness); | ||
| } | ||
|
|
||
| pub async fn test_copy_circuit_block(block_num: u64) { | ||
| const DEGREE: u32 = 16; | ||
|
|
||
| log::info!("test copy circuit, block number: {}", block_num); | ||
| let cli = get_client(); | ||
| let cli = BuilderClient::new(cli).await.unwrap(); | ||
| let (builder, _) = cli.gen_inputs(block_num).await.unwrap(); | ||
| let block = block_convert(&builder.block, &builder.code_db); | ||
|
|
||
| assert!(test_copy_circuit(DEGREE, block).is_ok()); | ||
| } | ||
|
|
||
| macro_rules! declare_tests { | ||
| ($test_evm_name:ident, $test_state_name:ident, $block_tag:expr) => { | ||
| #[tokio::test] | ||
| async fn $test_evm_name() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_evm_circuit_block(*block_num).await; | ||
| } | ||
| ($name:ident, $block_tag:expr) => { | ||
| paste! { | ||
| #[tokio::test] | ||
| async fn [<serial_test_evm_ $name>]() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_evm_circuit_block(*block_num).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn [<serial_test_state_ $name>]() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_state_circuit_block(*block_num).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn [<serial_test_tx_ $name>]() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_tx_circuit_block(*block_num).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn [<serial_test_bytecode_ $name>]() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_bytecode_circuit_block(*block_num).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn [<serial_test_copy_ $name>]() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_copy_circuit_block(*block_num).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn $test_state_name() { | ||
| log_init(); | ||
| let block_num = GEN_DATA.blocks.get($block_tag).unwrap(); | ||
| test_state_circuit_block(*block_num).await; | ||
| } | ||
| }; | ||
| } | ||
|
|
@@ -94,17 +196,14 @@ declare_tests!( | |
| ); | ||
| */ | ||
| declare_tests!( | ||
| test_evm_circuit_erc20_openzeppelin_transfer_fail, | ||
| test_state_circuit_erc20_openzeppelin_transfer_fail, | ||
| circuit_erc20_openzeppelin_transfer_fail, | ||
| "ERC20 OpenZeppelin transfer failed" | ||
| ); | ||
| declare_tests!( | ||
| test_evm_circuit_erc20_openzeppelin_transfer_succeed, | ||
| test_state_circuit_erc20_openzeppelin_transfer_succeed, | ||
| circuit_erc20_openzeppelin_transfer_succeed, | ||
| "ERC20 OpenZeppelin transfer successful" | ||
| ); | ||
| declare_tests!( | ||
| test_evm_circuit_multiple_erc20_openzeppelin_transfers, | ||
| test_state_circuit_multiple_erc20_openzeppelin_transfers, | ||
| circuit_multiple_erc20_openzeppelin_transfers, | ||
| "Multiple ERC20 OpenZeppelin transfers" | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,4 +59,5 @@ harness = false | |
|
|
||
| [features] | ||
| default = [] | ||
| test = [] | ||
| test = [ "dev" ] | ||
| dev = [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| //! The bytecode circuit implementation. | ||
|
|
||
| pub(crate) mod bytecode_unroller; | ||
| /// Bytecode circuit tester | ||
| pub mod dev; | ||
|
ChihChengLiang marked this conversation as resolved.
|
||
| pub(crate) mod param; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.