Skip to content

blockifier: record pre-migration compiled class hash as initial read#14612

Closed
yoavGrs wants to merge 1 commit into
mainfrom
yoav/migration-initial-reads-fix
Closed

blockifier: record pre-migration compiled class hash as initial read#14612
yoavGrs wants to merge 1 commit into
mainfrom
yoav/migration-initial-reads-fix

Conversation

@yoavGrs

@yoavGrs yoavGrs commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

When migrating a class's compiled class hash, set_compiled_class_hash_migration
wrote the post-migration (v2) value into the write cache without first recording
the pre-block (v1) value as an initial read. Since get_compiled_class_hash
resolves the write cache before the initial reads, the v2 write shadowed the
pre-block value, so it was never captured. This made to_state_diff panic in
strict_subtract_mappings (the migrated write had no matching initial read to
subtract against) and left the OS without the pre-block class-trie leaf needed to
replay the block.

Force-read the pre-migration compiled class hash into the initial reads before
applying the migration write, and add a unit test covering the fix.

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

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

yoavGrs commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@yoavGrs yoavGrs self-assigned this Jun 23, 2026
@yoavGrs yoavGrs marked this pull request as ready for review June 23, 2026 13:32
@cursor

cursor Bot commented Jun 23, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches block execution state accounting for class-hash migration; the change is small and tested but affects correctness of diffs and OS replay.

Overview
Fixes compiled class hash migration so the pre-block (v1) value is recorded in CachedState initial reads before the v2 write is applied. set_compiled_class_hash_migration now calls get_compiled_class_hash ahead of set_compiled_class_hash, so the v2 cache entry no longer hides the on-chain v1 hash.

That restores correct to_state_diff behavior (avoids strict_subtract_mappings panics when the migrated write had no matching initial read) and preserves the pre-block class-trie leaf data the OS needs for block replay.

Adds a focused unit test that checks the post-migration hash, the diff, and (with reexecution) initial reads.

Reviewed by Cursor Bugbot for commit cdbf3ab. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

Artifacts upload workflows:

When migrating a class's compiled class hash, `set_compiled_class_hash_migration`
wrote the post-migration (v2) value into the write cache without first recording
the pre-block (v1) value as an initial read. Since `get_compiled_class_hash`
resolves the write cache before the initial reads, the v2 write shadowed the
pre-block value, so it was never captured. This made `to_state_diff` panic in
`strict_subtract_mappings` (the migrated write had no matching initial read to
subtract against) and left the OS without the pre-block class-trie leaf needed to
replay the block.

Force-read the pre-migration compiled class hash into the initial reads before
applying the migration write, and add a unit test covering the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yoavGrs yoavGrs force-pushed the yoav/migration-initial-reads-fix branch from 94279be to cdbf3ab Compare June 23, 2026 14:42
@yoavGrs yoavGrs requested a review from Yoni-Starkware June 23, 2026 14:53

@Yoni-Starkware Yoni-Starkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoni-Starkware made 1 comment.
Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on yoavGrs).


crates/blockifier/src/state/compiled_class_hash_migration.rs line 36 at r1 (raw file):

            // Capture the pre-block (v1) hash as an initial read before the v2 write shadows it.
            self.get_compiled_class_hash(*class_hash)?;

Every migrated class should have triggered a call to get_compiled_class_hash before this point. See here:

let state_compiled_class_hash = state_reader.get_compiled_class_hash(class_hash)?;

Also, it's clear from the function API - it gets the previous compiled class hash, so not sure why this read is needed

Code quote:

            // Capture the pre-block (v1) hash as an initial read before the v2 write shadows it.
            self.get_compiled_class_hash(*class_hash)?;

@yoavGrs yoavGrs closed this Jun 23, 2026
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