Callable.instructions_recursive()

Returns the set of all instructions from the current function entry in the control flow graph.

instructions_recursive() -> APISet[Instruction]

The function is the recursive/inter-procedural variant of the instructions(), meaning that it works recursively. It returns a set of Instructions object representing all the instructions which are reachable from the target function, the differences between instructions_recursive() and instructions() the latter will only return instructions directly accessible from the function. At the same time, the recursive version will find all the instructions recursively, which are eventually called when executing the function.

Also, note that the return types of instructions_recursive() -> APISet[Instruction] and instructions() -> Instructions are different, the recursive version returns an APISet of Instruction objects, while the original one returns Instructions (queryable) object.

Query Example

from glider import *

def query():
    # Let's find a function with name transferFrom
    functions = Functions().with_name('transferOwnership').exec(1)

    # Print the code of the function
    print(functions[0].source_code())

    # Return the list of (recursive) instructions, as it return a set, we need to cast it to list
    return list(functions[0].instructions_recursive().exec(10))

For the function:

function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

The output is:

Example Output

Last updated