Skip to content

Implement dynamic storage based StorageVec#7614

Open
ironcev wants to merge 16 commits intomasterfrom
ironcev/dynamic-storage-storage-vec
Open

Implement dynamic storage based StorageVec#7614
ironcev wants to merge 16 commits intomasterfrom
ironcev/dynamic-storage-storage-vec

Conversation

@ironcev
Copy link
Copy Markdown
Member

@ironcev ironcev commented Apr 30, 2026

Description

This PR is an additional step in implementing #7560. It implements StorageVec<V> for dynamic storage.

Additionally the PR:

  • adds comprehensive test coverage for StorageVec in the form of in-language tests. Existing SDK harness tests are deleted in favor of new in-language tests. This is aligned with the agreed strategy to migrate SDK harness tests to in-language tests.
  • closes StorageVec::insert() does not work with nested storage types #6040 by properly documenting the semantics of zero-sized types in relation to storage. Every StorageVec<V> methods that does not work with zero-sized types, which are assumed to be nested storage types, is now documented for limitations.
  • fixes Fix StorageVec<V>::store_vec and load_vec for non-aligned types #7618 by accepting non-aligned types of any size in store_vec and load_vec and padding them accordingly.
  • fixes existing issue of over-allocating memory and having larger amount of slot writes than needed in the quads-based implementation of store_vec.
  • consistently add reverts to all existing StorageVec<V> methods in the quads-based implementation that cannot be used with nested storage types. For more details see Breaking Changes below.

When running in-language tests using forc test on the whole workspace two blocking issues occur:

Workarounds for those issues are commented in code and linked to the issues.

Additional in-language tests for other storage types will be added in a separate PR.

Breaking Changes

Existing StorageVec<V> methods in the quads-based implementation that cannot be used with nested storage types, e.g., swap now consistently reverts if V is a nested storage type.

Previously, those methods:

  • sometimes always reverted,
  • sometimes reverted in specific paths,
  • sometimes executed with undefined behavior.

Consistently reverting can be a breaking change if some existing code called these methods and they were not reverting. Note that such calls represent invalid usage of the storage API (although it was up to now not clearly documented as such) and reverting will actually point to bugs in existing callers code.

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Apr 30, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 30, 2026

PR Summary

High Risk
High risk because it adds a new StorageVec implementation for experimental_dynamic_storage and changes behavior for nested/zero-sized element types (new panics/reverts) plus modifies storage read/write intrinsics coverage, all of which can affect on-chain storage semantics and test stability.

Overview
Implements a dynamic-slot-backed StorageVec<V> (#[cfg(experimental_dynamic_storage = true)]), including new error types (StorageVecError, OutOfBounds) and method implementations that differentiate between non-storage vs nested storage (zero-sized) element types.

Tightens StorageVec semantics for nested storage types across implementations by adding explicit checks/reverts/panics and updating docs; also fixes store_vec/load_vec padding to support any non-word-aligned element sizes (and reduces over-allocation/extra writes in the quads-based path).

Reworks test execution and coverage: CI and justfile now run in-language tests via a new run_in_language_tests.sh (per-project forc test workaround), adds many new in-language contract tests for StorageKey/StorageVec (including dynamic-storage variants) while removing an older storage_vec_insert SDK-harness test, and extends VM/intrinsics tests (e.g., zero-length slot updates/truncation) with updated snapshots.

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

@ironcev ironcev added the lib: std Standard library label Apr 30, 2026
@ironcev
Copy link
Copy Markdown
Member Author

ironcev commented Apr 30, 2026

👍

@ironcev ironcev added the breaking May cause existing user code to break. Requires a minor or major release. label Apr 30, 2026
@ironcev ironcev changed the title Implement dynamic storage StorageVec Implement dynamic storage based StorageVec Apr 30, 2026
Comment thread test/src/in_language_tests/run_in_language_tests.sh
@ironcev ironcev temporarily deployed to fuel-sway-bot May 1, 2026 07:43 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot May 1, 2026 13:40 — with GitHub Actions Inactive
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.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit f6e7fd7. Configure here.

Comment thread sway-lib-std/src/storage/storage_vec.sw
@ironcev ironcev temporarily deployed to fuel-sway-bot May 2, 2026 13:31 — with GitHub Actions Inactive
@ironcev ironcev marked this pull request as ready for review May 2, 2026 15:42
@ironcev ironcev requested review from a team as code owners May 2, 2026 15:42
@ironcev ironcev enabled auto-merge (squash) May 2, 2026 15:42
@ironcev ironcev requested review from Dentosal, bitzoic and xunilrj May 2, 2026 15:42
@ironcev ironcev temporarily deployed to fuel-sway-bot May 3, 2026 11:49 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot May 4, 2026 07:13 — with GitHub Actions Inactive
/// at all, or if it has any limitations or exceptional behaviors,
/// refer to method documentation.
#[cfg(experimental_dynamic_storage = true)]
pub struct StorageVec<V> {}
Copy link
Copy Markdown
Contributor

@xunilrj xunilrj May 7, 2026

Choose a reason for hiding this comment

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

What is the difference from the declaration above? I am only seeing a small diff on the doc-comments. I think it makes more sense to keep just one and make the difference more explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking May cause existing user code to break. Requires a minor or major release. lib: std Standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix StorageVec<V>::store_vec and load_vec for non-aligned types StorageVec::insert() does not work with nested storage types

2 participants