frxETHMinter.depositEther may run out of gas, leading to lost ETH
The depositEther function loops over all possible deposits based on the contract's balance, which can exceed the block gas limit when a large amount of ETH is deposited, making the function unusable and trapping the ETH. An attacker could deposit a large amount of ETH to cause this denial of service, preventing further deposits and requiring emergency failover.
Submitted by Lambda, also found by 0x52, Bahurum, Bnke0x0, KIntern_NA, lukris02, rbserver, Respx, rotcivegaf, Soosh, TomJ, Trust, V_B, and yixxas
frxETHMinter.depositEther always iterates over all deposits that are possible with the current balance ((address(this).balance - currentWithheldETH) / DEPOSIT_SIZE). However, when a lot of ETH was deposited into the contract / it was not called in a long time, this loop can reach the gas limit. When this happens, no more calls to depositEther are possible, as it will always run out of gas.
Of course, the probability that such a situation arises depends on the price of ETH. For >1,000 USD it would require someone to deposit a large amount of money (which can also happen, there are whales with thousands of ETH, so if one of them would decide to use frxETH, the problem can arise). For lower prices, it can happen even for small (in dollar terms) deposits. And in general, the correct functionality of a protocol should not depend on the price of ETH.
Proof Of Concept
Jerome Powell continues to raise interest rates, he just announced the next rate hike to 450%. The crypto market crashes, ETH is at 1 USD. Bob buys 100,000 ETH for 100,000 USD and deposits them into frxETHMinter. Because of this deposit, numDeposit within depositEther is equal to 3125. Therefore, every call to the function runs out of gas and it is not possible to deposit this ETH into the deposit contract.
Recommended Mitigation Steps
It should be possible to specify an upper limit for the number of deposits such that progress is possible, even when a lot of ETH was deposited into the contract.
FortisFortuna (Frax) confirmed, but decreased severity to Low and commented:
Adding a maxLoops parameter or similar can help mitigate this for sure.
0xean (judge) increased severity to Medium and commented:
Warden(s) fail to demonstrate how this leads to a loss of funds which would be required for High Severity. This does however lead directly to emergency failover’s having to be called to remove the now stuck ETH, and ultimately impairs the functionality and availability of the protocol, so Medium severity is appropriate.
Context
Frax Ether is a liquid staking product. Users deposit ETH into a minter contract, and the contract forwards that ETH to the Ethereum deposit contract in fixed-size chunks, minting a liquid staking token in return. The function at the centre of this report is frxETHMinter.depositEther, which is responsible for pushing the accumulated ETH onward to the deposit contract.
The behaviour that matters here is how depositEther decides how many deposits to perform. It always iterates over every deposit that is possible with the contract's current balance, computed as (address(this).balance - currentWithheldETH) / DEPOSIT_SIZE. There is no cap on the number of iterations, so the amount of work the function does grows with the amount of ETH sitting in the contract.
Setup
This is a contest finding against the Frax Ether Liquid Staking codebase. The relevant preconditions are simply that the minter holds ETH and that depositEther is called:
- The contract holds a balance of ETH, minus whatever is withheld in
currentWithheldETH. DEPOSIT_SIZEis the fixed size of each deposit to the deposit contract.- The number of loop iterations is
(address(this).balance - currentWithheldETH) / DEPOSIT_SIZE.
No special role, tool or version is described in the report. The finding was submitted by Lambda and independently found by 0x52, Bahurum, Bnke0x0, KIntern_NA, lukris02, rbserver, Respx, rotcivegaf, Soosh, TomJ, Trust, V_B and yixxas.
Finding it
The researcher noticed that the loop bound in depositEther is unbounded: it scales directly with the contract balance. When a lot of ETH has been deposited into the contract, or when the function has not been called for a long time and ETH has accumulated, the loop can reach the block gas limit. Once that happens, every subsequent call to depositEther also runs out of gas, because the balance has not gone down and the loop bound is unchanged. Every subsequent call to depositEther also runs out of gas, because the balance has not gone down and the loop bound is unchanged, so no more calls to depositEther are possible.
Exploitation
Step 1: accumulate enough ETH in the minter
The trigger is a large balance relative to DEPOSIT_SIZE. The report frames the required size in dollar terms, because the number of iterations depends on the ETH amount, not its price. At an ETH price above 1,000 USD, the deposit needed to hit the gas limit is large in dollar terms, though the report notes that whales holding thousands of ETH could produce it by deciding to use frxETH. At lower prices, even small deposits in dollar terms can be enough.
Step 2: call depositEther and exhaust the gas
The proof of concept is a price scenario. The report sets the scene with a rate hike to 450%, a market crash and ETH at 1 USD. Bob buys 100,000 ETH for 100,000 USD and deposits them into frxETHMinter. With that balance, numDeposit inside depositEther is 3125. Every call to the function therefore runs out of gas, and it is not possible to deposit this ETH into the deposit contract.
The number 3125 is the loop count implied by the balance divided by DEPOSIT_SIZE; the report does not state the value of DEPOSIT_SIZE itself. The point is that the iteration count alone is enough to exceed the gas available to a transaction.
Step 3: the function stays stuck
Because the balance is unchanged and the loop bound is recomputed from it on every call, retrying does not help. The ETH cannot be moved to the deposit contract through this path; the judge noted that this forces emergency failovers to be called to remove the now stuck ETH.
Root cause
The design assumes that iterating over all possible deposits in a single call will always fit in a block. That assumption fails as soon as the balance divided by DEPOSIT_SIZE is large enough that the loop's gas cost exceeds the transaction gas limit. There is no upper bound on the number of iterations and no way for the caller to request partial progress, so the failure is total rather than gradual: the same unbounded loop is re-entered on every attempt.
The report also makes the broader point that correct functionality of a protocol should not depend on the price of ETH, since the price determines how large a deposit, in dollar terms, is needed to trigger the condition.
Impact
The direct effect is a denial of service on depositEther: no further deposits can be processed while the balance remains above the threshold, and the ETH already in the contract cannot be forwarded to the deposit contract through this function. The judge's assessment was that the finding does not demonstrate a loss of funds, which would be required for High severity, but that it directly forces emergency failovers to be called to remove the stuck ETH and impairs the functionality and availability of the protocol. On that basis the severity was raised from Low to Medium.
The condition depends on the size of the ETH balance in the contract, which can build up when the function is not called for a long time; the probability of reaching it depends on the price of ETH.
Fix
The recommended mitigation is to allow an upper limit to be specified for the number of deposits, so that progress is possible even when a lot of ETH has been deposited into the contract. The Frax team confirmed the finding and noted that adding a maxLoops parameter or similar can help mitigate it. The report does not describe a specific patch being applied.
Variants to test
- Look for loops whose iteration count is derived from a contract balance or an array length that grows with user deposits, and check whether the count can exceed what fits in a block. A positive result is a function that reverts out of gas once the balance or array passes a threshold, and keeps reverting on retry.
- Check batch-processing functions that iterate over all pending items with no caller-supplied cap. A positive result is a queue that can be grown by an unprivileged user until processing becomes impossible.
- Check whether the loop bound is recomputed from state that the failing call does not change. A positive result is a permanent lock rather than a transient failure.
- Check whether an emergency or admin path exists to drain the stuck balance, and whether that path is the only recovery. A positive result is that recovery requires privileged intervention, which supports an availability impact.
Hunting notes
This class of bug hides in functions that combine a balance-derived or length-derived loop with no iteration cap, especially in staking, vault and reward-distribution contracts where balances can grow large between calls. During recon, look for loops over balance / CONSTANT, over dynamic arrays of user-controlled length, and for functions that are expected to be called periodically but have no bound on the work they do per call. The signal is a function whose gas cost scales with state that users can inflate.
On impact, the report is instructive: the judge accepted Medium on availability grounds, because the stuck ETH forces emergency failover, even though no direct loss of funds was shown. When reporting this kind of issue, showing that the failure is permanent (the same call keeps failing) and that recovery needs a privileged emergency path is what carries the severity.
What happened, in plain words
Frax Ether is a product that lets people earn rewards on their ETH without locking it up. You hand your ETH to a smart contract (a program that lives on the Ethereum blockchain and runs automatically), and the contract passes that ETH on to Ethereum's official staking deposit contract in fixed-size chunks. In return you get a token that represents your share, and that token can be traded or used elsewhere.
The function at the centre of this report is called frxETHMinter.depositEther. Its job is to take the ETH that has piled up inside the minter contract and push it onward to the deposit contract.
The problem is how depositEther decides how much work to do. It looks at the contract's balance and works out how many fixed-size deposits fit into it, then loops over every single one of them in a single transaction. There is no upper limit on how many times it loops. So the more ETH sits in the contract, the more work the function tries to do in one go.
Every transaction on Ethereum has a gas limit. Gas is the unit used to measure computational work, and each transaction is only allowed to consume so much of it. If a function tries to do more work than the limit allows, the transaction runs out of gas and fails. That is what happens here: once enough ETH has accumulated, the loop is too long to finish, so depositEther always fails. And because the balance has not gone down (the call failed), the next attempt computes the same oversized loop and fails again. The ETH cannot be deposited through this function until the balance is reduced by some other means.
Background concepts
Before the details, a few ideas from zero.
- Blockchain and smart contracts. A blockchain is a shared record book that many computers keep in sync. A smart contract is a program stored on that blockchain. Anyone can call its functions by sending a transaction, and the code runs exactly as written.
- ETH and gas. ETH is the currency of Ethereum. Every operation a transaction performs costs a small amount of ETH, measured in gas. A transaction carries a gas limit: the maximum work it is allowed to do. If the code needs more than the limit, the whole transaction is cancelled and the gas spent so far is lost. Think of it like a taxi meter with a hard budget: if the journey costs more than you have, you do not arrive.
- A minter contract. In this product, the minter is the contract that receives users' ETH and forwards it to the official deposit contract. It is the middleman.
- A loop. A loop is a piece of code that repeats the same steps many times. If a loop repeats 10 times, the work is small. If it repeats 3,000 times, the work is large. Gas cost grows with the number of repetitions.
- Denial of service (DoS). A denial of service is when something that should work is made impossible to use. Here it is not an attacker flooding a server; it is the contract's own design making its own function impossible to call once a condition is met.
- Liquid staking token. When you stake ETH normally, it is locked and you cannot spend it. A liquid staking product gives you a token in return that represents your staked ETH, so you keep something you can use while the ETH earns rewards.
Context
Frax Ether is a liquid staking product. Users deposit ETH into a minter contract, and the contract forwards that ETH to the Ethereum deposit contract in fixed-size chunks, minting a liquid staking token in return. The function at the centre of this report is frxETHMinter.depositEther, which is responsible for pushing the accumulated ETH onward to the deposit contract.
The behaviour that matters here is how depositEther decides how many deposits to perform. It always iterates over every deposit that is possible with the contract's current balance, computed as (address(this).balance - currentWithheldETH) / DEPOSIT_SIZE. There is no cap on the number of iterations, so the amount of work the function does grows with the amount of ETH sitting in the contract.
In plain words: the contract takes its own ETH balance, subtracts an amount it is holding back (currentWithheldETH), divides what is left by the fixed size of one deposit (DEPOSIT_SIZE), and then repeats the deposit step that many times. If the answer is 5, it does 5 deposits. If the answer is 3,000, it tries to do 3,000 deposits in one transaction, and that is where the gas runs out.
Setup
This is a contest finding against the Frax Ether Liquid Staking codebase. A contest is an event where many independent researchers review the same code and submit findings, and a judge decides which are valid and how serious they are.
The relevant preconditions are simply that the minter holds ETH and that depositEther is called:
- The contract holds a balance of ETH, minus whatever is withheld in
currentWithheldETH. DEPOSIT_SIZEis the fixed size of each deposit to the deposit contract.- The number of loop iterations is
(address(this).balance - currentWithheldETH) / DEPOSIT_SIZE.
No special role, tool or version is described in the report. The finding was submitted by Lambda and independently found by 0x52, Bahurum, Bnke0x0, KIntern_NA, lukris02, rbserver, Respx, rotcivegaf, Soosh, TomJ, Trust, V_B and yixxas. Several people finding the same thing separately is a sign that the issue is easy to spot once you look at the loop.
Finding it
The researcher noticed that the loop bound in depositEther is unbounded: it scales directly with the contract balance. When a lot of ETH has been deposited into the contract, or when the function has not been called for a long time and ETH has accumulated, the loop can reach the block gas limit. Once that happens, every subsequent call to depositEther also runs out of gas, because the balance has not gone down and the loop bound is unchanged. The function becomes permanently uncallable until the balance is reduced by some other means.
Why does the balance not go down? Because a transaction that runs out of gas is cancelled entirely. None of its effects are kept. So the failed attempt does not move any ETH, and the next attempt starts from exactly the same balance and computes exactly the same oversized loop. It is a trap that resets itself every time.
Exploitation
Step 1: accumulate enough ETH in the minter
The trigger is a large balance relative to DEPOSIT_SIZE. The report frames the required size in dollar terms, because the number of iterations depends on the ETH amount, not its price. At an ETH price above 1,000 USD, the deposit needed to hit the gas limit is large in dollar terms, though the report notes that whales holding thousands of ETH could produce it by deciding to use frxETH. At lower prices, even small deposits in dollar terms can be enough.
This is the key insight for a beginner: the loop count depends on how many ETH are in the contract, not on what those ETH are worth. If ETH is expensive, you need a lot of money to reach the dangerous count. If ETH is cheap, the same count costs much less money. The protocol's correct behaviour should not depend on the market price, and that is part of the researcher's argument.
Step 2: call depositEther and exhaust the gas
The proof of concept is a price scenario. The report sets the scene with a rate hike to 450%, a market crash and ETH at 1 USD. Bob buys 100,000 ETH for 100,000 USD and deposits them into frxETHMinter. With that balance, numDeposit inside depositEther is 3125. Every call to the function therefore runs out of gas, and it is not possible to deposit this ETH into the deposit contract.
The number 3125 is the loop count implied by the balance divided by DEPOSIT_SIZE; the report does not state the value of DEPOSIT_SIZE itself. The point is that the iteration count alone is enough to exceed the gas available to a transaction.
In everyday terms: imagine a checkout till that must scan every item in the shop before it can close the day. With ten items that is fine. With three thousand items, the till gives up partway through, and because it never finishes, the shop never closes and the items never leave the shelf. Bob's deposit is the shop full of items.
Step 3: the function stays stuck
Because the balance is unchanged and the loop bound is recomputed from it on every call, retrying does not help. The ETH cannot be moved to the deposit contract through this path; the judge noted that this forces emergency failovers to be called to remove the now stuck ETH.
The judge noted that the stuck ETH forces emergency failovers to be called, which impairs the availability of the protocol.
Root cause
The design assumes that iterating over all possible deposits in a single call will always fit in a block. That assumption fails as soon as the balance divided by DEPOSIT_SIZE is large enough that the loop's gas cost exceeds the transaction gas limit. There is no upper bound on the number of iterations and no way for the caller to request partial progress, so the failure is total rather than gradual: the same unbounded loop is re-entered on every attempt.
The report also makes the broader point that correct functionality of a protocol should not depend on the price of ETH, since the price determines how large a deposit, in dollar terms, is needed to trigger the condition.
A useful comparison: a lift with no weight limit works fine until enough people get in, and then it stops between floors. The fix is not to ask people to weigh less; it is to put a limit on how many get in at once and send the rest on the next trip.
Impact
The direct effect is a denial of service on depositEther: no further deposits can be processed while the balance remains above the threshold, and the ETH already in the contract cannot be forwarded to the deposit contract through this function. The judge's assessment was that the finding does not demonstrate a loss of funds, which would be required for High severity, but that it directly forces emergency failovers to be called to remove the now stuck ETH and impairs the functionality and availability of the protocol. On that basis the severity was raised from Low to Medium.
The condition depends on the size of the ETH balance in the contract, which can build up when the function is not called for a long time; the probability of reaching it depends on the price of ETH.
Severity levels in these contests are a way of ranking how bad a bug is. High usually means money can be stolen or lost. Medium covers serious damage to how the protocol works, even without direct theft. Here the judge accepted that the stuck ETH and the forced emergency action were serious enough for Medium.
Fix
The recommended mitigation is to allow an upper limit to be specified for the number of deposits, so that progress is possible even when a lot of ETH has been deposited into the contract. The Frax team confirmed the finding and noted that adding a maxLoops parameter or similar can help mitigate it. The report does not describe a specific patch being applied.
A maxLoops parameter would be an input the caller supplies, saying "do at most this many deposits in this call". If there are more deposits waiting, the next call handles the next batch. Each call stays within the gas budget, and the queue drains over several transactions instead of failing forever in one.
Variants to test
These are patterns to look for in other code, written for someone learning to review contracts.
- Look for loops whose iteration count is derived from a contract balance or an array length that grows with user deposits, and check whether the count can exceed what fits in a block. A positive result is a function that reverts out of gas once the balance or array passes a threshold, and keeps reverting on retry.
- Check batch-processing functions that iterate over all pending items with no caller-supplied cap. A positive result is a queue that can be grown by an unprivileged user until processing becomes impossible.
- Check whether the loop bound is recomputed from state that the failing call does not change. A positive result is a permanent lock rather than a transient failure.
- Check whether an emergency or admin path exists to drain the stuck balance, and whether that path is the only recovery. A positive result is that recovery requires privileged intervention, which supports an availability impact.
Hunting notes
This class of bug hides in functions that combine a balance-derived or length-derived loop with no iteration cap, especially in staking, vault and reward-distribution contracts where balances can grow large between calls. During recon, look for loops over balance / CONSTANT, over dynamic arrays of user-controlled length, and for functions that are expected to be called periodically but have no bound on the work they do per call. The signal is a function whose gas cost scales with state that users can inflate.
On impact, the report is instructive: the judge accepted Medium on availability grounds, because the stuck ETH forces emergency failover, even though no direct loss of funds was shown. When reporting this kind of issue, showing that the failure is permanent (the same call keeps failing) and that recovery needs a privileged emergency path is what carries the severity.
Glossary
- Blockchain: a shared, tamper-resistant record of transactions kept in sync by many computers.
- Smart contract: a program stored on a blockchain that runs automatically when called.
- ETH: the native currency of Ethereum.
- Gas: the unit that measures computational work on Ethereum; every operation costs gas.
- Gas limit: the maximum amount of gas a transaction is allowed to consume; exceeding it cancels the transaction.
- Out of gas: the state where a transaction needs more gas than its limit allows, so it fails and is cancelled.
- Transaction: a request sent to the blockchain to run a function or move funds.
- Loop: code that repeats the same steps a number of times; more repetitions mean more gas.
- Loop bound: the number that decides how many times a loop repeats.
- Unbounded loop: a loop with no fixed upper limit, whose repetition count depends on data that can grow.
- Minter contract: the contract that receives users' ETH and forwards it to the deposit contract.
- Deposit contract: Ethereum's official contract that accepts staked ETH.
depositEther: the minter function that forwards accumulated ETH to the deposit contract.DEPOSIT_SIZE: the fixed amount of ETH in each individual deposit to the deposit contract.currentWithheldETH: an amount of ETH held back inside the contract and excluded from the deposit calculation.numDeposit: the computed number of deposits the function will attempt in one call.maxLoops: a proposed parameter that would cap how many deposits a single call performs.- Denial of service (DoS): making a function or service impossible to use.
- Availability: whether a system's features can actually be used when needed.
- Liquid staking: staking ETH while receiving a tradeable token that represents the staked amount.
- Liquid staking token: the tradeable token you receive for staked ETH.
- Whale: an individual or entity holding a very large amount of a cryptocurrency.
- Emergency failover: a privileged recovery mechanism used when normal operation is broken.
- Severity: a ranking of how serious a bug is, from Low through Medium to High.
- Proof of concept (PoC): a concrete scenario showing that a bug can actually happen.
- Contest: an event where independent researchers review the same code and submit findings for judging.
- Recon: the exploratory phase of a review, where you map out the code and its assumptions.