Attackathon _ Fuel Network 32548 - [Smart Contract - Low] Uncaught Integer Overflow During AbstractI
Submitted on Wed Jun 26 2024 06:02:05 GMT-0400 (Atlantic Standard Time) by @anatomist for Attackathon | Fuel Network
Report ID: #32548
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
multiplies Constants without checking whether the result overflows. This might incorrectly optimize away overflowing operations.
Vulnerability Details
const_indexing_aggregates_function()
constant folds the MUL
instruction if both operands are Constant values. However, it does not check whether the result overflows, and can incorrectly optimize overflowing multiplications.
Compilation of the code would replace the load with a direct read from hp
, where all the overflowing intermediate calculations on a
are constant folded away.
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/2cbc24dc2e4ecab1e2b65fb8542d4650e313db99/sway-core/src/asm_generation/fuel/optimizations.rs#L115
Proof of concept
Proof of Concept
This test would fail because the overflowing multiplications on a
is constant folded away and not included in the generated bytecode.
The PoC should be run with release build of forc
because rust debug build includes arithmetic overflow checks.
Last updated