# Boss Bridge Audit: Four High Severity Findings in a Cross-Chain Bridge

> **Quick note before you read:** Boss Bridge is a teaching codebase from the Cyfrin Updraft Smart Contract Security course. This was a mock audit done for practice, not a paid engagement against a live protocol. Everything below is reproducible from the public repo linked at the end.

---

## 1\. A bridge is just a promise

A bridge is a promise that one token on chain A is worth one token on chain B.

On the L1 side, tokens get locked in a vault and an event is emitted. An off-chain relayer picks up that event and mints the matching amount on L2. On the way back, the user burns on L2, an operator signs a message, and the L1 vault releases the tokens.

Break the promise and you mint money that does not exist. That is why bridges are the highest-value target in the ecosystem. Poly Network lost about $611M in 2021 from a single authentication flaw, and the pattern has repeated every year since.

Boss Bridge is a small version of this design:

| Contract | What it does | Lines |
| --- | --- | --- |
| `L1BossBridge` | Deposits, withdrawals, signature verification | 157 |
| `L1Vault` | Holds locked tokens, approves the bridge | 25 |
| `TokenFactory` | Deploys new ERC20 tokens | 45 |
| `L1Token` | The bridged ERC20 | 13 |

Scope: `audit-by-ayaan` branch, cut from `main` because the commit hash listed in the onboarding material was stale. That is worth saying out loud: an audit is only valid for an exact commit, and if the hash in the docs does not resolve, you cut your own branch and record it.

---

## 2\. How I audited it

Order of work:

1. **Onboarding and sizing.** Read the docs, pull the repo, check the commit, run `cloc` / Solidity Metrics for nSLoc and complexity so I know how big the surface actually is.
2. **Static analysis first.** Slither across 22 contracts, 13 results. Aderyn gave 1 High and 10 Low. Neither tool found the bugs below. What they gave me was a map of where to look manually.
3. **Manual review, protocol first.** I read the deposit path, then the withdrawal path, then the deployment helper. Tools tell you where code is unusual; they do not tell you what the protocol promises and where that promise breaks.
4. **Proof of Concept for every High.** Foundry tests, one per finding, named with an `_AUDIT` suffix so the suite is self-documenting.

The whole audit produced 10 findings: 4 High, 6 Informational. Two of the Highs are not really two bugs, they are one authorised hole that produces two different attacks. That is the part I want to show you, because it is the difference between reading code and thinking like an attacker.

---

## 3\. Findings at a glance

| ID | Severity | Finding | Contract |
| --- | --- | --- | --- |
| H-1 | High | `deployToken` uses raw bytecode `create`, which can never work on ZKsync Era | `TokenFactory` |
| H-2 | High | Arbitrary `from` in `depositTokensToL2`, anyone can deposit someone else's approved tokens | `L1BossBridge` |
| H-3 | High | `from = address(vault)` self-transfer, unlimited unbacked mint on L2 | `L1BossBridge` |
| H-4 | High | Signature verified but never marked used, one signed withdrawal replays forever | `L1BossBridge` |
| I-1 | Info | `INITIAL_SUPPLY` large numeric literal, use scientific notation | `L1Token` |
| I-2 | Info | No zero address check for `token` in `L1Vault` | `L1Vault` |
| I-3 | Info | `DEPOSIT_LIMIT` never changes, should be `constant` | `L1BossBridge` |
| I-4 | Info | `Deposit` emitted after the external call, no CEI ordering | `L1BossBridge` |
| I-5 | Info | Unbounded `message` length in `sendToL1` | `L1BossBridge` |
| I-6 | Info | `L1Vault.token` set once in the constructor, should be `immutable` | `L1Vault` |

---

## 4\. H-2: anyone can deposit on someone else's behalf

The deposit function takes the address to pull tokens from as a parameter:

```solidity
function depositTokensToL2(
    address from,
    address l2Recipient,
    uint256 amount
) external whenNotPaused {
    if (token.balanceOf(address(vault)) + amount > DEPOSIT_LIMIT) {
        revert L1BossBridge__DepositLimitReached();
    }
    token.safeTransferFrom(from, address(vault), amount);

    // off-chain relayer mints `amount` to `l2Recipient` on L2
    emit Deposit(from, l2Recipient, amount);
}
```

`from` is a parameter and `msg.sender` is never compared to it. Every user who wants to use the bridge has to `approve` it first, and that approval is the only thing `transferFrom` needs. So the attacker never needs the victim to do anything beyond the approval they were going to give anyway.

Attack:

1. Victim approves the bridge for their balance. Normal usage.
2. Attacker calls `depositTokensToL2(victim, attacker, victimBalance)`.
3. Tokens move victim to vault. The `Deposit` event credits the attacker on L2.

The victim loses their L1 tokens and receives nothing on L2. The attacker spends gas and nothing else.

The PoC:

