3.20: Shielded storage opcodes are emitted for pre-Mercury EVM versions#201
Merged
cdrappi merged 2 commits intozellic-auditfrom Feb 16, 2026
Merged
3.20: Shielded storage opcodes are emitted for pre-Mercury EVM versions#201cdrappi merged 2 commits intozellic-auditfrom
cdrappi merged 2 commits intozellic-auditfrom
Conversation
520a5b6 to
892b9c6
Compare
Add comprehensive test coverage for shielded type validation across different EVM versions. Tests verify that shielded types are rejected on pre-Mercury EVM versions with error 9978. State storage variables: - shielded_storage_evm_version_paris.sol: Single suint256 on Paris - shielded_storage_evm_version_cancun.sol: Multiple shielded types on Cancun - shielded_storage_struct_evm_version.sol: Struct containing shielded type - shielded_storage_sbytes_evm_version.sol: Shielded byte array Other variable contexts: - shielded_local_variable_evm_version.sol: Local function variable - shielded_immutable_evm_version.sol: Immutable variable (error 7491) - shielded_constant_evm_version.sol: Constant variable (error 7491) Positive test: - shielded_storage_evm_version_mercury.sol: Confirms Mercury support All tests run with both legacy and via-IR pipelines (compileViaYul: true). Note: Immutable and constant tests expect error 7491 (existing validation) rather than 9978, as shielded types cannot be immutable or constant.
Prevent emission of CLOAD/CSTORE opcodes on pre-Mercury EVM versions when using shielded types (suint, sbool, saddress, sbytes) in ANY context. ## Problem Compiling with --evm-version paris (or any pre-Mercury version) incorrectly emitted cload/cstore opcodes for shielded types, causing "invalid opcode" runtime errors on pre-Mercury VMs. ## Solution: Two-Layer Defense ### Layer 1: Type Checker (libsolidity/analysis/TypeChecker.cpp) Add comprehensive early validation in visit(VariableDeclaration) to reject ALL uses of shielded types on pre-Mercury versions: **Checked contexts:** - State storage variables (regular, non-constant, non-immutable) - Local storage references/pointers - Local value-type variables (stack/memory) - Immutable variables (value types only) - Constant variables **Safety considerations:** - For immutables: only check if value type (non-value types already error at line 532) - For constants: always safe (must be value types) - For state variables: always safe (storage location guaranteed) - For local storage: safe (storage location) - For local value types: safe (no nested mapping issues) Error 9978 provides actionable message guiding users to --evm-version mercury. ### Layer 2: Codegen Assertions **Legacy Pipeline (libsolidity/codegen/LValue.cpp)** Add 6 defensive assertions to catch any cases that slip through: - GenericStorageItem::retrieveValue() - line 237 - GenericStorageItem::storeValue() - line 310 - GenericStorageItem::setToZero() - line 521 - StorageByteArrayElement::retrieveValue() - line 569 - StorageByteArrayElement::storeValue() - line 584 - StorageByteArrayElement::setToZero() - line 614 **Via-IR Pipeline (libsolidity/codegen/YulUtilFunctions.cpp)** Add assertions in key functions: - readFromStorageValueType() - line 2864 - resizeDynamicByteArrayFunction() - line 1448 - storageArrayPopFunction() - line 1648 - storageArrayPushZeroFunction() - line 1799 ## Coverage - All variable contexts (state, local, immutable, constant) - Arrays/structs containing shielded types (containsShieldedType check) - Shielded byte arrays (StorageByteArrayElement handlers) - Both legacy and via-IR compilation pipelines - All shielded type categories (suint, sbool, saddress, sbytes)
215dcc3 to
293eab1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.