Skip to content

Commit 50636ff

Browse files
committed
Add vulnerable smart contracts.
1 parent 70f0689 commit 50636ff

File tree

71 files changed

+1582
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1582
-30
lines changed

.gitignore

100644100755
File mode changed.

config/dataset/dataset.yaml

100644100755
File mode changed.

config/tools/mythril.yaml

100644100755
File mode changed.

config/tools/oyente.yaml

100644100755
File mode changed.

config/tools/securify.yaml

100644100755
File mode changed.

config/tools/smartcheck.yaml

100644100755
File mode changed.

dataset/access_control/WalletLibrary.sol

+403
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-124#arbitrary-location-write-simplesol
3+
* @author: Suhabe Bugrara
4+
*/
5+
6+
pragma solidity ^0.4.25;
7+
8+
contract Wallet {
9+
uint[] private bonusCodes;
10+
address private owner;
11+
12+
constructor() public {
13+
bonusCodes = new uint[](0);
14+
owner = msg.sender;
15+
}
16+
17+
function () public payable {
18+
}
19+
20+
function PushBonusCode(uint c) public {
21+
bonusCodes.push(c);
22+
}
23+
24+
function PopBonusCode() public {
25+
require(0 <= bonusCodes.length);
26+
bonusCodes.length--;
27+
}
28+
29+
function UpdateBonusCodeAt(uint idx, uint c) public {
30+
require(idx < bonusCodes.length);
31+
bonusCodes[idx] = c;
32+
}
33+
34+
function Destroy() public {
35+
require(msg.sender == owner);
36+
selfdestruct(msg.sender);
37+
}
38+
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* @source: https://github.com/thec00n/smart-contract-honeypots/blob/master/CryptoRoulette.sol
3+
*/
4+
pragma solidity ^0.4.19;
5+
6+
// CryptoRoulette
7+
//
8+
// Guess the number secretly stored in the blockchain and win the whole contract balance!
9+
// A new number is randomly chosen after each try.
10+
//
11+
// To play, call the play() method with the guessed number (1-20). Bet price: 0.1 ether
12+
13+
contract CryptoRoulette {
14+
15+
uint256 private secretNumber;
16+
uint256 public lastPlayed;
17+
uint256 public betPrice = 0.1 ether;
18+
address public ownerAddr;
19+
20+
struct Game {
21+
address player;
22+
uint256 number;
23+
}
24+
Game[] public gamesPlayed;
25+
26+
function CryptoRoulette() public {
27+
ownerAddr = msg.sender;
28+
shuffle();
29+
}
30+
31+
function shuffle() internal {
32+
// randomly set secretNumber with a value between 1 and 20
33+
secretNumber = uint8(sha3(now, block.blockhash(block.number-1))) % 20 + 1;
34+
}
35+
36+
function play(uint256 number) payable public {
37+
require(msg.value >= betPrice && number <= 10);
38+
39+
Game game;
40+
game.player = msg.sender;
41+
game.number = number;
42+
gamesPlayed.push(game);
43+
44+
if (number == secretNumber) {
45+
// win!
46+
msg.sender.transfer(this.balance);
47+
}
48+
49+
shuffle();
50+
lastPlayed = now;
51+
}
52+
53+
function kill() public {
54+
if (msg.sender == ownerAddr && now > lastPlayed + 1 days) {
55+
suicide(msg.sender);
56+
}
57+
}
58+
59+
function() public payable { }
60+
}

dataset/access_control/incorrect_constructor.sol

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @source: https://github.com/trailofbits/not-so-smart-contracts/blob/master/wrong_constructor_name/incorrect_constructor.sol
3+
* @author: Ben Perez
4+
* Modified by Gerhard Wagner
5+
*/
6+
7+
pragma solidity ^0.4.24;
8+
9+
contract Missing{
10+
address private owner;
11+
12+
modifier onlyowner {
13+
require(msg.sender==owner);
14+
_;
15+
}
16+
17+
// The name of the constructor should be Missing
18+
// Anyone can call the IamMissing once the contract is deployed
19+
function IamMissing()
20+
public
21+
{
22+
owner = msg.sender;
23+
}
24+
25+
function () payable {}
26+
27+
function withdraw()
28+
public
29+
onlyowner
30+
{
31+
owner.transfer(this.balance);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @source: https://github.com/trailofbits/not-so-smart-contracts/blob/master/wrong_constructor_name/incorrect_constructor.sol
3+
* @author: Ben Perez
4+
* Modified by Gerhard Wagner
5+
*/
6+
7+
8+
pragma solidity 0.4.24;
9+
10+
contract Missing{
11+
address private owner;
12+
13+
modifier onlyowner {
14+
require(msg.sender==owner);
15+
_;
16+
}
17+
18+
function missing()
19+
public
20+
{
21+
owner = msg.sender;
22+
}
23+
24+
function () payable {}
25+
26+
function withdraw()
27+
public
28+
onlyowner
29+
{
30+
owner.transfer(this.balance);
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @source: https://github.com/trailofbits/not-so-smart-contracts/blob/master/wrong_constructor_name/incorrect_constructor.sol
3+
* @author: Ben Perez
4+
* Modified by Gerhard Wagner
5+
*/
6+
7+
pragma solidity 0.4.24;
8+
9+
contract Missing{
10+
address private owner;
11+
12+
modifier onlyowner {
13+
require(msg.sender==owner);
14+
_;
15+
}
16+
17+
function Constructor()
18+
public
19+
{
20+
owner = msg.sender;
21+
}
22+
23+
function () payable {}
24+
25+
function withdraw()
26+
public
27+
onlyowner
28+
{
29+
owner.transfer(this.balance);
30+
}
31+
32+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-124#mapping-writesol
3+
* @author: Suhabe Bugrara
4+
*/
5+
6+
pragma solidity ^0.4.24;
7+
8+
//This code is derived from the Capture the Ether https://capturetheether.com/challenges/math/mapping/
9+
10+
contract Map {
11+
address public owner;
12+
uint256[] map;
13+
14+
function set(uint256 key, uint256 value) public {
15+
if (map.length <= key) {
16+
map.length = key + 1;
17+
}
18+
19+
map[key] = value;
20+
}
21+
22+
function get(uint256 key) public view returns (uint256) {
23+
return map[key];
24+
}
25+
function withdraw() public{
26+
require(msg.sender == owner);
27+
msg.sender.transfer(address(this).balance);
28+
}
29+
}

dataset/access_control/parity_wallet_library.sol

100644100755
File mode changed.

dataset/access_control/phishable.sol

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @source: https://github.com/sigp/solidity-security-blog
3+
* @author: -
4+
*/
5+
6+
pragma solidity ^0.4.22;
7+
8+
contract Phishable {
9+
address public owner;
10+
11+
constructor (address _owner) {
12+
owner = _owner;
13+
}
14+
15+
function () public payable {} // collect ether
16+
17+
function withdrawAll(address _recipient) public {
18+
require(tx.origin == owner);
19+
_recipient.transfer(this.balance);
20+
}
21+
}

dataset/access_control/proxy.sol

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-112#proxysol
3+
* @author: -
4+
*/
5+
6+
pragma solidity ^0.4.24;
7+
8+
contract Proxy {
9+
10+
address owner;
11+
12+
constructor() public {
13+
owner = msg.sender;
14+
}
15+
16+
function forward(address callee, bytes _data) public {
17+
require(callee.delegatecall(_data));
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-123#requirement-simplesol
3+
* @author: Suhabe Bugrara
4+
*/
5+
6+
pragma solidity ^0.4.25;
7+
8+
contract Bar {
9+
Foo private f = new Foo();
10+
function doubleBaz() public view returns (int256) {
11+
return 2 * f.baz(0);
12+
}
13+
}
14+
15+
contract Foo {
16+
function baz(int256 x) public pure returns (int256) {
17+
require(0 < x);
18+
return 42;
19+
}
20+
}

dataset/access_control/rubixi.sol

100644100755
File mode changed.

dataset/access_control/storage.sol

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-108#storagesol
3+
* @author: -
4+
*/
5+
6+
pragma solidity 0.4.24;
7+
8+
contract TestStorage {
9+
10+
uint storeduint1 = 15;
11+
uint constant constuint = 16;
12+
uint32 investmentsDeadlineTimeStamp = uint32(now);
13+
14+
bytes16 string1 = "test1";
15+
bytes32 private string2 = "test1236";
16+
string public string3 = "lets string something";
17+
18+
mapping (address => uint) public uints1;
19+
mapping (address => DeviceData) structs1;
20+
21+
uint[] uintarray;
22+
DeviceData[] deviceDataArray;
23+
24+
struct DeviceData {
25+
string deviceBrand;
26+
string deviceYear;
27+
string batteryWearLevel;
28+
}
29+
30+
function testStorage() public {
31+
address address1 = 0xbccc714d56bc0da0fd33d96d2a87b680dd6d0df6;
32+
address address2 = 0xaee905fdd3ed851e48d22059575b9f4245a82b04;
33+
34+
uints1[address1] = 88;
35+
uints1[address2] = 99;
36+
37+
DeviceData memory dev1 = DeviceData("deviceBrand", "deviceYear", "wearLevel");
38+
39+
structs1[address1] = dev1;
40+
41+
uintarray.push(8000);
42+
uintarray.push(9000);
43+
44+
deviceDataArray.push(dev1);
45+
}
46+
}

dataset/access_control/unprotected0.sol

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @source: https://github.com/sigp/solidity-security-blog#visibility
3+
* @author: SigmaPrime
4+
* Modified by Gerhard Wagner
5+
*/
6+
7+
pragma solidity ^0.4.24;
8+
9+
contract HashForEther {
10+
11+
function withdrawWinnings() {
12+
// Winner if the last 8 hex characters of the address are 0.
13+
require(uint32(msg.sender) == 0);
14+
_sendWinnings();
15+
}
16+
17+
function _sendWinnings() {
18+
msg.sender.transfer(this.balance);
19+
}
20+
}

0 commit comments

Comments
 (0)