```solidity
function test_CanExploitFundsOfOtherUsers_AUDIT() public {
    vm.prank(user);
    token.approve(address(tokenBridge), type(uint256).max);
    uint256 depositAmount = token.balanceOf(user);

    address attacker = makeAddr("attacker");
    vm.startPrank(attacker);
    vm.expectEmit(address(tokenBridge));
    emit Deposit(user, attacker, depositAmount);

    tokenBridge.depositTokensToL2(user, attacker, depositAmount);

    assertEq(token.balanceOf(user), 0);
    assertEq(token.balanceOf(address(vault)), depositAmount);
    vm.stopPrank();
}
```

```bash
forge test --mt test_CanExploitFundsOfOtherUsers_AUDIT -vv
```

The fix is one line: stop taking `from` from the caller, take it from `msg.sender`.

```diff
-    function depositTokensToL2(address from, address l2Recipient, uint256 amount) external whenNotPaused {
+    function depositTokensToL2(address l2Recipient, uint256 amount) external whenNotPaused {
         if (token.balanceOf(address(vault)) + amount > DEPOSIT_LIMIT) {
             revert L1BossBridge__DepositLimitReached();
         }
-        token.safeTransferFrom(from, address(vault), amount);
+        token.safeTransferFrom(msg.sender, address(vault), amount);
```

If a relayer genuinely needs to deposit on behalf of users, that is a different design: per-user signed orders with a nonce, or an EIP-2612 `permit` flow where the user signs the exact amount for the exact caller.

---

## 5\. H-3: the vault that deposits to itself

This is where H-2 stops being "someone can steal an approval" and becomes "anyone can mint infinite tokens".

The bridge constructor gives itself unlimited spending rights over the vault, which it needs for withdrawals:

```solidity
constructor(IERC20 _token) Ownable(msg.sender) {
    token = _token;
    vault = new L1Vault(token);
    // Allows the bridge to move tokens out of the vault to facilitate withdrawals
    vault.approveTo(address(this), type(uint256).max);
}
```

Now remember that `depositTokensToL2` does not care who `from` is. So pass `from = address(vault)`:

```solidity
token.safeTransferFrom(from, address(vault), amount);
emit Deposit(from, l2Recipient, amount);
```

That executes `transferFrom(vault, vault, amount)`. A self-transfer. The allowance exists, the call succeeds, and the vault's balance does not change by a single wei.

But the `Deposit` event still fires, and the off-chain relayer mints `amount` on L2 to `l2Recipient`.

And the deposit limit check reads the vault balance, which never moves on a self-transfer, so nothing stops the next call. Or the one after that.

```solidity
function test_InfiniteMintFromVault_AUDIT() public {
    address attacker = makeAddr("attacker");
    uint256 vaultBalance = 500 ether;

    deal(address(token), address(vault), vaultBalance);
    vm.startPrank(attacker);

    vm.expectEmit(address(tokenBridge));
    emit Deposit(address(vault), attacker, vaultBalance);
    tokenBridge.depositTokensToL2(address(vault), attacker, vaultBalance);

    // ... five more identical calls, every one of them emits and mints again

    vm.stopPrank();
}
```

Six calls, six `Deposit(vault, attacker, 500e18)` events, zero tokens moved on L1. The L2 supply is now unbacked by 3,000 tokens, and there is no upper bound on how many times it can repeat.

This is the finding I am most happy with, because it is not visible from any single function. `depositTokensToL2` looks like a deposit function. `L1Vault` looks like a passive holder. The constructor approval looks like plumbing. You only get the bug by holding all three in your head at once and asking "what if `from` is the vault". That is the whole job.

Fixes:

1. The `msg.sender` change from H-2 kills this class outright, because the caller can never be the vault.
2. If `from` must stay, reject protocol-controlled addresses explicitly.
3. Stop giving the bridge a blanket `type(uint256).max` approval over the vault. Approve per withdrawal, or move the transfer logic into the vault behind a signed order, so a self-transfer can never be mistaken for a real deposit.

---

## 6\. H-4: a signature you can spend twice

The withdrawal path builds a message and verifies it with `ECDSA.recover`:

```solidity
function sendToL1(uint8 v, bytes32 r, bytes32 s, bytes memory message) public nonReentrant whenNotPaused {
    address signer = ECDSA.recover(
        MessageHashUtils.toEthSignedMessageHash(keccak256(message)),
        v, r, s
    );

    if (!signers[signer]) {
        revert L1BossBridge__Unauthorized();
    }

    (address target, uint256 value, bytes memory data) = abi.decode(message, (address, uint256, bytes));

    (bool success, ) = target.call{value: value}(data);
    if (!success) {
        revert L1BossBridge__CallFailed();
    }
}
```

The signature is checked. The signer is checked. What is missing is the third thing every signature scheme needs: a record that this exact message has already been used.

There is no nonce, no chain id, no deadline, and no `usedDigest` mapping. A valid signature is valid forever, and valid as many times as you submit it. `nonReentrant` does not help, because each replay is a separate transaction.

The PoC: the operator signs one withdrawal of `100e18`, and the test submits the same `v, r, s` in a loop until the vault is empty.

