Attackathon _ Fuel Network 32696 - [Smart Contract - High] incorrect setting of non_negative value i
Submitted on Sat Jun 29 2024 20:22:34 GMT-0400 (Atlantic Standard Time) by @zeroK for Attackathon | Fuel Network
Report ID: #32696
Report type: Smart Contract
Report severity: High
Target: https://github.com/FuelLabs/sway-libs/tree/0f47d33d6e5da25f782fc117d4be15b7b12d291b
Impacts:
Contract fails to deliver promised returns, but doesn't lose value
Description
Brief/Intro
the function ceil in all of IFP libs used to return smallest number that is equal or greater than the self.underlying
, this function have crucial rule as it will be used in many Defi protocols that will built on fuel, however there is incorrect set of non_negative
value when this function called and the else
case run, as there is possibility of setting the non_negative
value to true when its false in specific case if ceil == UFP64::from(1)
but this value will not be set in the self when its returned and used by the third party or the round
function itself when calling the ceil function.
Vulnerability Details
let's take a look at the ceil
function in the IFP128:
as shown above when the ceil value we get is equal to UFP64::from(1)
then the non negative should be true, but in the Self we set the non negative value to the input that we use as self
which is false in our case, this can lead to critical issue for defi protocols when they use ceil function or round function which returns ceil in specific situation:
we believe this can be high issue but it can be downgraded to medium as its logical issue if we saw it as issue in lib but critical issue if we think about how can cause damage to protocols directly. (we set this as medium and leave the judging to immunefi team for upgrading the impact level)
Impact Details
incorrect set of non_negative value in ceil can cause trouble when its called/used
References
while there is possibility of non_negative value to get updated then the Self.non_negative should be set to the let non_negative
variable
Proof of concept
Proof of Concept
run this test right below the ceil function in IFP128.sw by runing forc test
Last updated