Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

[FIX] Handling oog for sha256 precompile #1095

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,7 @@ impl<'a> CircuitInputStateRef<'a> {
if is_precompiled(&code_address) {
let precompile_call: PrecompileCalls = code_address[19].into();
match precompile_call {
PrecompileCalls::Sha256
| PrecompileCalls::Ripemd160
| PrecompileCalls::Blake2F => {
PrecompileCalls::Ripemd160 | PrecompileCalls::Blake2F => {
// Log the precompile address and gas left. Since this failure is mainly
// caused by out of gas.
log::trace!(
Expand Down
11 changes: 10 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGPrecompileGadget<F> {
GasCost::PRECOMPILE_ECRECOVER_BASE.expr(),
),
// These are handled in PrecompileFailedGadget
// addr_bits.value_equals(PrecompileCalls::Sha256),
(
addr_bits.value_equals(PrecompileCalls::Sha256),
GasCost::PRECOMPILE_SHA256_BASE.expr()
+ n_words.quotient() * GasCost::PRECOMPILE_SHA256_PER_WORD.expr(),
),
// addr_bits.value_equals(PrecompileCalls::Ripemd160),
// addr_bits.value_equals(PrecompileCalls::Blake2F),
(
Expand Down Expand Up @@ -198,6 +202,11 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGPrecompileGadget<F> {
precompile_call.base_gas_cost().as_u64()
+ n_words * GasCost::PRECOMPILE_IDENTITY_PER_WORD.as_u64()
}
PrecompileCalls::Sha256 => {
let n_words = (call.call_data_length + 31) / 32;
precompile_call.base_gas_cost().as_u64()
+ n_words * GasCost::PRECOMPILE_SHA256_PER_WORD.as_u64()
}
PrecompileCalls::Bn128Add | PrecompileCalls::Bn128Mul | PrecompileCalls::Ecrecover => {
precompile_call.base_gas_cost().as_u64()
}
Expand Down