mirror of
https://github.com/paradigmxyz/solidity-lean.git
synced 2026-11-15 19:56:39 +00:00
A contract-level *storage* (or transient/immutable) state variable shadows a
same-name file-level `constant` inside that contract, but the entrypoint
lowering constant-folded the bare read to the file-level value.
Repro (adjudicated observable success|w:9, sto=0:9; engine produced success|w:5):
uint256 constant X = 5;
contract B {
uint256 internal X = 9;
function run() external view returns (uint256) { return X; }
}
Root cause: ContractDecl.directCoreFunctions? re-elaborates each contract's raw
entrypoint/getter bodies via FunctionDecl.toCore?, which re-inlines against the
constant env passed in. The call site passed the flat whole-program
`constants` (StateVars.constantEnv stateVars ++ sourceConstantEnv ++ qualified),
which still carried the file-level X=5 — a storage state var contributes no
`constantEntry?`, so nothing suppressed it — so `run`'s `X` folded to 5 and the
SLOAD never happened. #16 fixed only the internal-dispatch/helper path
(contextual* functions), not this direct-entrypoint path.
Fix: introduce ContractDecl.scopedStateVarShadowNames (non-constant state vars
in a contract's own+inherited C3 scope) and ContractDecl.scopedConstantEnv,
which builds each contract's own scoped constant env (own/inherited constants
over the file-level + qualified tail) minus any name shadowed by a non-constant
state variable. directCoreFunctions? is now invoked per-contract with that
scoped env, and the contextual function/modifier lowering routes through the
same helper — so a shadowing storage/immutable variable is read from storage and
a derived constant still cannot leak into an inherited base body.
Regression: SolidCore/Witness/StateVarShadowsFileConst.lean (run reads storage
slot 0 = 9, not the folded file-level constant 5). Full `lake build` green.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
116 lines
3.8 KiB
116 lines
3.8 KiB