Skip to content

Add StorageVec support#86

Open
smiasojed wants to merge 15 commits into
mainfrom
sm/vec
Open

Add StorageVec support#86
smiasojed wants to merge 15 commits into
mainfrom
sm/vec

Conversation

@smiasojed
Copy link
Copy Markdown
Collaborator

@smiasojed smiasojed commented May 27, 2026

This PR adds first-class support for Solidity-compatible dynamic arrays via StorageVec in the pvm-storage typed-storage layer, and extends the storage codec to support fixed-size arrays [T; N] (for T != u8) so arrays can be used inside Lazy, Mapping, and StorageVec while preserving solc’s storage layout rules.

Changes:

Introduces StorageVec (plus nested StorageVec<StorageVec> and Mapping<K, StorageVec>) with solc-compatible length/body addressing, packing, and clearing semantics.
Adds [T; N] storage encoding/decoding gated by a new StorageArrayElement marker trait, and auto-derives StorageArrayElement for static SolType structs.
Adds extensive StorageVec layout/behavior tests and new template examples/bench variants showcasing typed-storage usage.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds first-class support for Solidity-compatible dynamic arrays via StorageVec<T> in the pvm-storage typed-storage layer, and extends the storage codec to support fixed-size arrays [T; N] (for T != u8) so arrays can be used inside Lazy, Mapping, and StorageVec while preserving solc’s storage layout rules.

Changes:

  • Introduces StorageVec<T> (plus nested StorageVec<StorageVec<T>> and Mapping<K, StorageVec<T>>) with solc-compatible length/body addressing, packing, and clearing semantics.
  • Adds [T; N] storage encoding/decoding gated by a new StorageArrayElement marker trait, and auto-derives StorageArrayElement for static SolType structs.
  • Adds extensive StorageVec layout/behavior tests and new template examples/bench variants showcasing typed-storage usage.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
crates/pvm-storage/tests/ui/lazy_of_fixed_array_non_u8_rejected.stderr Removes compile-fail expectation now that non-u8 fixed arrays are supported.
crates/pvm-storage/tests/ui/lazy_of_fixed_array_non_u8_rejected.rs Removes compile-fail test now that [T; N] storage is implemented for more T.
crates/pvm-storage/src/tests.rs Adds comprehensive runtime tests for StorageVec layouts and behaviors (packed/subword/multislot/dynamic/nested/mapping).
crates/pvm-storage/src/lib.rs Implements StorageVec, Mapping<K, StorageVec<T>>, nested StorageVec<StorageVec<T>>, and supporting helpers (read_len_u64, inc_slot_by, etc.).
crates/pvm-contract-types/src/storage_codec.rs Adds StorageArrayElement and [T; N] StorageEncode/StorageDecode implementations matching solc layout.
crates/pvm-contract-types/src/mock_host.rs Minor comment wording update.
crates/pvm-contract-types/src/lib.rs Re-exports StorageArrayElement.
crates/pvm-contract-types/src/host.rs Minor comment wording update.
crates/pvm-contract-sdk/src/lib.rs Re-exports StorageVec and StorageArrayElement from the SDK surface.
crates/pvm-contract-macros/tests/derive_sol_type_storage.rs Adds tests ensuring derived static structs auto-implement StorageArrayElement and work in [T; N] storage contexts.
crates/pvm-contract-macros/src/codegen/sol_type.rs Auto-emits impl StorageArrayElement for static (non-dynamic-body) SolType structs.
crates/pvm-contract-macros/src/codegen/sol_storage.rs Minor comment wording update.
crates/pvm-contract-macros/src/codegen/contract.rs Minor comment wording update.
crates/pvm-contract-benchmarks/src/bin/build-and-measure.rs Updates benchmark variants/contracts list to include storage-focused example contracts.
crates/cargo-pvm-contract/templates/examples/mytoken_storage/MyToken.sol Adds Solidity interface for typed-storage ERC20-style example.
crates/cargo-pvm-contract/templates/examples/mytoken_storage/mytoken_storage_with_alloc.rs Adds with-alloc Rust example using Lazy/Mapping.
crates/cargo-pvm-contract/templates/examples/mytoken_storage/mytoken_storage_no_alloc.rs Adds no-alloc Rust example using Lazy/Mapping.
crates/cargo-pvm-contract/templates/examples/amm_reserves/AmmReserves.sol Adds Solidity interface for packed-reserves example.
crates/cargo-pvm-contract/templates/examples/amm_reserves/amm_reserves_with_alloc.rs Adds with-alloc Rust example demonstrating packed struct-in-Lazy.
crates/cargo-pvm-contract/templates/examples/amm_reserves/amm_reserves_no_alloc.rs Adds no-alloc Rust example demonstrating packed struct-in-Lazy.
crates/cargo-pvm-contract/templates/examples/allowlist/Allowlist.sol Adds Solidity interface for StorageVec-backed allowlist example.
crates/cargo-pvm-contract/templates/examples/allowlist/allowlist_with_alloc.rs Adds with-alloc Rust example using StorageVec<Address>.
crates/cargo-pvm-contract/templates/examples/allowlist/allowlist_no_alloc.rs Adds no-alloc Rust example using StorageVec<Address>.
CLAUDE.md Updates documentation to reflect StorageVec<T> and removes Stylus references in a few spots.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/pvm-storage/src/lib.rs
Comment thread crates/pvm-storage/src/lib.rs
Comment thread crates/pvm-contract-types/src/storage_codec.rs
Comment thread crates/pvm-storage/src/lib.rs
@smiasojed smiasojed marked this pull request as ready for review June 5, 2026 12:05
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 28 out of 29 changed files in this pull request and generated 3 comments.

