Mitigation Audit _ Folks Finance 34942 - [Smart Contract - Insight] In function function getTwapPric
Submitted on Sun Sep 01 2024 16:10:07 GMT-0400 (Atlantic Standard Time) by @Paludo0x for Mitigation Audit | Folks Finance
Report ID: #34942
Report type: Smart Contract
Report severity: Insight
Target: https://github.com/Folks-Finance/folks-finance-xchain-contracts/pull/9
Impacts:
Contract fails to deliver promised returns, but doesn't lose value
Description
Vulnerability Details
In ChainlinkNode::getTwapPrice()
there's a while (latestRoundId > 0)
iteration. Inside the try / catch block there's the following check:
This check is useless and unnecessarily consumes gas because the termination condition of the while cycle is latestRoundId > 0
, therefore the break
from the while cycle will be done anyway when latestRoundId = 0
.
This is the relevant code
Impact Details
The impact is unecessary consuming of gas
Proof of concept
Proof of Concept
This test shall be run in remix. First you need to deploy the contract AlwaysRevert
and then deploy Test
using address of AlwaysRevert
.
The function getTwapPrice
is a simplified version of original version, while getTwapPrice_without_break
is without if statement.
Both reach the status where latestRoundId = 0
without issues.
Last updated