Skip to content

Commit

Permalink
allow n_pairs to have a larger range (scroll-tech#847)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhang Zhuo <[email protected]>
  • Loading branch information
kunxian-xia and lispc authored Aug 29, 2023
1 parent c34c889 commit 2691944
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions zkevm-circuits/src/evm_circuit/execution/error_oog_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) struct ErrorOOGPrecompileGadget<F> {
precompile_addr: Cell<F>,
addr_bits: BinaryNumberGadget<F, 4>,
call_data_length: Cell<F>,
n_pairs: ConstantDivisionGadget<F, 1>, // 1 is enough as call_data_length < 192*256
n_pairs: ConstantDivisionGadget<F, N_BYTES_MEMORY_WORD_SIZE>,
n_words: ConstantDivisionGadget<F, N_BYTES_MEMORY_WORD_SIZE>,
required_gas: Cell<F>,
insufficient_gas: LtGadget<F, N_BYTES_GAS>,
Expand All @@ -44,13 +44,23 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGPrecompileGadget<F> {

// read call data length
let call_data_length = cb.call_context(None, CallContextFieldTag::CallDataLength);
let n_pairs =
ConstantDivisionGadget::construct(cb, call_data_length.expr(), N_BYTES_EC_PAIR as u64);
let n_words = ConstantDivisionGadget::construct(
cb,
call_data_length.expr() + (N_BYTES_WORD - 1).expr(),
N_BYTES_WORD as u64,
let n_pairs = cb.condition(
addr_bits.value_equals(PrecompileCalls::Bn128Pairing),
|cb| {
ConstantDivisionGadget::construct(
cb,
call_data_length.expr(),
N_BYTES_EC_PAIR as u64,
)
},
);
let n_words = cb.condition(addr_bits.value_equals(PrecompileCalls::Identity), |cb| {
ConstantDivisionGadget::construct(
cb,
call_data_length.expr() + (N_BYTES_WORD - 1).expr(),
N_BYTES_WORD as u64,
)
});

// calculate required gas for precompile
let precompiles_required_gas = vec![
Expand Down

0 comments on commit 2691944

Please sign in to comment.