Skip to content

fix: preserve shielded ops for bytes(sbytes) aliases (#248)#249

Merged
cdrappi merged 2 commits intoseismicfrom
cdai__semantic-test-rob-invalidprivatestorageaccess
Mar 23, 2026
Merged

fix: preserve shielded ops for bytes(sbytes) aliases (#248)#249
cdrappi merged 2 commits intoseismicfrom
cdai__semantic-test-rob-invalidprivatestorageaccess

Conversation

@drappi-ai
Copy link
Copy Markdown
Contributor

@drappi-ai drappi-ai commented Mar 23, 2026

Summary

Fixes #248.

bytes(sbytes_storage_ref) could lose the fact that the alias still points at shielded storage. That made the compiler emit ordinary storage ops for paths that still touch private slots, which then failed at runtime with InvalidPrivateStorageAccess.

Affected cases included:

  • inline reads like return bytes(m[0]);
  • storage aliases like bytes storage ref = bytes(data);
  • alias reads and writes such as return ref, ref[i], ref[i] = ..., ref.push(...), and ref.pop()
  • internal helpers that take or return bytes storage aliases derived from shielded storage

Fix

The compiler now preserves an internal shielded-storage marker on bytes / string storage references produced from shielded storage.

Both codegen pipelines use that marker to keep using shielded storage ops while the alias still points at shielded storage:

  • storage-to-memory reads use cload
  • alias writes use cstore
  • indexed alias helpers preserve shielded storage ops as well

The marker is only for storage-op selection. It does not change the surface type of bytes: user-visible typing like .length stays ordinary, and deep copies into genuinely public storage stay on ordinary storage ops.

Tests

Added and expanded coverage for:

  • the original inline bytes(sbytes_storage) bug
  • direct storage aliases created from bytes(sbytes_storage_ref)
  • alias reads and writes through locals, internal parameters, and internal return values
  • chained aliases, ternary/reassignment flows, modifiers, and .length
  • short and long byte arrays
  • plain storage, mappings, arrays, structs, mapping-of-struct, and nested mappings

@drappi-ai drappi-ai requested a review from cdrappi as a code owner March 23, 2026 14:47
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch 2 times, most recently from ce39504 to 407ce00 Compare March 23, 2026 16:57
@drappi-ai drappi-ai changed the title test: inline cast semantic tests for all shielded types fix: inline bytes(sbytes_storage) uses SLOAD instead of CLOAD (#248) Mar 23, 2026
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch from 407ce00 to 8db99ce Compare March 23, 2026 18:02
@drappi-ai drappi-ai changed the title fix: inline bytes(sbytes_storage) uses SLOAD instead of CLOAD (#248) fix: preserve shielded storage ops for bytes(sbytes) aliases (#248) Mar 23, 2026
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch 2 times, most recently from 81fcc4b to f74d0d6 Compare March 23, 2026 19:12
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch from f74d0d6 to 6a75ff4 Compare March 23, 2026 19:50
@drappi-ai drappi-ai changed the title fix: preserve shielded storage ops for bytes(sbytes) aliases (#248) fix: preserve shielded ops for bytes(sbytes) aliases (#248) Mar 23, 2026
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch from 6a75ff4 to 4575d03 Compare March 23, 2026 20:26
@drappi-ai drappi-ai force-pushed the cdai__semantic-test-rob-invalidprivatestorageaccess branch from 4575d03 to 27c079b Compare March 23, 2026 20:32
@cdrappi cdrappi merged commit beba69f into seismic Mar 23, 2026
2 checks passed
@cdrappi cdrappi deleted the cdai__semantic-test-rob-invalidprivatestorageaccess branch March 23, 2026 20:51
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.

Inline bytes(sbytes) cast from storage emits SLOAD instead of CLOAD (InvalidPrivateStorageAccess)

2 participants