Boost _ Folks Finance 33643 - [Smart Contract - Low] PriceFeed from PythNode will always revert for some pools
Submitted on Thu Jul 25 2024 12:16:44 GMT-0400 (Atlantic Standard Time) by @arno for Boost | Folks Finance
Report ID: #33643
Report type: Smart Contract
Report severity: Low
Target: https://testnet.snowtrace.io/address/0xA758c321DF6Cd949A8E074B22362a4366DB1b725
Impacts:
Temporary freezing of funds of at least 24h
Description
Brief/Intro
The PythNode
library's process
function causes transactions to revert when processing price feeds for certain tokens with pythData.expo > -18
. This is due to the incorrect handling of the price precision factor, leading to potential disruptions in operations such as deposits, borrowings, and liquidations within the protocol.
Vulnerability Details
Description:
The OracleManager
contract is used to manage price feeds from different oracles. The setNodeId
function in the OracleManager
contract is used to bind a pool to a node, facilitating price feeds.
setNodeId
Function:
setNodeId
Function:Nodes are registered using the registerNode
function. These nodes facilitate price feeds by first registering nodes using the registerNode
function from NodeManager
contract.
registerNode
Function:
registerNode
Function:The nodeType
can be CHAINLINK
, PYTH
, or EXTERNAL
.
When functions like deposit
, borrow
, or liquidate
are called in the protocol, they use the processPriceFeed
function from the OracleManager
contract.
processPriceFeed
Function:
processPriceFeed
Function:To fetch prices of the assets, when nodeType
is PYTH
, the following library's process
function is used.
process
Function in PythNode
Library:
process
Function in PythNode
Library:Bug:
The bug arises in the process
function of the PythNode
library when it attempts to standardize the price to 18 decimal places. The issue lies in how the precision factor is calculated and subsequently converted to uint256
. If pythData.expo
is greater than -18, the precision factor (PRECISION + pythData.expo
) becomes negative, causing the conversion to uint256
to revert because toUint256()
reverts when the input is less than 0 to avoid overflow. This causes a denial of service (DOS) in two ways:
When a new pool is initiated for a token with an exponent > -18, deposits will be halted for this pool if the Pyth node is used.
If a node is updated for a particular pool using the
setNodeId
function from the OracleManager contract and the token has an exponent > -18, all transactions that include price feeds will fail, including deposits for repayment or collateral deposits to avoid liquidation.
Impact Details
Transaction Failures: Any transaction that relies on the
process
function for price feeds, such as deposits, borrowings, and liquidations, will revert if the price feed’s exponent is greater than -18. This can halt essential protocol operations and cause significant disruptions.Financial Loss: If critical operations fail due to this bug, users may experience financial losses, especially during volatile market conditions where timely transactions are crucial.
References
https://github.com/Folks-Finance/folks-finance-xchain-contracts/blob/fb92deccd27359ea4f0cf0bc41394c86448c7abb/contracts/oracle/nodes/PythNode.sol#L36
Proof of concept
Last updated