Skip to content

fix(l2genesis): explicitly initialize WETH storage slots after vm.etch - #372

Open
dev-khimesh wants to merge 1 commit into
base:mainfrom
dev-khimesh:fix/l2genesis-weth-storage-init
Open

fix(l2genesis): explicitly initialize WETH storage slots after vm.etch#372
dev-khimesh wants to merge 1 commit into
base:mainfrom
dev-khimesh:fix/l2genesis-weth-storage-init

Conversation

@dev-khimesh

Copy link
Copy Markdown

Description

The setWETH() function deploys the WETH predeploy via vm.etch, which skips constructor execution. While the WETH contract:

  • Has pure name()/symbol() reading from L1Block (no storage)
  • Has constant decimals (no storage slot)
  • Has _balanceOf (slot 0) and _allowance (slot 1) that correctly start empty

This change adds explicit vm.store calls to zero both storage slots for audit clarity and updates the NatSpec to document the safety invariant.

Changes

  1. Added vm.store calls for _balanceOf (slot 0) and _allowance (slot 1)
  2. Updated NatSpec comment with detailed storage layout documentation

Test Plan

  • Existing L2Genesis tests (L2Genesis.t.sol) already verify WETH bytecode is set: assertGt(Predeploys.WETH.code.length, 0)
  • Genesis WETH should return correct name() / symbol() via L1Block
  • Genesis WETH should return decimals = 18

Closes #357

@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

The setWETH() function uses vm.etch to deploy WETH bytecode, which skips constructor execution. While the WETH contract has no constructor side effects (name/symbol are pure L1Block readers, decimals is constant, and mappings correctly start empty), this change makes the initialization explicit by:

1. Zeroing _balanceOf (slot 0) and _allowance (slot 1) via vm.store for clarity
2. Updating the NatSpec comment to document why each storage slot is correct

This addresses Lumi audit finding base#357 and makes the safety invariant auditable at a glance.

Closes base#357
@dev-khimesh
dev-khimesh force-pushed the fix/l2genesis-weth-storage-init branch from 0b83314 to a9babf2 Compare August 4, 2026 11:35
@dev-khimesh

Copy link
Copy Markdown
Author

Hi maintainers — friendly bump on this L2Genesis.s.sol fix that explicitly initializes WETH storage slots after vm.etch. Rebased against latest main (StepSecurity CI green). Open ~3.5 weeks — a review would be appreciated. Happy to adjust on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants