solc-typed-ast icon indicating copy to clipboard operation
solc-typed-ast copied to clipboard

Cannot evaluate constant referred by several module aliases

Open blitz-1306 opened this issue 2 years ago • 0 comments

Environment

Any

Scenario

  1. Have a file A.sol, that declares file-level constant uint constant X = 100;.
  2. Have a file B.sol, that imports A.sol and aliases it as A.
  3. Have a file C.sol, that:
    • imports B.sol and aliases it as B.
    • declares file-level constant uint constant Y = 50 + B.A.X;
  4. Run constant evaluator on Y

Expected behavior

Expected Y to resolve to 150

Current behavior

Get two crashes:

  • InferType would crash here: https://github.com/Consensys/solc-typed-ast/blob/f467859fcc7e375d4df681ac4745e300793a1cf6/src/types/infer.ts#L1299-L1305
  • evalConstantExpr() would crash as it cannot proceed evaluation without a type: https://github.com/Consensys/solc-typed-ast/blob/f467859fcc7e375d4df681ac4745e300793a1cf6/src/types/eval_const.ts#L403-L407

Description

See https://github.com/Consensys/solc-typed-ast/pull/225#discussion_r1348669937

Suggested solution

  1. Probably reintroduce ModuleType (that is not in package distribution and used for tests only).
  2. Fix InferType.
  3. Fix evalConstantExpr() to handle tree of MemberAcceeses, that refers to a variable via multiple aliases.

blitz-1306 avatar Oct 06 '23 13:10 blitz-1306