tintinweb / solgrep

🧠 A scriptable semantic grep utility for solidity
https://www.npmjs.com/package/solgrep
142 stars 17 forks source link

Fails to extract #1

Closed mrx23dot closed 2 years ago

mrx23dot commented 2 years ago

Running solgrep --find="function.name" test.sol

on

contract ReEntrancyGuard {
    bool internal locked;

    modifier noReentrant() {
        require(!locked, "No re-entrancy");
        locked = true;
        _;
        selfdestruct(343434);
        locked = false;
    }
}

contract ReEntrancyGuard2 {
    bool internal locked;
}

gives no results:

� SolGrep v0.0.6 ready!

  Enabled Modules:
    ✔️ GenericGrep          _function.name,test.sol

   ────────────────────────────
cheers �
    @tintinweb
    ConsenSys Diligence @ https://consensys.net/diligence/
    https://github.com/tintinweb/solgrep/
tintinweb commented 2 years ago

Hey @mrx23dot,

function.name will currently only work with real functions, not modifiers. If there's a use case for you to extract all modifier names we might be able to make that happen in the same fashion. Otherwise there's an example in the Readme that shows how to find specific modifier names 🙌

mrx23dot commented 2 years ago

Works great with non-modifiers, thanks!

tintinweb commented 2 years ago

the version released today should allow you to extract modifier names too. cheers 🙌

mrx23dot commented 2 years ago

Could you also release it on npm then I will give it a go.

Is there an option to dump the AST to file from cli for further processing? thank you

mrx23dot commented 2 years ago

Should --find="contract.name" return interface names too? 02253dfa1f23e72e2e3e1c6b9cd2b8b0a2fc7bc5_SoEToken.txt

tintinweb commented 2 years ago

@mrx23dot, yes, it matches interface contracts too.

image

You can include/exclude interfaces like this:

⇒  ./bin/main.js examples/02253dfa1f23e72e2e3e1c6b9cd2b8b0a2fc7bc5_SoEToken.sol --find="contract.name && contract.kind=='interface'"