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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
POTHURI HARIKA
Smart Contract Security
Commits
831033d9
Commit
831033d9
authored
1 year ago
by
POTHURI HARIKA
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
d7e9de60
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_REVERT_REQUIRE.md
+160
-0
160 additions, 0 deletions
Tools/SmartCheck/Solidity/Rules/SOLIDITY_REVERT_REQUIRE.md
with
160 additions
and
0 deletions
Tools/SmartCheck/Solidity/Rules/SOLIDITY_REVERT_REQUIRE.md
0 → 100644
+
160
−
0
View file @
831033d9
# Analysis of Smart Contract Security Vulnerabilities and Tools 






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


<br/>

<br/>

## SOLIDITY_REVERT_REQUIRE
### Rule Description
<p>
Using the construction
<code>
if (condition) {revert();}
</code>
instead of
<code>
require(condition);
</code></p>
### Solidity-Rules


```
ifStatement[statement[not(descendant::ifStatement)]//throwRevertStatement]
```
### Sample Code
```
contract f{
function a(){
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if (x>y) { revert(); }
}
modifier atStage(Stages _stage) {
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if (stage != _stage)
revert();
_;
}
}
contract f{
function a(){
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if (x>y) { throw; }
if (tokensToSend > 0) {
allocatedTokens -= tokensToSend;
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if (!token.issue(msg.sender, tokensToSend)) {
revert();
}
}
if (ethToSend > 0) {
allocatedEth -= ethToSend;
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if (!msg.sender.send(ethToSend)) {
revert();
}
}
if (stage == Stages.PresaleStarted) {
buyPresale(receiver);
}
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
else if (stage == Stages.MainSaleStarted) {
buyMainSale(receiver);
} else {
revert();
}
// <yes> <report> SOLIDITY_REVERT_REQUIRE c56b12
if(!ico_ended) {
eth_received = Add(eth_received, msg.value);
} else {
revert();
}
}
}
```
### Abstract Syntax Tree
[
Click Here
](
https://astexplorer.net/#/gist/aa0b52bca154c4266d720f6ed8b0abd5/c89a3def722472c09a5b696db1888775e031aeb2
)
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: 16
column: 19
content: throw
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 4
column: 8
content: if(x>y){revert();}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 8
column: 8
content: if(stage!=_stage)revert();
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 16
column: 8
content: if(x>y){throw;}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 20
column: 12
content: if(!token.issue(msg.sender,tokensToSend)){revert();}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 27
column: 12
content: if(!msg.sender.send(ethToSend)){revert();}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 35
column: 13
content: if(stage==Stages.MainSaleStarted){buyMainSale(receiver);}else{revert();}
ruleId: SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 41
column: 8
content: if(!ico_ended){eth_received=Add(eth_received,msg.value);}else{revert();}
ruleId: SOLIDITY_SEND
patternId: 430636
severity: 1
line: 27
column: 28
content: send(ethToSend)
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 2
column: 4
content: functiona(){if(x>y){revert();}}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 14
column: 4
content: functiona(){if(x>y){throw;}if(tokensToSend>0){allocatedTokens-=tokensToSend;if(!token.issue(msg.sender,tokensToSend)){revert();}}if(ethToSend>0){allocatedEth-=ethToSend;if(!msg.sender.send(ethToSend)){revert();}}if(stage==Stages.PresaleStarted){buyPresale(receiver);}elseif(stage==Stages.MainSaleStarted){buyMainSale(receiver);}else{revert();}if(!ico_ended){eth_received=Add(eth_received,msg.value);}else{revert();}}
SOLIDITY_VISIBILITY :2
SOLIDITY_DEPRECATED_CONSTRUCTIONS :1
SOLIDITY_REVERT_REQUIRE :7
SOLIDITY_SEND :1
```
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