Consensys / scribble

Scribble instrumentation tool
Apache License 2.0
313 stars 29 forks source link

Crash: AST parsing problem causes `Expected CustomValueType to be a type name, not UserDefinedValueTypeDefinition` #192

Closed NeverFearTomorrow closed 1 year ago

NeverFearTomorrow commented 2 years ago

I ran scribble on the following file (which compiles just fine):

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract Dummy2 {
  type CustomValueType is uint32;

  /// #if_updated
  ///   forall(CustomValueType t in _map)
  ///     true;
  mapping(CustomValueType => uint) private _map;
}

and it crashes with:

/home/un/nifty/web/sc/node_modules/solc-typed-ast/dist/misc/utils.js:36
    throw new Error(message);
          ^

Error: Expected CustomValueType to be a type name, not UserDefinedValueTypeDefinition
    at assert (/home/un/nifty/web/sc/node_modules/solc-typed-ast/dist/misc/utils.js:36:11)
    at makeUserDefinedType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:39:33)
    at peg$c301 (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:692:16)
    at peg$parseUserDefinedType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:8812:22)
    at peg$parseSimpleType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:8543:38)
    at peg$parseArrayType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:8828:14)
    at peg$parseMappingType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:9100:18)
    at peg$parsePointerType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:9132:14)
    at peg$parseFunctionType (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:9577:18)
    at peg$parseFor_All (/home/un/nifty/web/sc/node_modules/eth-scribble/dist/spec-lang/expr_parser.js:1550:30)

Defining the custom value type and the mapping aren't problems, but it seems that the crash is happening in the forall. I believe the code is valid, but even if there is an issue with the code, I think scribble should fail cleanly and with a line number into Dummy2.sol - in order to cut a minimal example for this report, I kinda had to binary search my large contract file to figure out what was causing the problem, because the crash trace doesn't give a line number.

blitz-1306 commented 2 years ago

Hello @NeverFearTomorrow. I created a small pull request #193 to fix the issue - it would need to pass a review and get into a next release. Thank you for reporting this.