Skip to content
Business logic Audit finding Intermediate

Adapters revert when 0 shares are minted, making it impossible to deposit under certain conditions

The `_stake()` function in several adapters reverts when the targeted protocol mints zero shares, which can happen when the stake amount is small but non-zero. This prevents users from depositing funds under those conditions.

no Follow with zzykxx

Originally disclosed on Sherlock

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

Found by

no, zzykxx

Summary

Users are unable to deposit into an Adapter in some situations due to the _stake() function reverting.

Vulnerability Detail

The function _stake() in all of the in-scope adapters reverts if the amounts of minted shares of the targeted protocol is 0.

Funds are deposited in an adapter via the prefundedDeposit() function, which internally calls _stake() by passing the amount to stake in the protocol, stakeAmount:

Solidity
    ...SNIP...
    uint256 stakeAmount;
    unchecked {
        stakeAmount = availableEth + queueEthCache - targetBufferEth;
    }

    if (stakeAmount > availableEth) {
@>      stakeAmount = availableEth;
    }

    ...SNIP...
@>   stakeAmount = _stake(stakeAmount); // stake amount can be 0
    ...SNIP...

The amount to stake in the protocol, stakeAmount, can be restricted to availableEth. If availableEth/stakeAmount is low enough (but not 0) for the targeted protocol to mint 0 shares all of the adapters in-scope will revert by throwing an InvariantViolation(); error:

Impact

Users won't not be able to deposit funds if the stakeAmount is not enough to mint at least 1 share. The protocol genrally allows users to deposit both when stakeAmount is 0 and when the maximum deposit cap has been reached on the target protocol, which is incosistent with the behaviour outlined in this report.

A similar finding was disclosed in the previous Napier contest.

Code Snippet

Tool used

Manual Review

Recommendation

The function _stake() in the adapters should ensure that the shares minted are at least 1 before actually depositing the funds. This might introduce a lot of overhead for the calculations, an alternative solution is to have the _stake() functions always return 0 if stakeAmount is lower than a certain (small) threshold:

Solidity
function _stake(uint256 stakeAmount) internal override returns (uint256) {
    if (stakeAmount < 1e6) return 0;
    ...SNIP...
}

If going for a different fix please note that the EETHAdapter will actually revert on the internal call to deposit() if 0 shares are minted, instead of in the adapter.

Discussion

sherlock-admin2

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

zzykxx

An edge case was found in the proposed fix. _stake() could still revert if RSETH_DEPOSIT_POOL.minAmountToDeposit() returns 0. This has been fixed in a new PR: https://github.com/napierfi/napier-uups-adapters/pull/23

sherlock-admin2

The Lead Senior Watson signed off on the fix.

The original report as published on Sherlock, by no. 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

Impact

Users may be unable to deposit funds if the stake amount is too small to mint at least one share, which is inconsistent with the protocol's general allowance of zero-stake deposits and deposits at the cap.

What the attacker needed

StakeAmount small enough to mint 0 shares

The fix

The `_stake()` functions should ensure that at least one share is minted before depositing, or return zero if the stake amount is below a small threshold; the issue was fixed in subsequent pull requests.

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.

When you deposit money into a savings protocol, you receive shares representing your deposit. If the amount you deposit is very small, the protocol might round down and give you zero shares. In this case, the adapter contract treats zero shares as an error and cancels the whole deposit, so you cannot deposit small amounts.

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.