Skip to content

Commit

Permalink
normalize row usage: 1M means 100% (#221)
Browse files Browse the repository at this point in the history
* normalize row usage: 1M means 100%

* normalize row usage: 1M means 100%

* Update capacity_checker.rs

* Update capacity_checker.rs
  • Loading branch information
lispc authored Aug 17, 2023
1 parent 01aea2d commit 9fc33fd
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
54 changes: 52 additions & 2 deletions prover/src/zkevm/capacity_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,56 @@ impl RowUsage {
row_usage_details: Vec::new(),
}
}
// We treat 1M as 100%
pub fn normalize(&self) -> Self {
/*
const MAX_TXS: usize = 100;
const MAX_INNER_BLOCKS: usize = 100;
const MAX_EXP_STEPS: usize = 10_000;
const MAX_CALLDATA: usize = 400_000;
const MAX_BYTECODE: usize = 400_000;
const MAX_MPT_ROWS: usize = 400_000;
const MAX_KECCAK_ROWS: usize = 524_000;
const MAX_RWS: usize = 1_000_000;
const MAX_PRECOMPILE_EC_ADD: usize = 50;
const MAX_PRECOMPILE_EC_MUL: usize = 50;
const MAX_PRECOMPILE_EC_PAIRING: usize = 2;
*/
use super::circuit::{
MAX_BYTECODE, MAX_CALLDATA, MAX_EXP_STEPS, MAX_KECCAK_ROWS, MAX_MPT_ROWS, MAX_RWS,
};
// 14 in total
// "evm", "state", "bytecode", "copy",
// "keccak", "tx", "rlp", "exp", "modexp", "pi",
// "poseidon", "sig", "ecc", "mpt",
let real_available_rows = [
MAX_RWS,
MAX_RWS,
MAX_BYTECODE,
MAX_RWS,
MAX_KECCAK_ROWS,
MAX_CALLDATA,
MAX_CALLDATA,
7 * MAX_EXP_STEPS, // exp
MAX_KECCAK_ROWS,
MAX_RWS,
MAX_MPT_ROWS, // poseidon
(1 << 20) - 256, // sig
(1 << 20) - 256, // FIXME: pairing may be limit to 1, fix later
MAX_MPT_ROWS,
]
.map(|x| (x as f32 * 0.95) as usize);
let details = self
.row_usage_details
.iter()
.zip_eq(real_available_rows.iter())
.map(|(x, limit)| SubCircuitRowUsage {
name: x.name.clone(),
row_number: (1_000_000u64 * (x.row_number as u64) / (*limit as u64)) as usize,
})
.collect_vec();
Self::from_row_usage_details(details)
}
pub fn from_row_usage_details(row_usage_details: Vec<SubCircuitRowUsage>) -> Self {
let row_number = row_usage_details
.iter()
Expand Down Expand Up @@ -63,7 +113,7 @@ impl RowUsage {
.map(|x| x.row_number)
.max()
.unwrap();
self.is_ok = self.row_number < (1 << *INNER_DEGREE) - 256;
self.is_ok = self.row_number < 1_000_000;
}
}

Expand Down Expand Up @@ -126,6 +176,6 @@ impl CircuitCapacityChecker {
let tx_row_usage = RowUsage::from_row_usage_details(row_usage_details);
self.row_usages.push(tx_row_usage.clone());
self.acc_row_usage.add(&tx_row_usage);
Ok((self.acc_row_usage.clone(), tx_row_usage))
Ok((self.acc_row_usage.normalize(), tx_row_usage.normalize()))
}
}
22 changes: 11 additions & 11 deletions prover/src/zkevm/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ pub use self::builder::{
// TODO: more smart row capacity checking rather than max_of(row_usage_details) > 1<<20 - 256
// Need to compare with real row nums like MAX_MPT_ROWS/MAX_KECCAK_ROWS etc.
////// params for degree = 20 ////////////
const MAX_TXS: usize = 100;
const MAX_INNER_BLOCKS: usize = 100;
const MAX_EXP_STEPS: usize = 10_000;
const MAX_CALLDATA: usize = 400_000;
const MAX_BYTECODE: usize = 400_000;
const MAX_MPT_ROWS: usize = 400_000;
const MAX_KECCAK_ROWS: usize = 524_000;
const MAX_RWS: usize = 1_000_000;
const MAX_PRECOMPILE_EC_ADD: usize = 50;
const MAX_PRECOMPILE_EC_MUL: usize = 50;
const MAX_PRECOMPILE_EC_PAIRING: usize = 2;
pub const MAX_TXS: usize = 100;
pub const MAX_INNER_BLOCKS: usize = 100;
pub const MAX_EXP_STEPS: usize = 10_000;
pub const MAX_CALLDATA: usize = 400_000;
pub const MAX_BYTECODE: usize = 400_000;
pub const MAX_MPT_ROWS: usize = 400_000;
pub const MAX_KECCAK_ROWS: usize = 524_000;
pub const MAX_RWS: usize = 1_000_000;
pub const MAX_PRECOMPILE_EC_ADD: usize = 50;
pub const MAX_PRECOMPILE_EC_MUL: usize = 50;
pub const MAX_PRECOMPILE_EC_PAIRING: usize = 2;

static CHAIN_ID: Lazy<u64> = Lazy::new(|| read_env_var("CHAIN_ID", 53077));
static AUTO_TRUNCATE: Lazy<bool> = Lazy::new(|| read_env_var("AUTO_TRUNCATE", false));
Expand Down

0 comments on commit 9fc33fd

Please sign in to comment.