unpackdev / solgo

Solidity parser in Go, designed to transform Solidity code into a structured format for enhanced analysis, particularly beneficial for developers using Go to analyze Solidity smart contracts.
https://unpack.dev
Apache License 2.0
2 stars 0 forks source link

AST Reference Discovery Ideas #115

Open 0x19 opened 11 months ago

0x19 commented 11 months ago

Forward statement resolution in AST seems to be a bit more complicated than it should. However, I am not yet sure how to handle it in the future.

Problematic with forward statement means that node can be anywhere. What that means is that reference for any particular statement can be:

Knowing the problem, dealing with solution becomes troublesome when types descriptions are in question. We basically need to understand the type itself and regularly I need to come back to references during testing as some type is not discovered efficiently. For example, node is not found at all, resulting in skewed AST results and panics due to type description object is not found.

For now I am patching the code to resolve it. However, I'd like in the future to find out proper way how to traverse through the tree and figure out all of the types without doing some ad-hoc kumbaya patches to the resolver.

Moreover, even if node is found, are we certain that that particular node corresponds to the proper reference or just globally defined reference? This calls for a node reverse lookup.

Anyway, just ideas posting here so this story can be upgraded in the future and perhaps better solution can be done.

This is just so we are on a same page, a severe amount of work and will broke the entire code resolution once touched.

0x19 commented 11 months ago

One of the ideas is to build node trees prior ast is built. However, generics in Go still sucks in this particular case especially if you wish to lets say build sane protocol buffer representation of each node and in the end having it result with nice JSON without bunch of things in the object that do not even relate to the expression itself.

0x19 commented 11 months ago

Note that at this moment, until millions of contracts are parsed through it there's no valid reason of doing this task as we need to know all of the edge cases prior doing anything sane.