mirror of
https://github.com/paradigmxyz/solidity-lean.git
synced 2026-11-15 19:56:39 +00:00
solc 0.8.35 accepts a local variable named `msg` that SHADOWS the `msg` magic
global, so `msg.<member>` becomes an ordinary struct field access:
contract T {
struct M { uint256 value; }
function run() public returns (uint256) {
M memory msg; msg.value = 9;
return msg.value;
}
}
`run()` returns 9. solidity-lean failed closed in the type checker with
`mutabilityViolation "msg.value in a non-payable function"`: the
`Expr.member (Expr.ident "msg") member` arm of `checkExpr` matched the magic
global UNCONDITIONALLY, imposing the G2 payable-mutability obligation (and the
`msg.value` builtin TYPE) even when `msg` was a shadowing local — an
over-rejection of an in-scope, solc-accepted program.
Guard that arm on `env.lookupVar? "msg"`: an unshadowed `msg` keeps the
magic-global handling (extracted verbatim to `checkMsgGlobalMember` — the
`msg.data`/`msg.sig` receive check G10 and the payable-mutability check G2),
while a shadowing local routes `msg.<member>` through the ordinary struct-field
member path (field type, no payable obligation), mirroring the generic
`Expr.member` arm. Lowering already handles this: `resolveStructs` rewrites
`msg.value` -> `msg[0]` because the local `msg` is in its `typeEnv`, so
execution reads the memory struct field and returns 9.
Witness MsgShadowStructLocal pins the target: the contract is accepted and
`run()` returns 9. Full `lake build` (all witnesses + proofs) and the curated
smoke replay (29 cases, pinned solc 0.8.35) stay green.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
125 lines
4.4 KiB
125 lines
4.4 KiB