File tree Expand file tree Collapse file tree
packages/rules/src/solidity Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ pub mod parser;
2+ pub mod uint8_vs_uint256;
Original file line number Diff line number Diff line change 1+ use crate :: rule_engine:: { Rule , RuleResult } ;
2+ use crate :: solidity:: parser:: SolidityASTNode ;
3+
4+ pub struct Uint8VsUint256Rule ;
5+
6+ impl Rule for Uint8VsUint256Rule {
7+ fn id ( & self ) -> & ' static str {
8+ "uint8-vs-uint256"
9+ }
10+
11+ fn description ( & self ) -> & ' static str {
12+ "Using uint8 outside structs is often more gas-expensive than uint256 on EVM chains."
13+ }
14+
15+ fn analyze ( & self , ast : & SolidityASTNode ) -> Vec < RuleResult > {
16+ let mut results = Vec :: new ( ) ;
17+
18+ ast. walk ( |node, parent| {
19+ // Match variable declarations
20+ if let SolidityASTNode :: VariableDeclaration { type_name, location } = node {
21+ // Only uint8
22+ if type_name == "uint8" {
23+ // Ignore struct members
24+ if matches ! ( parent, Some ( SolidityASTNode :: StructDefinition { .. } ) ) {
25+ return ;
26+ }
27+
28+ results. push ( RuleResult {
29+ rule_id : self . id ( ) ,
30+ message : "uint8 used outside a struct. Consider using uint256 for better gas efficiency." . to_string ( ) ,
31+ location : location. clone ( ) ,
32+ severity : "LOW" ,
33+ } ) ;
34+ }
35+ }
36+ } ) ;
37+
38+ results
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments