Underconstrained hints in initailize_jumpdests, risk of manipulation of valid_jumpdests #26
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-67
grade-a
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_primary
AI based primary recommendation
🤖_27_group
AI based duplicate group recommendation
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/utils/utils.cairo#L922-L925
Vulnerability details
Proof of Concept
In a deployment tx,
initialize_jumpdests
will be called in interpreter::execute flow. It loops through the bytecode byte by byte and writes to jumpdests dictionary. (dict_write{dict_ptr=valid_jumpdests}(i, TRUE)
)To determine whether to exit the loop, it compares the iterator(byte index)
next_i
and bytecode length (bytecode_len
). It only exits the loop whennext_i
>=bytecode_len
. (0<=tempvar a = next_i - bytecode_len
< range_check_builtin.bound)The issue is the checking of
next_i - bytecode_len
is done in hint, but the hint resultmemory[ap]
is never checked to be correct. As a result, a malicious prover can assign any value ascontinue_loop
. For example, a malicious prover assigns 1 tocontinue_loop
after the next_i equals bytecode_len, which keeps the loop running longer while increasingnext_i
to read unsafe memory location afterbytecode
.(https://github.com/kkrt-labs/kakarot/blob/7411a5520e8a00be6f5243a50c160e66ad285563/src/utils/utils.cairo#L922-L925)
As seen above, in the
end
section, it verifies loop termination by checking whether bytecode_len <= i. This is also insufficient considering a malicious prover can extend the loop resulting bytecode_len < i and reading unsafe memory regions while still passing the check.POC:
Recommended Mitigation Steps
Consider adding check after the hint to ensure when continue_loop !=0 , (bytecode_len - 1 - next_i) is in range and when continue_loop == 0, (next_i - bytecode_len) is in range.
Assessed type
Other
The text was updated successfully, but these errors were encountered: