slither icon indicating copy to clipboard operation
slither copied to clipboard

Storage method of control flow diagram

Open zhangzone opened this issue 1 year ago • 2 comments

Hello, may I ask if the control flow diagram in Slither is stored in bytecode format or in the semantics of solidity. Is the control flow diagram stored in a data structure? I need to use Slither's control flow chart data and data dependencies.

zhangzone avatar Mar 14 '24 08:03 zhangzone

Each function has a control flow graph (CFG) with its list of nodes aka blocks. Each node has sons aka successors or outgoing edges and fathers aka predecessors or incoming edges. The CFG is based off the solidity AST and reflects the control flow of if-else, for loop, while loop, and break/continue statements. For example, an if-statement node will have two sons, the branch taken if the condition is true and the branch taken if false. You can see the CFG using slither test.sol --print cfg.

There is an example of how to use the data dependency API here

0xalpharush avatar Mar 14 '24 17:03 0xalpharush

Hello, does Slither convert functions into nodes when transforming the control flow graph, such as custom functions or Solidity's built-in functions like call? I noticed that there are no node types specifically related to functions.

zhangzone avatar May 06 '24 08:05 zhangzone