Skip to main content

Module matcher

Module matcher 

Source
Expand description

The root-cause matcher: decides which failing tests of different agents prove the same bug.

root_cause_groups is the only entry point, so another matcher can replace this one. A claim with a @bug <Contract>.<function> <file>:<line> tag names its target, and two tagged claims agree on the target. Other claims are free text, and the word matcher compares them.

Re-exportsΒ§

use regex::Regex; πŸ”’
use std::collections::HashSet; πŸ”’
use std::sync::LazyLock; πŸ”’

StructsΒ§

BugTag πŸ”’
The target of a tagged claim: two tagged claims agree when they name the same function in the same file, at lines that are near.
RootCause πŸ”’
What two failing tests with free-text claims must share to have one root cause: the file that their claims name, and a function name at near lines or most of the claims’ words.

ConstantsΒ§

CLAIM_OVERLAP πŸ”’
Two claims agree when at least 3/10 of their combined words are shared, the threshold of the offline analysis.
LINE_WINDOW πŸ”’
Two tagged claims about one function agree only when their lines are at most this far apart. A function rarely spans more lines, so the window keeps apart functions with one name in one file, such as overloads or functions of two contracts, but not two lines of one function.
STOP_WORDS πŸ”’
Words that do not tell two claims apart.

StaticsΒ§

BUG_TAG πŸ”’
A @bug <Contract>.<function> <file>:<line> tag at the start of a claim, also as the NatSpec tag @custom:bug. The contract and an argument list after the function are optional.
CAMEL_CASE πŸ”’
A camelCase identifier.
FUNCTION_CALL πŸ”’
A function name followed by its argument list.
GENERIC_CALL πŸ”’
A call that names no function of the code under test, such as a builtin or a type conversion.
SOLIDITY_FILE πŸ”’
A Solidity file path.
SOLIDITY_LOCATION πŸ”’
A Solidity file path and an optional line.
WORD πŸ”’
A lowercase word.

FunctionsΒ§

root_cause_groups πŸ”’
Returns a group number for the claim of each failing test: tests with the same number have one root cause. Two tagged claims agree by their tags. Otherwise the word matcher compares the claims, also when only one of them has a tag. Groups use complete linkage: in claim order, a test joins the first group whose every test agrees with it, else starts a group numbered by its index. A chain of agreeing pairs, such as a bare Vault.sol between two Vault.sol files or lines that step across the line window, does not link two tests, so it cannot inflate the quorum. A test without a claim, or whose claim names no Solidity file, agrees with no other test.
same_file πŸ”’
Returns whether two Solidity paths of claims can name the same file: one is the other or ends with it. Agents name a file relative to the project, by its file name, or by its path in their copy of the project, so Vault.sol and /tmp/copy/src/Vault.sol agree with src/Vault.sol, but src/one/Vault.sol and src/two/Vault.sol do not.