```solidity
// one operator signature, replayed until the vault is empty
while (token.balanceOf(address(vault)) > 0) {
    tokenBridge.withdrawTokensToL1(attacker, attackerInitialBalance, v, r, s);
}
assertEq(token.balanceOf(attacker), attackerInitialBalance + vaultInitialbalance);
assertEq(token.balanceOf(address(vault)), 0);
```

Fix pattern:

1. Track used signatures: `mapping(bytes32 digest => bool used)`, revert if already used, set it before the external call.
2. Put a nonce and `block.chainid` inside the signed payload. EIP-712 with a domain separator gives you both, plus typed data that wallets can display correctly.
3. Add a deadline so a signature leaked years later is worthless.

---

## 7\. H-1: the contract that cannot deploy on ZKsync

`TokenFactory` deploys tokens from bytecode handed in at runtime:

```solidity
function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
    assembly {
        addr := create(0, add(contractBytecode, 0x20), mload(contractBytecode))
    }
    s_tokenToAddress[symbol] = addr;
    emit TokenDeployed(symbol, addr);
}
```

The client deploys this factory on Ethereum Mainnet and on ZKsync Era. On EraVM that cannot work, and the official docs use this exact snippet as their example:

> "using `create`/`create2` in assembly blocks is unsafe, because the compiler will most likely silently produce broken bytecode... For instance, the following code will never work because contracts cannot be deployed on EraVM using any kind of bytecode."

The reason is structural: on ZKsync the operator must know the contract's code before the transaction is submitted. Deployment passes a bytecode hash to the `ContractDeployer` system contract, and the bytecode itself travels in the transaction's `factory_deps` field. Bytecode supplied as a runtime argument is unknown at submission time, so there is nothing to hash.

The impact is not a fund loss, it is a dead feature that works on one chain and silently fails on the other. That is the kind of bug that ships, because staging on Mainnet says everything is fine.

Fix: stop accepting arbitrary bytecode. Deploy a known contract type with constructor arguments, so the compiler knows the creation code and the zkSync tooling can put it in `factory_deps`.

```diff
-    function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
-        assembly {
-            addr := create(0, add(contractBytecode, 0x20), mload(contractBytecode))
-        }
+    function deployToken(string memory symbol, string memory name, uint256 initialSupply) public onlyOwner returns (address addr) {
+        L1Token token = new L1Token(name, symbol, initialSupply);
+        addr = address(token);
```

One more note: do not "fix" this by swapping `create` for `create2`. The same docs page says assembly `create2` is unsafe on EraVM too.

---

## 8\. What I would do differently

- **I read the deposit path before the vault.** H-3 came late because I looked at `depositTokensToL2` in isolation first. Next time the constructor approval in `L1BossBridge` goes on the list in the first ten minutes, because "who has unlimited allowance over the money" is the question that finds these bugs.
- **Static analysis gave me almost nothing here.** 13 Slither results, none of them the four Highs. Tools are a map, not a finding list. I now timebox tool triage to 30 minutes and spend the rest on protocol reading.
- **Every High needs a test, no exceptions.** Three of these have a passing PoC in the repo. The one that does not (H-1) has the official documentation as proof instead, which is stronger than a test I write against my own assumption.

---

## 9\. Repo, report, and what is next

- Audit repo with all findings, PoCs and reports: <https://github.com/moayaan1911/security>
- Full 17-page Boss Bridge report (all 10 findings, PoCs, severity reasoning, fixes): [Boss Bridge report (PDF)](https://github.com/moayaan1911/security/blob/main/07-bridge_audit/audit_data/report.pdf)
- Previous post: "What I Learnt From My First Smart Contract Audit" on Medium

Next in this series: TSwap, an AMM with 22 findings, a wrong fee formula, and an invariant test suite that took longer to write than the audit itself.

---

## Disclaimer

This was a **mock audit for learning purposes**, performed against Cyfrin Updraft's Boss Bridge training codebase as part of the Cyfrin Updraft Smart Contract Security course. It is not a paid engagement, not a security guarantee, and not a review of any deployed protocol. All vulnerabilities described here exist in a deliberately vulnerable teaching repo. Nothing in this post is financial or security advice. If you are shipping a bridge, get a real audit from a qualified firm, and remember that an audit is a point-in-time snapshot, not a proof of safety.

---

## About the author

I am MD Ayaan Siddiqui, a blockchain developer from India with 2+ years of production experience. I have built and shipped contracts for a DeFi stablecoin protocol audited by Cyfrin and ScaleBit, worked on hardware wallet features at Cypherock, and published pre-print research on cross-chain agentic infrastructure.

Currently working through smart contract security full time: five practice audits so far (PasswordStore, Puppy Raffle, TSwap, Thunder Loan, Boss Bridge), 62 findings, all with reports and PoCs in the repo.

- Portfolio: <https://moayaan.com>
- GitHub: <https://github.com/moayaan1911>
- X: <https://x.com/moayaan1911>
- Telegram: <https://t.me/moayaan1911>
- Medium: <https://medium.com/@moayaan.eth>

If you are hiring for audit or security work, or you want a second pair of eyes on a Solidity codebase, my inbox is open.
