solc-typed-ast
solc-typed-ast copied to clipboard
Cannot evaluate constant referred by several module aliases
Environment
Any
Scenario
- Have a file
A.sol, that declares file-level constantuint constant X = 100;. - Have a file
B.sol, that importsA.soland aliases it asA. - Have a file
C.sol, that:- imports
B.soland aliases it asB. - declares file-level constant
uint constant Y = 50 + B.A.X;
- imports
- Run constant evaluator on
Y
Expected behavior
Expected Y to resolve to 150
Current behavior
Get two crashes:
InferTypewould crash here: https://github.com/Consensys/solc-typed-ast/blob/f467859fcc7e375d4df681ac4745e300793a1cf6/src/types/infer.ts#L1299-L1305evalConstantExpr()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
- Probably reintroduce
ModuleType(that is not in package distribution and used for tests only). - Fix
InferType. - Fix
evalConstantExpr()to handle tree ofMemberAcceeses, that refers to a variable via multiple aliases.