scribble icon indicating copy to clipboard operation
scribble copied to clipboard

Javascript call stack exceeded

Open axic opened this issue 4 years ago • 8 comments

On the same codebase whatever I do (like adding an invariant or a if_succeeds statement) I keep getting Javascript Maximum call stack size exceeded errors.

Two kinds in particular:

  1. The first seems to be inside type checking:
Internal error in type-checking: Maximum call stack size exceeded
  1. The seconds seems to be around recursive imports:
/Users/alex/Projects/scribble/dist/bin/scribble.js:494
            throw e;
            ^

RangeError: Maximum call stack size exceeded
    at ImportDirective.get vSymbolAliases [as vSymbolAliases] (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/implementation/meta/import_directive.js:55:45)
    at lookupInSourceUnit (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/definitions.js:101:28)
    at lookupInSourceUnit.next (<anonymous>)
    at new Set (<anonymous>)
    at lookupInScope (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/definitions.js:229:12)
    at lookupInSourceUnit (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/definitions.js:104:35)
    at lookupInSourceUnit.next (<anonymous>)
    at new Set (<anonymous>)
    at lookupInScope (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/definitions.js:229:12)
    at lookupInSourceUnit (/Users/alex/Projects/scribble/node_modules/solc-typed-ast/dist/ast/definitions.js:104:35)

(It is a local install of 912a472)

I think the second case may be connected to #64.

I tried for a quite bit of time create a reduced example, but can't really spend too many hours on it. @cd1m0 do you have any idea based on the above?

axic avatar Sep 21 '21 11:09 axic

@axic Thanks for the feedback. It appears that issue originates from solc-typed-ast. However, I'm not sure if Scribble manipulated AST somehow to make that happend. We will keep track the issue in case if we will be able to rootcause.

@cd1m0 There were few commits to the mentioned file in error trace. The current last one is https://github.com/ConsenSys/solc-typed-ast/commit/f5f0d7217fe1d9a308d2b5001238b084d0066306.

blitz-1306 avatar Sep 21 '21 13:09 blitz-1306

@axic thanks for pointing this out! Do you have a sample/link to a codebase so we can reproduce it too? And yeah, this looks like its related to the fix to #64.

cd1m0 avatar Sep 21 '21 18:09 cd1m0

Do you have a sample/link to a codebase so we can reproduce it too?

I have tried creating an example a few times, probably spent over an hour on it, but couldn't yet reduce it. I cannot share the source yet :(

axic avatar Sep 21 '21 18:09 axic

Ok. Will try to look at the code and find anything suspicious

cd1m0 avatar Sep 21 '21 18:09 cd1m0

I was able to reproduce the issue by trying to look-up an identifier that doesn't exist. Here are the samples: A.sol:

import "./B.sol";

/// #invariant dummy > 0;
contract A {
  function a(B arg) external returns (B) {return arg;}
}

B.sol:

import "./A.sol";

contract B {
  function a(A arg) external returns (A) { return arg; }
}

Doing scribble A.sol crashes with the same stack trace. The issue however is in solc-typed-ast. Essentially if we don't find a definition for the dummy at the root level of A.sol, we try looking it up at the root level of B.sol, and then we ping-pong back and forth.

cd1m0 avatar Oct 01 '21 01:10 cd1m0

Tried 0.5.7, but it still happens.

The repository however now is public: https://github.com/tempus-finance/tempus-protocol

@cd1m0 as an extremely simple example, add /// #invariant version == 1; at https://github.com/tempus-finance/tempus-protocol/blob/master/contracts/TempusPool.sol#L22

axic avatar Nov 05 '21 00:11 axic

@axic thanks for following up! Will reproduce this and try to give you rootcause/fix :)

cd1m0 avatar Nov 05 '21 00:11 cd1m0

@cd1m0 much appreciated, can't wait to create some scribble specifications 😅

axic avatar Nov 06 '21 22:11 axic