plotchy / evm-cfg

Symbolic stack CFG generator for EVM
178 stars 14 forks source link

Fix recursion #5

Open igorline opened 1 year ago

igorline commented 1 year ago
contract Fib {
    function fib(uint256 x) public pure returns (uint256) {
        if (x <= 1) return x;
        unchecked {
            return fib(x - 1) + fib(x - 2);
        }
    }
}
plotchy commented 1 year ago

idk if generally there is a good solution here. for this example I'm thinking you can read the stack size delta upon entry into the node, if it is positive then clone the current stack values within that size delta temporarily, and upon node exit compare the cloned stack values to the ones currently there. If they match, don't let the traverser continue.

but there are edge cases galore in doing things like this. ie:

graph TD;
    A[A: <br/> jumpdest <br/> push 1] --> B[B: <br/> jumpdest <br/> push 1];
    B --> C[C: <br/> push A <br/> jump];
    C --> A;

would break at B exit when it shouldnt