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
0360cb12
Commit
0360cb12
authored
2 years ago
by
POTHURI HARIKA
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
db7a2a66
Branches
Branches containing commit
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_DO_WHILE_CONTINUE.md
+117
-0
117 additions, 0 deletions
...s/SmartCheck/Solidity/Rules/SOLIDITY_DO_WHILE_CONTINUE.md
with
117 additions
and
0 deletions
Tools/SmartCheck/Solidity/Rules/SOLIDITY_DO_WHILE_CONTINUE.md
0 → 100644
+
117
−
0
View file @
0360cb12
# Analysis of Smart Contract Security Vulnerabilities and Tools 






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


<br/>

<br/>

## SOLIDITY_DO_WHILE_CONTINUE
### Rule Description
Prior to version 0.5.0, Solidity compiler handles code inside do-while loop incorrectly it will ignores code while condition.
### Solidity-Rules


```
sourceUnit[pragmaDirective
[not(//versionOperator) or //versionOperator[text()[1] = "^"]]
[//versionLiteral[not(matches(text()[1], "^0\.\s*[5-9]\s*\.|^0\.\s*[0-9]{2,}\s*\.|^[1-9]"))]]]
//doWhileStatement
[statement//continueStatement
[
not(ancestor::forStatement[ancestor::doWhileStatement])
and not(ancestor::whileStatement[ancestor::doWhileStatement])
]
]
```
### Sample Code
```
pragma solidity ^0.4.24;
contract DoWhileFalse {
function doWhile() {
// <yes> <report> SOLIDITY_DO_WHILE_CONTINUE 94fra3
do {
continue;
} while(false);
}
function doWhile_2() {
do {
while(false) {
continue;
}
} while(false);
do {
for(uint i;i<10;i++) {
continue;
}
} while(false);
// <yes> <report> SOLIDITY_DO_WHILE_CONTINUE 94fra3
do {
for(uint j;j<10;j++) {
continue;
}
continue;
} while(false);
}
}
```
### Abstract Syntax Tree
[
Click Here
](
https://astexplorer.net/#/gist/a598063096828250367456ebe5e2e558/68ae004784bda74743e4963c19c4aaec06546a01
)
to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_
### Code Result
```
SOLIDITY_DO_WHILE_CONTINUE
patternId: 94fra3
severity: 1
line: 7
column: 8
content: do{continue;}while(false)
ruleId: SOLIDITY_DO_WHILE_CONTINUE
patternId: 94fra3
severity: 1
line: 25
column: 8
content: do{for(uintj;j<10;j++){continue;}continue;}while(false)
ruleId: SOLIDITY_GAS_LIMIT_IN_LOOPS
patternId: 17f23a
severity: 1
line: 14
column: 18
content: false
ruleId: SOLIDITY_PRAGMAS_VERSION
patternId: 23fc32
severity: 1
line: 1
column: 16
content: ^
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 5
column: 4
content: functiondoWhile(){do{continue;}while(false);}
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 12
column: 4
content: functiondoWhile_2(){do{while(false){continue;}}while(false);do{for(uinti;i<10;i++){continue;}}while(false);do{for(uintj;j<10;j++){continue;}continue;}while(false);}
SOLIDITY_VISIBILITY :2
SOLIDITY_PRAGMAS_VERSION :1
SOLIDITY_GAS_LIMIT_IN_LOOPS :1
SOLIDITY_DO_WHILE_CONTINUE :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