Exercises
Last updated
Last updated
In this section, we will present several exercises that will fortify your Instructions query skills. Each exercise provided comes along with a solution if you get stuck.
Now, let’s update this query to find instructions that make external calls to other contracts. To achieve this, we can reference the of the Glider API documentation to identify the function that queries for external calls.
Challenge: Update the following query such that it queries for external call instructions:
Now that we’ve identified external call instructions, let’s take it a step further and find the instructions executed immediately after those external calls.
To achieve this, we need to iterate over each instruction and check how many next instructions exist. If 1 or more instructions do exist, then we have a positive hit.
Challenge: Update the query below to only return external call instructions that are followed by other instructions.
Extra Challenge: Use the filter() function to exclude instructions that don’t have any next instructions.
Now that we’ve identified cases where additional instructions are executed after an external call, let’s take it further by examining these instructions to see if any of them write to the contract’s storage (i.e., update a state variable).
Challenge: Use the is_storage_write()
method to filter instructions and return only external call instructions that are followed by instructions that update the contract’s storage.
So far, our query identifies external calls and checks if any of the following instructions write to storage.
In this final exercise, we want to take it a step further by identifying external call instructions that also invoke abi.encode. To achieve this, you’ll need to add an additional filter to your query that checks for cases where the external call instruction includes a call to abi.encode.
We have a query that finds Solidity instructions:
We want to update this query to find delegatecall instructions.
Challenge: Identify the Glider function that, when called on Instructions()
, will return only delegatecall instructions.
Refer to this to learn how to retrieve an instruction’s next instructions.
To check if an instruction is writing to contract storage, Glider provides a we can use. This function allows us to determine whether a given instruction performs a write operation on the contract’s state.
To retrieve all the calls made within an instruction, use the function.