-
Notifications
You must be signed in to change notification settings - Fork 843
Fix to handle successful run with Uint64 overflow for multiple opcodes #1317
Fix to handle successful run with Uint64 overflow for multiple opcodes #1317
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass review, so far I've reviewed:
- common_gadget
- circuits: jumpi, extcodecopy, codecopy, error_invalid_jump
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review completed: In general everything looks correct! My only notes are about a redundant constraint, and a few IsZero gadget that seem to be unused. I think they should be used: the Lt check is only correct if the value uses the specified number of bytes, and that's what the IsZero gadget inside of WordByteRangeGadget can check. So probably the logic should be something like:
let src_addr = select::expr(
code_offset.overflow(),
code_size.expr(),
select::expr(
code_offset.lt_cap(),
code_offset.valid_value(),
code_size.expr()),
);
Thanks for review. I will try to resolve merge conflicts and review comments. Thanks. |
…-cases-with-overflow-input-params
This reverts commit c17ba9d.
LGTM Amazing work @silathdiir Also I see that this PR also activates e.g.
|
from_bytes::expr(&self.original.cells[..VALID_BYTES]) | ||
} | ||
|
||
pub(crate) fn within_range(&self) -> Expression<F> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: maybe is more readable if we name not_overflow()
instead valid_range()
, overflow/not_overflow is more dualistic over the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename within_range
to not_overflow
in commit 11f8eb3.
for (i, byte) in calldata_bytes.iter_mut().enumerate() { | ||
if call.is_root { | ||
// Fetch from tx call data. | ||
if src_addr.checked_add(i as u64).unwrap() < tx.call_data_length as u64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better just adding instead using checked_add with an unwrap later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace check_add
and unwrap
with just adding in commit 594553d.
} | ||
} else { | ||
// Fetch from memory. | ||
if src_addr.checked_add(i as u64).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace check_add and unwrap with just adding in commit 594553d.
…-cases-with-overflow-input-params
…-cases-with-overflow-input-params
…` function (only leave it in `construct`).
… is Uint64 overflow` in `jumpi`.
Seems that
|
It may be caused by |
Head branch was pushed to by a user without write access
Description
Fix successful run cases with Uint64 overflow for multiple opcodes.
Add
WordByteRangeGadget
to constrain if Word is within the specified byte range.Add
WordByteCapGadget
to constrain if Word is within the specified byte range (implemented by WordByteRangeGadget) and less than a maximum cap (used to replace a WordByteRangeGadget and LtGadget).Fix bus-mapping and zkevm-circuits to handle overflow cases. And add unit-tests for these cases.
TODO: will try to handle memory offset overflow with zero length in another PR (try to rebase for this local PR scroll-tech#393) and related issue #1301.
Rationale
Reference detailed code in
go-etherum
as:. BLOCKHASH
. CALLDATALOAD
. CALLDATACOPY
. CODECOPY
. EXTCODECOPY
. JUMPI
Issue Link
Close #1276
Type of change
How Has This Been Tested?
Add unit-test cases for Uint64 overflow values.