Skip to content

fix: clear dst1 to zero#110

Open
0xVolosnikov wants to merge 1 commit into
masterfrom
vv/dst1-clear
Open

fix: clear dst1 to zero#110
0xVolosnikov wants to merge 1 commit into
masterfrom
vv/dst1-clear

Conversation

@0xVolosnikov

Copy link
Copy Markdown
Contributor

Change

Mirrors zk_evm's mechanism

zk_evm pin

Bumped zk_evm/zkevm_opcode_defs/zk_evm_abstractions to ac58f328 (v0.153.12)

@0xVolosnikov 0xVolosnikov requested a review from a team as a code owner July 2, 2026 22:14
@0xVolosnikov 0xVolosnikov requested a review from dimazhornyk July 2, 2026 22:14
Before executing each opcode, zk_evm clears the decoded dst1 register and,
after execution, leaves it at zero unless the instruction produced a second
output (see zksync-protocol#222). vm2 previously left dst1 untouched, so an
instruction with a "dirty" non-r0 dst1 field, or one that panics before
writing dst1 (UMA read with increment), could leave dst1 in a different state
than zk_evm. A panic caught by a near-call frame does not reset registers, so
the divergence is observable.

Mirror zk_evm's behavior:

- Store the dst1 register for every opcode during decoding (it already fits in
  the destination register slot of Arguments).
- Track whether the second output was written (Mul/Div and UMA reads with
  increment) via a transient State flag.
- In full_boilerplate, after the business logic runs, clear dst1 to zero unless
  it was written. The clear happens after the primary output so that a
  dst0/dst1 alias resolves to zero, and after pre-execution panics have already
  returned, matching zk_evm's opcode masking.

Bump the zk_evm pin to a commit that includes the matching reference fix, and
add regression tests for the alias and UMA-increment-panic cases.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant