Pull Request: Unified AST, Extensible Rule Engine & Auto-Fix Suite (#186, #187, #189, #190)#195
Merged
mijinummi merged 1 commit intoApr 23, 2026
Conversation
|
@elizabetheonoja-art Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
This PR executes a foundational refactor of the GasGuard ecosystem. It bridges the gap between different smart contract languages by introducing a Common AST (CAST) and unlocks community-driven growth through a new Plugin System. Furthermore, it completes the developer loop with Auto-Fix capabilities and a plug-and-play GitHub Action.
🎯 Key Changes by Module
The CAST Schema: Defined a language-agnostic Abstract Syntax Tree in libs/ast/ that maps high-level constructs (Loops, Variable Assignments, Storage Access) across Solidity, Rust (Soroban), and Vyper.
Adapters: Implemented specialized parsers in libs/parsers/ that normalize language-specific outputs into the GasGuard CAST format.
Plugin Core: Decoupled the rule engine. Rules are now standalone TypeScript modules that implement a standardized GasRule interface.
Dynamic Loading: The CLI now supports --plugin , allowing external contributors to run custom analysis without modifying the core codebase.
Automation: Created a Docker-based GitHub Action that scans contracts on every PR.
PR Annotations: Findings are now injected directly into the GitHub "Files Changed" view as line-item comments, including gas-saving estimates.
Safe Transformations: Introduced the libs/auto-fix/ engine which can automatically apply "Safe" optimizations (e.g., changing memory to calldata in Solidity or optimizing vec iterations in Rust).
CLI Preview: Added gasguard fix --preview to show a git-style diff before applying changes.
💻 Implementation Detail: The Plugin Interface
TypeScript
// packages/types/ast/plugin.ts
export interface GasRule {
id: string;
meta: {
description: string;
impact: 'High' | 'Medium' | 'Low';
};
// Works on the Unified AST regardless of source language
check(node: CASTNode): Diagnostic | null;
fix?(node: CASTNode): Patch | null;
}
✅ Acceptance Criteria Checklist
[x] Cross-Language: A single rule can now detect "Unused State Variables" in both Solidity and Rust files.
[x] Extensibility: Successfully loaded a sample "Third-Party" rule from an external directory.
[x] Automation: Verified that the GitHub Action fails the build if a "High" impact gas leak is detected.
[x] Actionable: gasguard fix successfully generates valid .patch files for detected issues.
🚀 How to Verify
Test Unified AST: Run npm run test:ast to see Solidity and Rust snippets generate the same CAST structure.
Test Auto-Fix: ```bash
cd apps/cli && ts-node src/index.ts fix ./contracts/Vulnerable.sol --auto-fix
CI Simulation: Run the GitHub Action locally using act or push to a test repository to see the PR annotations in action.
🔗 Linked Issues
Closes #186,
Closes #187,
Closes #189,
Closes #190