Semgrep Rule Creator (MX)
This skill guides you in writing Semgrep rules to catch MultiversX-specific patterns automatically.
1. Common Patterns
- Unsafe Math:
x + ywherexisu64. - Floating Point:
f64. - Endpoint without Payment Check:
#[payable]function withoutcall_value().
2. Template
rules:
- id: mvx-unsafe-addition
languages: [rust]
message: "Potential arithmetic overflow. Use checked_add or BigUint."
severity: ERROR
patterns:
- pattern: $X + $Y
- pattern-not: $X.checked_add($Y)
- pattern-inside: |
#[multiversx_sc::contract]
trait Contract {
...
}
3. Workflow
- Identify Pattern: See
mvx_variant_analysis. - Write Rule: Use the template.
- Test: Run on the codebase using
semgrep --config rules.yaml . - Refine: Reduce false positives.