Lucene search

K
code423n4Code4renaCODE423N4:2023-04-EIGENLAYER-FINDINGS-ISSUES-452
HistoryMay 04, 2023 - 12:00 a.m.

StrategyBase.underlyingToShares() cannot be overridden to intended mutability

2023-05-0400:00:00
Code4rena
github.com
2
implementation
strategybase
state modifications
contract inheritance

Lines of code

Vulnerability details

Impact

An implementation of underlyingToShares(), as inherited from StrategyBase.sol, cannot (contrary to intentions) make state modifications. This implies that StrategyBase.sol may become useless as a base contract to inherit from.

Proof of Concept

StrategyBase.sol โ€œis designed to be inherited by more complex strategies, which can then override its functions as necessaryโ€.
Its function underlyingToShares() is explicitly intended to allow for an implementation that โ€œmay make state modificationsโ€:

/**
* @notice Used to convert an amount of underlying tokens to the equivalent amount of shares in this strategy.
* @notice In contrast to underlyingToSharesView, this function **may** make state modifications
* @param amountUnderlying is the amount of underlyingToken to calculate its conversion into strategy shares
* @dev Implementation for these functions in particular may vary signifcantly for different strategies
*/
function underlyingToShares(uint256 amountUnderlying) external view virtual returns (uint256) {
    return underlyingToSharesView(amountUnderlying);
}

However, it is declared as view. Overriding functions can only restrict state mutability, never expand it. This means that any overriding function can only be view or pure, and therefore cannot make state changes.
Note that IStrategy correctly declares underlyingToShares() as nonpayable.

There is a similar issue with sharesToUnderlying(), and probably also with explanation(), both reported separately.

Recommended Mitigation Steps

Declare underlyingToShares() as the default nonpayable.

- function underlyingToShares(uint256 amountUnderlying) external view virtual returns (uint256) {
+ function underlyingToShares(uint256 amountUnderlying) external virtual returns (uint256) {

Assessed type

Context


The text was updated successfully, but these errors were encountered:

All reactions