Possible wrong accounting in L1Staking.sol
A staker can commit a wrong batch and then withdraw their stake before the challenge period ends, so when the batch is later proven invalid the slashing has no effect and the contract's accounting becomes incorrect. This could lead to a shortfall where the last withdrawal reverts because the contract holds less ETH than it accounts for.
0xRajkumar Follow with PASCAL, PapaPitufo and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/104
The protocol has acknowledged this issue.
Found by
0xRajkumar, PASCAL, PapaPitufo, n4nika
Summary
Possible wrong accounting in L1Staking.sol during some slashing occasions.
Vulnerability Detail
Stakers are permitted to commit batches in the rollup contract and these batches can be challenged by challengers, if the challenge is successful the challenger gets part of the stakers ETH and staker is removed, the owner also takes the rest; if it wasn't succesful the prover takes all the challengeDeposit from the challenger. According to the readMe https://github.com/sherlock-audit/2024-08-morphl2-Pascal4me#q-are-there-any-limitations-on-values-set-by-admins-or-other-roles-in-the-codebase-including-restrictions-on-array-lengths proofWindow which is the time a challenged batch has to go without being proven for it to be successfully challenged can be set to as high as 604800 seconds which is 7 days and withdrawalLockBlocks default value is also 7 days(No relation between the two was done and owner can change proofWindow value in rollup contract). For this vulnerability we'll assume proofWindow is set to 7 days. The issue stems from a staker being able to commit a wrong batch and still being able to withdraw from the staking contract without that batch being finalized or proven.
Let's site this example with proofWindow being set to 7 days
- Alice a staker commits a wrong batch and immediately goes ahead to withdraw her ETH from the staking contract, her 7 days period countdown start
- Bob a challenger sees that wrong batch and challenges it and it since it's a wrong batch theres no proof for it, then 7 days couuntdown starts.
But remember the withdraw function 7 days started counting first so when it elapses Alice quickly goes ahead to withdraw her ETH, then when Bob calls
proveState(), Alice is supposedly slashed but it's useless as she's already left the system. Then the contract is updated as though Alice's ETH is still in the contract
uint256 reward = (valueSum * rewardPercentage) / 100; slashRemaining += valueSum - reward; _transfer(rollupContract, reward);
So a current staker's ETH is the one being sent to the rollup contract and being assigned to the owner via slashRemaining. So there's less ETH than the contract is accounting for which already an issue. This will be detrimental when all the ETH is being withdrawn by stakers and owner the last person transaction will revert becuase that ETH is not in the contract.
Impact
Incorrect contract accounting
Code Snippet
https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/staking/L1Staking.sol#L197-L201 https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/rollup/Rollup.sol#L484-L487 https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/rollup/Rollup.sol#L697-L707 https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/staking/L1Staking.sol#L307-L311 https://github.com/sherlock-audit/2024-08-morphl2/blob/main/morph/contracts/contracts/l1/staking/L1Staking.sol#L217-L237
Tool used
Manual Review
Recommendation
Ensure stakers can't withdraw if they have a batch that is unfinalized or unproven and always ensure that withdraw time block is > proofWindow
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 withdrawal lock period is not enforced to be longer than the proof window, and the withdrawal function does not check for pending unfinalised batches, allowing a staker to exit before slashing can occur.
Impact
The contract's accounting becomes incorrect, with less ETH than recorded, which could cause the last withdrawal to revert.
What the attacker needed
Staker role; proofWindow set to 7 days; withdrawalLockBlocks set to 7 days
How it was found
- A staker commits a wrong batch to the rollup contract.
- The staker immediately initiates a withdrawal from the staking contract, starting a 7-day countdown.
- A challenger challenges the wrong batch, starting a separate 7-day proof window.
- The staker's withdrawal countdown finishes first, so they withdraw their ETH.
- The challenger later proves the batch invalid, but the slashing is ineffective because the staker has already left.
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.
A staker puts up money as a promise to process transactions correctly. If they cheat, someone can challenge them and take part of their money. Here, the cheater can take their money out before the challenge finishes, so the punishment never actually happens and the contract's records no longer match the real money it holds.
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.