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
5b3d5464
Commit
5b3d5464
authored
1 year ago
by
POTHURI HARIKA
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
ede4de3c
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_SHOULD_RETURN_STRUCT.md
+135
-0
135 additions, 0 deletions
...martCheck/Solidity/Rules/SOLIDITY_SHOULD_RETURN_STRUCT.md
with
135 additions
and
0 deletions
Tools/SmartCheck/Solidity/Rules/SOLIDITY_SHOULD_RETURN_STRUCT.md
0 → 100644
+
135
−
0
View file @
5b3d5464
# Analysis of Smart Contract Security Vulnerabilities and Tools 






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


<br/>

<br/>

## SOLIDITY_SHOULD_RETURN_STRUCT
### Rule Description
<p>
Consider using struct instead of multiple return values for
<code>
internal
</code>
or
<code>
private
</code>
functions. It can improve code readability.
</p>
### Solidity-Rules


```
sourceUnit
[
not(pragmaDirective//versionLiteral
[matches(text()[1], "^0\.\s*[5-9]\s*\.|^0\.\s*[0-9]{2,}\s*\.|^[1-9]")])
and not(pragmaDirective/pragmaExperimental//stringLiteral
[text()[1] = "ABIEncoderV2"])
]
//functionDefinition[visibleType[matches(text()[1], "internal|private")]]
/returnsParameters/parameterList[count(parameter) > 3]
```


```
sourceUnit
[
pragmaDirective//versionLiteral
[matches(text()[1], "^0\.\s*[5-9]\s*\.|^0\.\s*[0-9]{2,}\s*\.|^[1-9]")]
or pragmaDirective/pragmaExperimental//stringLiteral
[text()[1] = "ABIEncoderV2"]
]
//functionDefinition/returnsParameters/parameterList[count(parameter) > 3]
```


```
expression[text()[1] = "="]
[expression[1]/tupleExpression[count(expression) > 3]]
[expression[2]/functionCall]
```
### Sample Code
```
pragma solidity 0.4.24;
contract C {
// <yes> <report> SOLIDITY_SHOULD_RETURN_STRUCT 7d54ca
function f1() internal returns(uint a, uint b, uint c, uint d) {
a = 1;
b = 2;
c = 3;
d = 4;
}
// <yes> <report> SOLIDITY_SHOULD_RETURN_STRUCT 7d54ca
function f2() private returns(uint a, uint b, uint c, uint d) {
a = 1;
b = 2;
c = 3;
d = 4;
}
function f5() external returns(uint a, uint b, uint c, uint d) {
a = 1;
b = 2;
c = 3;
d = 4;
}
function f6() returns(uint a) {
a = 1;
}
function f7() public returns(uint a, uint b, uint c, uint d) {
a = 1;
b = 2;
c = 3;
d = 4;
}
function f8() public returns(uint a, uint b) {
(a, b) = f7();
}
function f9() public returns(uint a, uint b, uint c, uint d) {
// <yes> <report> SOLIDITY_SHOULD_RETURN_STRUCT e5gh7l
(a, b, c, d) = f2();
}
function f10() public returns(uint a) {
(a, , , ) = f2();
}
}
```
### Abstract Syntax Tree
[
Click Here
](
https://astexplorer.net/#/gist/3600fc939d721a465259258985b48432/e0c31089dc5266ebbfcbd0ee79b07d08b98fe084
)
to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_
### Code Result
```
SOLIDITY_SHOULD_RETURN_STRUCT
patternId: 7d54ca
severity: 1
line: 5
column: 34
content: (uinta,uintb,uintc,uintd)
ruleId: SOLIDITY_SHOULD_RETURN_STRUCT
patternId: 7d54ca
severity: 1
line: 12
column: 33
content: (uinta,uintb,uintc,uintd)
ruleId: SOLIDITY_VISIBILITY
patternId: 910067
severity: 1
line: 26
column: 4
content: functionf6()returns(uinta){a=1;}
SOLIDITY_VISIBILITY :1
SOLIDITY_SHOULD_RETURN_STRUCT :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