Skip to content

Commit e15a206

Browse files
committed
Adding the missing assignment rule
1 parent 520e81c commit e15a206

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ olympus-dao-staking-incorrect-call-order | OlympusDAO, FloorDAO, Heavens Gate, J
134134
compound-precision-loss | Hundred Finance, Midas Finance, Onyx Protocol | In Compound forks if there is a market with totalSupply = 0 and collateralFactor != 0 a precision loss attack is possible if redeemAmount is taken from the arguments of redeemFresh()
135135
thirdweb-vulnerability | Swopple Token, TIME Token, NAME Token, HXA Token | In contracts that support Multicall and ERC2771Context an Arbitrary Address Spoofing attack is possible
136136
exact-balance-check | Generic | Testing the balance of an account as a basis for some action has risks associated with unexpected receipt of ether or another token, including tokens deliberately transfered to cause such tests to fail, as an MEV attack.
137+
missing-assignment | Generic | Meaningless statement that does not change any values could be a sign of missed security checks or other important changes.
138+
137139

138140
## Gas Optimization Rules
139141

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
contract Test {
2+
// ok: missing-assignment
3+
struct Kek {
4+
// ok: missing-assignment
5+
mapping(uint256 => uint256) lol;
6+
}
7+
8+
// ok: missing-assignment
9+
function smth(uint256 _id) {
10+
// ok: missing-assignment
11+
Kek puk;
12+
// ruleid: missing-assignment
13+
puk.lol[_id];
14+
// ok: missing-assignment
15+
uint256 haha = 123;
16+
// ok: missing-assignment
17+
haha = 321;
18+
// ruleid: missing-assignment
19+
haha;
20+
// ruleid: missing-assignment
21+
haha == 123;
22+
// ok: missing-assignment
23+
haha += 1;
24+
// ok: missing-assignment
25+
haha -= 1;
26+
// ok: missing-assignment
27+
haha++;
28+
// ok: missing-assignment
29+
haha--;
30+
// ok: missing-assignment
31+
--haha;
32+
// ok: missing-assignment
33+
++haha;
34+
// ok: missing-assignment
35+
return haha;
36+
}
37+
38+
// ok: missing-assignment
39+
function doit(uint256 a) {}
40+
41+
function heh(uint256 _id) {
42+
// ok: missing-assignment
43+
Kek puk;
44+
// ok: missing-assignment
45+
doit(puk.lol[_id]);
46+
// ok: missing-assignment
47+
doit(puk.lol[_id]);
48+
// ruleid: missing-assignment
49+
"heh";
50+
// ok: missing-assignment
51+
return;
52+
}
53+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
rules:
2+
- id: missing-assignment
3+
message: Meaningless statement that does not change any values could be a sign of missed security checks or other important changes.
4+
metadata:
5+
category: security
6+
technology:
7+
- solidity
8+
cwe: "CWE-1164: Irrelevant Code"
9+
confidence: HIGH
10+
likelihood: HIGH
11+
impact: MEDIUM
12+
subcategory:
13+
- vuln
14+
patterns:
15+
- pattern-either:
16+
- pattern: |
17+
$X;
18+
- pattern: |
19+
$X[$Y];
20+
- pattern: |
21+
$X == $Y;
22+
- pattern-not: $FUNC(...);
23+
- pattern-not: $FUNC();
24+
- pattern-not: $VAR++;
25+
- pattern-not: $VAR--;
26+
- pattern-not: ++$VAR;
27+
- pattern-not: --$VAR;
28+
- pattern-not: ... = ...;
29+
- pattern-not: ... += ...;
30+
- pattern-not: ... -= ...;
31+
- pattern-not: $TYPE $VAR;
32+
- pattern-not: return $VAR;
33+
- pattern-not: return;
34+
- pattern-not: continue;
35+
- pattern-not: break;
36+
- pattern-not: _;
37+
- pattern-not: error $NAME();
38+
- pattern-not: error $NAME($ARGS);
39+
#- pattern-not: function $NAME($ARGS) virtual {} # doesn't work
40+
- pattern-not: | # let's not match empty function bodies
41+
{}
42+
- metavariable-regex:
43+
metavariable: $X
44+
regex: "^\\S+$"
45+
languages:
46+
- solidity
47+
severity: WARNING

0 commit comments

Comments
 (0)