solidity-lean/SolidCore/Witness/EmitMemoryNestedRef.lean
Dan Robinson e54392af2c fix: emitEvent and custom-error revert args deep-materialize nested memory/storage refs
Adjudicated soundness gap: Stmt.emitEvent evaluated its arguments but never
deep-materialized them, so an event argument NESTING a memory reference (e.g.
a uint256[][] whose rows are Value.memoryRefs) reached the Runtime-free event
encoder (EventDecl.encodeFields? / abiEncodeValues?) with bare ref leaves ->
none -> Panic(0), while solc+EVM emit the event with the full ABI encoding.

Root fix: route the evaluated emit arguments through
Runtime.materializeForValueUseList (the same deep structural materializer the
abi.encode*/keccak256/bytes.concat value-use boundaries use) before
Runtime.emitEvent. Same-class audit: the custom-error revert payload
boundaries (Stmt.revert, Stmt.requireCustom) construct RevertData.custom
values that are ABI-encoded OUTSIDE the runtime (Contract.encodeRevertData?
is Runtime-free); they now materialize identically.

Witness: SolidCore/Witness/EmitMemoryNestedRef.lean (pre-fix: reverted
Panic(0); post-fix: emits N with topic0 = keccak("N(uint256[][])") and
data = abi.encode([[7],[8,9]])).
Real-EVM lane: tests/forge-harness/emit-memory-nested (forge pins the log,
Lean matches topics+data byte-for-byte; paired_cases_passed=yes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 03:49:50 -04:00

167 lines
5.8 KiB