Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Smart Contract Security
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
POTHURI HARIKA
Smart Contract Security
Commits
d7e9de60
Commit
d7e9de60
authored
Jun 15, 2023
by
POTHURI HARIKA
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
3adcb9c2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tools/SmartCheck/Solidity/Rules/SOLIDITY_REDUNDANT_FALLBACK_REJECT.md
+169
-0
169 additions, 0 deletions
...heck/Solidity/Rules/SOLIDITY_REDUNDANT_FALLBACK_REJECT.md
with
169 additions
and
0 deletions
Tools/SmartCheck/Solidity/Rules/SOLIDITY_REDUNDANT_FALLBACK_REJECT.md
0 → 100644
+
169
−
0
View file @
d7e9de60
# Analysis of Smart Contract Security Vulnerabilities and Tools 






<br/>
!
[](
https://img.shields.io/badge/BlockchainCourse-21CY712-green
)


<br/>

<br/>

## SOLIDITY_REDUNDANT_FALLBACK_REJECT
### Rule Description
<p>
The payment rejection fallback is redundant.
</p>
<p>
Contracts should reject unexpected payments. Before Solidity 0.4.0, it was done manually:
</p>
<pre>
<code>
function () { revert(); }
</code>
</pre>
<p>
Starting from Solidity 0.4.0, contracts without a fallback function automatically
revert payments, making the code above redundant.
</p>
### Solidity-Rules


```
sourceUnit
[pragmaDirective/pragmaSolidity/version[versionLiteral >= "0.4.0"]]
/contractDefinition/contractPartDefinition/functionFallBackDefinition/block
[count(descendant-or-self::statement) = 1]
[statement/throwRevertStatement]
```
### Sample Code
```
pragma solidity 0.4.24;
contract C1 {
// <yes> <report> SOLIDITY_REDUNDANT_FALLBACK_REJECT b85a32
function() payable {
throw;
}
}
contract C2 {
// <yes> <report> SOLIDITY_REDUNDANT_FALLBACK_REJECT b85a32
function() {
revert();
}
}
contract C3 {
function() payable {
if(msg.sender == address(0)) {
revert();
}
}
}
contract C4 {
address a;
function() payable {
a = msg.sender;
revert();
}
}
```
### Abstract Syntax Tree
[
Click Here
](
https://astexplorer.net/#/gist/d80d293b48b3017a2df3a5ebdab3b2e5/95b3a55d434885f042b9be0ef0f664661e0a4e04
)
to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_
### Code Result
```
SOLIDITY_DEPRECATED_CONSTRUCTIONS
patternId: 49bd2a
severity: 1
line: 6
column: 8
content: throw
ruleId: SOLIDITY_LOCKED_MONEY
patternId: 30281d
severity: 3
line: 3
column: 0
content: contractC1{function()payable{throw;}}
ruleId: SOLIDITY_LOCKED_MONEY
patternId: 30281d
severity: 3
line: 15
column: 0
content: contractC3{function()payable{if(msg.sender==address(0)){revert();}}}
ruleId: SOLIDITY_LOCKED_MONEY
patternId: 30281d
severity: 3
line: 22
column: 0
content: contractC4{addressa;function()payable{a=msg.sender;revert();}}
ruleId: SOLIDITY_REDUNDANT_FALLBACK_REJECT
patternId: b85a32
severity: 1
line: 5
column: 23
content: {throw;}
ruleId: SOLIDITY_REDUNDANT_FALLBACK_REJECT
patternId: b85a32
severity: 1
line: 11
column: 15
content: {revert();}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 17
column: 8
content: if(msg.sender==address(0)){revert();}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 5
column: 4
content: function()payable{throw;}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 11
column: 4
content: function(){revert();}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 16
column: 4
content: function()payable{if(msg.sender==address(0)){revert();}}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 24
column: 4
content: function()payable{a=msg.sender;revert();}
ruleId: SOLIDITY_VISIBILITY
patternId: b51ce0
severity: 1
line: 23
column: 4
content: addressa;
SOLIDITY_VISIBILITY :5
SOLIDITY_DEPRECATED_CONSTRUCTIONS :1
SOLIDITY_REVERT_REQUIRE :1
SOLIDITY_LOCKED_MONEY :3
SOLIDITY_REDUNDANT_FALLBACK_REJECT :2
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment