Skip to content

Commit

Permalink
Add incorrect-exp detector
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Oct 11, 2023
1 parent 4d738ec commit f7ab4a7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Test.bad1() (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#9-12) has bitwise-xor operator ^ instead of the exponentiation operator **:
- UINT_MAX = 2 ^ 256 - 1 (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#10)

Test.bad0(uint256) (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#5-7) has bitwise-xor operator ^ instead of the exponentiation operator **:
- a ^ 2 (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#6)

Derived.slitherConstructorVariables() (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#30) has bitwise-xor operator ^ instead of the exponentiation operator **:
- my_var = 2 ^ 256 - 1 (tests/e2e/detectors/test_data/incorrect-exp/0.7.6/incorrect_exp.sol#3)

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
contract Test {

uint my_var = 2 ^ 256-1;

function bad0(uint a) internal returns (uint) {
return a^2;
}

function bad1() internal returns (uint) {
uint UINT_MAX = 2^256-1;
return UINT_MAX;
}

/* Correct exponentiation operator */
function good0(uint a) internal returns (uint) {
return a**2;
}

/* Neither operand is a constant */
function good1(uint a) internal returns (uint) {
return a^a;
}

/* The constant operand 0xff in hex typically means bitwise xor */
function good2(uint a) internal returns (uint) {
return a^0xff;
}
}

contract Derived is Test {}
Binary file not shown.

0 comments on commit f7ab4a7

Please sign in to comment.