solidity-lean/SolidCore/Witness/NestedArrayLiteralStorageCopy.lean
arena-lean-staging-agent[bot] 79facbd774
fix(typecheck+interpreter): inline array literal copied into a dynamic storage array over-rejected then Panic(0) (#72)
`a3[0][1] = [5,6]` for a nested `uint8[]` storage element (and the flat
`uint8[] s; s = [5,6]`) is accepted and run by solc 0.8.35: the literal is
typed bottom-up as `uint8[2] memory` and copied (fixed->dynamic storage copy)
into the dynamic storage array.

solidity-lean failed closed at typecheck (over_reject): `[5,6]` carried the
over-wide `uint256[2]` `checked.ty`, and the `=` storage-array-copy branch used
that instead of solc's bottom-up mobile type, so `storageArrayCopyAssignable?`
saw a uint256->uint8 narrowing and rejected. Once accepted, the interpreter
Panic(0)'d: `State.storeStorageLayoutAt` at a `dynamicArray` layout demanded a
`Value.dynamicArray`, but a memory array literal is a `Value.fixedArray`.

Fix (two minimal seams):
  * TypeCheck: the storage-array-copy branch substitutes the inline literal's
    bottom-up type (`inlineArrayBottomUpTy?`) for its over-wide `checked.ty`; a
    typed/variable element leaves it `none`, keeping `checked.ty` (and the
    struct-element legacy carve-out).
  * Interpreter: `storeStorageLayoutAt` accepts a `Value.fixedArray` at a
    `dynamicArray` layout (resize to the source length, copy) — the fixed->dynamic
    storage copy.

Regression witness `NestedArrayLiteralStorageCopy` pins the submission's exact
solc+EVM storage (slot 0 = 1, keccak(0) = 0, keccak(0)+1 = 2, data slot = 0x0605)
plus flat and fixed controls. Full `lake build` (all proofs + witnesses) green.

Co-authored-by: Lean Semantics Review Agent <agent@solidcore.local>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 18:26:45 +00:00

163 lines
6.3 KiB