教育学习

ZKsync Era 协议防御复盘

回顾一次没有可提交发现的漏洞赏金审查,归纳协议防护、既有审计覆盖和投入取舍。

提示词

# LIVE HUNT: ZKsync Era (Immunefi) — COMPLETED, 0 FINDINGS

> **Outcome**: 0 submittable findings after 5+ sessions, 22+ agents, 25+ contracts, 25+ attack vectors
> **Lesson**: This file exists as a DEFENSE STUDY — what a hardened protocol looks like, and when to stop hunting.

---

## TARGET PROFILE

| Field | Value |
|-------|-------|
| Protocol | ZKsync Era (L2 rollup) |
| Platform | Immunefi |
| TVL | $322M (L2BEAT Total Value Secured) |
| Bounty | $100K minimum Critical, $1.1M max |
| Codebase | 750K LOC (Solidity + Rust + Yul) |
| Audits | OpenZeppelin V29 (June 2025), multiple prior audits |
| Version | Protocol V29.4 |
| Repo | `github.com/matter-labs/era-contracts` |
| Primacy | Primacy of Impact — even out-of-scope assets qualify |
| Prior payouts | $50K (ChainLight ZK circuit bug) |

### Pre-Dive Scorecard

| Check | Result | Score |
|-------|--------|-------|
| TVL > $500K | $322M | PASS |
| Max payout > $10K | $100K minimum | PASS |
| Simple protocol? | 750K LOC, L1↔L2 bridge + ZK + governance | PASS (complex) |
| < 500 lines? | 750K LOC | PASS |
| **Audit quality** | OpenZeppelin (top-tier) on ALL critical paths | **WARNING** |

> **REFINEMENT**: Pre-dive should weight audit quality MORE for large protocols.
> A protocol passing TVL/LOC/payout checks can still be unhuntable if OZ/ToB audited the exact code you'd hunt.
> Add "audit firm tier" as a SOFT kill signal for 500K+ LOC protocols.

---

## ARCHITECTURE (What Makes It Hardened)

### L1 Bridge Stack
```
Bridgehub (router)
  ├── L1AssetRouter (token routing)
  │     ├── L1Nullifier (deposit/withdrawal state)
  │     └── L1NativeTokenVault (token custody)
  ├── ChainTypeManager (chain registration)
  └── ValidatorTimelock (RBAC execution delay)
```

### L2 System Contracts (kernel space 0x8000-0xFFFF)
```
Bootloader (0x8001) → AccountCodeStorage, NonceHolder, KnownCodeStorage,
ImmutableSimulator, ContractDeployer, L1Messenger (0x8008),
MsgValueSimulator, L2BaseToken (0x800a), SystemContext (0x800b),
BootloaderUtilities, Compressor, ComplexUpgrader
```

### L2 User Space Contracts (0x10000+)
```
Create2Factory, Bridgehub, AssetRouter, NativeTokenVault, MessageRoot
```

### Diamond Proxy Pattern (EIP-2535)
- All facets (Admin, Executor, Mailbox, Getters) share single `ZKChainStorage` struct
- No storage collision possible between facets
- Function selectors explicitly mapped in DiamondCut

---

## ALL 25 ATTACK VECTORS TESTED

### Critical Path (Vectors 1-8)

| # | Vector | Target | Why It Failed |
|---|--------|--------|---------------|
| 1 | UnsafeBytes offset miscalculation | L1Nullifier `_parseL2WithdrawalMessage` | All callers pre-validate message length before UnsafeBytes calls |
| 2 | Legacy/new boundary double-withdrawal | L1Nullifier | `_isLegacyTxDataHash` try/catch returns false on decode failure; encoding prefix discriminator prevents collision |
| 3 | `secondBridgeAddress` return value manipulation | Bridgehub `requestL2TransactionTwoBridges` | `>0xFFFF` check blocks system contracts; L2-side `msg.sender` auth makes crafted returns useless |
| 4 | Failed deposit claim wrong amount (legacy encoding) | L1Nullifier `claimFailedDeposit` | Legacy hash uses try/catch; `depositHappened` correctly tracks per-encoding-version |
| 5 | V29 interop root forgery | Executor | `addChainBatchRoot` requires `onlyChain + onlyL2`; historical roots verified via Merkle |
| 6 | Missing access control on sibling function | All bridge contracts | Every external function has appropriate modifier; checked all 50+ external functions |
| 7 | Fee-on-transfer token accounting desync | NativeTokenVault | L1ERC20Bridge: `if (amount != _amount) revert TokensWithFeesNotSupported()` |
| 8 | Governance timelock bypass | ValidatorTimelock | 5-role RBAC via AccessControlEnumerable; `block.timestamp >= commitTimestamp + delay` |

### Extended Surface (Vectors 9-25)

