Fix bugs in wcopy and update_mem_words (#934)

* Fix bugs in wcopy and update_mem_words

* Update comment
This commit is contained in:
wborgeaud 2023-03-22 19:14:55 +01:00 committed by GitHub
parent 15bafce5dd
commit f4e65feb65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -201,7 +201,7 @@ global sys_basefee:
// stack: old_num_words, num_words, kexit_info
DUP2 DUP2 GT
// stack: old_num_words > num_words, old_num_words, num_words, kexit_info
%jumpi(%%end)
%jumpi(%%no_update)
// stack: old_num_words, num_words, kexit_info
%memory_cost
// stack: old_cost, num_words, kexit_info
@ -214,6 +214,10 @@ global sys_basefee:
SUB
// stack: additional_cost, kexit_info
%charge_gas
%jump(%%end)
%%no_update:
// stack: old_num_words, num_words, kexit_info
%pop2
%%end:
// stack: kexit_info
%endmacro

View File

@ -124,14 +124,14 @@ sys_calldataload_after_mload_packing:
// stack: kexit_info, dest_offset, offset, size
DUP4 %num_bytes_to_num_words %mul_const(@GAS_COPY) %add_const(@GAS_VERYLOW) %charge_gas
%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, dest_offset, offset, size, kexit_info)
%stack (kexit_info, dest_offset, offset, size) -> (dest_offset, size, kexit_info, dest_offset, offset, size)
ADD // TODO: check for overflow, see discussion here https://github.com/mir-protocol/plonky2/pull/930/files/a4ea0965d79561c345e2f77836c07949c7e0bc69#r1143630253
// stack: expanded_num_bytes, dest_offset, offset, size, kexit_info
// stack: expanded_num_bytes, kexit_info, dest_offset, offset, size, kexit_info
DUP1 %ensure_reasonable_offset
%update_mem_bytes
GET_CONTEXT
%stack (context, dest_offset, offset, size, kexit_info) ->
%stack (context, kexit_info, dest_offset, offset, size) ->
(context, @SEGMENT_MAIN_MEMORY, dest_offset, context, $segment, offset, size, %%after, kexit_info)
%jump(memcpy)
%%after: