Skip to content

Fix literal parsing in legacy AST for older Solidity versions#2953

Open
ep0chzer0 wants to merge 1 commit intocrytic:masterfrom
ep0chzer0:fix/legacy-ast-literal-quotes
Open

Fix literal parsing in legacy AST for older Solidity versions#2953
ep0chzer0 wants to merge 1 commit intocrytic:masterfrom
ep0chzer0:fix/legacy-ast-literal-quotes

Conversation

@ep0chzer0
Copy link
Contributor

Summary

  • Fixes parsing failure for fixed-size array declarations in Solidity 0.4.x contracts
  • Some older Solidity versions store numeric literals with embedded quotes in legacy AST

Root Cause

In Solidity versions like 0.4.23, the legacy AST format stores numeric literal values with embedded double-quotes. For example, the array declaration uint256[12] has its length stored as '"12"' (with quote characters) instead of just '12'.

This caused ValueError: invalid literal for int() with base 10: '"12"' when computing storage layout.

Fix

Strip surrounding double-quotes from literal values when parsing legacy AST (lines 447-450 in expression_parsing.py).

if isinstance(value, str) and value.startswith('"') and value.endswith('"'):
    value = value[1:-1]

Test Case

pragma solidity 0.4.23;
contract C {
    uint256[12] private c = [4,8,12,16,20,24,28,32,36,40,44,48];
}

This should now parse without errors.

Fixes #2215

@ep0chzer0 ep0chzer0 requested a review from smonicas as a code owner January 23, 2026 19:04
Some older Solidity versions (e.g., 0.4.23) store numeric literal values
in the legacy AST with embedded double-quotes like '"12"' instead of '12'.
This caused parsing failures for fixed-size array declarations like
`uint256[12]` when computing storage layout.

The fix strips surrounding double-quotes from literal values in the
legacy AST parsing path.

Fixes crytic#2215
@ep0chzer0 ep0chzer0 force-pushed the fix/legacy-ast-literal-quotes branch from 8262e7d to 633504f Compare February 23, 2026 17:54
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.

[Bug]: Misinterpretation of literals in legacy-ast

1 participant