| # | Vector | Why It Failed |
|---|--------|---------------|
| 9 | GatewayTransactionFilterer bypass | Era mainnet: `transactionFilterer == address(0)`, not used |
| 10 | Precommitment sentinel collision | `_revertBatches` properly resets precommitment; sentinel values don't collide |
| 11 | L2→L1 message forgery via `sendToL1` | Anyone can call `sendToL1`, but L1 verifies `sender=0x8008` in log — can't forge system log sender |
| 12 | Compressor state diff manipulation | `publishCompressedBytecode` called only from bootloader context |
| 13 | Admin privilege escalation | Diamond proxy admin is governance; no facet can self-modify |
| 14 | Fee calculation overflow | All fee math uses SafeMath or checked arithmetic |
| 15 | Free L2 transaction abuse | `reservedDynamic` field properly handled; bootloader validates gas |
| 16 | DataEncoding L1/L2 mismatch | All 10 encode/decode pairs verified consistent across L1↔L2 |
| 17 | NTV token registration race | `_ensureTokenRegistered` is idempotent; double registration returns same assetId |
| 18 | Asset ID collision | `keccak256(chainId, ntvAddress, tokenAddress)` — no collision possible |
| 19 | Beacon proxy CREATE2 collision | Standard CREATE2; address determined by deployer+salt+bytecodeHash |
| 20 | Cross-contract reentrancy | Each contract has independent ReentrancyGuard AND follows CEI |
| 21 | Address aliasing collision | Bijective mapping (add/subtract offset mod 2^160) |
| 22 | Diamond proxy selector clash | Explicit selector mapping in DiamondCut; duplicates would revert |
| 23 | Priority tree manipulation | Merkle range proofs; `unprocessedIndex` only moves forward |
| 24 | Chain migration state corruption | `forwardedBridgeMint` validates consistency; atomic revert on mismatch |
| 25 | Cross-chain message replay | `isWithdrawalFinalized[chainId][batch][index]` prevents replay |

---

## WHY THIS PROTOCOL IS UNHUNTABLE (Solidity Surface)

### Defense Pattern 1: CEI Everywhere
```solidity
// L1Nullifier._finalizeDeposit (line 411)
isWithdrawalFinalized[chainId][l2BatchNumber][l2MessageIndex] = true; // EFFECT first
// ... then external call to NTV
```
Every single withdrawal/claim/deposit path follows Check-Effect-Interact.

### Defense Pattern 2: Independent Access Control on L2
Each L2 system contract independently enforces access:
- `L2BaseToken.transferFromTo`: checks `msg.sender` against 3 allowed callers
- `L1Messenger.sendToL1`: open to anyone, but L1 verifies sender field in log
- `SystemContext`: `onlyCallFromBootloader` on all state-changing functions
- No single RBAC failure cascades

### Defense Pattern 3: Encoding Collision Resistance
```
LEGACY_ENCODING_VERSION = 0x00  (first byte)
NEW_ENCODING_VERSION    = 0x01  (first byte)
```
Different first byte = impossible to confuse one format for another.

### Defense Pattern 4: Mature Legacy Boundary Handling
Three bridge generations coexist cleanly:
1. L1ERC20Bridge (legacy wrapper → delegates to AssetRouter)
2. L1SharedBridge (previous → absorbed into AssetRouter/Nullifier)
3. L1AssetRouter + L1Nullifier (current)

Each boundary has explicit version checks, try/catch decoding, and fallback paths.

### Defense Pattern 5: Audit Fix Quality
V29 OZ audit found 3 HIGHs. All fixes were thorough — not just patches but architectural improvements.
The "least audited code" assumption (that fixes are hastily applied) did NOT hold here.

---

## STRATEGIC TAKEAWAYS

### When to Abandon a Large L1 Bridge Target
1. After systematically testing top 8 attack vectors (Days 1-2): if all blocked, ROI drops exponentially
2. If OZ/ToB audited the EXACT codebase version you're reviewing (not an older version)
3. If 22+ automated agents all return clean across all contracts
4. If encoding, access control, and CEI are all consistently applied with zero exceptions

### What Could Still Work on ZKsync
1. **ZK circuits** (Rust/RISC-V) — different skillset, different attack surface, prior $50K payout proves bugs exist there
2. **Bootloader assembly** (Yul) — 5000+ lines of hand-written Yul, complex gas accounting, less audited
3. **New code drops** (V30+) — fresh code = fresh bugs. Monitor `era-contracts` releases
4. **EVM emulation edge cases** — `EvmGasManager`, EVM opcode compatibility gaps
5. **Interop protocol** (when launched) — `L2InteropRootStorage` is minimal now, but interop = massive new surface

### Pre-Dive Scoring Refinement
Add to the scorecard:
```
SOFT KILL: If protocol has OZ/ToB/Cyfrin audit on current version AND codebase > 500K LOC
           → expect 40+ hours for MAYBE 1 finding
           → only proceed if bounty floor > $50K AND you have protocol-specific expertise
```

---

同类提示词

教育学习

带时间戳的讲座复习笔记

提供带时间信息的讲座转录稿,按授课顺序整理主题、定义和关键内容,方便回看对应片段。

# 身份与目的 作为一名条理清晰、技艺精湛的专业讲师,你的任务是从讲座逐字稿中提取最相关的主题,并使用项目符号和定义列表,为每个主题提供结构化总结。你还要标注时间戳,指出这些主题在视频中出现的位置。 退一步思考,逐步想清楚如何完成这项工作。你可能会先通过逐字稿“观看”视频,记下讲座中的每个定义;由于你做事有条理,你还会为讲座中所有相关主题拟定标题并列出清单,拆解复杂部分。你可能还会记下讨论过的主题及其讨论时间。然后,根据这些笔记整理出主题和时间戳列表。 # 步骤 完整阅读逐字稿,就像正在观看或聆听内容一样。 深入思考所学到的主题,以及内容中最相关的
教育学习· Google Flow / Gemini

纸质答题卡静默勾选问答视频

选题类和题量,生成同页答题纸和Google Flow场景指令,每题读完静默五秒,再手勾正确答案。

教育问答视频提示词系统 你是一名专业的问答内容策划、教育视频导演、题目编写者、图像提示词工程师和 Google Flow 视频提示词工程师。 你的任务是使用一张真实的纸质答题卡,制作简短、有趣的教育问答视频。 每道题的固定流程: 朗读题目 → 停止说话 → 静默思考 5 秒 → 手在正确选项旁打勾 必须严格按照以下流程执行,不得跳过步骤。 第一步:选择问答类别 启动后,只显示以下 10 个类别: 综合知识 人体知识 科学 数学 地理 动物与自然 太空与宇宙 历史 心理与大脑 综合脑力挑战 请用户选择一个类别。此时不要生成题目。 第二步
需参考图中文原创
教育学习

家庭网络覆盖规划与设备选型

提供住宅与联网需求,获得分步搭建方案、设备推荐和平价替代,并比较覆盖、速度和预算的取舍。

# 网络工程师:家庭版 – Mr. Data 模式 v2.0.3 ## 作者 - Scott Malin, CISSP ## 目标 以《星际迷航》中 *Mr. Data* 的风格,扮演一位严谨、善于分析的网络工程师。收集用户家庭环境的精确信息,提供详细的分步网络配置方案,包含各项取舍、硬件推荐、兼顾预算的替代方案,以及符合现实的可行性评估。 ## 目标受众 - 正在搭建或升级家庭网络的房主或租户 - 需要可靠网络连接的远程工作者 - 拥有多台设备的家庭(流媒体、游戏、智能家居) - 预算有限的技术爱好者 - 希望获得条理清晰、不夸大其词的指导的非专
可填 2 项
教育学习

Claude使用技巧随聊教练

说明你最常用的两三种场景,先获得个性化技巧,再在日常对话遇到合适时机时收到改进建议。

# Claude 教练——你的进阶用户伙伴 在正常对话中并行运行的指导层。它会教用户了解 Claude 实际能做什么,再通过实时发现错过的机会,不断强化所学。 ## 何时调用此技能 **首次激活时**(用户明确要求学习): - “教我使用 Claude” - “让我成为 Claude 的进阶用户” - “有哪些使用秘诀?” - “教我如何更好地使用 Claude” - “我怎样才能更充分地利用 Claude?” **此后的每一轮对话**(被动指导模式): 首次激活后,此技能持续开启。每次回复时,留意是否有适合指导的时机。大多数轮次不会给出任何提示
可填 1 项
教育学习

俯视角三车道像素赛车游戏

生成单文件 HTML5 网页游戏,玩家用键盘或触屏换道躲避路障,难度随分数和等级上升。

## 角色 (Role) 资深HTML5游戏开发者。 ## 任务 (Task) 创建一款单文件、像素风格的HTML5俯视角赛车躲避游戏,具备以下特性,确保代码清晰、可玩性高且难度递增。 ## 格式 (Format) 1. 核心玩法 玩家控制赛车在三车道公路上躲避迎面障碍物,生命耗尽则游戏结束。 2. 操控 键盘: 左右箭头键切换车道。 触摸: 屏幕底部提供左右虚拟方向按钮(⬅️、➡️)切换车道。 3. 视觉与界面 主题: 深色主题 (例如,背景 #1a202c, 容器 #2d3748)。UI元素使用Tailwind CSS。 画布: 默认尺寸 50
中文原创
教育学习

单门课程专属辅导与备考计划

填写课程、当前水平与备考偏好,可贴学习材料,先分析学习重点,再按确认的计划辅导。

==================================================================== 角色 ==================================================================== 你是我针对一门课程的顶级私人导师,集五位专家的能力于一身: • 顶尖大学教授(深入、严谨、从第一性原理清晰讲解) • 奥林匹克竞赛教练(解题直觉、模式识别、速度) • 认知科学家(设计我的学习方式,而不只是学习内容) • 一对一私人导师(耐心、灵活调整、始终聚焦
可填 3 项
✓