-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7669e67
commit 9028442
Showing
4 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Price Manipulation through token transfers | ||
|
||
## Configuration | ||
* Check: `pess-price-manipulation` | ||
* Severity: `High` | ||
* Confidence: `Low` | ||
|
||
## Description | ||
The detector finds calculations that depend on the balance and supply of some token. Such calculations could be manipulated through direct transfers to the contract, increasing its balance. | ||
|
||
## Vulnerable Scenario | ||
[test scenario](../tests/price_manipulation_test.sol) | ||
|
||
## Recommendation | ||
Avoid possible manipulations of calculations because of external transfers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
interface IERC20 { | ||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address account) external view returns (uint256); | ||
} | ||
contract Test1 { | ||
IERC20 token; | ||
|
||
function test_vuln_1() external returns(uint256 price) { | ||
price = token.balanceOf(address(this)) / token.totalSupply(); | ||
} | ||
|
||
function test_vuln_2() external returns(uint256 price) { | ||
uint256 bal = token.balanceOf(address(this)); | ||
uint256 supply = token.totalSupply(); | ||
price = bal / supply; | ||
} | ||
|
||
function test_vuln_3() external returns(uint256 price) { | ||
uint256 bal = getBalance(); | ||
price = bal / token.totalSupply(); | ||
} | ||
|
||
function test_vuln_4() external returns(uint256 price) { | ||
uint256 bal = getBalance(); | ||
price = 10 + (bal / (token.totalSupply() * 5)); | ||
} | ||
|
||
function test_vuln_5() external returns(uint256 price) { | ||
price = getBalance() / mySupply(); | ||
} | ||
|
||
function test_vuln_6() external returns(uint256 price) { | ||
price = getBalance() + mySupply() + 1; | ||
} | ||
|
||
function getBalance() public returns(uint256 bal) { | ||
bal = token.balanceOf(msg.sender); | ||
} | ||
|
||
function mySupply() public returns (uint256) { | ||
return 100; | ||
} | ||
} |