decode_legacy_tx
allows validation of signatures with chain_id that are larger than felt, and overflows
#69
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-04
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
selected for report
This submission will be included/highlighted in the audit report
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/eth_transaction.cairo#L72
Vulnerability details
Impact
In decode_legacy_tx, data_len for chain_id is not constrained to be <31, which allows validation of signatures with chain_id that are larger than felt, and overflows
Proof of Concept
chain_id is gotten from items[6].data via the bytes_to_felt helper function.
Looking at bytes_to_felt function, we will observe that the return value will overflow if len>31, because current would have been shifted 2^(8*32) times, which overflows the max felt value of 2^252:
Since items[6].data_len is not constrained to be <=31, absurd values of chain_id(containing >31 data_len) can be passed, which would overflow, and pass the signature validation
Recommended Mitigation Steps
assert that items[6].data_len<=31:
Assessed type
Under/Overflow
The text was updated successfully, but these errors were encountered: