Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QA Report #247

Open
code423n4 opened this issue Jun 19, 2022 · 2 comments
Open

QA Report #247

code423n4 opened this issue Jun 19, 2022 · 2 comments
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

code423n4 commented Jun 19, 2022

ChainLink price data could be stale

Lines of code

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L122-L137

Vulnerability details

Impact

At ConnextPriceOracle.sol, getPriceFromChainlink() function invokes aggregator.latestRoundData(). However, there are no checks if the return value indicates stale or subzero data. This could lead to wrong prices.

Proof of Concept

  function getPriceFromChainlink(address _tokenAddress) public view returns (uint256) {
    AggregatorV3Interface aggregator = aggregators[_tokenAddress];
    if (address(aggregator) != address(0)) {
      (, int256 answer, , , ) = aggregator.latestRoundData();


      // It's fine for price to be 0. We have two price feeds.
      if (answer == 0) {
        return 0;
      }


      // Extend the decimals to 1e18.
      uint256 retVal = uint256(answer);
      uint256 price = retVal.mul(10**(18 - uint256(aggregator.decimals())));


      return price;
    }

https://github.com/code-423n4/2022-06-connext/blob/b4532655071566b33c41eac46e75be29b4a381ed/contracts/contracts/core/connext/helpers/ConnextPriceOracle.sol#L122-L137

According to the Chainlink documentation:
“A timestamp with zero value means the round is not complete and should not be used.”
“if answeredInRound < roundId could indicate stale data.”

Another reference

See example of mitigation here: https://github.com/cryptexfinance/contracts/blob/master/contracts/oracles/ChainlinkOracle.sol#L58-L65

Tools Used

Manual review

Recommended Mitigation Steps

Adding missing the checks to validate the data is not stale

(roundId, rawPrice,, updatedAt, answeredInRound) = aggregator.latestRoundData();
require(rawPrice > 0, "Chainlink price <= 0");
require(updateTime != 0, "Incomplete round");
require(answeredInRound >= roundId, "Stale price");
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Jun 19, 2022
code423n4 added a commit that referenced this issue Jun 19, 2022
@ecmendenhall
Copy link

Duplicate of #190

@jakekidd jakekidd added the duplicate This issue or pull request already exists label Jun 24, 2022
@jakekidd
Copy link
Collaborator

closed as dup of #190

@0xleastwood 0xleastwood added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Aug 12, 2022
@0xleastwood 0xleastwood changed the title ChainLink price data could be stale QA Report Aug 12, 2022
@0xleastwood 0xleastwood reopened this Aug 12, 2022
@0xleastwood 0xleastwood removed the duplicate This issue or pull request already exists label Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

4 participants