What is a security graph in smart contracts?
A security graph is a model of a codebase as nodes and edges: contracts, functions, state variables and roles are the nodes, and calls, reads, writes, token transfers and permission checks are the edges. It answers questions that a file-by-file read struggles with, such as which public functions can reach a transfer of funds and which of those paths skip the owner check.
What does a security graph record?
Read top to bottom, this contract looks guarded: the transfer checks the owner. As a graph, it has a path from any caller to the destination of the transfer with no check on it.
A contract whose bug shows up as a path in the graph (illustrative, not audited code) FeeVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
contract FeeVault {
address public immutable owner;
IERC20 public immutable token;
address public feeRecipient;
constructor(IERC20 token_) {
owner = msg.sender;
token = token_;
}
function setFeeRecipient(address recipient) external {
feeRecipient = recipient; // no owner check
}
function collectFees(uint256 amount) external {
require(msg.sender == owner, "not owner");
require(token.transfer(feeRecipient, amount), "transfer failed");
}
}
| From | Edge | To |
|---|---|---|
| Any caller | calls, no check | setFeeRecipient |
| setFeeRecipient | writes | feeRecipient |
| Owner only | calls | collectFees |
| collectFees | transfers tokens to | feeRecipient |
Following the edges shows the bug, because the owner decides when fees move but anyone decides where they go.
How is it different from a call graph?
A call graph shows which function calls which. A security graph adds what surrounds each call: the state it reads and writes, the checks that guard it, where value moves and who holds each role. Research tools build similar models. Clue merges a call trace graph, a control flow graph and a data dependence graph from EVM executions, and traverses it to find reentrancy, access control and price manipulation attacks (Qin et al., 2023).
How does QuillShield use a security graph?
QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep. It then checks every pull request on GitHub or GitLab.com against that graph.
FAQ
Can a security graph find bugs on its own?
No, it is a map, and a reviewer or a tool still has to ask it the right questions, such as which paths reach a transfer without a check. Its value is that each question covers the whole codebase at once.