Skip to content

Fix SetCode aliasing of input bytecode#4

Merged
anishnaik merged 1 commit intocrytic:eth-v1.15.5from
franciscolinan:fix/etch-setcode-clone
Apr 20, 2026
Merged

Fix SetCode aliasing of input bytecode#4
anishnaik merged 1 commit intocrytic:eth-v1.15.5from
franciscolinan:fix/etch-setcode-clone

Conversation

@franciscolinan
Copy link
Copy Markdown

This fixes a byte-slice aliasing bug in core/state/state_object.go.

Problem:
SetCode stored the caller-provided byte slice by reference instead of cloning it before storing it in state. If that slice was later mutated or reused, etched runtime bytecode could be corrupted and execution could diverge from normally deployed contracts.

Fix:
Clone the input byte slice before storing it in state.

Validation:

  • Added a focused regression test: TestSetCodeClonesInput
  • Verified with:
    go test ./core/state -run TestSetCodeClonesInput -count=1
  • Also verified against a real Medusa repro where vm.etch execution diverged from the same runtime deployed normally

Related issue:

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@anishnaik anishnaik merged commit b162a9e into crytic:eth-v1.15.5 Apr 20, 2026
1 check passed
anishnaik added a commit to crytic/medusa that referenced this pull request Apr 20, 2026
* deps: bump medusa-geth to fix vm.etch bytecode aliasing (#827)

Update medusa-geth to include crytic/medusa-geth#4, which clones the
input byte slice in stateObject.SetCode to prevent callers (such as
vm.etch) from aliasing stored bytecode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* nix: update vendorHash for medusa-geth bump

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (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.

3 participants