Skip to content

Commit

Permalink
many fixes after sync upstream (scroll-tech#287)
Browse files Browse the repository at this point in the history
* many fixes after sync upstream

* fixing

* limit mainnet test k = 22

* fix CircuitTestBuilder k

* revert to upstream test_util

* fix k; disable ecdsa
  • Loading branch information
lispc authored Feb 6, 2023
1 parent 7cdeda5 commit b08a539
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[target.'cfg(target_os="macos")']
rustflags = ["-C", "link-args=-framework CoreFoundation -framework Security"]
[net]
git-fetch-with-cli = true
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ jobs:
build:
needs: [skip_check]
if: |
false &&
github.event.pull_request.draft == false &&
(github.event.action == 'ready_for_review' || needs.skip_check.outputs.should_skip != 'true')
Expand Down
29 changes: 1 addition & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions bus-mapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@
extern crate alloc;
extern crate core;

mod util;

pub mod circuit_input_builder;
pub mod error;
pub mod evm;
Expand All @@ -241,5 +239,6 @@ pub mod operation;
pub mod precompile;
pub mod rpc;
pub mod state_db;
pub mod util;

pub use error::Error;
4 changes: 3 additions & 1 deletion bus-mapping/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! ..
use once_cell::sync::Lazy;
use std::str::FromStr;

fn read_env_var<T: Clone + FromStr>(var_name: &'static str, default: T) -> T {
/// ..
pub fn read_env_var<T: Clone + FromStr>(var_name: &'static str, default: T) -> T {
std::env::var(var_name)
.map(|s| s.parse::<T>().unwrap_or_else(|_| default.clone()))
.unwrap_or(default)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ serde_json = "1.0.66"
serde = { version = "1.0.130", features = ["derive"] }
bus-mapping = { path = "../bus-mapping" }
eth-types = { path = "../eth-types" }
zkevm-circuits = { path = "../zkevm-circuits", features = ["test"] }
zkevm-circuits = { path = "../zkevm-circuits", default-features = false, features = ["test", "onephase"] }
tokio = { version = "1.13", features = ["macros", "rt-multi-thread"] }
url = "2.2.2"
pretty_assertions = "1.0.0"
Expand Down
17 changes: 12 additions & 5 deletions integration-tests/tests/mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bus_mapping::circuit_input_builder::{keccak_inputs, BuilderClient, CircuitsParams};
use bus_mapping::Error::JSONRpcError;
use halo2_proofs::circuit::Value;
use halo2_proofs::dev::MockProver;
use halo2_proofs::dev::VerifyFailure;
Expand Down Expand Up @@ -101,11 +102,11 @@ async fn test_super_circuit_all_block() {
let block_num = blk as u64;
log::info!("test super circuit, block number: {}", block_num);
let cli = get_client();
// target k = 19
// target k = 22
let params = CircuitsParams {
max_rws: 4_000_000,
max_copy_rows: 4_000_000,
max_txs: 500,
max_txs: 235, // 2**22 / ROWS_PER_SIG
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_bytecode: 3_000_000,
Expand All @@ -114,7 +115,12 @@ async fn test_super_circuit_all_block() {
let cli = BuilderClient::new(cli, params).await.unwrap();
let builder = cli.gen_inputs(block_num).await;
if builder.is_err() {
log::error!("invalid builder {} {:?}, err num NA", block_num, builder);
let err = builder.err().unwrap();
let err_msg = match err {
JSONRpcError(_json_rpc_err) => "JSONRpcError".to_string(), // too long...
_ => format!("{err:?}"),
};
log::error!("invalid builder {} {:?}, err num NA", block_num, err_msg);
continue;
}
let builder = builder.unwrap().0;
Expand All @@ -125,10 +131,11 @@ async fn test_super_circuit_all_block() {
}

let (k, circuit, instance) =
SuperCircuit::<Fr, 500, 2_000_000, 64, 0x1000>::build_from_circuit_input_builder(
SuperCircuit::<Fr, 235, 2_000_000, 64, 0x1000>::build_from_circuit_input_builder(
&builder,
)
.unwrap();
debug_assert!(k <= 22);
let prover = MockProver::<Fr>::run(k, &circuit, instance).unwrap();
let result = prover.verify_par();
let errs = result.err().unwrap_or_default();
Expand All @@ -155,7 +162,7 @@ async fn test_circuit_all_block() {
let params = CircuitsParams {
max_rws: 4_000_000,
max_copy_rows: 4_000_000,
max_txs: 500,
max_txs: 235,
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_bytecode: 3_000_000,
Expand Down
5 changes: 3 additions & 2 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ env_logger = "0.9"

# halo2_base = { path = "../../halo2-ecc/halo2_base" }
# halo2_ecc = { path = "../../halo2-ecc/halo2_ecc" }
halo2_base = { git = "ssh://git@github.com/scroll-tech/halo2-ecc.git", branch = "halo2-ecc-ecdsa-0129" }
halo2_ecc = { git = "ssh://git@github.com/scroll-tech/halo2-ecc.git", branch = "halo2-ecc-ecdsa-0129" }
halo2_base = { git = "ssh://git@github.com/scroll-tech/halo2-ecc.git", branch = "halo2-ecc-ecdsa-0129", default-features = false }
halo2_ecc = { git = "ssh://git@github.com/scroll-tech/halo2-ecc.git", branch = "halo2-ecc-ecdsa-0129",default-features = false }

ecdsa = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2022_09_09" }
ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2022_09_09" }
Expand All @@ -45,6 +45,7 @@ subtle = "2.4"
rand_chacha = "0.3"
hex = "0.4.3"
rayon = "1.5"
once_cell = "1.17.0"

[dev-dependencies]
bus-mapping = { path = "../bus-mapping", features = ["test"] }
Expand Down
25 changes: 21 additions & 4 deletions zkevm-circuits/src/bytecode_circuit/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use halo2_proofs::{
poly::Rotation,
};
use keccak256::EMPTY_HASH_LE;
use log::trace;
use std::vec;

use super::{
Expand Down Expand Up @@ -353,6 +352,7 @@ impl<F: Field> SubCircuitConfig<F> for BytecodeCircuitConfig<F> {
is_byte_to_header(meta),
]))
});
#[cfg(feature = "codehash")]
meta.lookup_any(
"keccak256_table_lookup(cur.value_rlc, cur.length, cur.hash)",
|meta| {
Expand Down Expand Up @@ -424,7 +424,7 @@ impl<F: Field> BytecodeCircuitConfig<F> {
assert!(size > self.minimum_rows);
let last_row_offset = size - self.minimum_rows + 1;

trace!(
log::debug!(
"size: {}, minimum_rows: {}, last_row_offset:{}",
size,
self.minimum_rows,
Expand All @@ -435,9 +435,21 @@ impl<F: Field> BytecodeCircuitConfig<F> {
.evm_word()
.map(|challenge| rlc::value(EMPTY_HASH_LE.as_ref(), challenge));

let mut is_first_time = true;
layouter.assign_region(
|| "assign bytecode",
|mut region| {
if is_first_time {
is_first_time = false;
self.set_padding_row(
&mut region,
&push_data_left_is_zero_chip,
empty_hash,
last_row_offset,
last_row_offset,
)?;
return Ok(());
}
let mut offset = 0;
for bytecode in witness.iter() {
self.assign_bytecode(
Expand Down Expand Up @@ -540,6 +552,7 @@ impl<F: Field> BytecodeCircuitConfig<F> {
F::from(push_data_size as u64),
)?;

/*
trace!(
"bytecode.set_row({}): last:{} h:{:?} t:{:?} i:{:?} c:{:?} v:{:?} pdl:{} rlc:{:?} l:{:?} pds:{:?}",
offset,
Expand All @@ -554,6 +567,7 @@ impl<F: Field> BytecodeCircuitConfig<F> {
length.get_lower_32(),
push_data_size
);
*/

*offset += 1;
push_data_left = next_push_data_left
Expand Down Expand Up @@ -775,7 +789,7 @@ impl<F: Field> SubCircuit<F> for BytecodeCircuit<F> {
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
config.load_aux_tables(layouter)?;
config.assign_internal(layouter, self.size, &self.bytecodes, challenges, false)
config.assign_internal(layouter, self.size, &self.bytecodes, challenges, true)
}
}

Expand Down Expand Up @@ -922,6 +936,7 @@ mod tests {
}

/// Test invalid code_hash data
#[cfg(feature = "codehash")]
#[test]
fn bytecode_invalid_hash_data() {
let k = 9;
Expand All @@ -932,7 +947,7 @@ mod tests {
{
let mut invalid = unrolled;
invalid.rows[0].code_hash += Word::one();
trace!("bytecode_invalid_hash_data: Change the code_hash on the first position");
log::trace!("bytecode_invalid_hash_data: Change the code_hash on the first position");
test_bytecode_circuit_unrolled::<Fr>(k, vec![invalid], false);
}
// TODO: other rows code_hash are ignored by the witness generation, to
Expand Down Expand Up @@ -965,6 +980,8 @@ mod tests {
}

/// Test invalid byte data
#[cfg(feature = "codehash")]
#[test]
fn bytecode_invalid_byte_data() {
let k = 9;
Expand Down
10 changes: 8 additions & 2 deletions zkevm-circuits/src/evm_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,19 @@ impl<F: Field> SubCircuit<F> for EvmCircuit<F> {
fn min_num_rows_block(block: &witness::Block<F>) -> (usize, usize) {
let num_rows_required_for_execution_steps: usize =
Self::get_num_rows_required_no_padding(block);
let _num_rows_required_for_fixed_table: usize = detect_fixed_table_tags(block)
let num_rows_required_for_fixed_table: usize = detect_fixed_table_tags(block)
.iter()
.map(|tag| tag.build::<F>().count())
.sum();
(
num_rows_required_for_execution_steps,
block.evm_circuit_pad_to,
std::cmp::max(
block.evm_circuit_pad_to,
std::cmp::max(
num_rows_required_for_fixed_table,
num_rows_required_for_execution_steps,
),
),
)
}

Expand Down
9 changes: 7 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
table::{LookupTable, RwTableTag, TxReceiptFieldTag},
util::{query_expression, Challenges, Expr},
};
use bus_mapping::util::read_env_var;
use eth_types::{evm_unimplemented, Field};
use gadgets::util::not;
use halo2_proofs::{
Expand Down Expand Up @@ -40,6 +41,10 @@ use halo2_proofs::plonk::ThirdPhase;

use strum::{EnumCount, IntoEnumIterator};

use once_cell::sync::Lazy;
pub(crate) static CHECK_RW_LOOKUP: Lazy<bool> =
Lazy::new(|| read_env_var("CHECK_RW_LOOKUP", false));

mod add_sub;
mod addmod;
mod address;
Expand Down Expand Up @@ -1330,8 +1335,8 @@ impl<F: Field> ExecutionConfig<F> {
// Fill in the witness values for stored expressions
let assigned_stored_expressions = self.assign_stored_expressions(region, offset, step)?;

// enable with `RUST_LOG=debug`
if log::log_enabled!(log::Level::Debug) {
// enable with `CHECK_RW_LOOKUP=true`
if *CHECK_RW_LOOKUP {
let is_padding_step = matches!(step.execution_state, ExecutionState::EndBlock)
&& step.rw_indices.is_empty();
if !is_padding_step {
Expand Down
15 changes: 9 additions & 6 deletions zkevm-circuits/src/rlp_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::marker::PhantomData;

use bus_mapping::circuit_input_builder::get_dummy_tx_hash;
use eth_types::Field;
use gadgets::binary_number::{BinaryNumberChip, BinaryNumberConfig};
use gadgets::is_equal::{IsEqualChip, IsEqualConfig, IsEqualInstruction};
Expand Down Expand Up @@ -1311,12 +1312,14 @@ impl<F: Field> RlpCircuitConfig<F> {
];

for (signed_tx_idx, signed_tx) in signed_txs.iter().enumerate() {
log::debug!(
"rlp circuit assign {}th tx at offset:{}, tx hash {:?}",
signed_tx_idx,
offset,
signed_tx.tx.hash
);
if signed_tx.tx.hash != get_dummy_tx_hash(signed_tx.tx.chain_id) {
log::debug!(
"rlp circuit assign {}th tx at offset:{}, tx hash {:?}",
signed_tx_idx,
offset,
signed_tx.tx.hash
);
}
// tx hash (signed tx)
let mut all_bytes_rlc_acc = Value::known(F::zero());
let tx_hash_rows = signed_tx.gen_witness(challenges);
Expand Down
5 changes: 1 addition & 4 deletions zkevm-circuits/src/state_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,9 @@ impl<F: Field> StateCircuitConfig<F> {
let mut end_state_root: Option<AssignedCell<_, F>> = None;

for (offset, (row, prev_row)) in rows.zip(prev_rows).enumerate() {
if offset >= padding_length {
if offset == 0 || offset + 1 >= padding_length {
log::trace!("state circuit assign offset:{} row:{:?}", offset, row);
}
if offset + 1 >= n_rows || offset == padding_length {
log::debug!("state circuit assign offset:{} row:{:?}", offset, row);
}

region.assign_fixed(
|| "selector",
Expand Down
2 changes: 0 additions & 2 deletions zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,6 @@ impl<

self.rlp_circuit
.synthesize_sub(&config.rlp_circuit, challenges, layouter)?;
self.tx_circuit
.synthesize_sub(&config.tx_circuit, challenges, layouter)?;
// load both poseidon table and zktrie table
#[cfg(feature = "zktrie")]
{
Expand Down
Loading

0 comments on commit b08a539

Please sign in to comment.