Skip to content

Implemented and fixed SLOT-Vis, Implemented ZERO-verifier, Est inline… - #680

Merged
mijinummi merged 1 commit into
MDTechLabs:mainfrom
Sadeequ:ish-664-666-669-671
Jul 28, 2026
Merged

Implemented and fixed SLOT-Vis, Implemented ZERO-verifier, Est inline…#680
mijinummi merged 1 commit into
MDTechLabs:mainfrom
Sadeequ:ish-664-666-669-671

Conversation

@Sadeequ

@Sadeequ Sadeequ commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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 includes parse_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 implements type_size_of() (mapping Solidity type names to byte sizes), classify_variable() (determining packability), and compute_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).

… yul and an instant detect for unverified declarations
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@mijinummi
mijinummi merged commit a6a4837 into MDTechLabs:main Jul 28, 2026
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants