Exercises
Last updated
Last updated
In this section, we will present several exercises that will fortify your Functions query skills. Each exercise provided comes along with a solution if you get stuck.
In this exercise, your task is to identify contracts that contain the term "Swap" in their contract names.
As we’ve done in previous sections, start by reviewing the to find any Glider functions that can help you find contracts by their name.
Challenge: Find the necessary Glider function that finds contracts given a regex. Then update the query with the found Glider function.
Now that we’ve identified contracts with names containing the word "Swap", let’s take it a step further by filtering for contracts that contain the setOracleAddress function.
Challenge: Update your query from Example #1 to filter out contracts that don’t contain the setOracleAddress function.
A Solidity contract may inherit from parent contracts. Both the main contract and its parent contracts share the same address. When querying contracts, Glider may return multiple associated contracts in the results.
To specifically identify the main contract, you can use Glider’s mains()
method.
Challenge: Update the query to return only the main contracts from the query results.
This query has focused on identifying swap-like contracts that update their oracle address through a Solidity function called setOracleAddress. But what if we want to return all functions that don’t have modifiers?
Identifying functions without modifiers can help us uncover potential access control vulnerabilities, as these functions may be publicly accessible without restrictions.
Thankfully, we can achieve this with Glider!
To do so, we’ll:
1. Iterate through each contract function.
2. Count the number of modifiers applied to each function.
3. Filter out functions with modifiers to focus only on unrestricted functions.
This approach will give us a list of functions without modifiers, helping us identify any security risks in the contract.
Challenge: Update the query from Exercise #4 to return functions without modifiers.
We want to look for state variables in a contract.
Challenge: Identify the Glider class that will query for state variables.
Refer to the to find the function needed to complete this challenge.
In this query, we’ll need to retrieve each contract’s functions. As a hint, refer to the relevant in the documentation that allows you to query a contract’s functions.