Skip to content
Business logic Audit finding Intermediate

Kelp adapter won't allow users to deposit if `getAssetCurrentLimit` returns `0`

The Kelp adapter's stake function caps the deposit amount by the protocol's current limit, but if that limit is zero, the capped amount becomes zero and subsequent calls revert. This prevents users from depositing into the adapter when the limit is reached.

merlin Follow with zzykxx

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-05-napier-update-judging/issues/75

Found by

merlin, zzykxx

Summary

Users will be unable to deposit into the Kelp adapter when

Vulnerability Detail

The function _stake() in the RsETHAdapter::_stake() checks the current limits on ETH deposits of the Kelp protocol before depositing:

Solidity
function _stake(uint256 stakeAmount) internal override returns (uint256) {
    if (stakeAmount == 0) return 0;

    uint256 stakeLimit = RSETH_DEPOSIT_POOL.getAssetCurrentLimit(Constants.ETH);
    if (stakeAmount > stakeLimit) {
        stakeAmount = stakeLimit;
    }
    ...SNIP..
}

The returned value of the call to RSETH_DEPOSIT_POOL.getAssetCurrentLimit(Constants.ETH) is assigned to the variable stakeAmount. This is the implementation of the called function, wich can be found here:

Solidity
function getAssetCurrentLimit(address asset) public view override returns (uint256) {
    uint256 totalAssetDeposits = getTotalAssetDeposits(asset);
    if (totalAssetDeposits > lrtConfig.depositLimitByAsset(asset)) {
        return 0;
    }

    return lrtConfig.depositLimitByAsset(asset) - totalAssetDeposits;
}

As it can be seen it's possible for the function to return 0, which will make the subsequent calls in the _stake() function revert. This is inconsistent with the general behaviour of the software, which always returns 0 when stakeAmount is 0.

Impact

Users won't not be able to deposit funds in the RsETHAdapter because RsETHAdapter::_stake() will revert.

Code Snippet

Tool used

Manual Review

Recommendation

In RsETHAdapter::_stake() move the if (stakeAmount == 0) return 0; line after the assets limits have been queried:

Solidity
function _stake(uint256 stakeAmount) internal override returns (uint256) {
    // Check LRTDepositPool stake limit
    uint256 stakeLimit = RSETH_DEPOSIT_POOL.getAssetCurrentLimit(Constants.ETH);
    if (stakeAmount > stakeLimit) {
        // Cap stake amount
        stakeAmount = stakeLimit;
    }

@>  if (stakeAmount == 0) return 0;

    // Check LRTDepositPool minAmountToDeposit
    if (stakeAmount <= RSETH_DEPOSIT_POOL.minAmountToDeposit()) return 0;
    // Check paused of LRTDepositPool
    if (RSETH_DEPOSIT_POOL.paused()) revert ProtocolPaused();

    // Interact
    IWETH9(Constants.WETH).withdraw(stakeAmount);
    uint256 _rsETHAmt = RSETH.balanceOf(address(this));
    RSETH_DEPOSIT_POOL.depositETH{value: stakeAmount}(0, REFERRAL_ID);
    _rsETHAmt = RSETH.balanceOf(address(this)) - _rsETHAmt;

    if (_rsETHAmt == 0) revert InvariantViolation();

    return stakeAmount;
}

RsETHAdapter.sol#L77

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/napierfi/napier-uups-adapters/pull/13

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by merlin. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The zero-check on stakeAmount occurs before the stake limit is applied, so a zero limit leads to a zero stakeAmount that is not handled and causes a revert.

Impact

Users cannot deposit funds into the RsETHAdapter because the stake function reverts when the limit is zero.

What the attacker needed

Kelp deposit limit reached

The fix

The zero-check should be moved after the stake limit is applied, so that a zero stakeAmount returns zero instead of reverting.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract bug where a deposit function fails when a limit is reached. The code checks a limit and sets the deposit amount to that limit, but if the limit is zero, it tries to deposit zero, which causes an error. Users cannot deposit until the limit is increased.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Napier Finance - LST/LRT Integrations

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.