Withdrawal transactions can get stuck if output root is reproposed
Withdrawal transactions can become permanently stuck if the L2 output root for the block containing the withdrawal is challenged and replaced with a different root that does not include the withdrawal. The reproving mechanism only allows reproving at the same output index, so the withdrawal can never be finalized, locking funds.
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/53
Found by
Allarious, Barichek, HE1M, cmichel, unforgiven
Summary
Withdrawal transactions may never be executed if the L2 output root for the block, for which the withdrawal was proven, is challenged and reproposed.
Vulnerability Detail
Withdrawal transactions can be reproven in the case that the output root for their previously proven output index has been updated. This can happen if the L2 output root was removed by the challenger. However, to circumvent malicious users from reproving messages all the time and resetting the withdrawal countdown, reproving can only be done on the same L2 block number (and if the output root changed).
If the challenger deletes the block with the withdrawal transaction and the proposer proposes a different block that does not have the withdrawal transaction, the withdrawal transaction can never be finalized - even if a future block includes the legitimate withdrawal transaction again, as reproving it is bound to the old provenWithdrawals[withdrawalHash].l2OutputIndex.
Impact
Legitimate withdrawal transactions will never be finalized if the proposed block was challenged and replaced with a different one not having the withdrawal transaction. As this call fails on the "lowest level", the OptimismPortal, these transactions also cannot be replayed or be issued refunds. In case the withdrawal transaction was a token bridge transfer, the tokens are stuck on the other chain and cannot be recovered by the user.
Code Snippet
https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/OptimismPortal.sol#L196-L197 https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/L2OutputOracle.sol#L128
Tool used
Manual Review
Recommendation
Loosen the restriction of reproving: Allow reproving under a new L2 output index whenever the output root of the proven output index changes. This still balances the other concern of malicious users reproving transactions to reset the withdrawal countdown well as in the case where the output root changed, the withdrawal needs to be proved again anyway to be finalized.
- require(
- provenWithdrawal.timestamp == 0 ||
- (_l2OutputIndex == provenWithdrawal.l2OutputIndex &&
- outputRoot != provenWithdrawal.outputRoot),
- "OptimismPortal: withdrawal hash has already been proven"
- );
+ require(
+ provenWithdrawal.timestamp == 0 ||
+ L2_ORACLE.getL2Output(provenWithdrawal.l2OutputIndex) != provenWithdrawal.outputRoot,
+ "OptimismPortal: withdrawal hash has already been proven"
+ );
Discussion
rcstanciu
Comment from Optimism
Description: cannot reprove if you would need to do so on a different output index
Reason: Yeah, this LGTM.
Allarious
Escalate for 60 USDC
While this issue is mostly discussed here as something that can happen among honest actors, this can be an attack vector from the proposer role to users that disrupts the liveness of the system. This attack can lock the funds of many transactions and I believe this should be labelled as high.
The Attack
A proposer can block many transactions by submitting a faulty output root to the oracle and proving the transaction before the actual transaction reaches the L2. This can cause the total lock of funds and there is no way to recover the funds after.
Justification of this issue being high
- The
proposeris not a trusted role, and thechallengerrole can not stop this sinceprovenWithdrawalsare already written to L1. Furthermore, Faulty proofs should not be able to lock funds up and they should just make temporary disturbance in the system. - Can block many incoming transactions at any time, proposer can wait as long as he wants to maximize the attack value.
- There is no longer a guarantee for the liveness of the system since there is no guarantee anymore that withdrawal transactions from L1 can be executed.
- This attack can be escalated if
proposerand thesequencerare working together. Which means that user of the system who deposits into L2 has to trust Optimism not to lock up their funds (at the start of the project), which makes a centralized authority for L2. - Since the
proposerrole is going to be decentralized in the future, this can have catastrophic outcomes.
The variations of this attack
- Proposer can target several transactions in L1 mempool or receive them from the sequencer on L2 to lock up. He can attack as many transaction before the
outputrootis challenged. - Proposer can submit an
outputrootwhere all the leaves of the tree is set to true, in this case, everyone in the network will be able to front-run each other to lock up each others transactions. (Such output root can be built with O(log(n)) - If the proposer unknowingly sends an incorrect output root due to a faulty off-chain program, an attacker could exploit this by using it to obstruct all the incorrectly included withdrawal proofs, even if the proposer is not intentionally acting malicious.
sherlock-admin
Escalate for 60 USDC
While this issue is mostly discussed here as something that can happen among honest actors, this can be an attack vector from the
proposerrole to users that disrupts the liveness of the system. This attack can lock the funds of many transactions and I believe this should be labelled as high.The Attack
A
proposercan block many transactions by submitting a faulty output root to the oracle and proving the transaction before the actual transaction reaches the L2. This can cause the total lock of funds and there is no way to recover the funds after.Justification of this issue being high
- The
proposeris not a trusted role, and thechallengerrole can not stop this sinceprovenWithdrawalsare already written to L1. Furthermore, Faulty proofs should not be able to lock funds up and they should just make temporary disturbance in the system.- Can block many incoming transactions at any time, proposer can wait as long as he wants to maximize the attack value.
- There is no longer a guarantee for the liveness of the system since there is no guarantee anymore that withdrawal transactions from L1 can be executed.
- This attack can be escalated if
proposerand thesequencerare working together. Which means that user of the system who deposits into L2 has to trust Optimism not to lock up their funds (at the start of the project), which makes a centralized authority for L2.- Since the
proposerrole is going to be decentralized in the future, this can have catastrophic outcomes.The variations of this attack
- Proposer can target several transactions in L1 mempool or receive them from the sequencer on L2 to lock up. He can attack as many transaction before the
outputrootis challenged.- Proposer can submit an
outputrootwhere all the leaves of the tree is set to true, in this case, everyone in the network will be able to front-run each other to lock up each others transactions. (Such output root can be built with O(log(n))- If the proposer unknowingly sends an incorrect output root due to a faulty off-chain program, an attacker could exploit this by using it to obstruct all the incorrectly included withdrawal proofs, even if the proposer is not intentionally acting malicious.
You've created a valid escalation for 60 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Evert0x
Escalation rejected.
Although the statements in the justifications section seem all correct to me, we take into account that the proposer role will be controlled by Optimism, this restriction makes the attack extremely unlikely as it requires a private key to be leaked.
Because Optimism documented plans to decentralize this role we keep it medium severity.
sherlock-admin
Escalation rejected.
Although the statements in the justifications section seem all correct to me, we take into account that the proposer role will be controlled by Optimism, this restriction makes the attack extremely unlikely as it requires a private key to be leaked.
Because Optimism documented plans to decentralize this role we keep it medium severity.
This issue's escalations have been rejected!
Watsons who escalated this issue will have their escalation amount deducted from their next payout.
Issue S-1: Batch validation logic is ordered differently to specification
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/283
Found by
obront
Summary
Optimism L2 block derivation has a long list of validation steps performed on incoming blocks. They are described in the spec page, but the code implements the validations in a different order than the spec lays out.
Vulnerability Detail
There is an error in the order which is described in the spec versus the one in the implementation.
According to the specs, the following check comes first:
batch.timestamp > batch_origin.time + max_sequencer_drift -> drop: i.e. a batch that does not adopt the next L1 within time will be dropped, in favor of an empty batch that can advance the L1 origin. This enforces the max L2 timestamp rule.
After it comes this check:
batch.timestamp < batch_origin.time -> drop: enforce the min L2 timestamp rule.
However, in code in batches.go executes in reverse:
if batch.Batch.Timestamp < batchOrigin.Time {
log.Warn("batch timestamp is less than L1 origin timestamp", "l2_timestamp", batch.Batch.Timestamp, "l1_timestamp", batchOrigin.Time, "origin", batchOrigin.ID())
return BatchDrop
}
// If we ran out of sequencer time drift, then we drop the batch and produce an empty batch instead,
// as the sequencer is not allowed to include anything past this point without moving to the next epoch.
if max := batchOrigin.Time + cfg.MaxSequencerDrift; batch.Batch.Timestamp > max {
log.Warn("batch exceeded sequencer time drift, sequencer must adopt new L1 origin to include transactions again", "max_time", max)
return BatchDrop
}
In practice this should not lead to any issues because both are drop rules and are right next to each other.
Impact
The code does not align with the ordering laid out in the specification.
Code Snippet
Tool used
Manual Review
Recommendation
Change the code so that it is in line with the specification.
Issue S-2: Specification of the new base fee calculation is inconsistent with the code
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/266
Found by
shw
Summary
Specification of the new base fee calculation is inconsistent with the code.
Vulnerability Detail
The "Guaranteed Gas Fee Market" specification provides a pseudocode explaining how a new base fee is calculated, which has two inconsistencies with the actual code implementation:
- When multiple blocks are skipped, the new base fee is applied with a 7/8 reduction per block. The code uses the updated
newBaseFee(seeResourceMetering.sol#L115) while the specification uses the un-updatedprev_basefee. - The maximum new base fee in the specification is
UINT_64_MAX_VALUEbut is set totype(uint128).maxin the code.
Impact
The specification does not match the code.
Code Snippet
Tool used
Manual Review
Recommendation
Fix either the specification or the code.
Issue S-3: Incorrect code comments in the StandardBridge.sol contract
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/264
Found by
unforgiven, tsvetanovv, shw
Summary
Incorrect code comments in the StandardBridge.sol contract.
Vulnerability Detail
The code comments for the bridgeERC20 and bridgeERC20To functions in the universal/StandardBridge.sol contract do not match the actual code. The comments say the bridge returns tokens to the sender if the bridging fails, but the refund logic has been removed since PR#3535.
Impact
Specfication error only.
Code Snippet
https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/universal/StandardBridge.sol#L219-L222 https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/universal/StandardBridge.sol#L251-L254
Tool used
Manual Review
Recommendation
Remove the outdated code comments.
Issue S-4: Incorrect owner check
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/263
Found by
csanuragjain
Summary
The depositTransaction of OptimismPortal can directly be called by user instead of intermediate contract. This means from address wont be aliased. But this is not considered in CrossDomainOwnable contract which plainly undoL1ToL2Alias the caller
Vulnerability Detail
- Assume
depositTransactionis called by User A directly. Since no intermediary contract so no aliasing is done - On L2 side, if _checkOwner is checked
function _checkOwner() internal view override {
require(
owner() == AddressAliasHelper.undoL1ToL2Alias(msg.sender),
"CrossDomainOwnable: caller is not the owner"
);
}
- This will try undoL1ToL2Alias on User A address and then match with owner which is incorrect since User A address was never aliased on L1
Impact
The owner check might fail for genuine transaction
Code Snippet
Tool used
Manual Review
Recommendation
This check need to be revised. If the transaction came directly from tx.origin (without any intermediary contract) then no need of removing aliasing
Discussion
csanuragjain
Escalate for 28 USDC
This is mentioning a valid issue where CrossDomainOwnable.sol#L21 is always assuming call to depositTransaction coming from contract (as undo Alias is always done).
If depositTransaction is called by a user instead then CrossDomainOwnable will fail to check properly and not allow a genuine user
sherlock-admin
Escalate for 28 USDC
This is mentioning a valid issue where CrossDomainOwnable.sol#L21 is always assuming call to
depositTransactioncoming from contract (as undo Alias is always done). IfdepositTransactionis called by a user instead thenCrossDomainOwnablewill fail to check properly and not allow a genuine user
You've created a valid escalation for 28 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Evert0x
Escalation accepted and labeling as specification issue
sherlock-admin
Escalation accepted and labeling as specification issue
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
Issue S-5: Block number is not an input to proveWithdrawalTransaction in OptimismPortal
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/233
Found by
ck
Summary
According to the Withdrawals spec, a block number is one of the submitted inputs to the OptimismPortal which is not the case.
Vulnerability Detail
The documentation says:
"A relayer submits the required inputs to the OptimismPortal contract. The relayer need not be the same entity which initiated the withdrawal on L2. These inputs include the withdrawal transaction data, inclusion proofs, and a block number. The block number must be one for which an L2 output root exists, which commits to the withdrawal as registered on L2."
In the contract, the _l2OutputIndex is the one used to check for existence of the outputRoot and not the block number.
function proveWithdrawalTransaction(
Types.WithdrawalTransaction memory _tx,
uint256 _l2OutputIndex,
Types.OutputRootProof calldata _outputRootProof,
bytes[] calldata _withdrawalProof
) external {
// Prevent users from creating a deposit transaction where this address is the message
// sender on L2. Because this is checked here, we do not need to check again in
// `finalizeWithdrawalTransaction`.
require(
_tx.target != address(this),
"OptimismPortal: you cannot send messages to the portal contract"
);
// Get the output root and load onto the stack to prevent multiple mloads. This will
// revert if there is no output root for the given block number.
bytes32 outputRoot = L2_ORACLE.getL2Output(_l2OutputIndex).outputRoot;
// Verify that the output root can be generated with the elements in the proof.
require(
outputRoot == Hashing.hashOutputRootProof(_outputRootProof),
"OptimismPortal: invalid output root proof"
);
Impact
Misleading spec
Code Snippet
Tool used
Manual Review
Recommendation
The specification should refer to _l2OutputIndex as one of the inputs instead of 'block number'.
Issue S-6: system_config: incorrect variable name and missing config update type
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/213
Found by
lemonmon
Summary
The specs for system config contains incorrect information and incorrect names for its contents.
- The names for
overheadandscalarare falsely stated asl1FeeOverheadandl1FeeScalarin multiple occasions. - The list of the configuration update types is missing the unsafe block signer update
Vulnerability Detail
In the SystemConfig contract, there are public variables overhead and scalar:
Below the variables overhead and scalar are incorrectly named as l1FeeOverhead and l1FeeScalar in multiple occasions:
https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L34 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L73 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L86-L90
In the above snippet:
Line 89: the names of overhead and scalar
It also is missing the type 3:
- type
3:unsafeBlockSigneroverwrite, asaddresspayload.
The corresponding update code snippets from SystemConfig are below:
https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/SystemConfig.sol#L25-L30 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/SystemConfig.sol#L169-L175
Impact
factually incorrect information
- incorrect name of variables
- missing config update type
As the name of variables double as interface to fetch the value, anybody uses the incorrect name in the specs to fetch the values will fail.
Also the specs do not list the possible config update types, so the users may not know that the unsafeBlockSigner can be updated.
Code Snippet
https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/SystemConfig.sol#L51-L59 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L34 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L73 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/specs/system_config.md?plain=1#L86-L90 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/SystemConfig.sol#L25-L30 https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/SystemConfig.sol#L169-L175
Tool used
Manual Review
Recommendation
Correct the names of the variables and add the missing config update type
Issue S-7: Address collision in cross - chain contract creation (breaks tooling)
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/204
Found by
Bahurum, Ro
Summary
When creating a contract from L1 (mainnet) to L2 (optimism) the nonce of the sender is kept at 0 in the context of the transaction receipt and thus the existing infrastructure (Etherscan) will incorrectly interpret the address of the new contract (creating a collision).
Vulnerability Detail
It is possible to create a contract in Layer 2 from Layer 1 by sending a transaction to the optimism portal. This is the function of interest:
function depositTransaction(
address _to,
uint256 _value,
uint64 _gasLimit,
bool _isCreation,
bytes memory _data
) public payable metered(_gasLimit)
To create a contract the "_to" address needs to be set to "address(0x0), " the "_isCreation" needs to be set to "true" and the bytecode needs to be passed in the "_data" field.
- The contract is then created through the "create" opcode, therefore the address is computed by hashing the nonce and the address of the sender.
If the nonce is kept at 0 during some time of the execution, the new contract address will always be the same (nonce is always 0).
NOTE: In reality, the new contract is created with the proper nonce (and the nonce is updated), but the receipt displays it wrongly and during a point in the execution is also kept at 0 so it breaks Etherscan, Blockscout and the rest of the block exploreres.
Impact
Infrastructure tooling like Etherscan is the source of truth for most users, therefore having inconsistent data between these tools and Optimism is not recommended.
This bug causes existing tooling like Etherscan and Blockscout to display wrong data in the following ways:
- The first contract created will always appear as the new contract in contract creation.
See this link for reference: https://goerli-optimism.etherscan.io/address/0x5d7ee88447367b9212fa655dc863a1e83f7e189d
When the account 0x7d.. creates a new contract from Layer 1, the address "0x5d.." will always appear as the new contract created.
- It incorrectly displays contracts as EOA's
See this address on etherscan goerli optimism: https://goerli-optimism.etherscan.io/address/0x0a1c3c13c35275d030ff9fb660946cf2fca74ece It appears to be a regular EOA, while in reality, it is a contract. Run the following command to verify:
cast code 0x0a1c3c13c35275d030ff9fb660946cf2fca74ece --rpc-url https://goerli.optimism.io
Code Snippet
Tool used
Manual Review
Recommendation
The nonce should be set to the sender's nonce from the op-node.
Discussion
rcstanciu
Comment from Optimism
Description: Address collision in cross - chain contract creation (breaks tooling)
Reason: This is correct, but is unexpected behavior external to the scope of the code. Thus, this is a low issue.
Action: Increment the nonce in the op-node to make transaction receipts use the correct nonce for contract creation on L1 -> L2 bridge.
rodrigoherrerai
Escalate for 250 USDC
This bug clearly breaks the specifications from Optimism. The debate here is if this is marked as a Medium or as a spec.
It could be marked as medium because it breaks EVM complete equivalence (as shown below):
Bedrock’s design aims for EVM equivalence, meaning that smart contract developers should be able to safely deploy the same contracts to Optimism as they would on Ethereum, without concern for differences in the execution.
Here are concrete examples where this bug causes the specifications to differ:
Just to recap, this issue is manifested when creating contracts from L1 -> L2. The nonce is not incremented and thus the contract created in the transaction receipt will always be the same (nonce is always 0).
When creating a contract, the address is computed as follows:
computed_address = keccak256(rlp.encode([address, nonce]))
canonical_address = computed_address[-20:]
padded_address = left_pad_zero_bytes(canonical_address, 20)
return Address(padded_address)
If the nonce is kept at 0 during the receipt, then the new contract address will always be the same. https://github.com/ethereum/execution-specs/blob/master/src/ethereum/london/utils/address.py#L42
This issue breaks the following specifications:
1:
Nonce Handling Despite the lack of signature validation, we still increment the nonce of the from account when a deposit transaction is executed. In the context of a deposit-only roll up, this is not necessary for transaction ordering or replay prevention, however it maintains consistency with the use of nonces during contract creation. It may also simplify integration with downstream tooling (such as wallets and block explorers).
Link: https://github.com/ethereum-optimism/optimism/blob/develop/specs/deposits.md#nonce-handling
Quote: "however it maintains consistency with the use of nonces during contract creation. It may also simplify integration with downstream tooling (such as wallets and block explorers)."
This issue completely breaks the integration with downstream tooling:
- Etherscan and the rest of the block explorers show contract accounts without code (as EOA's):
This is an account with code (contract) on Optimism goerli: 0x0a1c3c13c35275d030ff9fb660946cf2fca74ece
But Etherscan and the rest of the block explorers display it as an EOA:
- Etherscan and the rest of the block explorers incorrectly show the contract creation as the first contract will always appear to be the contract created:
Take this transaction for example:
It appears as if the contract created was "0x5d7..", while in reality it is incorrect. Note that the nonce also appears as "0".
It breaks complete "EVM Equivalence"
From the Optimism blog post:
…What is EVM equivalence? In short: EVM equivalence is complete compliance with the Ethereum yellow paper, the formal definition of the protocol. By definition, L1 Ethereum software must comply with this specification.
This means that — down to the very deepest depths — the existing Ethereum stack will now integrate with the L2 system, too. Every debugger. Every toolchain. Every node implementation. We believe that any L2 offering any EVM experience will have to meet this bar — anything less is unacceptable.
Quote: "This means that — down to the very deepest depths — the existing Ethereum stack will now integrate with the L2 system, too. Every debugger. Every toolchain. Every node implementation. We believe that any L2 offering any EVM experience will have to meet this bar — anything less is unacceptable." Link: https://medium.com/ethereum-optimism/introducing-evm-equivalence-5c2021deb306
Apart from breaking downstream tooling like block explorers and debuggers, it can also break frontend / backend applications that rely on the transaction receipt as the source of truth.
For example, when the address 0x7dF608C479d2D2a7df677fEEc6f2535Eb268da01 creates a contract from L1 to L2, the contract address in the receipt will always be the same, because the nonce is kept at 0:
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
The reproving logic requires the new proof to use the same L2 output index as the original proof, preventing reproving when the output root changes to a different index.
Impact
Legitimate withdrawals, including token bridge transfers, can be permanently stuck and funds cannot be recovered.
What the attacker needed
Withdrawal must be proven; output root must be challenged and replaced
The fix
The restriction on reproving should be loosened to allow reproving under a new L2 output index whenever the output root of the proven output index changes.
How it was found
- A withdrawal is proven against an L2 output root.
- A challenger deletes that output root.
- The proposer proposes a different output root that does not include the withdrawal.
- The user tries to reprove the withdrawal but cannot because the output index must match the original.
- The withdrawal can never be finalized.
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.
When you withdraw from a rollup, you first prove your withdrawal on the main chain, then wait a period before finalizing it. If someone challenges the block data and it gets replaced with different data that doesn't include your withdrawal, you normally need to prove it again. But the code only lets you re-prove using the same old block reference, so you're stuck and your funds are locked.
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.