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






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


<br/>

<br/>

## SOLIDITY_TX_ORIGIN
### Rule Description
<p>
<code>
tx.origin
</code>
is used for authorization.
</p>
<p>
Vulnerability type by SmartDec classification:
<a
href=
"https://github.com/smartdec/classification#authorization"
>
Authorization with tx.origin
</a>
.
</p>
### Solidity-Rules


```
environmentalVariable
[matches(text()[1], "^tx\.origin$")]
/parent::*
[parent::*
[not(comparison
and expression/environmentalVariable[matches(text()[1], "^msg\.sender$")])
]
]
```
### Sample Code
```
pragma solidity 0.6.0;
contract SolidityTxOrigin {
function dangerousWithdraw() public returns (bool) {
address owner;
// <yes> <report> SOLIDITY_TX_ORIGIN 12e802
if (tx.origin == owner) {
return true;
}
string memory origin = "foo";
if (msg.sender != tx.origin) {
revert();
}
require(tx.origin == msg.sender);
// <yes> <report> SOLIDITY_TX_ORIGIN 12e802
owner = tx.origin;
}
}
contract Check060 {
function foo(address a) external returns (bool, bool) {
try SolidityTxOrigin(a).dangerousWithdraw() returns (bool v) {
return (v, true);
} catch Error(string memory reason) {
return (false, false);
} catch (bytes memory lowLevelData) {
return (false, false);
}
}
}
```
### Abstract Syntax Tree
[
Click Here
](
https://astexplorer.net/#/gist/bba45258f7aeb5e4737fb9eeef020abe/7f50557e2fa59533b50dcccab2431dc3b263be3b
)
to view the AST for the above code. Code generated from AST Explorer using _solidity-parser-antlr-0.4.11_
### Code Result
```
SOLIDITY_REVERT_REQUIRE
patternId: c56b12
severity: 1
line: 11
column: 8
content: if(msg.sender!=tx.origin){revert();}
ruleId: SOLIDITY_SHOULD_RETURN_STRUCT
patternId: 83hf3l
severity: 1
line: 21
column: 45
content: (bool,bool)
ruleId: SOLIDITY_TX_ORIGIN
patternId: 12e802
severity: 2
line: 7
column: 12
content: tx.origin
ruleId: SOLIDITY_TX_ORIGIN
patternId: 12e802
severity: 2
line: 16
column: 16
content: tx.origin
SOLIDITY_REVERT_REQUIRE :1
SOLIDITY_SHOULD_RETURN_STRUCT :1
SOLIDITY_TX_ORIGIN :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