Skip to content

Commit

Permalink
Latest test contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexroan committed Sep 2, 2024
1 parent 853f3f7 commit edcf2b2
Show file tree
Hide file tree
Showing 74 changed files with 6,082 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cache/solidity-files-cache.json

Large diffs are not rendered by default.

2,366 changes: 2,366 additions & 0 deletions report.md

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/AbstractContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.19;

abstract contract AbstractContract {
address public admin;
function transferAdmin(address newAdmin) public virtual {
if (admin != msg.sender) {
revert("CallerNotAdmin");
}
require(newAdmin != address(0), "InvalidAdmin");
admin = newAdmin;
}
}
30 changes: 30 additions & 0 deletions src/AderynIgnoreCustomDetectors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract AderynCustomIgnore {

// This will be reported by empty-block and useless-public-function
function f1() public {

}


// This will be not reported by either of the detectors
// aderyn-ignore-next-line(useless-public-function , empty-block)
function f2() public {

}

// This will never be reported
// aderyn-ignore-next-line
function f3() public {

}

// This will be reported only by useless-public-function
// aderyn-ignore-next-line (empty-block)
function f4() public {

}

}
16 changes: 16 additions & 0 deletions src/AssertStateChange.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

// COPIED from Slither
contract AssertUsage {
uint s_a;

function bad() public {
assert((s_a += 1) > 10);
}

function good() public {
s_a += 1;
assert(s_a > 10);
}
}
31 changes: 31 additions & 0 deletions src/BooleanEquality.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pragma solidity 0.4.22;

contract BooleanEquality {
function badCheck(bool isEven) external pure returns (uint256) {
if (isEven == true) {
return 100;
}
return 0;
}

function badCheck2(bool isEven) external pure returns (uint256) {
if (isEven == !true) {
return 200;
}
return 130;
}

function badCheck3(bool isEven) external pure returns (uint256) {
if (isEven == false) {
return 100;
}
return 0;
}

function badCheck4(bool isEven) external pure returns (uint256) {
if (isEven == !false) {
return 200;
}
return 130;
}
}
23 changes: 23 additions & 0 deletions src/BuiltinSymbolShadow.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.0;

contract BuiltinSymbolShadow {
uint now; // BAD

// BAD
function assert(bool condition) public {}

function get_next_expiration(
uint earlier_time
) private blockhash returns (uint) {
return now + 259200; // References overshadowed timestamp.
}

// BAD
modifier blockhash() {
_;
}

// BAD
event sha256();
}
55 changes: 55 additions & 0 deletions src/CacheArrayLength.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

contract CacheArrayLength {
uint[] array;
uint[] anotherArray;

function c1() external view {
uint total = 0;

// BAD (length is not cached)
for (uint i = 0; i < array.length; i++) {
total += array[i];
}
}

function c2() external view {
uint array_length = array.length;
// GOOD (length is cached)
for (uint i = 0; i < array_length; i++) {}
}

function c3() external {
// GOOD
for (uint i = 0; i < array.length; i++) {
array[i] = 100;
array.push(100);
array.pop();
}
}

function c4() external {
// GOOD (even though anotherArray.length doesn't change, static analysis should assume that the condition as
// a whole can change even if just one of the involved state variable changes)
for (uint i = 0; i < array.length + anotherArray.length; i++) {
array[i] = 100;
array.push(100);
array.pop();
}
}

function c5() external view {
// BAD (can cache)
for (uint i = 0; i < array.length + anotherArray.length; i++) {}
}

function c6() external view {
uint total = 0;
// BAD (can cache)
for (uint i = 0; i < array.length + anotherArray.length; i++) {
// Only reading from storage (not changing them)
total += array[i] * anotherArray[i];
}
}
}
75 changes: 75 additions & 0 deletions src/CallGraphTests.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

contract Tower1 {

function visitEighthFloor1() internal {
require(msg.sender == address(0x11));
}

modifier passThroughNinthFloor1() {
visitEighthFloor1();
_;
}

// Start Here
function enterTenthFloor1() external passThroughNinthFloor1() {

}

}


contract Tower2 {

function visitEighthFloor2(address x) internal {
(bool success,) = x.call{value: 10}("calldata");
if (!success) {
revert();
}
}

modifier passThroughNinthFloor2(address x) {
visitEighthFloor2(x);
_;
}

// Start Here
function enterTenthFloor2(address x) external passThroughNinthFloor2(x) {

}

}


contract Tower3 {

function visitEighthFloor3(address x) internal {
(bool success,) = x.call{value: 10}("calldata");
if (!success) {
revert();
}
}

modifier passThroughNinthFloor3(address x) {
visitEighthFloor3(x);
_;
}

// Start Here
function enterTenthFloor3(address x) external passThroughNinthFloor3(x) {
visitSeventhFloor3();
}

function visitSeventhFloor3() internal {
require(msg.sender == address(0x11));
}

}

contract Tower4 {
// A recursive function should have itself as upstream and downstream
function recurse(string memory something) private {
recurse(something);
}
}
17 changes: 17 additions & 0 deletions src/CompilerBugStorageSignedIntegerArray.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.0;

contract CompilerBugStorageSignedIntegerArray {
int256[3] affectedArray;
int256[4] unaffectedArray;

function assignBadValue() private {
affectedArray = [-1, 5, 2];
}

function assignGoodValue() private {
unaffectedArray[0] = -1;
unaffectedArray[1] = 5;
unaffectedArray[2] = 2;
}
}
23 changes: 23 additions & 0 deletions src/ConstFuncChangeState.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.0;

contract ConstantFunctionChangeState {
uint counter;

// BAD (it is declared as view but changes state)
function changeState() public view returns (uint) {
counter = counter + 1;
return counter;
}

// GOOD (because it's not declared as view)
function changeState2() public returns (uint) {
counter = counter + 1;
return counter;
}

// GOOD (it's declared as view and it doesn't change state)
function dontChangeState() public view returns (uint) {
return counter + 1;
}
}
39 changes: 39 additions & 0 deletions src/ConstantFuncsAssembly.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.4.0;

contract AssemblyExample {
// State variable
uint256 public value;

// BAD (view function contains assembly)
function setValue(uint256 _value) external view {
assembly {
// Load the location of the 'value' storage slot
sstore(0, _value)
}
}

// BAD (pure function contains assembly)
function getConstantValue() external pure returns (uint256) {
uint256 result;
assembly {
// Inline assembly to set the result to a constant value
result := 42
}
return result;
}

function useAssembly() internal pure returns (uint256) {
uint256 result;
assembly {
// Inline assembly to set the result to a constant value
result := 42
}
return result;
}

// BAD (pure function contains assembly)
function getConstantValue2() external pure returns (uint256) {
return useAssembly();
}
}
1 change: 1 addition & 0 deletions src/ConstantsLiterals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ contract ConstantsLiterals {
address multipleUseOfAddress = 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5;
multipleUseOfAddress = 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5;
bytes32 multipleUseOfBytes32 = 0x8a1b3dbe6301650442bfa765d4de23775fc9a4ec4329ebb5995ec7f1e3777dc4;
// aderyn-ignore-next-line
multipleUseOfBytes32 = 0x8a1b3dbe6301650442bfa765d4de23775fc9a4ec4329ebb5995ec7f1e3777dc4;
}

Expand Down
Loading

0 comments on commit edcf2b2

Please sign in to comment.