Attackathon _ Fuel Network 33170 - [Smart Contract - Medium] UFP Exp In Sway-lib Logic Vulnerability
Submitted on Sat Jul 13 2024 10:02:26 GMT-0400 (Atlantic Standard Time) by @Minato7namikazi for Attackathon | Fuel Network
Report ID: #33170
Report type: Smart Contract
Report severity: Medium
Target: https://github.com/FuelLabs/sway-libs/tree/0f47d33d6e5da25f782fc117d4be15b7b12d291b
Impacts:
Permanent freezing of funds
Description
Brief/Intro
During my audit of the UFP (unsigned fixed-point number) implementations in the sway-libs , this logic vulnerability were identified. This could lead to incorrect calculations in any smart contracts or scripts relying on this function and cause massive losses.
Vulnerability Details
The function calculates _res_minus_1
correctly .. but then it ignores this calculation and simply returns one
. This means the exponential function will always return 1, regardless of the input.
_res_minus_1
correctly .. but then it ignores this calculation and simply returns one
. This means the exponential function will always return 1, regardless of the input.The impact is Loss of funds because of
Incorrect Financial Calculations : using the vulnerable exponential function for compound interest, option pricing, or yield calculations. With this bug, all such calculations would return 1, regardless of the input.
Some token distribution models or staking rewards systems use exponential decay or growth. This bug would make such systems non-functional, potentially: Distributing incorrect amounts of tokens
Recommendation
we should use the calculated result like
Now it's calculates the exponential function using a Taylor series approximation and should return the correct result. the function now adds 1 to the calculated
res_minus_1
to get the final result, as the original calculation was for (e^x - 1).
Proof of concept
Add this PoC test in the end of the ufp128.sw
Last updated