Skip to content

fix(precompile-storage): clear stale dynamic tail chunks after Cobalt#3987

Open
arjun-dureja wants to merge 2 commits into
mainfrom
arjundureja/bop-339-24-dynamic-storage-shrink-overwrites-leave-stale-tail-slots
Open

fix(precompile-storage): clear stale dynamic tail chunks after Cobalt#3987
arjun-dureja wants to merge 2 commits into
mainfrom
arjundureja/bop-339-24-dynamic-storage-shrink-overwrites-leave-stale-tail-slots

Conversation

@arjun-dureja

Copy link
Copy Markdown

Summary

  • clear retired backing slots when shorter Bytes, String, or Vec<T> values overwrite longer values
  • preserve legacy storage and gas behavior before Cobalt
  • route zero writes through normal SSTORE accounting so EIP-2200/EIP-3529 refunds propagate

Implementation

  • add typed StorageSemantics::{Legacy, Cobalt} selected by BasePrecompiles
  • thread the selected semantics through direct and dynamically looked-up B-20 precompiles
  • clear long bytes/string chunks before writing new metadata
  • clear fully retired packed vector slots and recursively delete retired unpacked elements
  • preserve handler-based vector pushes so reused pre-Cobalt dynamic slots are cleaned correctly
  • reject static writes before preparatory cleanup SLOADs

Scope

This prevents new stale tails at and after Cobalt and cleans legacy tails when their metadata remains reachable. Historical orphaned slots whose old length metadata was already overwritten cannot be discovered without a separate state migration or high-water metadata.

Testing

  • cargo +nightly fmt --all -- --check
  • cargo test -p base-precompile-storage --all-features
  • cargo test -p base-common-precompiles
  • cargo test -p base-common-evm
  • cargo check -p base-precompile-storage --no-default-features
  • RISC0_SKIP_BUILD_KERNELS=1 BASE_SUCCINCT_ELF_STUB=1 cargo clippy -p base-precompile-storage -p base-common-precompiles -p base-common-evm --all-targets -- -D warnings

References

@linear

linear Bot commented Jul 16, 2026

Copy link
Copy Markdown

BOP-339

@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 0
Sum 1

@arjun-dureja
arjun-dureja force-pushed the arjundureja/bop-339-24-dynamic-storage-shrink-overwrites-leave-stale-tail-slots branch 2 times, most recently from c9b7b7f to c7259cc Compare July 17, 2026 17:41
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
@arjun-dureja
arjun-dureja force-pushed the arjundureja/bop-339-24-dynamic-storage-shrink-overwrites-leave-stale-tail-slots branch from c7259cc to 588372f Compare July 17, 2026 17:46
precompiles,
admin_config,
observer,
StorageSemantics::Legacy,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

install_with_observer hardcodes StorageSemantics::Legacy, unlike the other precompiles (B20Factory, PolicyRegistryPrecompile, BerylLookup) which derive semantics from the upgrade parameter. If a caller uses ActivationRegistry::install_with_observer directly at Cobalt, they'd silently get Legacy semantics.

This is safe today because the central BasePrecompiles::install_with_observer always passes the correct semantics, but consider adding an upgrade parameter (or at least a doc comment warning that this always uses Legacy) to keep the API consistent and prevent future misuse.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in 044530b. Activation Registry convenience paths now derive StorageSemantics::Legacy vs StorageSemantics::Cobalt from ActivationAdminConfig::state_enabled, including install_with_config, install_with_observer, and precompile_with_observer. Added a focused test covering static-fallback and state-backed configurations.

@arjun-dureja arjun-dureja changed the title fix(precompile-storage): clear stale dynamic tails after Cobalt fix(precompile-storage): clear stale dynamic tail chunks after Cobalt Jul 17, 2026
Co-authored-by: OpenCode <opencode-noreply@coinbase.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.

2 participants