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

Wrong liquidity checking lead to token being stuck #281

Closed
howlbot-integration bot opened this issue Jul 8, 2024 · 2 comments
Closed

Wrong liquidity checking lead to token being stuck #281

howlbot-integration bot opened this issue Jul 8, 2024 · 2 comments
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-218 edited-by-warden 🤖_10_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/CapsLibrary.sol#L67-#L71

Vulnerability details

Vulnerability details

Function validateVariablePoolHasEnoughLiquidity() is used to check if pool have enough token or not:

function validateVariablePoolHasEnoughLiquidity(State storage state, uint256 amount) public view {
    uint256 liquidity = state.data.underlyingBorrowToken.balanceOf(address(state.data.variablePool));  // <---
    if (liquidity < amount) {
        revert Errors.NOT_ENOUGH_BORROW_ATOKEN_LIQUIDITY(liquidity, amount);
    }
}

Notice that it use address state.data.variablePool, which have supply() function, that is Pool contract in aave docs:

function depositUnderlyingBorrowTokenToVariablePool(State storage state, address from, address to, uint256 amount)
    external
{
    state.data.underlyingBorrowToken.safeTransferFrom(from, address(this), amount);

    IAToken aToken =
        IAToken(state.data.variablePool.getReserveData(address(state.data.underlyingBorrowToken)).aTokenAddress);

    uint256 scaledBalanceBefore = aToken.scaledBalanceOf(address(this));

    state.data.underlyingBorrowToken.forceApprove(address(state.data.variablePool), amount);
    state.data.variablePool.supply(address(state.data.underlyingBorrowToken), amount, address(this), 0);  // <---

    uint256 scaledAmount = aToken.scaledBalanceOf(address(this)) - scaledBalanceBefore;

    state.data.borrowAToken.mintScaled(to, scaledAmount);
}

Look at aave's deposit workflow:

function supply(
    address asset,
    uint256 amount,
    address onBehalfOf,
    uint16 referralCode
) public virtual override {
    SupplyLogic.executeSupply(    // <----
        _reserves,
        _reservesList,
        _usersConfig[onBehalfOf],
        DataTypes.ExecuteSupplyParams({
            asset: asset,
            amount: amount,
            onBehalfOf: onBehalfOf,
            referralCode: referralCode
        })
    );
}

It call executeSupply() function in SupplyLogic library:

function executeSupply(
    mapping(address => DataTypes.ReserveData) storage reservesData,
    mapping(uint256 => address) storage reservesList,
    DataTypes.UserConfigurationMap storage userConfig,
    DataTypes.ExecuteSupplyParams memory params
) external {
    .  .  .  .  .  .  .  .  .
    ValidationLogic.validateSupply(reserveCache, reserve, params.amount);

    reserve.updateInterestRates(reserveCache, params.asset, params.amount, 0);

    IERC20(params.asset).safeTransferFrom(msg.sender, reserveCache.aTokenAddress, params.amount);  // <---
    .  .  .  .  .  .  .  .  .
}

It can be seen that token is transfered to reserveCache.aTokenAddress address, not stay in pool address, which lead to checking condition in validateVariablePoolHasEnoughLiquidity function wrong, token can be stuck due to wrong checking condition

Impact

As token stay in reserveCache.aTokenAddress address, which is AToken contract link, this wrong checking condition can lead to unintended revert, and user's token can be stuck inside protocol

Tools Used

Manual review

Recommended Mitigation Steps

Replace state.data.variablePool address to AToken's address.

Assessed type

Other

@howlbot-integration howlbot-integration bot added 3 (High Risk) Assets can be stolen/lost/compromised directly 🤖_10_group AI based duplicate group recommendation bug Something isn't working duplicate-218 edited-by-warden sufficient quality report This report is of sufficient quality labels Jul 8, 2024
howlbot-integration bot added a commit that referenced this issue Jul 8, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jul 11, 2024
@c4-judge
Copy link
Contributor

hansfriese changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-218 edited-by-warden 🤖_10_group AI based duplicate group recommendation satisfactory satisfies C4 submission criteria; eligible for awards sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

1 participant