Attackathon _ Fuel Network 32438 - [Smart Contract - Low] Unhandled Bailout During AbstractInstructi
Submitted on Fri Jun 21 2024 18:21:27 GMT-0400 (Atlantic Standard Time) by @anatomist for Attackathon | Fuel Network
Report ID: #32438
Report type: Smart Contract
Report severity: Low
Target: https://github.com/FuelLabs/sway/tree/7b56ec734d4a4fda550313d448f7f20dba818b59
Impacts:
Incorrect sway optimization leading to incorrect bytecode
Description
Brief/Intro
const_indexing_aggregates_function()
process VirtualOp::LW
without handling the case if the offset in addr_reg
is not aligned to 8, resulting in the old constant being used and leading to incorrect program behavior.
Vulnerability Details
While processing a VirtualOp::LW
with non-aligned address offset, const_indexing_aggregates_function()
does not clear register information in reg_contents
and setup a new definition with record_new_def()
. This means the old state of the register stored in reg_contents
will still be used, causing incorrect value tracking after the LW
instruction. The incorrect tracking may then cause incorrect immediate replacement in other instructions.
Impact Details
As usual, it is hard to come up with a precise impact estimation of incorrect code generation because it depends on what code the user writes. The best case scenario would be contracts that run into those bugs getting bricked, and the worst case scenario would be that incorrect program behaviors lead to loss of funds.
References
https://github.com/FuelLabs/sway/blob/7b56ec734d4a4fda550313d448f7f20dba818b59/sway-core/src/asm_generation/fuel/optimizations.rs#L155
Proof of concept
Proof of Concept
This test would fail because addi a a i15
incorrectly uses the reg values before lw a a i0
Last updated