Implemented a heuristic-based security vulnerability detection system that analyzes Soroban smart contract transactions during replay to identify potential security issues.
-
internal/security/detector.go- Core detection engine- Implements 6 vulnerability checks
- Distinguishes between verified risks and heuristic warnings
- Analyzes transaction envelopes, events, and logs
-
internal/security/detector_test.go- Unit tests- Tests for each vulnerability type
- Edge case coverage
- Multiple findings scenarios
-
internal/security/integration_test.go- Integration tests- Flawed contract simulation
- Type distinction verification
- End-to-end detection validation
-
internal/security/example_test.go- Usage examples- Demonstrates API usage
- Serves as documentation
-
internal/security/README.md- Comprehensive documentation- Feature descriptions
- Usage guide
- Extension guidelines
internal/cmd/debug.go- Integrated security detector into debug command
- Added formatted security analysis output
- Displays verified risks and heuristic warnings separately
- Detects arithmetic failures in logs
- Keywords: overflow, underflow, checked_add, checked_sub, checked_mul
- Severity: HIGH
- Native XLM: > 1M XLM threshold
- Contract tokens: > 10M tokens threshold
- Severity: HIGH/MEDIUM
- Multiple contract invocations with state changes
- Severity: MEDIUM
- Failed auth checks in events
- Severity: HIGH
- Privileged operations without auth checks
- Severity: HIGH
- Contract execution panics
- Severity: HIGH
VERIFIED_RISK: Confirmed security issues with concrete evidence
- Integer overflow/underflow
- Authorization failures
- Contract panics
HEURISTIC_WARNING: Potential concerns based on patterns
- Large value transfers
- Reentrancy patterns
- Authorization bypass patterns
=== Security Analysis ===
⚠️ VERIFIED SECURITY RISKS: 2
⚡ HEURISTIC WARNINGS: 1
Findings:
1. ⚠️ [VERIFIED_RISK] HIGH - Integer Overflow/Underflow Detected
Arithmetic operation failed, indicating potential overflow or underflow
Evidence: checked_add failed: overflow detected
2. ⚡ [HEURISTIC_WARNING] HIGH - Large Value Transfer Detected
Transfer of 200000000000000 stroops (20000000.00 XLM) detected. Verify recipient address.
Evidence: Destination: GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H
3. ⚡ [HEURISTIC_WARNING] HIGH - Potential Authorization Bypass
Privileged operation detected without corresponding authorization check
Evidence: Review contract authorization logic
All tests pass:
$ go test ./internal/security/... -v
PASS
ok github.com/dotandev/hintents/internal/security 0.005s- ✅ Individual vulnerability detection
- ✅ Multiple findings in single transaction
- ✅ Flawed contract simulation
- ✅ Type distinction (verified vs heuristic)
- ✅ No false positives on clean execution
- ✅ Edge cases and error handling
import "github.com/dotandev/hintents/internal/security"
detector := security.NewDetector()
findings := detector.Analyze(envelopeXdr, resultMetaXdr, events, logs)
for _, finding := range findings {
fmt.Printf("[%s] %s - %s\n", finding.Type, finding.Severity, finding.Title)
}./erst debug <transaction-hash>Security analysis is automatically included in the output.
✅ CLI emits "Security Warning" for suspicious patterns
- Implemented with clear distinction between verified risks (
⚠️ ) and heuristic warnings (⚡)
✅ Integrate rule-based checkers
- 6 vulnerability checks implemented
- Pattern-based detection for common attack vectors
✅ Analyze event logs and state changes
- Events analyzed for auth failures, panics, state changes
- Logs analyzed for overflow, privileged operations
✅ Test against flawed contract
- Integration test simulates flawed contract
- Verifies all major vulnerability types detected
✅ Clearly differentiate risk types
- VERIFIED_RISK: Confirmed issues with evidence
- HEURISTIC_WARNING: Potential concerns requiring review
- Visual distinction in CLI output (
⚠️ vs ⚡)
- Configurable thresholds via CLI flags
- Custom rule definitions
- Integration with vulnerability databases
- Machine learning-based detection
- Source code mapping for findings
No new external dependencies added. Uses existing:
github.com/stellar/go/xdr- XDR parsing- Standard library - String matching, big integers
- Comprehensive README in
internal/security/ - Inline code documentation
- Example tests for API usage
- Integration guide in main README (to be added)