Possible arbitrage from Chainlink price discrepancy
The KelpDAO protocol uses Chainlink price feeds with large deviation thresholds and heartbeats to value liquid staking tokens, which can create temporary price discrepancies. An attacker could deposit the relatively undervalued token to receive more rsETH than fair, then later redeem for profit, extracting value from other users.
m_Rassska Follow with SBSecurity, Aamir and 12 others
Originally disclosed on Code4rena
Submitted by m_Rassska, also found by SBSecurity, Aamir, d3e4, adriro, CatsSecurity, jayfromthe13th, Bauchibred, deth, 0xDING99YA, HChang26, almurhasan, PENGUN, anarcheuz, and circlelooper
Some theory needed
- Currently KelpDAO relies on the following chainlink price feeds in order to calculate rsETH/ETH exchange rate:
| Price Feed | Deviation | Heartbeat |
1 | rETH/ETH | 2% | 86400s |
2 | cbETH/ETH | 1% | 86400s |
3 | stETH/ETH | 0.5% | 86400s |
- As we can see, an acceptable deviation for rETH/ETH price feed is about
[-2% 2%], meaning that the nodes will not update an on-chain price, in case the boundaries are not reached within the 24h period. These deviations are significant enough to open an arbitrage opportunities which will impact an overall rsETH/ETH exchange rate badly. - For a further analysis we have to look at the current LSD market distribution, which is represented here:
| LSD | Staked ETH | Market Share | LRTDepositPool ratio |
1 | Lido | 8.95m | ~77.35% | ~88.17% |
2 | Rocket Pool | 1.01m | ~8.76% | ~9.95% |
3 | Coinbase | 190.549 | ~1.65% | ~1.88% |
- Where
LRTDepositPool ratiois an approximate ratio of deposited lsts based on the overall LSD market.
An example of profitable arbitrage
See original submission for full details.
Final words
Basically, price feeds don’t have to reach those extreme boundaries in order to profit from it. In theory presented above we were able to get +2.3% profit, which is significant in case there is a huge liquidity supplied. The combination of deviations might be absolutely random, since it operates in set of rational numbers. But it will constantly open a small [+1%; +1.5%] arbitrage opportunities to be exploited.
Proof on Concept
-
To reproduce the case described above, slightly change:
-
LRTOracleMock:-
contract LRTOracleMock { uint256 public price; constructor(uint256 _price) { price = _price; } function getAssetPrice(address) external view returns (uint256) { return price; } function submitNewAssetPrice(uint256 _newPrice) external { price = _newPrice; } }
-
-
setUp():-
contract LRTDepositPoolTest is BaseTest, RSETHTest { LRTDepositPool public lrtDepositPool; 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)); // initialize RSETH. LRTCOnfig is already initialized in RSETHTest rseth.initialize(address(admin), address(lrtConfig)); vm.startPrank(admin); // add rsETH to LRT config lrtConfig.setRSETH(address(rseth)); // add oracle to LRT config lrtConfig.setContract(LRTConstants.LRT_ORACLE, address(new LRTOracle())); lrtConfig.setContract(LRTConstants.LRT_DEPOSIT_POOL, address(lrtDepositPool)); LRTOracle(lrtConfig.getContract(LRTConstants.LRT_ORACLE)).initialize(address(lrtConfig)); lrtDepositPool.initialize(address(lrtConfig)); // add minter role for rseth to lrtDepositPool rseth.grantRole(rseth.MINTER_ROLE(), address(lrtDepositPool)); } }
-
-
test_DepositAsset():-
function test_DepositAsset() external { address rETHPriceOracle = address(new LRTOracleMock(1.09149e18)); address stETHPriceOracle = address(new LRTOracleMock(0.99891e18)); address cbETHPriceOracle = address(new LRTOracleMock(1.05407e18)); LRTOracle(lrtConfig.getContract(LRTConstants.LRT_ORACLE)).updatePriceOracleFor(address(rETH), rETHPriceOracle); LRTOracle(lrtConfig.getContract(LRTConstants.LRT_ORACLE)).updatePriceOracleFor(address(stETH), stETHPriceOracle); LRTOracle(lrtConfig.getContract(LRTConstants.LRT_ORACLE)).updatePriceOracleFor(address(cbETH), cbETHPriceOracle); console.log("rETH/ETH exchange rate after", LRTOracleMock(rETHPriceOracle).getAssetPrice(address(0))); console.log("stETH/ETH exchange rate after", LRTOracleMock(stETHPriceOracle).getAssetPrice(address(0))); console.log("cbETH/ETH exchange rate after", LRTOracleMock(cbETHPriceOracle).getAssetPrice(address(0))); vm.startPrank(alice); // alice provides huge amount of liquidity to the pool rETH.approve(address(lrtDepositPool), 9950 ether); lrtDepositPool.depositAsset(rETHAddress, 9950 ether); stETH.approve(address(lrtDepositPool), 88170 ether); lrtDepositPool.depositAsset(address(stETH), 88170 ether); cbETH.approve(address(lrtDepositPool), 1880 ether); lrtDepositPool.depositAsset(address(cbETH), 1880 ether); vm.stopPrank(); vm.startPrank(carol); // carol deposits, when the price feeds return answer pretty close to a spot price uint256 carolBalanceBefore = rseth.balanceOf(address(carol)); rETH.approve(address(lrtDepositPool), 100 ether); lrtDepositPool.depositAsset(address(rETH), 100 ether); uint256 carolBalanceAfter = rseth.balanceOf(address(carol)); vm.stopPrank(); uint256 rETHNewPrice = uint256(LRTOracleMock(rETHPriceOracle).getAssetPrice(address(0))) * 102 / 100; // +2% uint256 stETHNewPrice = uint256(LRTOracleMock(stETHPriceOracle).getAssetPrice(address(0))) * 995 / 1000; // -0.5% uint256 cbETHNewPrice = uint256(LRTOracleMock(cbETHPriceOracle).getAssetPrice(address(0))) * 99 / 100; // -1% LRTOracleMock(rETHPriceOracle).submitNewAssetPrice(rETHNewPrice); LRTOracleMock(stETHPriceOracle).submitNewAssetPrice(stETHNewPrice); LRTOracleMock(cbETHPriceOracle).submitNewAssetPrice(cbETHNewPrice); console.log("rETH/ETH exchange rate after", LRTOracleMock(rETHPriceOracle).getAssetPrice(address(0))); console.log("stETH/ETH exchange rate after", LRTOracleMock(stETHPriceOracle).getAssetPrice(address(0))); console.log("cbETH/ETH exchange rate after", LRTOracleMock(cbETHPriceOracle).getAssetPrice(address(0))); vm.startPrank(bob); // bob balance of rsETH before deposit uint256 bobBalanceBefore = rseth.balanceOf(address(bob)); rETH.approve(address(lrtDepositPool), 100 ether); lrtDepositPool.depositAsset(address(rETH), 100 ether); uint256 bobBalanceAfter = rseth.balanceOf(address(bob)); vm.stopPrank(); assertEq(bobBalanceBefore, carolBalanceBefore, "the balances are not the same"); assertGt(bobBalanceAfter, carolBalanceAfter * 102 / 100, "some random shit happened"); assertLt(bobBalanceAfter, carolBalanceAfter * 103 / 100, "some random shittttt happened"); }
-
-
Recommended Mitigation Steps
Short term:
- N/A
Long term:
- I was thinking about utilizing multiple price oracles, which could potentially close any profitable opportunities, but the gas overhead and overall complexity grows rapidly. Unfortunately, I don’t have anything robust to offer by now, but open to discuss about it.
Assessed type
Math
gus (Kelp) disputed and commented:
We appreciate the explanation at length you have here. We see the arbitrage as a feature rather than a bug in the system. The past 2 year data on the price discrepancy assures us that this is a minor vector that will not impact deposits or withdraws significantly. Moreover, the fact that minters earn nominally more and withdrawals earn nominally less balances the system. We also want to call out that price arbitrage is not a unique problem to our design. It is virtually present across every staking protocol and we encourage healthy arbitrage opportunity here.
This is valid. Depositors will be able to deposit the minimally-priced asset and steal value from the deposit pool. The deviation % and heartbeat are too large and this will open up arbitrage opportunities to the detriment of Kelp’s users. When Kelp implements the withdrawal mechanism, we will have a better understanding of the profitability of such an attack. For example, if Kelp implements withdrawals without a staking delay, given the large amount of on-chain liquidity of the underlying assets, the pool may be able to be exploited for large amounts given even a 1% price discrepancy between the different LSTs.
Note: see original submission for full discussion.
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
Likely the use of Chainlink price feeds with wide deviation thresholds and long heartbeats, which allow temporary price discrepancies between assets that can be exploited for arbitrage.
Impact
An attacker could repeatedly exploit small price discrepancies to earn a profit of about 1-2.3%, potentially draining value from the deposit pool, though the protocol team disputes the severity and considers it a feature.
What the attacker needed
Ability to deposit assets into the pool; price discrepancy between assets; sufficient liquidity in the pool
The fix
The report does not propose a concrete fix, but suggests using multiple price oracles to reduce arbitrage opportunities, though acknowledging increased complexity and gas costs.
How it was found
- Deploy a mock oracle that allows setting arbitrary prices for each asset.
- Configure the protocol to use the mock oracle for rETH, stETH, and cbETH.
- Alice deposits large amounts of each asset to provide liquidity.
- Carol deposits rETH when prices are near spot.
- The oracle prices are updated: rETH +2%, stETH -0.5%, cbETH -1%.
- Bob deposits rETH and receives more rsETH than Carol did for the same amount.
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.
The protocol values different staking tokens using price feeds that only update when prices move by a certain percentage or after a day. If one token's price is temporarily low compared to others, someone can deposit that token and get more shares than they should, then later sell those shares for a profit. This takes value from other users in the pool.
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.