fix: harden G016/G017 rules, wire up heatmap reporter, and cover assembly-log event topics - #757
Merged
mijinummi merged 1 commit intoJul 31, 2026
Conversation
…mbly-log event topics PR MDTechLabs#716 previously landed the initial implementations for issues MDTechLabs#731, MDTechLabs#730, MDTechLabs#729, and MDTechLabs#728, but each still had real gaps against its original acceptance criteria: - G016 (redundant address casts): the check only did a flat substring search, so it missed deeper chains like address(uint160(uint256(x))) and address(payable(uint160(x))), and had no safeguard against matching inside comments. Added detection for those chains, comment stripping, and unit tests covering both the new positive cases and the "does not flag necessary bytes32 -> address conversions" negative case called out in the issue. - G017 (enum iteration): the check only looked for "any loop" plus "any enum keyword anywhere in the file", which fails the issue's own acceptance criterion of "passes cleanly on standard integer index loops" (it flagged unrelated loops whenever an enum was declared anywhere in the contract). Rewrote it to isolate each loop body and only flag loops that actually cast their index into a known enum type, added nested-loop and while-loop coverage, and added unit tests for both positive and negative cases. - Event topics (MDTechLabs#730): EventRegistry.sol's test file was a placeholder that asserted `true == true` and never verified the topic constants. Added ApprovalForAll/OwnershipTransferred constants, an emitViaAssembly() function demonstrating a low-level log call consuming a compile-time constant topic directly (per the issue's second requirement, which wasn't previously demonstrated), and a real test suite that checks each constant against ethers.id(...) of its canonical signature. - Heatmap reporter (MDTechLabs#728): reporter::heatmap was never declared in gasguard-cli's lib.rs, so it was dead code not compiled into the crate at all. Wired it up, added a legend describing the tiers and colors, added visual severity bars (the "summary visual bars" requirement wasn't previously implemented), and made functions with no gas estimate render as an explicit N/A tier instead of silently falling into the LOW bucket. Closes MDTechLabs#731 Closes MDTechLabs#730 Closes MDTechLabs#729 Closes MDTechLabs#728
|
@silifatzoffun74-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.
Context
Issues #731, #730, #729, and #728 were originally implemented in PR #716 (merged as commit 89801da), but the issues were left open. This PR does not duplicate that work — it adds concrete, itemized improvements on top of it, addressing gaps against each issue's own acceptance criteria.
What changed
G016 — Redundant address casts (#729)
rules/g016_redundant_casts.rspreviously only did a flat substring search foraddress(uint160(/address(payable(, so it missed deeper chains and had no protection against matching inside comments.address(uint160(uint256(x)))andaddress(payable(uint160(x)))/payable(address(uint160(x)))chains.//or/* */comments no longer produce false positives.test/fixtures/g016_samples.solwith the new positive/negative cases.G017 — Enum iteration (#731)
rules/g017_enum_iteration.rspreviously flagged any loop as soon as the contract contained any enum keyword anywhere in the file — which fails the issue's own acceptance criterion "Passes cleanly on standard integer index loops" (a plainforloop over an array in a contract that happens to declare an enum elsewhere was incorrectly flagged).enumtype viaEnumType(i).test/fixtures/g017_samples.solaccordingly.Event topics (#730)
test/events/EventRegistry.test.tswas a placeholder (expect(true).to.be.true) that never actually verified the topic constants.EVENT_APPROVAL_FOR_ALL_TOPICandEVENT_OWNERSHIP_TRANSFERRED_TOPICconstants.emitViaAssembly(), demonstrating the issue's second requirement — a low-levellogcall consuming a compile-time constant topic directly — which wasn't previously demonstrated anywhere in the contract.ethers.id(...)of its canonical event signature, plus tests for bothlogEventandemitViaAssembly.Heatmap reporter (#728)
gasguard-cli/src/reporterwas never declared as a module ingasguard-cli/src/lib.rs, soheatmap.rswas dead code, not compiled into the crate at all.pub mod reporter;intolib.rs.format_legend()/format_report()describing the tier thresholds and colors, so output is self-describing in CI logs.N/Atier instead of silently falling into the LOW bucket.--no-colorvs. color output.Testing
rustc --edition 2021 --test rules/g016_redundant_casts.rs— 6/6 passingrustc --edition 2021 --test rules/g017_enum_iteration.rs— 6/6 passingcd gasguard-cli && cargo test— 32/34 passing (the 2 failures are incommands::optimize_storage, pre-existing onmainand unrelated to this change)contracts/events/EventRegistry.solcompiles standalone viasolc; full-repohardhat compilecurrently fails onmaindue to unrelated pre-existing syntax errors in other contracts (StorageCleaner.sol,BatchGuardProcessor.sol,UnrolledSignatureVerifier.sol,YulMathLib.sol,DirectIndexRouter.sol), confirmed unaffected by this branch.Closes #731
Closes #730
Closes #729
Closes #728