Comment thread crates/pvm-contract-types/src/storage_codec.rs
Comment thread crates/pvm-contract-types/src/storage_codec.rs Outdated
Comment thread crates/pvm-contract-types/src/storage_codec.rs Outdated
smiasojed and others added 4 commits June 5, 2026 16:12
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@paritytech paritytech deleted a comment from github-actions Bot Jun 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 5, 2026

Benchmark Size Comparison (vs main)

Artifact Baseline Current Delta Status
allowlist_no-alloc.debug.polkavm (new) 63629 N/A NEW
allowlist_no-alloc.release.polkavm (new) 3186 N/A NEW
allowlist_with-alloc.debug.polkavm (new) 75249 N/A NEW
allowlist_with-alloc.release.polkavm (new) 3579 N/A NEW
amm_reserves_no-alloc.debug.polkavm (new) 42416 N/A NEW
amm_reserves_no-alloc.release.polkavm (new) 1969 N/A NEW
amm_reserves_with-alloc.debug.polkavm (new) 54136 N/A NEW
amm_reserves_with-alloc.release.polkavm (new) 2309 N/A NEW
fibonacci_builder-dsl.debug.polkavm 37321 37321 +0.00% OK
fibonacci_builder-dsl.release.polkavm 638 638 +0.00% OK
fibonacci_no-alloc.debug.polkavm 35941 35941 +0.00% OK
fibonacci_no-alloc.release.polkavm 595 595 +0.00% OK
fibonacci_with-alloc.debug.polkavm 46503 46503 +0.00% OK
fibonacci_with-alloc.release.polkavm 600 600 +0.00% OK
multi_builder-dsl.debug.polkavm 58598 58602 +0.01% OK
multi_builder-dsl.release.polkavm 3024 3024 +0.00% OK
multi_no-alloc.debug.polkavm 60405 60404 -0.00% OK
multi_no-alloc.release.polkavm 2919 2919 +0.00% OK
multi_with-alloc.debug.polkavm 72170 72169 -0.00% OK
multi_with-alloc.release.polkavm 3076 3076 +0.00% OK
mytoken_builder-dsl.debug.polkavm 56260 56257 -0.01% OK
mytoken_builder-dsl.release.polkavm 3683 3683 +0.00% OK
mytoken_no-alloc.debug.polkavm 59433 55541 -6.55% OK
mytoken_no-alloc.release.polkavm 2923 2922 -0.03% OK
mytoken_storage.debug.polkavm 65052 (gone) N/A DEL
mytoken_storage.release.polkavm 3127 (gone) N/A DEL
mytoken_storage_no-alloc.debug.polkavm (new) 61311 N/A NEW
mytoken_storage_no-alloc.release.polkavm (new) 3127 N/A NEW
mytoken_storage_with-alloc.debug.polkavm (new) 73962 N/A NEW
mytoken_storage_with-alloc.release.polkavm (new) 4192 N/A NEW
mytoken_with-alloc.debug.polkavm 73650 69762 -5.28% OK
mytoken_with-alloc.release.polkavm 3941 3941 +0.00% OK
---------------------------------------------------- ------------ ------------ ---------- --------
Total 589859 902963 +53.08%

OK: All artifacts within 5% regression threshold

Run 27022454253 | aacee86 | 2026-06-05 15:15 UTC

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