wise-foundation / lending-audit

5 stars 4 forks source link

[OHR-02M] Incorrect Assessment of Latest Update Delta #167

Open vm06007 opened 1 year ago

vm06007 commented 1 year ago

OHR-02M: Incorrect Assessment of Latest Update Delta

Type Severity Location
Logical Fault OracleHelper.sol:L68-L70

Description:

The OracleHelper::_chainLinkIsDead function will incorrectly calculate the time elapsed between the latest update and the block.timestamp in the case that the update occurred at the time the OracleHelper::_chainLinkIsDead function was invoked as block.timestamp would be equal to upd.

Impact:

All transactions submitted at the same block the latest Chainlink round was submitted will fail due to an incorrect dead Chainlink error.

Example:

/**
 * @dev Check if chainLink feed was
 * updated within expected timeFrame
 * for single {_tokenAddress}.
 */
function _chainLinkIsDead(
    address _tokenAddress
)
    internal
    view
    returns (bool)
{
    uint256 upd = latestRoundData(
        _tokenAddress
    );

    upd = block.timestamp > upd
        ? block.timestamp - upd
        : block.timestamp;

    return upd > heartBeat[_tokenAddress];
}

Recommendation:

We advise the code to adjust its ternary operator's conditional to be made inclusive, ensuring that an upd value of 0 is calculated when block.timestamp is equal to the upd time.