Features
- Heuristic analysis: Pattern matching against common error scenarios
- Confidence levels: Each suggestion includes a confidence rating (high, medium, low)
-
- Call tree analysis: Analyzes entire execution traces including nested contract calls
- Clear marking: All suggestions are clearly marked as βPotential Fixesβ
Suggestions are heuristic-based and may not always be accurate. Always verify before applying fixes.
How it works
The suggestion engine automatically integrates with theerst debug command:
Built-in error patterns
The engine includes seven built-in rules that detect common Soroban errors:1. Uninitialized contract
High confidence rule
- Events contain keywords:
empty,not found,missing,null - Storage-related events indicate empty state
2. Missing authorization
High confidence rule
- Events contain keywords:
auth,unauthorized,permission,signature - Authorization-related failures detected
3. Insufficient balance
High confidence rule
- Events contain keywords:
balance,insufficient,underfunded,funds - Balance-related errors detected
4. Invalid parameters
Medium confidence rule
- Events contain keywords:
invalid,malformed,bad,parameter - Parameter validation failures detected
5. Contract not found
High confidence rule
- Contract ID is empty or all zeros
- Events indicate missing contract
6. Resource limit exceeded
Medium confidence rule
- Events contain keywords:
limit,exceeded,quota,budget - Resource exhaustion detected
7. Reentrancy detected
Medium confidence rule
- Events contain keywords:
reentrant,recursive,loop - Reentrancy patterns detected
Confidence levels
Each suggestion includes a confidence indicator:π΄ High confidence
- Strong pattern match with well-known error scenarios
- Multiple indicators point to the same issue
- Solution is straightforward and commonly applicable
π‘ Medium confidence
- Partial pattern match or ambiguous indicators
- Multiple possible causes
- Solution may require additional investigation
π’ Low confidence
- Weak pattern match or speculative
- Limited evidence
- Suggestion is exploratory
Programmatic usage
Basic usage
Analyzing call trees
For comprehensive analysis of nested contract calls:Adding custom rules
Extend the engine with project-specific error patterns:Architecture
The suggestion engine follows a clean, extensible architecture:Processing flow
- Event collection: Gather all diagnostic events from transaction
- Pattern matching: Check each event against rule keywords and conditions
- Deduplication: Ensure each rule triggers only once
- Formatting: Present suggestions with confidence indicators
- Display: Show suggestions before security analysis
Best practices
For users
Always verify suggestions
Always verify suggestions
Suggestions are heuristic-based and may not always be accurate. Review each suggestion in the context of your specific contract logic.
Check confidence levels
Check confidence levels
Prioritize high-confidence suggestions first. Medium and low confidence suggestions may require more investigation.
Consider your context
Consider your context
Suggestions are general-purpose. Consider your specific contract logic and use case when applying fixes.
Combine with other tools
Combine with other tools
Use suggestions alongside trace analysis and security findings for a complete picture of the issue.
For developers
Keep rules focused
Keep rules focused
Each rule should target a specific error pattern. Avoid overly broad matching.
Avoid false positives
Avoid false positives
Test rules against various scenarios to minimize false positive suggestions.
Document patterns
Document patterns
Clearly document what triggers each rule and why it suggests a particular fix.
Update regularly
Update regularly
Add new rules as common error patterns emerge from the community.
Testing
Run the suggestion engine test suite:- All built-in rules
- Custom rule addition
- Call tree analysis
- Deduplication logic
- Formatting output
- Edge cases (empty events, no matches, etc.)
Example scenarios
Scenario 1: Uninitialized contract
initialize() function before other operations.
Scenario 2: Multiple issues detected
Scenario 3: No suggestions
If no patterns match, the engine provides no suggestions, allowing you to focus on manual debugging.Contributing
To add new error detection rules:- Identify a common error pattern from community issues
- Define keywords and event checks
- Write a clear, actionable suggestion
- Add comprehensive test cases
- Document the rule in this guide
- Submit a PR with real-world examples
Contributions of new error patterns are welcome! Help make Erst smarter for the entire community.
Future enhancements
- Machine learning-based pattern detection
- Integration with contract source code for context-aware suggestions
- Suggestion ranking based on historical accuracy
- Community-contributed rule database
- Multi-language support for suggestions
- Interactive suggestion refinement
- Link suggestions directly to relevant documentation