File Structure
A rule file contains reusable components (lists and macros) followed by rules. Components are defined first, then rules reference them:
Organizing Rules in Files
Best Practice: When grouping multiple rules in the same file, ensure they are related to each other (e.g., same category, same threat type, or same protocol). This makes maintenance easier and keeps your rule base organized. Whilelists and macros can be shared across rules in the same file, mixing unrelated rules in a single file can make maintenance complex. Consider organizing rules by:
- Category: All DEX-related rules together, all mixer-related rules together, etc.
- Threat Type: All flash loan attack rules, all phishing rules, etc.
- Protocol: All rules monitoring a specific protocol or contract
- Chain: Rules specific to a particular blockchain
rules/custom/dex-monitoring.yaml might contain:
- Lists of known DEX routers
- Macros for DEX interaction patterns
- Multiple rules detecting different DEX-related threats
- Find and update related rules
- Maintain shared
listsandmacros - Understand the purpose of each file
- Avoid conflicts when multiple team members work on rules
Required Fields
Every rule must include these fields:| Field | Type | Description | Example |
|---|---|---|---|
rule | string | Unique rule name | High Value Transfer |
desc | string | Human-readable description | Detects transfers over 100 ETH |
condition | string | Detection condition expression | tx.value > 100 ether |
output | string | Alert message with placeholders | Large transfer: %tx.value_eth ETH |
priority | string | Alert priority: NOTICE, WARNING, or CRITICAL | WARNING |
enabled | boolean | Whether rule is active | true |
Optional Fields
| Field | Type | Description | Example |
|---|---|---|---|
tags | array | Tags for categorization | ["security", "high-value"] |
chain | array | Target blockchain(s). If not specified, applies to all enabled chains | ["ethereum", "polygon"] |
references | array | URLs to threat intelligence, blog posts, or documentation | ["https://rekt.news/..."] |
Recommended Field Order
For consistency, follow this field order within each rule:rule- Rule identifierdesc- Descriptionreferences- Threat intelligence links (optional)tags- Categorization tags (optional)condition- Detection logicoutput- Alert messagepriority- Severity levelchain- Target networks (optional)enabled- Activation status
The validator will warn if fields are out of order, but won’t block validation. This helps maintain consistency across your rule base.
References Field
Thereferences field allows you to document threat intelligence sources, blog posts, exploit analyses, or any relevant context for your detection rule.
Example
dry-run, the references will be displayed in the output.
Next Steps
Fields
Learn about available transaction fields
Lists & Macros
Create reusable components
Operators
Build conditions with operators
Examples
See complete rule examples