Skip to content

Dynamic storage: Charge gas for new bytes properly#989

Closed
Dentosal wants to merge 7 commits intomasterfrom
dento/dynamic-storage-new-bytes
Closed

Dynamic storage: Charge gas for new bytes properly#989
Dentosal wants to merge 7 commits intomasterfrom
dento/dynamic-storage-new-bytes

Conversation

@Dentosal
Copy link
Copy Markdown
Member

@Dentosal Dentosal commented Feb 26, 2026

Follow-up to: #982

Part of: #987

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 26, 2026

PR Summary

High Risk
Changes gas metering for dynamic storage opcodes, which is consensus/validity-critical and can alter transaction acceptance and execution costs. Adds a new in-VM cache that affects charging behavior across repeated writes within an execution.

Overview
Fixes dynamic storage gas accounting so SWRD/SWRI and SUPD/SUPI charge additional new_storage_per_byte gas only for bytes that grow a slot, not for overwrites.

Adds an Interpreter-level storage_slot_size_cache keyed by (ContractId, Bytes32) and updates storage read/write/update/preload paths to populate it and use it when computing “new bytes” charges; dynamic storage opcode execution is refactored to call new helper methods (dynamic_storage_read/write/update) that encapsulate the updated gas charging.

Updates tests by raising a helper script gas limit and adding a regression test asserting the second write of the same length uses BYTES_TO_WRITE less gas than the first; includes a changelog entry.

Written by Cursor Bugbot for commit 31c78d6. This will update automatically on new commits. Configure here.

Comment thread fuel-vm/src/interpreter/executors/opcodes_impl.rs Outdated
Comment thread fuel-vm/src/interpreter/storage.rs
Comment thread fuel-vm/src/interpreter/storage.rs
Comment thread fuel-vm/src/interpreter/storage.rs
Comment thread fuel-vm/src/interpreter/storage.rs Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread fuel-vm/src/interpreter/storage.rs Outdated
@Dentosal Dentosal marked this pull request as ready for review March 2, 2026 14:58
@Dentosal Dentosal marked this pull request as draft March 4, 2026 17:32
@Dentosal Dentosal mentioned this pull request Mar 5, 2026
6 tasks
@Dentosal
Copy link
Copy Markdown
Member Author

Closing in favor of #996

@Dentosal Dentosal closed this Mar 10, 2026
@github-actions github-actions Bot mentioned this pull request Mar 10, 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.

1 participant