Implemented and fixed SLOT-Vis, Implemented ZERO-verifier, Est inline… - #680
Merged
Merged
Conversation
… yul and an instant detect for unverified declarations
|
@Sadeequ 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! 🚀 |
2 tasks
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.
Here is a full summary of all changes made across the four issues.
Issue 1: CLI Storage Slot Visualizer & Re-Packing Auto-Fixer [CLOSES #664] ✔️
I created a new gasguard-cli Rust crate with the following files:
gasguard-cli/Cargo.toml— Minimal crate manifest declaring the gasguard-cli package with edition 2021.gasguard-cli/src/lib.rs— Library entry point that exports two public modules: commands and storage_model.gasguard-cli/src/commands/mod.rs— Module root that re-exports optimize_storage.gasguard-cli/src/commands/optimize_storage.rs— Implements run_optimize_storage(contract_path) which parses Solidity source text to extract state variable declarations, computes optimal storage packing, and prints a before/after slot visual map to the terminal. It includesparse_state_variables()for lightweight text-based parsing of contract bodies and try_parse_variable() for matching declaration patterns like uint256 public balance;. The module also includes unit tests for parsing and the CLI runner.gasguard-cli/src/storage_model.rs— Core storage modeling module defining TypeSize, StateVariable, StorageSlot, and PackingResult structs. It implementstype_size_of()(mapping Solidity type names to byte sizes),classify_variable()(determining packability), andcompute_optimal_packing()which uses a first-fit decreasing bin-packing algorithm into 32-byte EVM storage slots. It also provides format_slot_visual() for rendering a terminal-friendly slot map with progress bars showing bytes used per slot. Includes comprehensive unit tests for type sizing, classification, packing computation, and visual formatting.Issue 2: Zero-Allocation Merkle Proof Verifier in Yul [CLOSES #666] ✔️
contracts/crypto/YulMerkleVerifier.sol— A Solidity library implementing Merkle proof verification entirely in Yul assembly. It provides three functions:verifyProof()— Uses canonical (sorted) ordering via bitwise comparison (gt) to determine sibling placement, computing keccak256(0x00, 0x40) in scratch memory for each proof step.verifyProofOrdered() — Uses explicit left-to-right ordering without canonical sorting.
Both functions maintain intermediate leaf hashes strictly in scratch memory (0x00–0x40) with no dynamic memory allocation.
Includes InvalidProof, InvalidLeaf, and InvalidProofLength errors.
test/crypto/YulMerkleVerifier.test.ts— Test suite covering valid single-element and multi-element proofs, invalid leaf detection, invalid proof path rejection, empty proof (leaf equals root), and gas efficiency with 10-element proofs.Issue 3: Inline Yul/Assembly Annotation Standard [CLOSES #669] ✔️
docs/ASSEMBLY_STYLE_GUIDE.md — A comprehensive assembly style guide defining:
Stack state annotation format (// [arg1, arg2] -> [result]) placed directly above every assembly block.
Safety invariants comments covering memory safety, storage safety, reentrancy safety, and gas safety.
Scratch memory (0x00–0x40) vs free memory pointer (0x40) conventions.
Required comment format: stack state annotation + safety invariants above every assembly block.
Variable naming conventions (camelCase, descriptive names).
Loop pattern annotations with invariant and termination guarantees.
Annotated contracts/utils/ files — All assembly blocks in three files now carry both stack state annotations and safety invariants:
contracts/utils/YulNativeTransfer.sol — Annotated the call(gas(), ...) assembly block in safeTransferETH.
contracts/utils/MappingResolver.sol — Annotated all five assembly blocks across computeSlot, computeNestedSlot, computeAddrSlot, computeUintSlot, and the three sload calls in MappingResolverConsumer.
contracts/utils/CodeCheckLib.sol — Annotated the extcodesize assembly block in isContract.
Issue 4: Rule G011 — Detect Unused State Variable Declarations [CLOSES #671] ✔️
rules/g011_unused_storage.rs — Implements detect_unused_storage() which takes a list of declared state variables (name + line number) and a list of function body source slices, then flags any variable that lacks read or write references across all function bodies. The contains_identifier_reference() helper distinguishes declarations from usage by checking for type keyword prefixes and identifier boundaries. Includes unit tests for flagging unused variables, ignoring used variables (read and write), handling multiple functions, handling multiple unused variables, and edge cases (empty inputs, no function bodies).
test/fixtures/g011_samples.sol — Three sample contracts for testing: UnusedStateVariables (has unusedVar, neverRead, neverWritten), AllVariablesUsed (all variables are read/written), and MixedUsage (some used, some unused).