Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

nobody2018 - Liquidation will fail in certain scenario #49

Closed
sherlock-admin opened this issue Apr 30, 2023 · 0 comments
Closed

nobody2018 - Liquidation will fail in certain scenario #49

sherlock-admin opened this issue Apr 30, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Apr 30, 2023

nobody2018

medium

Liquidation will fail in certain scenario

Summary

When an external protocol adds a new reward token, oracle does not support getting the price of this token. This will cause  BlueBerryBank#getPositionValue to revert, causing all transactions that call this function to fail.

Vulnerability Detail

BlueBerryBank#getPositionValue is used to calculate the value of a certain position, including collateral token and reward tokens of external protocols. It uses the IERC20Wrapper#pendingRewards function to get the reward token array of the external protocol, and then get  the price of each reward token by CoreOracle#getTokenValue.

function getPositionValue(
        uint256 positionId
    ) public view override returns (uint256 positionValue) {
        ...
        } else {
            ...

            uint rewardsValue;
->          (address[] memory tokens, uint256[] memory rewards) = IERC20Wrapper(
                pos.collToken
            ).pendingRewards(pos.collId, pos.collateralSize);
            for (uint256 i; i < tokens.length; i++) {
->              rewardsValue += oracle.getTokenValue(tokens[i], rewards[i]);
            }

            return collValue + rewardsValue;
        }
    }

CoreOracle#getTokenValue internally calls the _getPrice function, which checks whether the value of routes[token] is non-zero.

function _getPrice(
        address token
    ) internal view whenNotPaused returns (uint256) {
        address route = routes[token];
->      if (route == address(0)) revert Errors.NO_ORACLE_ROUTE(token);
        uint256 px = IBaseOracle(route).getPrice(token);
        if (px == 0) revert Errors.PRICE_FAILED(token);
        return px;
    }

Obviously, a new reward token has no route. Eventually BlueBerryBank#getPositionValue will revert. Therefore, functions that call this function will revert. Here I give the flow of the two functions:

  • BlueBerryBank#liquidate->isLiquidatable->getPositionRisk->getPositionValue->oracle.getTokenValue
  • BlueBerryBank#execute->isLiquidatable->getPositionRisk->getPositionValue->oracle.getTokenValue

Impact

Both BlueBerryBank#liquid and BlueBerryBank#execute will be affected. Due to the importance of liquidation time, untimely liquidation can result in financial losses for both parties involved in the liquidation.

Code Snippet

https://github.com/sherlock-audit/2023-04-blueberry/blob/main/blueberry-core/contracts/BlueBerryBank.sol#L408-L413

https://github.com/sherlock-audit/2023-04-blueberry/blob/main/blueberry-core/contracts/oracle/CoreOracle.sol#L74

Tool used

Manual Review

Recommendation

--- a/blueberry-core/contracts/BlueBerryBank.sol
+++ b/blueberry-core/contracts/BlueBerryBank.sol
@@ -409,7 +409,9 @@ contract BlueBerryBank is
                 pos.collToken
             ).pendingRewards(pos.collId, pos.collateralSize);
             for (uint256 i; i < tokens.length; i++) {
-                rewardsValue += oracle.getTokenValue(tokens[i], rewards[i]);
+                if (oracle.isTokenSupported(tokens[i])) {
+                    rewardsValue += oracle.getTokenValue(tokens[i], rewards[i]);
+                }
             }

Duplicate of #115

@github-actions github-actions bot closed this as completed May 3, 2023
@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels May 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label May 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant