Charge gas for keccak (#943)

This commit is contained in:
wborgeaud 2023-03-29 19:58:29 +02:00 committed by GitHub
parent b667c07497
commit 9f1a5f975c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,20 @@
global sys_keccak256:
// stack: kexit_info, offset, len
// TODO: Charge gas.
PUSH @GAS_KECCAK256
DUP4
// stack: len, static_gas, kexit_info, offset, len
ISZERO %jumpi(sys_keccak256_empty)
// stack: static_gas, kexit_info, offset, len
DUP4 %num_bytes_to_num_words %mul_const(@GAS_KECCAK256WORD)
ADD
%charge_gas
// stack: kexit_info, offset, len
%stack (kexit_info, offset, len) -> (offset, len, kexit_info, offset, len)
ADD // TODO: need to check for overflow?
DUP1 %ensure_reasonable_offset
%update_mem_bytes
%stack (kexit_info, offset, len) -> (offset, len, kexit_info)
PUSH @SEGMENT_MAIN_MEMORY
GET_CONTEXT
@ -10,6 +24,12 @@ global sys_keccak256:
SWAP1
EXIT_KERNEL
sys_keccak256_empty:
// stack: static_gas, kexit_info, offset, len
%charge_gas
%stack (kexit_info, offset, len) -> (kexit_info, @EMPTY_STRING_HASH)
EXIT_KERNEL
// Computes Keccak256(input_word). Clobbers @SEGMENT_KERNEL_GENERAL.
//
// Pre stack: input_word