Skip to content

fix(analysis): report uninitialized constants read from inline assembly - #55

Open
mdtanrikulu wants to merge 1 commit into
okcontract:mainfrom
mdtanrikulu:fix/analysis-uninitialized-constant-assembly
Open

mdtanrikulu wants to merge 1 commit into
okcontract:mainfrom
mdtanrikulu:fix/analysis-uninitialized-constant-assembly

Conversation

@mdtanrikulu

Copy link
Copy Markdown

Problem

Ran solc's syntaxTests/inlineAssembly/constant_access_non_initialized.sol through oksolc and it crashes. Reading a constant with no value from inline assembly is enough:

contract C {
    uint constant x;
    function f() public pure {
        assembly { let c1 := x }
    }
}

solc reports 4266 + 3224 ("Constant has no value."). oksolc fails with InvalidAst, so Standard JSON returns only error: InternalFailure. Going through a chain like uint constant y; uint constant x = y; crashes the same way.

Fix

I checked solc's ASTUtils.cpp, and its rootConstVariableDeclaration just stops and returns the declaration when there's no initializer. Ours returned InvalidAst there, so I made it return the declaration too. Both callers already handle a constant without a value, so nothing else needed to change.

Testing

  • I added a test that matches solc 0.8.39 byte for byte on the example and checks four more forms on every target (one and two constants deep, as an assignment target, and as bytes32). It fails without the fix.
  • zig build test-standard-json passes, and valid constants in assembly still produce the same bytecode as solc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant