Function evmil::analysis::find_dependencies

source ·
pub fn find_dependencies(insns: &[Instruction]) -> Dependencies
Expand description

For a given bytecode sequence, identify the dependency frames for all instructions. A dependency frame contains an entry for each operand of the instruction, where each entry identifies a source instruction within the sequence. If there are multiple paths through the sequence to the given instruction, then there may be multiple frames for a given instruction.

§Examples

The following illustrates a minimal example:

[0]   push 0x1
[1]   push 0x2
[2]   add          ;; [0,1]

Here, instruction indices have been inserted to aid readability and the dependency frames (if any) are given next to each instruction. In this case, there are no frames for the first two instructions (i.e. as they have no operands). For the add instruction, we have one frame [0,1] which identifies the two push instructions as its dependencies.

A more interesting example is:

[0]   calldatasize
[1]   push lab0
[2]   jumpi        ;; [1]
[3]   push 0x1
[4]   jump lab1    ;; [3]
lab0:
[5]   push 0x2
lab1:
[6]   neg          ;; [3][5]

Here, we can see that the neg instruction has two dependency frames indicating its dependency is either push 0x1 or push 0x2 (i.e. depending on which path was taken through the control-flow graph).