Consensys / surya

A set of utilities for exploring Solidity contracts
Apache License 2.0
1.06k stars 118 forks source link

Graph generation fails #190

Closed spaceh3ad closed 9 months ago

spaceh3ad commented 9 months ago

As mentioned in #137 there is an issue generating graphs for contracts that has mappings declared. Using SolidityAuditor extension I was able to generate graph for file without mappings however using cmd not. surya grap Test.sol | dot -Tpng > Test.png output produces empty Test.png file.

I am using MacOS. Surya version: 0.4.8 Graphviz: 9.0.0

GNSPS commented 9 months ago

Can you post the test Solidity file here so I can test locally, please? 🙏

spaceh3ad commented 9 months ago

now suddenly I got logs from the surya grap PositionManager.sol | dot -Tpng > Test.png

TypeError: Cannot read properties of undefined (reading 'undefined')
    at Object.UsingForDeclaration (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/lib/graph.js:210:44)
    at visit (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:37156:30)
    at /Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:37150:29
    at Array.forEach (<anonymous>)
    at visit (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:37150:10)
    at Object.visit (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/node_modules/@solidity-parser/parser/dist/index.cjs.js:37162:7)
    at _loop (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/lib/graph.js:107:12)
    at graph (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/lib/graph.js:226:18)
    at Object.handler (/Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/bin/surya:65:19)
    at /Users/jan-k/.nvm/versions/node/v16.20.2/lib/node_modules/surya/node_modules/yargs/build/index.cjs:1:8993

@GNSPS I tired to write minimal test for this case but it apparently worked with mapping now. I have trouble providing the minimal sample of when code fails, so I can provide link to my repo. From where the surya grap PositionManager.sol | dot -Tpng > Test.png is failing with error above.

GNSPS commented 9 months ago

From the error logs, I suspect the bug might be with the using for declaration and not with mappings. But I'll take a look, thanks! 🙏

GNSPS commented 9 months ago

Ahhh LOL, figured out quickly. I am not allowing using for declarations outside of contracts! 🙈 Back then it was not permitted in the grammar. I'll fix this.

GNSPS commented 9 months ago

Done! 😄 👍 Thank you for reporting it!

GNSPS commented 9 months ago

You can try v0.4.9

spaceh3ad commented 9 months ago

Thank you so much! 🎉

DutchBBS commented 9 months ago

I am still not able to generate graphs on contracts with named mappings. I tried all the solutions on different threads but nothing seems to work. Back to manual graphs i guess

GNSPS commented 9 months ago

Can you post here a Solidity snippet that fails? 🙏