Attackathon _ Fuel Network 33303 - [Smart Contract - Medium] Incorrect sign change
Last updated
Was this helpful?
Last updated
Was this helpful?
Submitted on Wed Jul 17 2024 10:37:38 GMT-0400 (Atlantic Standard Time) by @shadowHunter for
Report ID: #33303
Report type: Smart Contract
Report severity: Medium
Target: https://github.com/FuelLabs/sway-libs/tree/0f47d33d6e5da25f782fc117d4be15b7b12d291b
Impacts:
Compiler bug
This is a compiler bug since resulting value 0 sign is changed to negative. This library are meant to be used by third party apps as mentioned by Fuel team in github page
It seems that if you are adding same number with different sign then resulting 0 sign is changed which is not correct
If add
is called using number 3 and -3 then result should be 0 with positive sign
But since 3>3 is false so condition move to else condition which changes the sign even though it was not required
Ideally the condition should be if self.underlying >= other.underlying
Result will be with incorrect sign
https://github.com/FuelLabs/sway-libs/blob/2a869c583d2ab9fbe8de17a3301d928b224062c7/libs/src/fixed_point/ifp64.sw#L239C13-L244C14