├── .gitignore ├── Makefile ├── README.md ├── benchmark.py ├── benchmark └── reentrancy │ ├── test.txt │ ├── train.txt │ └── valid.txt ├── benchmark_generator.py ├── bytecode └── __init__.py ├── common ├── __init__.py ├── model │ ├── __init__.py │ ├── ggnn.py │ └── gmn.py └── utils │ ├── __init__.py │ ├── benchmark.py │ ├── contract.py │ └── prune.py ├── contracts_test ├── test │ ├── r │ │ ├── 0x01f8c4e3fa3edeb29e514cba738d87ce8c091d3f.sol │ │ ├── 0x23a91059fdc9579a9fbd0edc5f2ea0bfdb70deb4.sol │ │ ├── 0x4e73b32ed6c35f570686b89848e5f39f20ecc106.sol │ │ ├── 0x7a8721a9d64c74da899424c1b52acbf58ddc9782.sol │ │ ├── 0x7b368c4e805c3870b6c49a3f1f49f69af8662cf3.sol │ │ ├── 0x8c7777c45481dba411450c228cb692ac3d550344.sol │ │ ├── 0x93c32845fae42c83a70e5f06214c8433665c2ab5.sol │ │ └── 0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol │ └── u │ │ ├── 0x07f7ecb66d788ab01dc93b9b71a88401de7d0f2e.sol │ │ ├── 0x19cf8481ea15427a98ba3cdd6d9e14690011ab10.sol │ │ ├── 0x39cfd754c85023648bf003bea2dd498c5612abfa.sol │ │ ├── 0x52d2e0f9b01101a59b38a3d05c80b7618aeed984.sol │ │ ├── 0x70f9eddb3931491aab1aeafbc1e7f1ca2a012db4.sol │ │ ├── 0x78c2a1e91b52bca4130b6ed9edd9fbcfd4671c37.sol │ │ ├── 0x7a4349a749e59a5736efb7826ee3496a2dfd5489.sol │ │ ├── 0x7d09edb07d23acb532a82be3da5c17d9d85806b4.sol │ │ ├── 0x8fd1e427396ddb511533cf9abdbebd0a7e08da35.sol │ │ └── 0x9d06cbafa865037a01d322d3f4222fa3e04e5488.sol └── train │ ├── reentrancy │ ├── 0x4320e6f8c05b27ab4707cd1f6d5ce6f3e4b3a5a1.sol │ ├── 0x561eac93c92360949ab1f1403323e6db345cbf31.sol │ ├── 0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol │ ├── 0x7541b76cb60f4c60af330c208b0623b7f54bf615.sol │ ├── 0x941d225236464a25eb18076df7da6a91d0f95e9e.sol │ ├── 0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol │ ├── 0xaae1f51cf3339f18b6d3f3bdc75a5facd744b0b8.sol │ ├── 0xb5e1b1ee15c6fa0e48fce100125569d430f1bd12.sol │ ├── 0xb93430ce38ac4a6bb47fb1fc085ea669353fd89e.sol │ ├── 0xbaf51e761510c1a11bf48dd87c0307ac8a8c8a4f.sol │ ├── 0xbe4041d55db380c5ae9d4a9b9703f1ed4e7e3888.sol │ ├── 0xcead721ef5b11f1a7b530171aab69b16c5e66b6e.sol │ ├── 0xf015c35649c82f5467c9c74b7f28ee67665aad68.sol │ ├── etherbank.sol │ ├── etherstore.sol │ ├── modifier_reentrancy.sol │ ├── reentrance.sol │ ├── reentrance1.sol │ ├── reentrancy_bonus.sol │ ├── reentrancy_cross_function.sol │ ├── reentrancy_dao.sol │ ├── reentrancy_insecure.sol │ ├── reentrancy_simple.sol │ ├── simple_dao.ir │ ├── simple_dao.sol │ └── spank_chain_payment.sol │ └── unchecked_low_level_calls │ ├── 0x0cbe050f75bc8f8c2d6c0d249fea125fd6e1acc9.sol │ ├── 0x2972d548497286d18e92b5fa1f8f9139e5653fd2.sol │ ├── 0x3a0e9acd953ffc0dd18d63603488846a6b8b2b01.sol │ ├── 0x3e013fc32a54c4c5b6991ba539dcd0ec4355c859.sol │ ├── 0x3f2ef511aa6e75231e4deafc7a3d2ecab3741de2.sol │ ├── 0x4051334adc52057aca763453820cb0e045076ef3.sol │ ├── 0x4a66ad0bca2d700f11e1f2fc2c106f7d3264504c.sol │ ├── 0x4b71ad9c1a84b9b643aa54fdd66e2dec96e8b152.sol │ ├── 0x524960d55174d912768678d8c606b4d50b79d7b1.sol │ ├── 0x5aa88d2901c68fda244f1d0584400368d2c8e739.sol │ ├── 0x610495793564aed0f9c7fc48dc4c7c9151d34fd6.sol │ ├── 0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol │ ├── 0x663e4229142a27f00bafb5d087e1e730648314c3.sol │ ├── 0x806a6bd219f162442d992bdc4ee6eba1f2c5a707.sol │ ├── 0x84d9ec85c9c568eb332b7226a8f826d897e0a4a8.sol │ ├── 0x89c1b3807d4c67df034fffb62f3509561218d30b.sol │ ├── 0x958a8f594101d2c0485a52319f29b2647f2ebc06.sol │ ├── 0xa1fceeff3acc57d257b917e30c4df661401d6431.sol │ ├── 0xa46edd6a9a93feec36576ee5048146870ea2c3ae.sol │ ├── 0xb0510d68f210b7db66e8c7c814f22680f2b8d1d6.sol │ ├── 0xb11b2fed6c9354f7aa2f658d3b4d7b31d8a13b77.sol │ ├── 0xb37f18af15bafb869a065b61fc83cfc44ed9cc27.sol │ ├── 0xb620cee6b52f96f3c6b253e6eea556aa2d214a99.sol │ ├── 0xb7c5c5aa4d42967efe906e1b66cb8df9cebf04f7.sol │ ├── 0xbaa3de6504690efb064420d89e871c27065cdd52.sol │ ├── 0xbebbfe5b549f5db6e6c78ca97cac19d1fb03082c.sol │ ├── 0xd2018bfaa266a9ec0a1a84b061640faa009def76.sol │ ├── 0xd5967fed03e85d1cce44cab284695b41bc675b5c.sol │ ├── 0xdb1c55f6926e7d847ddf8678905ad871a68199d2.sol │ ├── 0xe09b1ab8111c2729a76f16de96bc86a7af837928.sol │ ├── 0xe4eabdca81e31d9acbc4af76b30f532b6ed7f3bf.sol │ ├── 0xe82f0742a71a02b9e9ffc142fdcb6eb1ed06fb87.sol │ ├── 0xe894d54dca59cb53fe9cbc5155093605c7068220.sol │ ├── 0xec329ffc97d75fe03428ae155fc7793431487f63.sol │ ├── 0xf2570186500a46986f3139f65afedc2afe4f445d.sol │ ├── 0xf29ebe930a539a60279ace72c707cba851a57707.sol │ ├── 0xf70d589d76eebdd7c12cc5eec99f8f6fa4233b9e.sol │ ├── etherpot_lotto.sol │ ├── king_of_the_ether_throne.sol │ ├── lotto.sol │ ├── mishandled.sol │ └── unchecked_return_value.sol ├── dataset ├── reentrancy │ ├── 0x01f8c4e3fa3edeb29e514cba738d87ce8c091d3f.sol │ ├── 0x23a91059fdc9579a9fbd0edc5f2ea0bfdb70deb4.sol │ ├── 0x4320e6f8c05b27ab4707cd1f6d5ce6f3e4b3a5a1.sol │ ├── 0x4e73b32ed6c35f570686b89848e5f39f20ecc106.sol │ ├── 0x561eac93c92360949ab1f1403323e6db345cbf31.sol │ ├── 0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol │ ├── 0x7541b76cb60f4c60af330c208b0623b7f54bf615.sol │ ├── 0x7a8721a9d64c74da899424c1b52acbf58ddc9782.sol │ ├── 0x7b368c4e805c3870b6c49a3f1f49f69af8662cf3.sol │ ├── 0x8c7777c45481dba411450c228cb692ac3d550344.sol │ ├── 0x93c32845fae42c83a70e5f06214c8433665c2ab5.sol │ ├── 0x941d225236464a25eb18076df7da6a91d0f95e9e.sol │ ├── 0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol │ ├── 0xaae1f51cf3339f18b6d3f3bdc75a5facd744b0b8.sol │ ├── 0xb5e1b1ee15c6fa0e48fce100125569d430f1bd12.sol │ ├── 0xb93430ce38ac4a6bb47fb1fc085ea669353fd89e.sol │ ├── 0xbaf51e761510c1a11bf48dd87c0307ac8a8c8a4f.sol │ ├── 0xbe4041d55db380c5ae9d4a9b9703f1ed4e7e3888.sol │ ├── 0xcead721ef5b11f1a7b530171aab69b16c5e66b6e.sol │ ├── 0xf015c35649c82f5467c9c74b7f28ee67665aad68.sol │ ├── 10107.sol │ ├── 10297.sol │ ├── 1044.sol │ ├── 10604.sol │ ├── 10715.sol │ ├── 1123.sol │ ├── 11705.sol │ ├── 11719.sol │ ├── 12182.sol │ ├── 12454.sol │ ├── 13076.sol │ ├── 13952.sol │ ├── 1403.sol │ ├── 14274.sol │ ├── 14284.sol │ ├── 1430.sol │ ├── 14353.sol │ ├── 14458.sol │ ├── 14579.sol │ ├── 14620.sol │ ├── 14741.sol │ ├── 14758.sol │ ├── 14945.sol │ ├── 14994.sol │ ├── 15458.sol │ ├── 16057.sol │ ├── 16643.sol │ ├── 16884.sol │ ├── 16925.sol │ ├── 17009.sol │ ├── 17043.sol │ ├── 1710.sol │ ├── 17215.sol │ ├── 1751.sol │ ├── 17518.sol │ ├── 17573.sol │ ├── 18145.sol │ ├── 18170.sol │ ├── 18438.sol │ ├── 1879.sol │ ├── 19128.sol │ ├── 19402.sol │ ├── 2013.sol │ ├── 2021.sol │ ├── 21111.sol │ ├── 21241.sol │ ├── 21277.sol │ ├── 21390.sol │ ├── 21697.sol │ ├── 21755.sol │ ├── 21886.sol │ ├── 2189.sol │ ├── 21900.sol │ ├── 21999.sol │ ├── 22074.sol │ ├── 22247.sol │ ├── 22416.sol │ ├── 22805.sol │ ├── 22902.sol │ ├── 2301.sol │ ├── 23088.sol │ ├── 23166.sol │ ├── 23387.sol │ ├── 23421.sol │ ├── 23803.sol │ ├── 2387.sol │ ├── 24007.sol │ ├── 25196.sol │ ├── 25808.sol │ ├── 26188.sol │ ├── 26523.sol │ ├── 27024.sol │ ├── 27159.sol │ ├── 27188.sol │ ├── 27248.sol │ ├── 27263.sol │ ├── 27334.sol │ ├── 27398.sol │ ├── 27486.sol │ ├── 28687.sol │ ├── 28869.sol │ ├── 28974.sol │ ├── 29517.sol │ ├── 29601.sol │ ├── 30046.sol │ ├── 30101.sol │ ├── 30178.sol │ ├── 30337.sol │ ├── 30460.sol │ ├── 3054.sol │ ├── 31565.sol │ ├── 31759.sol │ ├── 31912.sol │ ├── 3255.sol │ ├── 32559.sol │ ├── 32605.sol │ ├── 3270.sol │ ├── 33410.sol │ ├── 33450.sol │ ├── 33501.sol │ ├── 33835.sol │ ├── 33851.sol │ ├── 34577.sol │ ├── 347.sol │ ├── 35421.sol │ ├── 35617.sol │ ├── 35637.sol │ ├── 35649.sol │ ├── 35661.sol │ ├── 35806.sol │ ├── 35878.sol │ ├── 36334.sol │ ├── 36563.sol │ ├── 36645.sol │ ├── 36732.sol │ ├── 37329.sol │ ├── 37474.sol │ ├── 37676.sol │ ├── 37836.sol │ ├── 37891.sol │ ├── 38651.sol │ ├── 38724.sol │ ├── 38888.sol │ ├── 39019.sol │ ├── 39127.sol │ ├── 39191.sol │ ├── 39269.sol │ ├── 39326.sol │ ├── 39644.sol │ ├── 39662.sol │ ├── 39664.sol │ ├── 39684.sol │ ├── 39705.sol │ ├── 39749.sol │ ├── 39817.sol │ ├── 3985.sol │ ├── 39866.sol │ ├── 39890.sol │ ├── 39912.sol │ ├── 39932.sol │ ├── 39973.sol │ ├── 39994.sol │ ├── 40038.sol │ ├── 40090.sol │ ├── 40092.sol │ ├── 40118.sol │ ├── 40241.sol │ ├── 40340.sol │ ├── 40341.sol │ ├── 40353.sol │ ├── 40366.sol │ ├── 40416.sol │ ├── 40425.sol │ ├── 40469.sol │ ├── 40589.sol │ ├── 4472.sol │ ├── 4591.sol │ ├── 4598.sol │ ├── 4679.sol │ ├── 5515.sol │ ├── 5629.sol │ ├── 6881.sol │ ├── 7530.sol │ ├── 774.sol │ ├── 8342.sol │ ├── 9221.sol │ ├── 9600.sol │ ├── 9611.sol │ ├── 9920.sol │ ├── etherbank.sol │ ├── etherstore.sol │ ├── modifier_reentrancy.sol │ ├── reentrance.sol │ ├── reentrancy_bonus.sol │ ├── reentrancy_cross_function.sol │ ├── reentrancy_dao.sol │ ├── reentrancy_insecure.sol │ ├── reentrancy_simple.sol │ ├── simple_dao.sol │ └── spank_chain_payment.sol └── reentrancy_label_200.json ├── doc ├── paper.pdf ├── slide.pptx └── thesis.pdf ├── graph_generator ├── generate_gmn_data.py └── generate_graph.py ├── parser.py ├── requirements.txt ├── results ├── GMN_epoch_1 ├── GMN_epoch_2 └── GMN_epoch_3 ├── soucecode ├── ASGDetector.py └── __init__.py ├── test ├── test_filter_fun.py ├── test_gmn_data.py ├── test_mul.py ├── test_py_solc.py └── test_state.py └── tools ├── benchmark_generator.py └── data_excutor.py /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Misc 3 | .DS_Store 4 | 5 | # Editor 6 | .idea/ 7 | .vscode/ 8 | venv/ -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | CUR_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) 3 | BUILD_DIR = $(CUR_DIR)/build/ 4 | COMMON_DIR := $(wildcard $(CUR_DIR)/common) 5 | 6 | all:ASGVulDetector 7 | 8 | dependency: 9 | pip3 install -r requirements.txt 10 | 11 | BASGVulDetector: 12 | @echo "ASGVulDetector" 13 | @echo ${CUR_DIR} 14 | @echo ${BUILD_DIR}"ASGVulDetector" 15 | @echo ${COMMON_DIR} 16 | 17 | ASGVulDetector: 18 | @echo "ASGVulDetector" 19 | @echo ${CUR_DIR} 20 | @echo ${BUILD_DIR}"ASGVulDetector" 21 | @echo ${COMMON_DIR} 22 | 23 | benchmark: 24 | @mkdir -p build/ 25 | 26 | clean: 27 | @rm -rf build > /dev/null 2>&1|| true 28 | 29 | .PHONY: all benchmark check dependency clean banner-watcher 30 | 31 | .DEFAULT: all -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartCodeASG 2 | 3 | 一个简单采用 GMN 来检查智能合约漏洞的代码。代码框架如下: 4 | 5 | ![Framework](https://aliyun-typora-img.oss-cn-beijing.aliyuncs.com/imgs/202303231113230.png) 6 | 7 | 注:只包含通过源码分析的,后续会优化一下 8 | 9 | ## Citation 10 | 11 | English Version: [Toward Vulnerability Detection for Ethereum Smart Contracts Using Graph-Matching Network](./doc/paper.pdf) 12 | 13 | 中文论文:[以太坊智能合约漏洞检测方法研究](./doc/thesis.pdf) 14 | 15 | 中文汇报:[以太坊智能合约漏洞检测方法研究](./doc/slide.pptx) 16 | 17 | 18 | 19 | ## Dataset 20 | 21 | 数据集不全,之后补 -------------------------------------------------------------------------------- /bytecode/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/bytecode/__init__.py -------------------------------------------------------------------------------- /common/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/common/__init__.py -------------------------------------------------------------------------------- /common/model/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/common/model/__init__.py -------------------------------------------------------------------------------- /common/model/ggnn.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | from abc import ABC 3 | 4 | import torch 5 | import torch.nn as nn 6 | from torch.nn import Parameter 7 | import torch.nn.functional as F 8 | from torch_geometric.nn import MessagePassing, GatedGraphConv 9 | from torch_geometric.utils import degree, remove_self_loops, add_self_loops, softmax 10 | from torch_geometric.nn.inits import glorot, zeros 11 | from torch_geometric.nn.glob import GlobalAttention 12 | import sys 13 | import inspect 14 | 15 | 16 | class GGNN(torch.nn.Module): 17 | def __init__(self, vocablen, embedding_dim, num_layers, device): 18 | super(GGNN, self).__init__() 19 | self.device = device 20 | # self.num_layers=num_layers 21 | self.embed = nn.Embedding(vocablen, embedding_dim) 22 | self.edge_embed = nn.Embedding(20, embedding_dim) 23 | # self.gmn=nn.ModuleList([GMNlayer(embedding_dim,embedding_dim) for i in range(num_layers)]) 24 | self.ggnnlayer = GatedGraphConv(embedding_dim, num_layers) 25 | self.mlp_gate = nn.Sequential(nn.Linear(embedding_dim, 1), nn.Sigmoid()) 26 | self.pool = GlobalAttention(gate_nn=self.mlp_gate) 27 | 28 | def forward(self, data): 29 | x, edge_index, edge_attr = data 30 | x = self.embed(x) 31 | x = x.squeeze(1) 32 | if type(edge_attr) == type(None): 33 | edge_weight = None 34 | else: 35 | edge_weight = self.edge_embed(edge_attr) 36 | edge_weight = edge_weight.squeeze(1) 37 | x = self.ggnnlayer(x, edge_index) 38 | batch = torch.zeros(x.size(0), dtype=torch.long).to(self.device) 39 | hg = self.pool(x, batch=batch) 40 | return hg 41 | -------------------------------------------------------------------------------- /common/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/common/utils/__init__.py -------------------------------------------------------------------------------- /contracts_test/test/r/0x01f8c4e3fa3edeb29e514cba738d87ce8c091d3f.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PERSONAL_BANK 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum = 1 ether; 14 | 15 | LogFile Log = LogFile(0x0486cF65A2F2F3A392CBEa398AFB7F5f0B72FF46); 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)revert(); 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)revert(); 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x23a91059fdc9579a9fbd0edc5f2ea0bfdb70deb4.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 38 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateBank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function PrivateBank(address _log) 18 | { 19 | TransferLog = Log(_log); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value >= MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | { 35 | if(_am<=balances[msg.sender]) 36 | { 37 | // REENTRANCY 38 | if(msg.sender.call.value(_am)()) 39 | { 40 | balances[msg.sender]-=_am; 41 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 42 | } 43 | } 44 | } 45 | 46 | function() public payable{} 47 | 48 | } 49 | 50 | contract Log 51 | { 52 | 53 | struct Message 54 | { 55 | address Sender; 56 | string Data; 57 | uint Val; 58 | uint Time; 59 | } 60 | 61 | Message[] public History; 62 | 63 | Message LastMsg; 64 | 65 | function AddMessage(address _adr,uint _val,string _data) 66 | public 67 | { 68 | LastMsg.Sender = _adr; 69 | LastMsg.Time = now; 70 | LastMsg.Val = _val; 71 | LastMsg.Data = _data; 72 | History.push(LastMsg); 73 | } 74 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x4e73b32ed6c35f570686b89848e5f39f20ecc106.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PRIVATE_ETH_CELL 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | require(!intitalized); 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | require(!intitalized); 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x7a8721a9d64c74da899424c1b52acbf58ddc9782.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 52 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateDeposit 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | address public owner; 15 | 16 | Log TransferLog; 17 | 18 | modifier onlyOwner() { 19 | require(tx.origin == owner); 20 | _; 21 | } 22 | 23 | function PrivateDeposit() 24 | { 25 | owner = msg.sender; 26 | TransferLog = new Log(); 27 | } 28 | 29 | 30 | 31 | function setLog(address _lib) onlyOwner 32 | { 33 | TransferLog = Log(_lib); 34 | } 35 | 36 | function Deposit() 37 | public 38 | payable 39 | { 40 | if(msg.value >= MinDeposit) 41 | { 42 | balances[msg.sender]+=msg.value; 43 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 44 | } 45 | } 46 | 47 | function CashOut(uint _am) 48 | { 49 | if(_am<=balances[msg.sender]) 50 | { 51 | // REENTRANCY 52 | if(msg.sender.call.value(_am)()) 53 | { 54 | balances[msg.sender]-=_am; 55 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 56 | } 57 | } 58 | } 59 | 60 | function() public payable{} 61 | 62 | } 63 | 64 | contract Log 65 | { 66 | 67 | struct Message 68 | { 69 | address Sender; 70 | string Data; 71 | uint Val; 72 | uint Time; 73 | } 74 | 75 | Message[] public History; 76 | 77 | Message LastMsg; 78 | 79 | function AddMessage(address _adr,uint _val,string _data) 80 | public 81 | { 82 | LastMsg.Sender = _adr; 83 | LastMsg.Time = now; 84 | LastMsg.Val = _val; 85 | LastMsg.Data = _data; 86 | History.push(LastMsg); 87 | } 88 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x7b368c4e805c3870b6c49a3f1f49f69af8662cf3.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract W_WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function W_WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x8c7777c45481dba411450c228cb692ac3d550344.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 41 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_VAULT 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | Log TransferLog; 14 | 15 | uint public MinDeposit = 1 ether; 16 | 17 | function ETH_VAULT(address _log) 18 | public 19 | { 20 | TransferLog = Log(_log); 21 | } 22 | 23 | function Deposit() 24 | public 25 | payable 26 | { 27 | if(msg.value > MinDeposit) 28 | { 29 | balances[msg.sender]+=msg.value; 30 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 31 | } 32 | } 33 | 34 | function CashOut(uint _am) 35 | public 36 | payable 37 | { 38 | if(_am<=balances[msg.sender]) 39 | { 40 | // REENTRANCY 41 | if(msg.sender.call.value(_am)()) 42 | { 43 | balances[msg.sender]-=_am; 44 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 45 | } 46 | } 47 | } 48 | 49 | function() public payable{} 50 | 51 | } 52 | 53 | contract Log 54 | { 55 | 56 | struct Message 57 | { 58 | address Sender; 59 | string Data; 60 | uint Val; 61 | uint Time; 62 | } 63 | 64 | Message[] public History; 65 | 66 | Message LastMsg; 67 | 68 | function AddMessage(address _adr,uint _val,string _data) 69 | public 70 | { 71 | LastMsg.Sender = _adr; 72 | LastMsg.Time = now; 73 | LastMsg.Val = _val; 74 | LastMsg.Data = _data; 75 | History.push(LastMsg); 76 | } 77 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x93c32845fae42c83a70e5f06214c8433665c2ab5.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract X_WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function X_WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts_test/test/r/0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 63 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PENNY_BY_PENNY 10 | { 11 | struct Holder 12 | { 13 | uint unlockTime; 14 | uint balance; 15 | } 16 | 17 | mapping (address => Holder) public Acc; 18 | 19 | uint public MinSum; 20 | 21 | LogFile Log; 22 | 23 | bool intitalized; 24 | 25 | function SetMinSum(uint _val) 26 | public 27 | { 28 | if(intitalized)throw; 29 | MinSum = _val; 30 | } 31 | 32 | function SetLogFile(address _log) 33 | public 34 | { 35 | if(intitalized)throw; 36 | Log = LogFile(_log); 37 | } 38 | 39 | function Initialized() 40 | public 41 | { 42 | intitalized = true; 43 | } 44 | 45 | function Put(uint _lockTime) 46 | public 47 | payable 48 | { 49 | var acc = Acc[msg.sender]; 50 | acc.balance += msg.value; 51 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 52 | Log.AddMessage(msg.sender,msg.value,"Put"); 53 | } 54 | 55 | function Collect(uint _am) 56 | public 57 | payable 58 | { 59 | var acc = Acc[msg.sender]; 60 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 61 | { 62 | // REENTRANCY 63 | if(msg.sender.call.value(_am)()) 64 | { 65 | acc.balance-=_am; 66 | Log.AddMessage(msg.sender,_am,"Collect"); 67 | } 68 | } 69 | } 70 | 71 | function() 72 | public 73 | payable 74 | { 75 | Put(0); 76 | } 77 | 78 | } 79 | 80 | 81 | contract LogFile 82 | { 83 | struct Message 84 | { 85 | address Sender; 86 | string Data; 87 | uint Val; 88 | uint Time; 89 | } 90 | 91 | Message[] public History; 92 | 93 | Message LastMsg; 94 | 95 | function AddMessage(address _adr,uint _val,string _data) 96 | public 97 | { 98 | LastMsg.Sender = _adr; 99 | LastMsg.Time = now; 100 | LastMsg.Val = _val; 101 | LastMsg.Data = _data; 102 | History.push(LastMsg); 103 | } 104 | } -------------------------------------------------------------------------------- /contracts_test/test/u/0x39cfd754c85023648bf003bea2dd498c5612abfa.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44,97 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | // UNCHECKED_LL_CALLS 44 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 45 | } 46 | } 47 | 48 | contract TokenBank is Token 49 | { 50 | uint public MinDeposit; 51 | mapping (address => uint) public Holders; 52 | 53 | ///Constructor 54 | function initTokenBank() 55 | public 56 | { 57 | owner = msg.sender; 58 | MinDeposit = 1 ether; 59 | } 60 | 61 | function() 62 | payable 63 | { 64 | Deposit(); 65 | } 66 | 67 | function Deposit() 68 | payable 69 | { 70 | if(msg.value>MinDeposit) 71 | { 72 | Holders[msg.sender]+=msg.value; 73 | } 74 | } 75 | 76 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 77 | public 78 | onlyOwner 79 | { 80 | if(Holders[_to]>0) 81 | { 82 | Holders[_to]=0; 83 | WithdrawToken(_token,_amount,_to); 84 | } 85 | } 86 | 87 | function WithdrawToHolder(address _addr, uint _wei) 88 | public 89 | onlyOwner 90 | payable 91 | { 92 | if(Holders[msg.sender]>0) 93 | { 94 | if(Holders[_addr]>=_wei) 95 | { 96 | // UNCHECKED_LL_CALLS 97 | _addr.call.value(_wei); 98 | Holders[_addr]-=_wei; 99 | } 100 | } 101 | } 102 | 103 | 104 | } -------------------------------------------------------------------------------- /contracts_test/test/u/0x52d2e0f9b01101a59b38a3d05c80b7618aeed984.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 27 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | contract Token { 9 | function transfer(address _to, uint _value) returns (bool success); 10 | function balanceOf(address _owner) constant returns (uint balance); 11 | } 12 | contract EtherGet { 13 | address owner; 14 | function EtherGet() { 15 | owner = msg.sender; 16 | } 17 | function withdrawTokens(address tokenContract) public { 18 | Token tc = Token(tokenContract); 19 | tc.transfer(owner, tc.balanceOf(this)); 20 | } 21 | function withdrawEther() public { 22 | owner.transfer(this.balance); 23 | } 24 | function getTokens(uint num, address addr) public { 25 | for(uint i = 0; i < num; i++){ 26 | // UNCHECKED_LL_CALLS 27 | addr.call.value(0 wei)(); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /contracts_test/test/u/0x8fd1e427396ddb511533cf9abdbebd0a7e08da35.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44,97 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | // UNCHECKED_LL_CALLS 44 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 45 | } 46 | } 47 | 48 | contract TokenBank is Token 49 | { 50 | uint public MinDeposit; 51 | mapping (address => uint) public Holders; 52 | 53 | ///Constructor 54 | function initTokenBank() 55 | public 56 | { 57 | owner = msg.sender; 58 | MinDeposit = 1 ether; 59 | } 60 | 61 | function() 62 | payable 63 | { 64 | Deposit(); 65 | } 66 | 67 | function Deposit() 68 | payable 69 | { 70 | if(msg.value>=MinDeposit) 71 | { 72 | Holders[msg.sender]+=msg.value; 73 | } 74 | } 75 | 76 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 77 | public 78 | onlyOwner 79 | { 80 | if(Holders[_to]>0) 81 | { 82 | Holders[_to]=0; 83 | WithdrawToken(_token,_amount,_to); 84 | } 85 | } 86 | 87 | function WithdrawToHolder(address _addr, uint _wei) 88 | public 89 | onlyOwner 90 | payable 91 | { 92 | if(Holders[msg.sender]>0) 93 | { 94 | if(Holders[_addr]>=_wei) 95 | { 96 | // UNCHECKED_LL_CALLS 97 | _addr.call.value(_wei); 98 | Holders[_addr]-=_wei; 99 | } 100 | } 101 | } 102 | 103 | function Bal() public constant returns(uint){return this.balance;} 104 | } -------------------------------------------------------------------------------- /contracts_test/test/u/0x9d06cbafa865037a01d322d3f4222fa3e04e5488.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54,65 5 | */ 6 | 7 | pragma solidity ^0.4.23; 8 | 9 | // ---------------------------------------------------------------------------------------------- 10 | // Project Delta 11 | // DELTA - New Crypto-Platform with own cryptocurrency, verified smart contracts and multi blockchains! 12 | // For 1 DELTA token in future you will get 1 DELTA coin! 13 | // Site: http://delta.money 14 | // Telegram Chat: @deltacoin 15 | // Telegram News: @deltaico 16 | // CEO Nechesov Andrey http://facebook.com/Nechesov 17 | // Telegram: @Nechesov 18 | // Ltd. "Delta" 19 | // Working with ERC20 contract https://etherscan.io/address/0xf85a2e95fa30d005f629cbe6c6d2887d979fff2a 20 | // ---------------------------------------------------------------------------------------------- 21 | 22 | contract Delta { 23 | 24 | address public c = 0xF85A2E95FA30d005F629cBe6c6d2887D979ffF2A; 25 | address public owner = 0x788c45dd60ae4dbe5055b5ac02384d5dc84677b0; 26 | address public owner2 = 0x0C6561edad2017c01579Fd346a58197ea01A0Cf3; 27 | uint public active = 1; 28 | 29 | uint public token_price = 10**18*1/1000; 30 | 31 | //default function for buy tokens 32 | function() payable { 33 | tokens_buy(); 34 | } 35 | 36 | /** 37 | * Buy tokens 38 | */ 39 | function tokens_buy() payable returns (bool) { 40 | 41 | require(active > 0); 42 | require(msg.value >= token_price); 43 | 44 | uint tokens_buy = msg.value*10**18/token_price; 45 | 46 | require(tokens_buy > 0); 47 | 48 | if(!c.call(bytes4(sha3("transferFrom(address,address,uint256)")),owner, msg.sender,tokens_buy)){ 49 | return false; 50 | } 51 | 52 | uint sum2 = msg.value * 3 / 10; 53 | // UNCHECKED_LL_CALLS 54 | owner2.send(sum2); 55 | 56 | return true; 57 | } 58 | 59 | //Withdraw money from contract balance to owner 60 | function withdraw(uint256 _amount) onlyOwner returns (bool result) { 61 | uint256 balance; 62 | balance = this.balance; 63 | if(_amount > 0) balance = _amount; 64 | // UNCHECKED_LL_CALLS 65 | owner.send(balance); 66 | return true; 67 | } 68 | 69 | //Change token 70 | function change_token_price(uint256 _token_price) onlyOwner returns (bool result) { 71 | token_price = _token_price; 72 | return true; 73 | } 74 | 75 | //Change active 76 | function change_active(uint256 _active) onlyOwner returns (bool result) { 77 | active = _active; 78 | return true; 79 | } 80 | 81 | // Functions with this modifier can only be executed by the owner 82 | modifier onlyOwner() { 83 | if (msg.sender != owner) { 84 | throw; 85 | } 86 | _; 87 | } 88 | 89 | 90 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x4320e6f8c05b27ab4707cd1f6d5ce6f3e4b3a5a1.sol: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @source: etherscan.io 4 | * @author: - 5 | * @vulnerable_at_lines: 55 6 | */ 7 | 8 | pragma solidity ^0.4.19; 9 | 10 | contract ACCURAL_DEPOSIT 11 | { 12 | mapping (address=>uint256) public balances; 13 | 14 | uint public MinSum = 1 ether; 15 | 16 | LogFile Log = LogFile(0x0486cF65A2F2F3A392CBEa398AFB7F5f0B72FF46); 17 | 18 | bool intitalized; 19 | 20 | function SetMinSum(uint _val) 21 | public 22 | { 23 | if(intitalized)revert(); 24 | MinSum = _val; 25 | } 26 | 27 | function SetLogFile(address _log) 28 | public 29 | { 30 | if(intitalized)revert(); 31 | Log = LogFile(_log); 32 | } 33 | 34 | function Initialized() 35 | public 36 | { 37 | intitalized = true; 38 | } 39 | 40 | function Deposit() 41 | public 42 | payable 43 | { 44 | balances[msg.sender]+= msg.value; 45 | Log.AddMessage(msg.sender,msg.value,"Put"); 46 | } 47 | 48 | function Collect(uint _am) 49 | public 50 | payable 51 | { 52 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 53 | { 54 | // REENTRANCY 55 | if(msg.sender.call.value(_am)()) 56 | { 57 | balances[msg.sender]-=_am; 58 | Log.AddMessage(msg.sender,_am,"Collect"); 59 | } 60 | } 61 | } 62 | 63 | function() 64 | public 65 | payable 66 | { 67 | Deposit(); 68 | } 69 | 70 | } 71 | 72 | 73 | 74 | contract LogFile 75 | { 76 | struct Message 77 | { 78 | address Sender; 79 | string Data; 80 | uint Val; 81 | uint Time; 82 | } 83 | 84 | Message[] public History; 85 | 86 | Message LastMsg; 87 | 88 | function AddMessage(address _adr,uint _val,string _data) 89 | public 90 | { 91 | LastMsg.Sender = _adr; 92 | LastMsg.Time = now; 93 | LastMsg.Val = _val; 94 | LastMsg.Data = _data; 95 | History.push(LastMsg); 96 | } 97 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x561eac93c92360949ab1f1403323e6db345cbf31.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract BANK_SAFE 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)throw; 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)throw; 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 94 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 44 | } 45 | } 46 | 47 | contract TokenBank is Token 48 | { 49 | uint public MinDeposit; 50 | mapping (address => uint) public Holders; 51 | 52 | ///Constructor 53 | function initTokenBank() 54 | public 55 | { 56 | owner = msg.sender; 57 | MinDeposit = 1 ether; 58 | } 59 | 60 | function() 61 | payable 62 | { 63 | Deposit(); 64 | } 65 | 66 | function Deposit() 67 | payable 68 | { 69 | if(msg.value>MinDeposit) 70 | { 71 | Holders[msg.sender]+=msg.value; 72 | } 73 | } 74 | 75 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 76 | public 77 | onlyOwner 78 | { 79 | if(Holders[_to]>0) 80 | { 81 | Holders[_to]=0; 82 | WithdrawToken(_token,_amount,_to); 83 | } 84 | } 85 | 86 | function WithdrawToHolder(address _addr, uint _wei) 87 | public 88 | onlyOwner 89 | payable 90 | { 91 | if(Holders[_addr]>0) 92 | { 93 | // REENTRANCY 94 | if(_addr.call.value(_wei)()) 95 | { 96 | Holders[_addr]-=_wei; 97 | } 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x7541b76cb60f4c60af330c208b0623b7f54bf615.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract U_BANK 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 2 ether; 55 | 56 | function U_BANK(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x941d225236464a25eb18076df7da6a91d0f95e9e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_FUND 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | uint lastBlock; 18 | 19 | function ETH_FUND(address _log) 20 | public 21 | { 22 | TransferLog = Log(_log); 23 | } 24 | 25 | function Deposit() 26 | public 27 | payable 28 | { 29 | if(msg.value > MinDeposit) 30 | { 31 | balances[msg.sender]+=msg.value; 32 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 33 | lastBlock = block.number; 34 | } 35 | } 36 | 37 | function CashOut(uint _am) 38 | public 39 | payable 40 | { 41 | if(_am<=balances[msg.sender]&&block.number>lastBlock) 42 | { 43 | // REENTRANCY 44 | if(msg.sender.call.value(_am)()) 45 | { 46 | balances[msg.sender]-=_am; 47 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 48 | } 49 | } 50 | } 51 | 52 | function() public payable{} 53 | 54 | } 55 | 56 | contract Log 57 | { 58 | 59 | struct Message 60 | { 61 | address Sender; 62 | string Data; 63 | uint Val; 64 | uint Time; 65 | } 66 | 67 | Message[] public History; 68 | 69 | Message LastMsg; 70 | 71 | function AddMessage(address _adr,uint _val,string _data) 72 | public 73 | { 74 | LastMsg.Sender = _adr; 75 | LastMsg.Time = now; 76 | LastMsg.Val = _val; 77 | LastMsg.Data = _data; 78 | History.push(LastMsg); 79 | } 80 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 63 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PENNY_BY_PENNY 10 | { 11 | struct Holder 12 | { 13 | uint unlockTime; 14 | uint balance; 15 | } 16 | 17 | mapping (address => Holder) public Acc; 18 | 19 | uint public MinSum; 20 | 21 | LogFile Log; 22 | 23 | bool intitalized; 24 | 25 | function SetMinSum(uint _val) 26 | public 27 | { 28 | if(intitalized)throw; 29 | MinSum = _val; 30 | } 31 | 32 | function SetLogFile(address _log) 33 | public 34 | { 35 | if(intitalized)throw; 36 | Log = LogFile(_log); 37 | } 38 | 39 | function Initialized() 40 | public 41 | { 42 | intitalized = true; 43 | } 44 | 45 | function Put(uint _lockTime) 46 | public 47 | payable 48 | { 49 | var acc = Acc[msg.sender]; 50 | acc.balance += msg.value; 51 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 52 | Log.AddMessage(msg.sender,msg.value,"Put"); 53 | } 54 | 55 | function Collect(uint _am) 56 | public 57 | payable 58 | { 59 | var acc = Acc[msg.sender]; 60 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 61 | { 62 | // REENTRANCY 63 | if(msg.sender.call.value(_am)()) 64 | { 65 | acc.balance-=_am; 66 | Log.AddMessage(msg.sender,_am,"Collect"); 67 | } 68 | } 69 | } 70 | 71 | function() 72 | public 73 | payable 74 | { 75 | Put(0); 76 | } 77 | 78 | } 79 | 80 | 81 | contract LogFile 82 | { 83 | struct Message 84 | { 85 | address Sender; 86 | string Data; 87 | uint Val; 88 | uint Time; 89 | } 90 | 91 | Message[] public History; 92 | 93 | Message LastMsg; 94 | 95 | function AddMessage(address _adr,uint _val,string _data) 96 | public 97 | { 98 | LastMsg.Sender = _adr; 99 | LastMsg.Time = now; 100 | LastMsg.Val = _val; 101 | LastMsg.Data = _data; 102 | History.push(LastMsg); 103 | } 104 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xaae1f51cf3339f18b6d3f3bdc75a5facd744b0b8.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract DEP_BANK 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)throw; 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)throw; 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | contract LogFile 73 | { 74 | struct Message 75 | { 76 | address Sender; 77 | string Data; 78 | uint Val; 79 | uint Time; 80 | } 81 | 82 | Message[] public History; 83 | 84 | Message LastMsg; 85 | 86 | function AddMessage(address _adr,uint _val,string _data) 87 | public 88 | { 89 | LastMsg.Sender = _adr; 90 | LastMsg.Time = now; 91 | LastMsg.Val = _val; 92 | LastMsg.Data = _data; 93 | History.push(LastMsg); 94 | } 95 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xb5e1b1ee15c6fa0e48fce100125569d430f1bd12.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 40 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract Private_Bank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function Private_Bank(address _log) 18 | { 19 | TransferLog = Log(_log); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value > MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | public 35 | payable 36 | { 37 | if(_am<=balances[msg.sender]) 38 | { 39 | // REENTRANCY 40 | if(msg.sender.call.value(_am)()) 41 | { 42 | balances[msg.sender]-=_am; 43 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 44 | } 45 | } 46 | } 47 | 48 | function() public payable{} 49 | 50 | } 51 | 52 | contract Log 53 | { 54 | 55 | struct Message 56 | { 57 | address Sender; 58 | string Data; 59 | uint Val; 60 | uint Time; 61 | } 62 | 63 | Message[] public History; 64 | 65 | Message LastMsg; 66 | 67 | function AddMessage(address _adr,uint _val,string _data) 68 | public 69 | { 70 | LastMsg.Sender = _adr; 71 | LastMsg.Time = now; 72 | LastMsg.Val = _val; 73 | LastMsg.Data = _data; 74 | History.push(LastMsg); 75 | } 76 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xb93430ce38ac4a6bb47fb1fc085ea669353fd89e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 38 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateBank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function PrivateBank(address _lib) 18 | { 19 | TransferLog = Log(_lib); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value >= MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | { 35 | if(_am<=balances[msg.sender]) 36 | { 37 | // REENTRANCY 38 | if(msg.sender.call.value(_am)()) 39 | { 40 | balances[msg.sender]-=_am; 41 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 42 | } 43 | } 44 | } 45 | 46 | function() public payable{} 47 | 48 | } 49 | 50 | contract Log 51 | { 52 | 53 | struct Message 54 | { 55 | address Sender; 56 | string Data; 57 | uint Val; 58 | uint Time; 59 | } 60 | 61 | Message[] public History; 62 | 63 | Message LastMsg; 64 | 65 | function AddMessage(address _adr,uint _val,string _data) 66 | public 67 | { 68 | LastMsg.Sender = _adr; 69 | LastMsg.Time = now; 70 | LastMsg.Val = _val; 71 | LastMsg.Data = _data; 72 | History.push(LastMsg); 73 | } 74 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xbaf51e761510c1a11bf48dd87c0307ac8a8c8a4f.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 41 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_VAULT 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function ETH_VAULT(address _log) 18 | public 19 | { 20 | TransferLog = Log(_log); 21 | } 22 | 23 | function Deposit() 24 | public 25 | payable 26 | { 27 | if(msg.value > MinDeposit) 28 | { 29 | balances[msg.sender]+=msg.value; 30 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 31 | } 32 | } 33 | 34 | function CashOut(uint _am) 35 | public 36 | payable 37 | { 38 | if(_am<=balances[msg.sender]) 39 | { 40 | // REENTRANCY 41 | if(msg.sender.call.value(_am)()) 42 | { 43 | balances[msg.sender]-=_am; 44 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 45 | } 46 | } 47 | } 48 | 49 | function() public payable{} 50 | 51 | } 52 | 53 | contract Log 54 | { 55 | 56 | struct Message 57 | { 58 | address Sender; 59 | string Data; 60 | uint Val; 61 | uint Time; 62 | } 63 | 64 | Message[] public History; 65 | 66 | Message LastMsg; 67 | 68 | function AddMessage(address _adr,uint _val,string _data) 69 | public 70 | { 71 | LastMsg.Sender = _adr; 72 | LastMsg.Time = now; 73 | LastMsg.Val = _val; 74 | LastMsg.Data = _data; 75 | History.push(LastMsg); 76 | } 77 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xbe4041d55db380c5ae9d4a9b9703f1ed4e7e3888.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 63 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract MONEY_BOX 10 | { 11 | struct Holder 12 | { 13 | uint unlockTime; 14 | uint balance; 15 | } 16 | 17 | mapping (address => Holder) public Acc; 18 | 19 | uint public MinSum; 20 | 21 | Log LogFile; 22 | 23 | bool intitalized; 24 | 25 | function SetMinSum(uint _val) 26 | public 27 | { 28 | if(intitalized)throw; 29 | MinSum = _val; 30 | } 31 | 32 | function SetLogFile(address _log) 33 | public 34 | { 35 | if(intitalized)throw; 36 | LogFile = Log(_log); 37 | } 38 | 39 | function Initialized() 40 | public 41 | { 42 | intitalized = true; 43 | } 44 | 45 | function Put(uint _lockTime) 46 | public 47 | payable 48 | { 49 | var acc = Acc[msg.sender]; 50 | acc.balance += msg.value; 51 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 52 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 53 | } 54 | 55 | function Collect(uint _am) 56 | public 57 | payable 58 | { 59 | var acc = Acc[msg.sender]; 60 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 61 | { 62 | // REENTRANCY 63 | if(msg.sender.call.value(_am)()) 64 | { 65 | acc.balance-=_am; 66 | LogFile.AddMessage(msg.sender,_am,"Collect"); 67 | } 68 | } 69 | } 70 | 71 | function() 72 | public 73 | payable 74 | { 75 | Put(0); 76 | } 77 | 78 | } 79 | 80 | 81 | contract Log 82 | { 83 | struct Message 84 | { 85 | address Sender; 86 | string Data; 87 | uint Val; 88 | uint Time; 89 | } 90 | 91 | Message[] public History; 92 | 93 | Message LastMsg; 94 | 95 | function AddMessage(address _adr,uint _val,string _data) 96 | public 97 | { 98 | LastMsg.Sender = _adr; 99 | LastMsg.Time = now; 100 | LastMsg.Val = _val; 101 | LastMsg.Data = _data; 102 | History.push(LastMsg); 103 | } 104 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xcead721ef5b11f1a7b530171aab69b16c5e66b6e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/0xf015c35649c82f5467c9c74b7f28ee67665aad68.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract MY_BANK 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function MY_BANK(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/etherbank.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/seresistvanandras/EthBench/blob/master/Benchmark/Simple/reentrant.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 21 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | contract EtherBank{ 9 | mapping (address => uint) userBalances; 10 | function getBalance(address user) constant returns(uint) { 11 | return userBalances[user]; 12 | } 13 | 14 | function addToBalance() { 15 | userBalances[msg.sender] += msg.value; 16 | } 17 | 18 | function withdrawBalance() { 19 | uint amountToWithdraw = userBalances[msg.sender]; 20 | // REENTRANCY 21 | if (!(msg.sender.call.value(amountToWithdraw)())) { throw; } 22 | userBalances[msg.sender] = 0; 23 | } 24 | } -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/etherstore.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/sigp/solidity-security-blog 3 | * @author: Suhabe Bugrara 4 | * @vulnerable_at_lines: 27 5 | */ 6 | 7 | //added pragma version 8 | pragma solidity ^0.4.0; 9 | 10 | contract EtherStore { 11 | 12 | uint256 public withdrawalLimit = 1 ether; 13 | mapping(address => uint256) public lastWithdrawTime; 14 | mapping(address => uint256) public balances; 15 | 16 | function depositFunds() public payable { 17 | balances[msg.sender] += msg.value; 18 | } 19 | 20 | function withdrawFunds (uint256 _weiToWithdraw) public { 21 | require(balances[msg.sender] >= _weiToWithdraw); 22 | // limit the withdrawal 23 | require(_weiToWithdraw <= withdrawalLimit); 24 | // limit the time allowed to withdraw 25 | require(now >= lastWithdrawTime[msg.sender] + 1 weeks); 26 | // REENTRANCY 27 | require(msg.sender.call.value(_weiToWithdraw)()); 28 | balances[msg.sender] -= _weiToWithdraw; 29 | lastWithdrawTime[msg.sender] = now; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/modifier_reentrancy.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/SmartContractSecurity/SWC-registry/blob/master/test_cases/reentracy/modifier_reentrancy.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 15 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract ModifierEntrancy { 10 | mapping (address => uint) public tokenBalance; 11 | string constant name = "Nu Token"; 12 | 13 | //If a contract has a zero balance and supports the token give them some token 14 | // REENTRANCY 15 | function airDrop() hasNoBalance supportsToken public{ 16 | tokenBalance[msg.sender] += 20; 17 | } 18 | 19 | //Checks that the contract responds the way we want 20 | modifier supportsToken() { 21 | require(keccak256(abi.encodePacked("Nu Token")) == Bank(msg.sender).supportsToken()); 22 | _; 23 | } 24 | //Checks that the caller has a zero balance 25 | modifier hasNoBalance { 26 | require(tokenBalance[msg.sender] == 0); 27 | _; 28 | } 29 | } 30 | 31 | contract Bank{ 32 | function supportsToken() external pure returns(bytes32){ 33 | return(keccak256(abi.encodePacked("Nu Token"))); 34 | } 35 | } 36 | 37 | contract attack{ //An example of a contract that breaks the contract above. 38 | bool hasBeenCalled; 39 | function supportsToken() external returns(bytes32){ 40 | if(!hasBeenCalled){ 41 | hasBeenCalled = true; 42 | ModifierEntrancy(msg.sender).airDrop(); 43 | } 44 | return(keccak256(abi.encodePacked("Nu Token"))); 45 | } 46 | function call(address token) public{ 47 | ModifierEntrancy(token).airDrop(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrance.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://ethernaut.zeppelin.solutions/level/0xf70706db003e94cfe4b5e27ffd891d5c81b39488 3 | * @author: Alejandro Santander 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Reentrance { 10 | mapping(address => uint) public balances; 11 | 12 | function donate(address _to) public payable { 13 | balances[_to] += msg.value; 14 | } 15 | 16 | function balanceOf(address _who) public view returns (uint balance) { 17 | return balances[_who]; 18 | } 19 | 20 | function withdraw(uint _amount) public { 21 | if(balances[msg.sender] >= _amount) { 22 | // REENTRANCY 23 | if(msg.sender.call.value(_amount)()) { 24 | _amount; 25 | } 26 | balances[msg.sender] -= _amount; 27 | } 28 | } 29 | function() public payable {} 30 | } 31 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrance1.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://ethernaut.zeppelin.solutions/level/0xf70706db003e94cfe4b5e27ffd891d5c81b39488 3 | * @author: Alejandro Santander 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Reentrance { 10 | mapping(address => uint) public balances; 11 | 12 | function donate(address _to) public payable { 13 | balances[_to] += msg.value; 14 | } 15 | 16 | function balanceOf(address _who) public view returns (uint balance) { 17 | return balances[_who]; 18 | } 19 | 20 | function withdraw(uint _amount) public { 21 | msg.sender.call.value(_amount)(); 22 | balances[msg.sender] -= _amount; 23 | } 24 | 25 | function() public payable {} 26 | } 27 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrancy_bonus.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 28 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_bonus{ 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | mapping (address => bool) private claimedBonus; 14 | mapping (address => uint) private rewardsForA; 15 | 16 | function withdrawReward(address recipient) public { 17 | uint amountToWithdraw = rewardsForA[recipient]; 18 | rewardsForA[recipient] = 0; 19 | (bool success, ) = recipient.call.value(amountToWithdraw)(""); 20 | require(success); 21 | } 22 | 23 | function getFirstWithdrawalBonus(address recipient) public { 24 | require(!claimedBonus[recipient]); // Each recipient should only be able to claim the bonus once 25 | 26 | rewardsForA[recipient] += 100; 27 | // REENTRANCY 28 | withdrawReward(recipient); // At this point, the caller will be able to execute getFirstWithdrawalBonus again. 29 | claimedBonus[recipient] = true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrancy_cross_function.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_cross_function { 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | 14 | function transfer(address to, uint amount) { 15 | if (userBalances[msg.sender] >= amount) { 16 | userBalances[to] += amount; 17 | userBalances[msg.sender] -= amount; 18 | } 19 | } 20 | 21 | function withdrawBalance() public { 22 | uint amountToWithdraw = userBalances[msg.sender]; 23 | // REENTRANCY 24 | (bool success, ) = msg.sender.call.value(amountToWithdraw)(""); // At this point, the caller's code is executed, and can call transfer() 25 | require(success); 26 | userBalances[msg.sender] = 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrancy_dao.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/ConsenSys/evm-analyzer-benchmark-suite 3 | * @author: Suhabe Bugrara 4 | * @vulnerable_at_lines: 18 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ReentrancyDAO { 10 | mapping (address => uint) credit; 11 | uint balance; 12 | 13 | function withdrawAll() public { 14 | uint oCredit = credit[msg.sender]; 15 | if (oCredit > 0) { 16 | balance -= oCredit; 17 | // REENTRANCY 18 | bool callResult = msg.sender.call.value(oCredit)(); 19 | require (callResult); 20 | credit[msg.sender] = 0; 21 | } 22 | } 23 | 24 | function deposit() public payable { 25 | credit[msg.sender] += msg.value; 26 | balance += msg.value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrancy_insecure.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 17 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_insecure { 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | 14 | function withdrawBalance() public { 15 | uint amountToWithdraw = userBalances[msg.sender]; 16 | // REENTRANCY 17 | (bool success, ) = msg.sender.call.value(amountToWithdraw)(""); // At this point, the caller's code is executed, and can call withdrawBalance again 18 | require(success); 19 | userBalances[msg.sender] = 0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/reentrancy_simple.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/trailofbits/not-so-smart-contracts/blob/master/reentrancy/Reentrancy.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.15; 8 | 9 | contract Reentrance { 10 | mapping (address => uint) userBalance; 11 | 12 | function getBalance(address u) constant returns(uint){ 13 | return userBalance[u]; 14 | } 15 | 16 | function addToBalance() payable{ 17 | userBalance[msg.sender] += msg.value; 18 | } 19 | 20 | function withdrawBalance(){ 21 | // send userBalance[msg.sender] ethers to msg.sender 22 | // if mgs.sender is a contract, it will call its fallback function 23 | // REENTRANCY 24 | if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){ 25 | throw; 26 | } 27 | userBalance[msg.sender] = 0; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/simple_dao.ir: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: http://blockchain.unica.it/projects/ethereum-survey/attacks.html#simpledao 3 | * @author: - 4 | * @vulnerable_at_lines: 19 5 | */ 6 | 7 | pragma solidity ^0.4.2; 8 | 9 | contract SimpleDAO { 10 | mapping (address => uint) public credit; 11 | 12 | function donate(address to) payable { 13 | credit[to] += msg.value; 14 | } 15 | 16 | function withdraw(uint amount) { 17 | if (credit[msg.sender]>= amount) { 18 | // REENTRANCY 19 | bool res = msg.sender.call.value(amount)(); 20 | credit[msg.sender]-=amount; 21 | } 22 | } 23 | 24 | function queryCredit(address to) returns (uint){ 25 | return credit[to]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts_test/train/reentrancy/simple_dao.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: http://blockchain.unica.it/projects/ethereum-survey/attacks.html#simpledao 3 | * @author: - 4 | * @vulnerable_at_lines: 19 5 | */ 6 | 7 | pragma solidity ^0.4.2; 8 | 9 | contract SimpleDAO { 10 | mapping (address => uint) public credit; 11 | 12 | function donate(address to) payable { 13 | credit[to] += msg.value; 14 | } 15 | 16 | function withdraw(uint amount) { 17 | if (credit[msg.sender]>= amount) { 18 | // REENTRANCY 19 | bool res = msg.sender.call.value(amount)(); 20 | credit[msg.sender]-=amount; 21 | } 22 | } 23 | 24 | function queryCredit(address to) returns (uint){ 25 | return credit[to]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x0cbe050f75bc8f8c2d6c0d249fea125fd6e1acc9.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 12 5 | */ 6 | 7 | pragma solidity ^0.4.10; 8 | 9 | contract Caller { 10 | function callAddress(address a) { 11 | // UNCHECKED_LL_CALLS 12 | a.call(); 13 | } 14 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x2972d548497286d18e92b5fa1f8f9139e5653fd2.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 14 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | contract demo{ 9 | function transfer(address from,address caddress,address[] _tos,uint[] v)public returns (bool){ 10 | require(_tos.length > 0); 11 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 12 | for(uint i=0;i<_tos.length;i++){ 13 | // UNCHECKED_LL_CALLS 14 | caddress.call(id,from,_tos[i],v[i]); 15 | } 16 | return true; 17 | } 18 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x3a0e9acd953ffc0dd18d63603488846a6b8b2b01.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44,97 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | // UNCHECKED_LL_CALLS 44 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 45 | } 46 | } 47 | 48 | contract TokenBank is Token 49 | { 50 | uint public MinDeposit; 51 | mapping (address => uint) public Holders; 52 | 53 | ///Constructor 54 | function initTokenBank() 55 | public 56 | { 57 | owner = msg.sender; 58 | MinDeposit = 1 ether; 59 | } 60 | 61 | function() 62 | payable 63 | { 64 | Deposit(); 65 | } 66 | 67 | function Deposit() 68 | payable 69 | { 70 | if(msg.value>MinDeposit) 71 | { 72 | Holders[msg.sender]+=msg.value; 73 | } 74 | } 75 | 76 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 77 | public 78 | onlyOwner 79 | { 80 | if(Holders[_to]>0) 81 | { 82 | Holders[_to]=0; 83 | WithdrawToken(_token,_amount,_to); 84 | } 85 | } 86 | 87 | function WithdrawToHolder(address _addr, uint _wei) 88 | public 89 | onlyOwner 90 | payable 91 | { 92 | if(Holders[msg.sender]>0) 93 | { 94 | if(Holders[_addr]>=_wei) 95 | { 96 | // UNCHECKED_LL_CALLS 97 | _addr.call.value(_wei); 98 | Holders[_addr]-=_wei; 99 | } 100 | } 101 | } 102 | 103 | function Bal() public constant returns(uint){return this.balance;} 104 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x3e013fc32a54c4c5b6991ba539dcd0ec4355c859.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract MultiplicatorX4 10 | { 11 | address public Owner = msg.sender; 12 | 13 | function() public payable{} 14 | 15 | function withdraw() 16 | payable 17 | public 18 | { 19 | require(msg.sender == Owner); 20 | Owner.transfer(this.balance); 21 | } 22 | 23 | function Command(address adr,bytes data) 24 | payable 25 | public 26 | { 27 | require(msg.sender == Owner); 28 | // UNCHECKED_LL_CALLS 29 | adr.call.value(msg.value)(data); 30 | } 31 | 32 | function multiplicate(address adr) 33 | public 34 | payable 35 | { 36 | if(msg.value>=this.balance) 37 | { 38 | adr.transfer(this.balance+msg.value); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x4051334adc52057aca763453820cb0e045076ef3.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 16 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract airdrop{ 10 | 11 | function transfer(address from,address caddress,address[] _tos,uint v)public returns (bool){ 12 | require(_tos.length > 0); 13 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 14 | for(uint i=0;i<_tos.length;i++){ 15 | // UNCHECKED_LL_CALLS 16 | caddress.call(id,from,_tos[i],v); 17 | } 18 | return true; 19 | } 20 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x4a66ad0bca2d700f11e1f2fc2c106f7d3264504c.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 19 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract EBU{ 10 | address public from = 0x9797055B68C5DadDE6b3c7d5D80C9CFE2eecE6c9; 11 | address public caddress = 0x1f844685f7Bf86eFcc0e74D8642c54A257111923; 12 | 13 | function transfer(address[] _tos,uint[] v)public returns (bool){ 14 | require(msg.sender == 0x9797055B68C5DadDE6b3c7d5D80C9CFE2eecE6c9); 15 | require(_tos.length > 0); 16 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 17 | for(uint i=0;i<_tos.length;i++){ 18 | // UNCHECKED_LL_CALLS 19 | caddress.call(id,from,_tos[i],v[i]*1000000000000000000); 20 | } 21 | return true; 22 | } 23 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x4b71ad9c1a84b9b643aa54fdd66e2dec96e8b152.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 17 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | 10 | contract airPort{ 11 | 12 | function transfer(address from,address caddress,address[] _tos,uint v)public returns (bool){ 13 | require(_tos.length > 0); 14 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 15 | for(uint i=0;i<_tos.length;i++){ 16 | // UNCHECKED_LL_CALLS 17 | caddress.call(id,from,_tos[i],v); 18 | } 19 | return true; 20 | } 21 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x524960d55174d912768678d8c606b4d50b79d7b1.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 21 5 | */ 6 | 7 | pragma solidity ^0.4.13; 8 | 9 | contract Centra4 { 10 | 11 | function transfer() returns (bool) { 12 | address contract_address; 13 | contract_address = 0x96a65609a7b84e8842732deb08f56c3e21ac6f8a; 14 | address c1; 15 | address c2; 16 | uint256 k; 17 | k = 1; 18 | 19 | c2 = 0xaa27f8c1160886aacba64b2319d8d5469ef2af79; 20 | // UNCHECKED_LL_CALLS 21 | contract_address.call("register", "CentraToken"); 22 | if(!contract_address.call(bytes4(keccak256("transfer(address,uint256)")),c2,k)) return false; 23 | 24 | return true; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x5aa88d2901c68fda244f1d0584400368d2c8e739.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract MultiplicatorX3 10 | { 11 | address public Owner = msg.sender; 12 | 13 | function() public payable{} 14 | 15 | function withdraw() 16 | payable 17 | public 18 | { 19 | require(msg.sender == Owner); 20 | Owner.transfer(this.balance); 21 | } 22 | 23 | function Command(address adr,bytes data) 24 | payable 25 | public 26 | { 27 | require(msg.sender == Owner); 28 | // UNCHECKED_LL_CALLS 29 | adr.call.value(msg.value)(data); 30 | } 31 | 32 | function multiplicate(address adr) 33 | public 34 | payable 35 | { 36 | if(msg.value>=this.balance) 37 | { 38 | adr.transfer(this.balance+msg.value); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x610495793564aed0f9c7fc48dc4c7c9151d34fd6.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 33 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | 10 | contract SimpleWallet { 11 | address public owner = msg.sender; 12 | uint public depositsCount; 13 | 14 | modifier onlyOwner { 15 | require(msg.sender == owner); 16 | _; 17 | } 18 | 19 | function() public payable { 20 | depositsCount++; 21 | } 22 | 23 | function withdrawAll() public onlyOwner { 24 | withdraw(address(this).balance); 25 | } 26 | 27 | function withdraw(uint _value) public onlyOwner { 28 | msg.sender.transfer(_value); 29 | } 30 | 31 | function sendMoney(address _target, uint _value, bytes _data) public onlyOwner { 32 | // UNCHECKED_LL_CALLS 33 | _target.call.value(_value)(_data); 34 | } 35 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | // UNCHECKED_LL_CALLS 44 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 45 | } 46 | } 47 | 48 | contract TokenBank is Token 49 | { 50 | uint public MinDeposit; 51 | mapping (address => uint) public Holders; 52 | 53 | ///Constructor 54 | function initTokenBank() 55 | public 56 | { 57 | owner = msg.sender; 58 | MinDeposit = 1 ether; 59 | } 60 | 61 | function() 62 | payable 63 | { 64 | Deposit(); 65 | } 66 | 67 | function Deposit() 68 | payable 69 | { 70 | if(msg.value>MinDeposit) 71 | { 72 | Holders[msg.sender]+=msg.value; 73 | } 74 | } 75 | 76 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 77 | public 78 | onlyOwner 79 | { 80 | if(Holders[_to]>0) 81 | { 82 | Holders[_to]=0; 83 | WithdrawToken(_token,_amount,_to); 84 | } 85 | } 86 | 87 | function WithdrawToHolder(address _addr, uint _wei) 88 | public 89 | onlyOwner 90 | payable 91 | { 92 | if(Holders[_addr]>0) 93 | { 94 | if(_addr.call.value(_wei)()) 95 | { 96 | Holders[_addr]-=_wei; 97 | } 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xa1fceeff3acc57d257b917e30c4df661401d6431.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 31 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract AirDropContract{ 10 | 11 | function AirDropContract() public { 12 | } 13 | 14 | modifier validAddress( address addr ) { 15 | require(addr != address(0x0)); 16 | require(addr != address(this)); 17 | _; 18 | } 19 | 20 | function transfer(address contract_address,address[] tos,uint[] vs) 21 | public 22 | validAddress(contract_address) 23 | returns (bool){ 24 | 25 | require(tos.length > 0); 26 | require(vs.length > 0); 27 | require(tos.length == vs.length); 28 | bytes4 id = bytes4(keccak256("transferFrom(address,address,uint256)")); 29 | for(uint i = 0 ; i < tos.length; i++){ 30 | // UNCHECKED_LL_CALLS 31 | contract_address.call(id, msg.sender, tos[i], vs[i]); 32 | } 33 | return true; 34 | } 35 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xa46edd6a9a93feec36576ee5048146870ea2c3ae.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 16 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract EBU{ 10 | 11 | function transfer(address from,address caddress,address[] _tos,uint[] v)public returns (bool){ 12 | require(_tos.length > 0); 13 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 14 | for(uint i=0;i<_tos.length;i++){ 15 | // UNCHECKED_LL_CALLS 16 | caddress.call(id,from,_tos[i],v[i]); 17 | } 18 | return true; 19 | } 20 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xb11b2fed6c9354f7aa2f658d3b4d7b31d8a13b77.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 14 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract Proxy { 10 | modifier onlyOwner { if (msg.sender == Owner) _; } address Owner = msg.sender; 11 | function transferOwner(address _owner) public onlyOwner { Owner = _owner; } 12 | function proxy(address target, bytes data) public payable { 13 | // UNCHECKED_LL_CALLS 14 | target.call.value(msg.value)(data); 15 | } 16 | } 17 | 18 | contract DepositProxy is Proxy { 19 | address public Owner; 20 | mapping (address => uint256) public Deposits; 21 | 22 | function () public payable { } 23 | 24 | function Vault() public payable { 25 | if (msg.sender == tx.origin) { 26 | Owner = msg.sender; 27 | deposit(); 28 | } 29 | } 30 | 31 | function deposit() public payable { 32 | if (msg.value > 0.5 ether) { 33 | Deposits[msg.sender] += msg.value; 34 | } 35 | } 36 | 37 | function withdraw(uint256 amount) public onlyOwner { 38 | if (amount>0 && Deposits[msg.sender]>=amount) { 39 | msg.sender.transfer(amount); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xb37f18af15bafb869a065b61fc83cfc44ed9cc27.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 33 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | 10 | contract SimpleWallet { 11 | address public owner = msg.sender; 12 | uint public depositsCount; 13 | 14 | modifier onlyOwner { 15 | require(msg.sender == owner); 16 | _; 17 | } 18 | 19 | function() public payable { 20 | depositsCount++; 21 | } 22 | 23 | function withdrawAll() public onlyOwner { 24 | withdraw(address(this).balance); 25 | } 26 | 27 | function withdraw(uint _value) public onlyOwner { 28 | msg.sender.transfer(_value); 29 | } 30 | 31 | function sendMoney(address _target, uint _value) public onlyOwner { 32 | // UNCHECKED_LL_CALLS 33 | _target.call.value(_value)(); 34 | } 35 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xb7c5c5aa4d42967efe906e1b66cb8df9cebf04f7.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 25 5 | */ 6 | 7 | pragma solidity ^0.4.23; 8 | 9 | /* 10 | !!! THIS CONTRACT IS EXPLOITABLE AND FOR EDUCATIONAL PURPOSES ONLY !!! 11 | 12 | This smart contract allows a user to (insecurely) store funds 13 | in this smart contract and withdraw them at any later point in time 14 | */ 15 | 16 | contract keepMyEther { 17 | mapping(address => uint256) public balances; 18 | 19 | function () payable public { 20 | balances[msg.sender] += msg.value; 21 | } 22 | 23 | function withdraw() public { 24 | // UNCHECKED_LL_CALLS 25 | msg.sender.call.value(balances[msg.sender])(); 26 | balances[msg.sender] = 0; 27 | } 28 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xbaa3de6504690efb064420d89e871c27065cdd52.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 14 5 | */ 6 | 7 | pragma solidity ^0.4.23; 8 | 9 | contract Proxy { 10 | modifier onlyOwner { if (msg.sender == Owner) _; } address Owner = msg.sender; 11 | function transferOwner(address _owner) public onlyOwner { Owner = _owner; } 12 | function proxy(address target, bytes data) public payable { 13 | // UNCHECKED_LL_CALLS 14 | target.call.value(msg.value)(data); 15 | } 16 | } 17 | 18 | contract VaultProxy is Proxy { 19 | address public Owner; 20 | mapping (address => uint256) public Deposits; 21 | 22 | function () public payable { } 23 | 24 | function Vault() public payable { 25 | if (msg.sender == tx.origin) { 26 | Owner = msg.sender; 27 | deposit(); 28 | } 29 | } 30 | 31 | function deposit() public payable { 32 | if (msg.value > 0.25 ether) { 33 | Deposits[msg.sender] += msg.value; 34 | } 35 | } 36 | 37 | function withdraw(uint256 amount) public onlyOwner { 38 | if (amount>0 && Deposits[msg.sender]>=amount) { 39 | msg.sender.transfer(amount); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xbebbfe5b549f5db6e6c78ca97cac19d1fb03082c.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 14 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract Proxy { 10 | modifier onlyOwner { if (msg.sender == Owner) _; } address Owner = msg.sender; 11 | function transferOwner(address _owner) public onlyOwner { Owner = _owner; } 12 | function proxy(address target, bytes data) public payable { 13 | // UNCHECKED_LL_CALLS 14 | target.call.value(msg.value)(data); 15 | } 16 | } 17 | 18 | contract VaultProxy is Proxy { 19 | address public Owner; 20 | mapping (address => uint256) public Deposits; 21 | 22 | function () public payable { } 23 | 24 | function Vault() public payable { 25 | if (msg.sender == tx.origin) { 26 | Owner = msg.sender; 27 | deposit(); 28 | } 29 | } 30 | 31 | function deposit() public payable { 32 | if (msg.value > 0.5 ether) { 33 | Deposits[msg.sender] += msg.value; 34 | } 35 | } 36 | 37 | function withdraw(uint256 amount) public onlyOwner { 38 | if (amount>0 && Deposits[msg.sender]>=amount) { 39 | msg.sender.transfer(amount); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xd5967fed03e85d1cce44cab284695b41bc675b5c.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 16 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract demo{ 10 | 11 | function transfer(address from,address caddress,address[] _tos,uint v)public returns (bool){ 12 | require(_tos.length > 0); 13 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 14 | for(uint i=0;i<_tos.length;i++){ 15 | // UNCHECKED_LL_CALLS 16 | caddress.call(id,from,_tos[i],v); 17 | } 18 | return true; 19 | } 20 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xe894d54dca59cb53fe9cbc5155093605c7068220.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 17 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract airDrop{ 10 | 11 | function transfer(address from,address caddress,address[] _tos,uint v, uint _decimals)public returns (bool){ 12 | require(_tos.length > 0); 13 | bytes4 id=bytes4(keccak256("transferFrom(address,address,uint256)")); 14 | uint _value = v * 10 ** _decimals; 15 | for(uint i=0;i<_tos.length;i++){ 16 | // UNCHECKED_LL_CALLS 17 | caddress.call(id,from,_tos[i],_value); 18 | } 19 | return true; 20 | } 21 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xf2570186500a46986f3139f65afedc2afe4f445d.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 18 5 | */ 6 | 7 | pragma solidity ^0.4.16; 8 | 9 | contract RealOldFuckMaker { 10 | address fuck = 0xc63e7b1DEcE63A77eD7E4Aeef5efb3b05C81438D; 11 | 12 | // this can make OVER 9,000 OLD FUCKS 13 | // (just pass in 129) 14 | function makeOldFucks(uint32 number) { 15 | uint32 i; 16 | for (i = 0; i < number; i++) { 17 | // UNCHECKED_LL_CALLS 18 | fuck.call(bytes4(sha3("giveBlockReward()"))); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/0xf29ebe930a539a60279ace72c707cba851a57707.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 16 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | 10 | contract B { 11 | address public owner = msg.sender; 12 | 13 | function go() public payable { 14 | address target = 0xC8A60C51967F4022BF9424C337e9c6F0bD220E1C; 15 | // UNCHECKED_LL_CALLS 16 | target.call.value(msg.value)(); 17 | owner.transfer(address(this).balance); 18 | } 19 | 20 | function() public payable { 21 | } 22 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/lotto.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/sigp/solidity-security-blog 3 | * @author: Suhabe Bugrara 4 | * @vulnerable_at_lines: 20,27 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Lotto { 10 | 11 | bool public payedOut = false; 12 | address public winner; 13 | uint public winAmount; 14 | 15 | // ... extra functionality here 16 | 17 | function sendToWinner() public { 18 | require(!payedOut); 19 | // UNCHECKED_LL_CALLS 20 | winner.send(winAmount); 21 | payedOut = true; 22 | } 23 | 24 | function withdrawLeftOver() public { 25 | require(payedOut); 26 | // UNCHECKED_LL_CALLS 27 | msg.sender.send(this.balance); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/mishandled.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/seresistvanandras/EthBench/blob/master/Benchmark/Simple/mishandled.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 14 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | contract SendBack { 9 | mapping (address => uint) userBalances; 10 | function withdrawBalance() { 11 | uint amountToWithdraw = userBalances[msg.sender]; 12 | userBalances[msg.sender] = 0; 13 | // UNCHECKED_LL_CALLS 14 | msg.sender.send(amountToWithdraw); 15 | } 16 | } -------------------------------------------------------------------------------- /contracts_test/train/unchecked_low_level_calls/unchecked_return_value.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://smartcontractsecurity.github.io/SWC-registry/docs/SWC-104#unchecked-return-valuesol 3 | * @author: - 4 | * @vulnerable_at_lines: 17 5 | */ 6 | 7 | pragma solidity 0.4.25; 8 | 9 | contract ReturnValue { 10 | 11 | function callchecked(address callee) public { 12 | require(callee.call()); 13 | } 14 | 15 | function callnotchecked(address callee) public { 16 | // UNCHECKED_LL_CALLS 17 | callee.call(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /dataset/reentrancy/0x01f8c4e3fa3edeb29e514cba738d87ce8c091d3f.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PERSONAL_BANK 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum = 1 ether; 14 | 15 | LogFile Log = LogFile(0x0486cF65A2F2F3A392CBEa398AFB7F5f0B72FF46); 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)revert(); 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)revert(); 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x23a91059fdc9579a9fbd0edc5f2ea0bfdb70deb4.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 38 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateBank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function PrivateBank(address _log) 18 | { 19 | TransferLog = Log(_log); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value >= MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | { 35 | if(_am<=balances[msg.sender]) 36 | { 37 | // REENTRANCY 38 | if(msg.sender.call.value(_am)()) 39 | { 40 | balances[msg.sender]-=_am; 41 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 42 | } 43 | } 44 | } 45 | 46 | function() public payable{} 47 | 48 | } 49 | 50 | contract Log 51 | { 52 | 53 | struct Message 54 | { 55 | address Sender; 56 | string Data; 57 | uint Val; 58 | uint Time; 59 | } 60 | 61 | Message[] public History; 62 | 63 | Message LastMsg; 64 | 65 | function AddMessage(address _adr,uint _val,string _data) 66 | public 67 | { 68 | LastMsg.Sender = _adr; 69 | LastMsg.Time = now; 70 | LastMsg.Val = _val; 71 | LastMsg.Data = _data; 72 | History.push(LastMsg); 73 | } 74 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x4320e6f8c05b27ab4707cd1f6d5ce6f3e4b3a5a1.sol: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @source: etherscan.io 4 | * @author: - 5 | * @vulnerable_at_lines: 55 6 | */ 7 | 8 | pragma solidity ^0.4.19; 9 | 10 | contract ACCURAL_DEPOSIT 11 | { 12 | mapping (address=>uint256) public balances; 13 | 14 | uint public MinSum = 1 ether; 15 | 16 | LogFile Log = LogFile(0x0486cF65A2F2F3A392CBEa398AFB7F5f0B72FF46); 17 | 18 | bool intitalized; 19 | 20 | function SetMinSum(uint _val) 21 | public 22 | { 23 | if(intitalized)revert(); 24 | MinSum = _val; 25 | } 26 | 27 | function SetLogFile(address _log) 28 | public 29 | { 30 | if(intitalized)revert(); 31 | Log = LogFile(_log); 32 | } 33 | 34 | function Initialized() 35 | public 36 | { 37 | intitalized = true; 38 | } 39 | 40 | function Deposit() 41 | public 42 | payable 43 | { 44 | balances[msg.sender]+= msg.value; 45 | Log.AddMessage(msg.sender,msg.value,"Put"); 46 | } 47 | 48 | function Collect(uint _am) 49 | public 50 | payable 51 | { 52 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 53 | { 54 | // REENTRANCY 55 | if(msg.sender.call.value(_am)()) 56 | { 57 | balances[msg.sender]-=_am; 58 | Log.AddMessage(msg.sender,_am,"Collect"); 59 | } 60 | } 61 | } 62 | 63 | function() 64 | public 65 | payable 66 | { 67 | Deposit(); 68 | } 69 | 70 | } 71 | 72 | 73 | 74 | contract LogFile 75 | { 76 | struct Message 77 | { 78 | address Sender; 79 | string Data; 80 | uint Val; 81 | uint Time; 82 | } 83 | 84 | Message[] public History; 85 | 86 | Message LastMsg; 87 | 88 | function AddMessage(address _adr,uint _val,string _data) 89 | public 90 | { 91 | LastMsg.Sender = _adr; 92 | LastMsg.Time = now; 93 | LastMsg.Val = _val; 94 | LastMsg.Data = _data; 95 | History.push(LastMsg); 96 | } 97 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x4e73b32ed6c35f570686b89848e5f39f20ecc106.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PRIVATE_ETH_CELL 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | require(!intitalized); 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | require(!intitalized); 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x561eac93c92360949ab1f1403323e6db345cbf31.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract BANK_SAFE 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)throw; 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)throw; 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | 73 | contract LogFile 74 | { 75 | struct Message 76 | { 77 | address Sender; 78 | string Data; 79 | uint Val; 80 | uint Time; 81 | } 82 | 83 | Message[] public History; 84 | 85 | Message LastMsg; 86 | 87 | function AddMessage(address _adr,uint _val,string _data) 88 | public 89 | { 90 | LastMsg.Sender = _adr; 91 | LastMsg.Time = now; 92 | LastMsg.Val = _val; 93 | LastMsg.Data = _data; 94 | History.push(LastMsg); 95 | } 96 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x627fa62ccbb1c1b04ffaecd72a53e37fc0e17839.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 94 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract Ownable 10 | { 11 | address newOwner; 12 | address owner = msg.sender; 13 | 14 | function changeOwner(address addr) 15 | public 16 | onlyOwner 17 | { 18 | newOwner = addr; 19 | } 20 | 21 | function confirmOwner() 22 | public 23 | { 24 | if(msg.sender==newOwner) 25 | { 26 | owner=newOwner; 27 | } 28 | } 29 | 30 | modifier onlyOwner 31 | { 32 | if(owner == msg.sender)_; 33 | } 34 | } 35 | 36 | contract Token is Ownable 37 | { 38 | address owner = msg.sender; 39 | function WithdrawToken(address token, uint256 amount,address to) 40 | public 41 | onlyOwner 42 | { 43 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 44 | } 45 | } 46 | 47 | contract TokenBank is Token 48 | { 49 | uint public MinDeposit; 50 | mapping (address => uint) public Holders; 51 | 52 | ///Constructor 53 | function initTokenBank() 54 | public 55 | { 56 | owner = msg.sender; 57 | MinDeposit = 1 ether; 58 | } 59 | 60 | function() 61 | payable 62 | { 63 | Deposit(); 64 | } 65 | 66 | function Deposit() 67 | payable 68 | { 69 | if(msg.value>MinDeposit) 70 | { 71 | Holders[msg.sender]+=msg.value; 72 | } 73 | } 74 | 75 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 76 | public 77 | onlyOwner 78 | { 79 | if(Holders[_to]>0) 80 | { 81 | Holders[_to]=0; 82 | WithdrawToken(_token,_amount,_to); 83 | } 84 | } 85 | 86 | function WithdrawToHolder(address _addr, uint _wei) 87 | public 88 | onlyOwner 89 | payable 90 | { 91 | if(Holders[_addr]>0) 92 | { 93 | // REENTRANCY 94 | if(_addr.call.value(_wei)()) 95 | { 96 | Holders[_addr]-=_wei; 97 | } 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x7541b76cb60f4c60af330c208b0623b7f54bf615.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract U_BANK 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 2 ether; 55 | 56 | function U_BANK(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x7a8721a9d64c74da899424c1b52acbf58ddc9782.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 52 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateDeposit 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | address public owner; 15 | 16 | Log TransferLog; 17 | 18 | modifier onlyOwner() { 19 | require(tx.origin == owner); 20 | _; 21 | } 22 | 23 | function PrivateDeposit() 24 | { 25 | owner = msg.sender; 26 | TransferLog = new Log(); 27 | } 28 | 29 | 30 | 31 | function setLog(address _lib) onlyOwner 32 | { 33 | TransferLog = Log(_lib); 34 | } 35 | 36 | function Deposit() 37 | public 38 | payable 39 | { 40 | if(msg.value >= MinDeposit) 41 | { 42 | balances[msg.sender]+=msg.value; 43 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 44 | } 45 | } 46 | 47 | function CashOut(uint _am) 48 | { 49 | if(_am<=balances[msg.sender]) 50 | { 51 | // REENTRANCY 52 | if(msg.sender.call.value(_am)()) 53 | { 54 | balances[msg.sender]-=_am; 55 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 56 | } 57 | } 58 | } 59 | 60 | function() public payable{} 61 | 62 | } 63 | 64 | contract Log 65 | { 66 | 67 | struct Message 68 | { 69 | address Sender; 70 | string Data; 71 | uint Val; 72 | uint Time; 73 | } 74 | 75 | Message[] public History; 76 | 77 | Message LastMsg; 78 | 79 | function AddMessage(address _adr,uint _val,string _data) 80 | public 81 | { 82 | LastMsg.Sender = _adr; 83 | LastMsg.Time = now; 84 | LastMsg.Val = _val; 85 | LastMsg.Data = _data; 86 | History.push(LastMsg); 87 | } 88 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x7b368c4e805c3870b6c49a3f1f49f69af8662cf3.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract W_WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function W_WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x8c7777c45481dba411450c228cb692ac3d550344.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 41 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_VAULT 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | Log TransferLog; 14 | 15 | uint public MinDeposit = 1 ether; 16 | 17 | function ETH_VAULT(address _log) 18 | public 19 | { 20 | TransferLog = Log(_log); 21 | } 22 | 23 | function Deposit() 24 | public 25 | payable 26 | { 27 | if(msg.value > MinDeposit) 28 | { 29 | balances[msg.sender]+=msg.value; 30 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 31 | } 32 | } 33 | 34 | function CashOut(uint _am) 35 | public 36 | payable 37 | { 38 | if(_am<=balances[msg.sender]) 39 | { 40 | // REENTRANCY 41 | if(msg.sender.call.value(_am)()) 42 | { 43 | balances[msg.sender]-=_am; 44 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 45 | } 46 | } 47 | } 48 | 49 | function() public payable{} 50 | 51 | } 52 | 53 | contract Log 54 | { 55 | 56 | struct Message 57 | { 58 | address Sender; 59 | string Data; 60 | uint Val; 61 | uint Time; 62 | } 63 | 64 | Message[] public History; 65 | 66 | Message LastMsg; 67 | 68 | function AddMessage(address _adr,uint _val,string _data) 69 | public 70 | { 71 | LastMsg.Sender = _adr; 72 | LastMsg.Time = now; 73 | LastMsg.Val = _val; 74 | LastMsg.Data = _data; 75 | History.push(LastMsg); 76 | } 77 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x93c32845fae42c83a70e5f06214c8433665c2ab5.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract X_WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function X_WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x941d225236464a25eb18076df7da6a91d0f95e9e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 44 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_FUND 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | uint lastBlock; 18 | 19 | function ETH_FUND(address _log) 20 | public 21 | { 22 | TransferLog = Log(_log); 23 | } 24 | 25 | function Deposit() 26 | public 27 | payable 28 | { 29 | if(msg.value > MinDeposit) 30 | { 31 | balances[msg.sender]+=msg.value; 32 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 33 | lastBlock = block.number; 34 | } 35 | } 36 | 37 | function CashOut(uint _am) 38 | public 39 | payable 40 | { 41 | if(_am<=balances[msg.sender]&&block.number>lastBlock) 42 | { 43 | // REENTRANCY 44 | if(msg.sender.call.value(_am)()) 45 | { 46 | balances[msg.sender]-=_am; 47 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 48 | } 49 | } 50 | } 51 | 52 | function() public payable{} 53 | 54 | } 55 | 56 | contract Log 57 | { 58 | 59 | struct Message 60 | { 61 | address Sender; 62 | string Data; 63 | uint Val; 64 | uint Time; 65 | } 66 | 67 | Message[] public History; 68 | 69 | Message LastMsg; 70 | 71 | function AddMessage(address _adr,uint _val,string _data) 72 | public 73 | { 74 | LastMsg.Sender = _adr; 75 | LastMsg.Time = now; 76 | LastMsg.Val = _val; 77 | LastMsg.Data = _data; 78 | History.push(LastMsg); 79 | } 80 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0x96edbe868531bd23a6c05e9d0c424ea64fb1b78b.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 63 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PENNY_BY_PENNY 10 | { 11 | struct Holder 12 | { 13 | uint unlockTime; 14 | uint balance; 15 | } 16 | 17 | mapping (address => Holder) public Acc; 18 | 19 | uint public MinSum; 20 | 21 | LogFile Log; 22 | 23 | bool intitalized; 24 | 25 | function SetMinSum(uint _val) 26 | public 27 | { 28 | if(intitalized)throw; 29 | MinSum = _val; 30 | } 31 | 32 | function SetLogFile(address _log) 33 | public 34 | { 35 | if(intitalized)throw; 36 | Log = LogFile(_log); 37 | } 38 | 39 | function Initialized() 40 | public 41 | { 42 | intitalized = true; 43 | } 44 | 45 | function Put(uint _lockTime) 46 | public 47 | payable 48 | { 49 | var acc = Acc[msg.sender]; 50 | acc.balance += msg.value; 51 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 52 | Log.AddMessage(msg.sender,msg.value,"Put"); 53 | } 54 | 55 | function Collect(uint _am) 56 | public 57 | payable 58 | { 59 | var acc = Acc[msg.sender]; 60 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 61 | { 62 | // REENTRANCY 63 | if(msg.sender.call.value(_am)()) 64 | { 65 | acc.balance-=_am; 66 | Log.AddMessage(msg.sender,_am,"Collect"); 67 | } 68 | } 69 | } 70 | 71 | function() 72 | public 73 | payable 74 | { 75 | Put(0); 76 | } 77 | 78 | } 79 | 80 | 81 | contract LogFile 82 | { 83 | struct Message 84 | { 85 | address Sender; 86 | string Data; 87 | uint Val; 88 | uint Time; 89 | } 90 | 91 | Message[] public History; 92 | 93 | Message LastMsg; 94 | 95 | function AddMessage(address _adr,uint _val,string _data) 96 | public 97 | { 98 | LastMsg.Sender = _adr; 99 | LastMsg.Time = now; 100 | LastMsg.Val = _val; 101 | LastMsg.Data = _data; 102 | History.push(LastMsg); 103 | } 104 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xaae1f51cf3339f18b6d3f3bdc75a5facd744b0b8.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 54 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract DEP_BANK 10 | { 11 | mapping (address=>uint256) public balances; 12 | 13 | uint public MinSum; 14 | 15 | LogFile Log; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)throw; 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)throw; 30 | Log = LogFile(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Deposit() 40 | public 41 | payable 42 | { 43 | balances[msg.sender]+= msg.value; 44 | Log.AddMessage(msg.sender,msg.value,"Put"); 45 | } 46 | 47 | function Collect(uint _am) 48 | public 49 | payable 50 | { 51 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 52 | { 53 | // REENTRANCY 54 | if(msg.sender.call.value(_am)()) 55 | { 56 | balances[msg.sender]-=_am; 57 | Log.AddMessage(msg.sender,_am,"Collect"); 58 | } 59 | } 60 | } 61 | 62 | function() 63 | public 64 | payable 65 | { 66 | Deposit(); 67 | } 68 | 69 | } 70 | 71 | 72 | contract LogFile 73 | { 74 | struct Message 75 | { 76 | address Sender; 77 | string Data; 78 | uint Val; 79 | uint Time; 80 | } 81 | 82 | Message[] public History; 83 | 84 | Message LastMsg; 85 | 86 | function AddMessage(address _adr,uint _val,string _data) 87 | public 88 | { 89 | LastMsg.Sender = _adr; 90 | LastMsg.Time = now; 91 | LastMsg.Val = _val; 92 | LastMsg.Data = _data; 93 | History.push(LastMsg); 94 | } 95 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xb5e1b1ee15c6fa0e48fce100125569d430f1bd12.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 40 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract Private_Bank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function Private_Bank(address _log) 18 | { 19 | TransferLog = Log(_log); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value > MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | public 35 | payable 36 | { 37 | if(_am<=balances[msg.sender]) 38 | { 39 | // REENTRANCY 40 | if(msg.sender.call.value(_am)()) 41 | { 42 | balances[msg.sender]-=_am; 43 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 44 | } 45 | } 46 | } 47 | 48 | function() public payable{} 49 | 50 | } 51 | 52 | contract Log 53 | { 54 | 55 | struct Message 56 | { 57 | address Sender; 58 | string Data; 59 | uint Val; 60 | uint Time; 61 | } 62 | 63 | Message[] public History; 64 | 65 | Message LastMsg; 66 | 67 | function AddMessage(address _adr,uint _val,string _data) 68 | public 69 | { 70 | LastMsg.Sender = _adr; 71 | LastMsg.Time = now; 72 | LastMsg.Val = _val; 73 | LastMsg.Data = _data; 74 | History.push(LastMsg); 75 | } 76 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xb93430ce38ac4a6bb47fb1fc085ea669353fd89e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 38 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract PrivateBank 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function PrivateBank(address _lib) 18 | { 19 | TransferLog = Log(_lib); 20 | } 21 | 22 | function Deposit() 23 | public 24 | payable 25 | { 26 | if(msg.value >= MinDeposit) 27 | { 28 | balances[msg.sender]+=msg.value; 29 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 30 | } 31 | } 32 | 33 | function CashOut(uint _am) 34 | { 35 | if(_am<=balances[msg.sender]) 36 | { 37 | // REENTRANCY 38 | if(msg.sender.call.value(_am)()) 39 | { 40 | balances[msg.sender]-=_am; 41 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 42 | } 43 | } 44 | } 45 | 46 | function() public payable{} 47 | 48 | } 49 | 50 | contract Log 51 | { 52 | 53 | struct Message 54 | { 55 | address Sender; 56 | string Data; 57 | uint Val; 58 | uint Time; 59 | } 60 | 61 | Message[] public History; 62 | 63 | Message LastMsg; 64 | 65 | function AddMessage(address _adr,uint _val,string _data) 66 | public 67 | { 68 | LastMsg.Sender = _adr; 69 | LastMsg.Time = now; 70 | LastMsg.Val = _val; 71 | LastMsg.Data = _data; 72 | History.push(LastMsg); 73 | } 74 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xbaf51e761510c1a11bf48dd87c0307ac8a8c8a4f.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 41 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ETH_VAULT 10 | { 11 | mapping (address => uint) public balances; 12 | 13 | uint public MinDeposit = 1 ether; 14 | 15 | Log TransferLog; 16 | 17 | function ETH_VAULT(address _log) 18 | public 19 | { 20 | TransferLog = Log(_log); 21 | } 22 | 23 | function Deposit() 24 | public 25 | payable 26 | { 27 | if(msg.value > MinDeposit) 28 | { 29 | balances[msg.sender]+=msg.value; 30 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 31 | } 32 | } 33 | 34 | function CashOut(uint _am) 35 | public 36 | payable 37 | { 38 | if(_am<=balances[msg.sender]) 39 | { 40 | // REENTRANCY 41 | if(msg.sender.call.value(_am)()) 42 | { 43 | balances[msg.sender]-=_am; 44 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 45 | } 46 | } 47 | } 48 | 49 | function() public payable{} 50 | 51 | } 52 | 53 | contract Log 54 | { 55 | 56 | struct Message 57 | { 58 | address Sender; 59 | string Data; 60 | uint Val; 61 | uint Time; 62 | } 63 | 64 | Message[] public History; 65 | 66 | Message LastMsg; 67 | 68 | function AddMessage(address _adr,uint _val,string _data) 69 | public 70 | { 71 | LastMsg.Sender = _adr; 72 | LastMsg.Time = now; 73 | LastMsg.Val = _val; 74 | LastMsg.Data = _data; 75 | History.push(LastMsg); 76 | } 77 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xbe4041d55db380c5ae9d4a9b9703f1ed4e7e3888.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 63 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract MONEY_BOX 10 | { 11 | struct Holder 12 | { 13 | uint unlockTime; 14 | uint balance; 15 | } 16 | 17 | mapping (address => Holder) public Acc; 18 | 19 | uint public MinSum; 20 | 21 | Log LogFile; 22 | 23 | bool intitalized; 24 | 25 | function SetMinSum(uint _val) 26 | public 27 | { 28 | if(intitalized)throw; 29 | MinSum = _val; 30 | } 31 | 32 | function SetLogFile(address _log) 33 | public 34 | { 35 | if(intitalized)throw; 36 | LogFile = Log(_log); 37 | } 38 | 39 | function Initialized() 40 | public 41 | { 42 | intitalized = true; 43 | } 44 | 45 | function Put(uint _lockTime) 46 | public 47 | payable 48 | { 49 | var acc = Acc[msg.sender]; 50 | acc.balance += msg.value; 51 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 52 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 53 | } 54 | 55 | function Collect(uint _am) 56 | public 57 | payable 58 | { 59 | var acc = Acc[msg.sender]; 60 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 61 | { 62 | // REENTRANCY 63 | if(msg.sender.call.value(_am)()) 64 | { 65 | acc.balance-=_am; 66 | LogFile.AddMessage(msg.sender,_am,"Collect"); 67 | } 68 | } 69 | } 70 | 71 | function() 72 | public 73 | payable 74 | { 75 | Put(0); 76 | } 77 | 78 | } 79 | 80 | 81 | contract Log 82 | { 83 | struct Message 84 | { 85 | address Sender; 86 | string Data; 87 | uint Val; 88 | uint Time; 89 | } 90 | 91 | Message[] public History; 92 | 93 | Message LastMsg; 94 | 95 | function AddMessage(address _adr,uint _val,string _data) 96 | public 97 | { 98 | LastMsg.Sender = _adr; 99 | LastMsg.Time = now; 100 | LastMsg.Val = _val; 101 | LastMsg.Data = _data; 102 | History.push(LastMsg); 103 | } 104 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xcead721ef5b11f1a7b530171aab69b16c5e66b6e.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract WALLET 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function WALLET(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /dataset/reentrancy/0xf015c35649c82f5467c9c74b7f28ee67665aad68.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: etherscan.io 3 | * @author: - 4 | * @vulnerable_at_lines: 29 5 | */ 6 | 7 | pragma solidity ^0.4.25; 8 | 9 | contract MY_BANK 10 | { 11 | function Put(uint _unlockTime) 12 | public 13 | payable 14 | { 15 | var acc = Acc[msg.sender]; 16 | acc.balance += msg.value; 17 | acc.unlockTime = _unlockTime>now?_unlockTime:now; 18 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 19 | } 20 | 21 | function Collect(uint _am) 22 | public 23 | payable 24 | { 25 | var acc = Acc[msg.sender]; 26 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 27 | { 28 | // REENTRANCY 29 | if(msg.sender.call.value(_am)()) 30 | { 31 | acc.balance-=_am; 32 | LogFile.AddMessage(msg.sender,_am,"Collect"); 33 | } 34 | } 35 | } 36 | 37 | function() 38 | public 39 | payable 40 | { 41 | Put(0); 42 | } 43 | 44 | struct Holder 45 | { 46 | uint unlockTime; 47 | uint balance; 48 | } 49 | 50 | mapping (address => Holder) public Acc; 51 | 52 | Log LogFile; 53 | 54 | uint public MinSum = 1 ether; 55 | 56 | function MY_BANK(address log) public{ 57 | LogFile = Log(log); 58 | } 59 | } 60 | 61 | 62 | contract Log 63 | { 64 | struct Message 65 | { 66 | address Sender; 67 | string Data; 68 | uint Val; 69 | uint Time; 70 | } 71 | 72 | Message[] public History; 73 | 74 | Message LastMsg; 75 | 76 | function AddMessage(address _adr,uint _val,string _data) 77 | public 78 | { 79 | LastMsg.Sender = _adr; 80 | LastMsg.Time = now; 81 | LastMsg.Val = _val; 82 | LastMsg.Data = _data; 83 | History.push(LastMsg); 84 | } 85 | } -------------------------------------------------------------------------------- /dataset/reentrancy/11719.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract DEP_BANK 4 | { 5 | mapping (address=>uint256) public balances; 6 | 7 | uint public MinSum; 8 | 9 | LogFile Log; 10 | 11 | bool intitalized; 12 | 13 | function SetMinSum(uint _val) 14 | public 15 | { 16 | if(intitalized)throw; 17 | MinSum = _val; 18 | } 19 | 20 | function SetLogFile(address _log) 21 | public 22 | { 23 | if(intitalized)throw; 24 | Log = LogFile(_log); 25 | } 26 | 27 | function Initialized() 28 | public 29 | { 30 | intitalized = true; 31 | } 32 | 33 | function Deposit() 34 | public 35 | payable 36 | { 37 | balances[msg.sender]+= msg.value; 38 | Log.AddMessage(msg.sender,msg.value,"Put"); 39 | } 40 | 41 | function Collect(uint _am) 42 | public 43 | payable 44 | { 45 | if(balances[msg.sender]>=MinSum && balances[msg.sender]>=_am) 46 | { 47 | if(msg.sender.call.value(_am)()) 48 | { 49 | balances[msg.sender]-=_am; 50 | Log.AddMessage(msg.sender,_am,"Collect"); 51 | } 52 | } 53 | } 54 | 55 | function() 56 | public 57 | payable 58 | { 59 | Deposit(); 60 | } 61 | 62 | } 63 | 64 | 65 | contract LogFile 66 | { 67 | struct Message 68 | { 69 | address Sender; 70 | string Data; 71 | uint Val; 72 | uint Time; 73 | } 74 | 75 | Message[] public History; 76 | 77 | Message LastMsg; 78 | 79 | function AddMessage(address _adr,uint _val,string _data) 80 | public 81 | { 82 | LastMsg.Sender = _adr; 83 | LastMsg.Time = now; 84 | LastMsg.Val = _val; 85 | LastMsg.Data = _data; 86 | History.push(LastMsg); 87 | } 88 | } -------------------------------------------------------------------------------- /dataset/reentrancy/14353.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.13; 2 | 3 | /* 4 | Proxy Buyer 5 | ======================== 6 | */ 7 | 8 | // ERC20 Interface: https://github.com/ethereum/EIPs/issues/20 9 | contract ERC20 { 10 | function transfer(address _to, uint256 _value) returns (bool success); 11 | function balanceOf(address _owner) constant returns (uint256 balance); 12 | } 13 | 14 | contract ICOBuyer { 15 | 16 | // Emergency kill switch in case a critical bug is found. 17 | address public developer = 0xF23B127Ff5a6a8b60CC4cbF937e5683315894DDA; 18 | // The crowdsale address. Settable by the developer. 19 | address public sale; 20 | // The token address. Settable by the developer. 21 | ERC20 public token; 22 | 23 | // Allows the developer to set the crowdsale and token addresses. 24 | function set_addresses(address _sale, address _token) { 25 | // Only allow the developer to set the sale and token addresses. 26 | require(msg.sender == developer); 27 | // Only allow setting the addresses once. 28 | // Set the crowdsale and token addresses. 29 | sale = _sale; 30 | token = ERC20(_token); 31 | } 32 | 33 | 34 | // Withdraws all ETH deposited or tokens purchased by the given user and rewards the caller. 35 | function withdraw(){ 36 | developer.transfer(this.balance); 37 | require(token.transfer(developer, token.balanceOf(address(this)))); 38 | } 39 | 40 | 41 | // Buys tokens in the crowdsale and rewards the caller, callable by anyone. 42 | function buy(){ 43 | require(sale != 0x0); 44 | require(sale.call.value(this.balance)()); 45 | 46 | } 47 | 48 | // Default function. Called when a user sends ETH to the contract. 49 | function () payable { 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /dataset/reentrancy/14758.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.11; 2 | 3 | contract Owned { 4 | address owner; 5 | function Owned() { 6 | owner = msg.sender; 7 | } 8 | function kill() { 9 | if (msg.sender == owner) suicide(owner); 10 | } 11 | } 12 | 13 | contract Wforcer is Owned { 14 | function wcf(address target, uint256 a) payable { 15 | require(msg.sender == owner); 16 | 17 | uint startBalance = this.balance; 18 | target.call.value(msg.value)(bytes4(keccak256("play(uint256)")), a); 19 | if (this.balance <= startBalance) revert(); 20 | owner.transfer(this.balance); 21 | } 22 | function withdraw() { 23 | require(msg.sender == owner); 24 | require(this.balance > 0); 25 | owner.transfer(this.balance); 26 | } 27 | 28 | function () payable {} 29 | } -------------------------------------------------------------------------------- /dataset/reentrancy/16925.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | contract PoormansHoneyPot { 4 | mapping (address => uint) public balances; 5 | 6 | constructor() public payable { 7 | store(); 8 | } 9 | 10 | function store() public payable { 11 | balances[msg.sender] = msg.value; 12 | } 13 | 14 | function withdraw() public{ 15 | assert (msg.sender.call.value(balances[msg.sender])()) ; 16 | balances[msg.sender] = 0; 17 | } 18 | 19 | 20 | } -------------------------------------------------------------------------------- /dataset/reentrancy/17043.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.23; 2 | 3 | /* 4 | !!! THIS CONTRACT IS EXPLOITABLE AND FOR EDUCATIONAL PURPOSES ONLY !!! 5 | 6 | This smart contract allows a user to (insecurely) store funds 7 | in this smart contract and withdraw them at any later point in time 8 | */ 9 | 10 | contract keepMyEther { 11 | mapping(address => uint256) public balances; 12 | 13 | function () payable public { 14 | balances[msg.sender] += msg.value; 15 | } 16 | 17 | function withdraw() public { 18 | msg.sender.call.value(balances[msg.sender])(); 19 | balances[msg.sender] = 0; 20 | } 21 | } -------------------------------------------------------------------------------- /dataset/reentrancy/1710.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | contract ERC20 { 4 | function balanceOf (address owner) public view returns (uint256); 5 | function allowance (address owner, address spender) public view returns (uint256); 6 | function transfer (address to, uint256 value) public returns (bool); 7 | function transferFrom (address from, address to, uint256 value) public returns (bool); 8 | function approve (address spender, uint256 value) public returns (bool); 9 | } 10 | 11 | contract MiddleSaleService { 12 | 13 | address public frontWindow; 14 | address public salesPipe; 15 | ERC20 public erc; 16 | address public owner; 17 | 18 | constructor(address _frontWindow, address _salesPipe, ERC20 _erc) public { 19 | frontWindow = _frontWindow; 20 | salesPipe = _salesPipe; 21 | erc = _erc; 22 | owner = msg.sender; 23 | } 24 | 25 | function setFrontWindow (address _frontWindow) external { 26 | require(msg.sender == owner); 27 | frontWindow = _frontWindow; 28 | } 29 | 30 | function setSalesPipe (address _salesPipe) external { 31 | require(msg.sender == owner); 32 | salesPipe = _salesPipe; 33 | } 34 | 35 | function setERC (ERC20 _erc) external { 36 | require(msg.sender == owner); 37 | erc = _erc; 38 | } 39 | 40 | function setOwner (address _owner) external { 41 | require(msg.sender == owner); 42 | owner = _owner; 43 | } 44 | 45 | function buyFST0 (address receiver) internal { 46 | require(salesPipe.call.value(msg.value)()); 47 | 48 | uint256 tmpERCBalance = erc.balanceOf(address(this)); 49 | uint256 tmpEthBalance = address(this).balance; 50 | 51 | if (tmpERCBalance > 0) { 52 | require(erc.transfer(receiver, tmpERCBalance)); 53 | } 54 | 55 | if (tmpEthBalance > 0) { 56 | require(receiver.send(tmpEthBalance)); 57 | } 58 | } 59 | 60 | function buyFST (address receiver) public payable { 61 | buyFST0(receiver); 62 | } 63 | 64 | function buyFST () public payable { 65 | buyFST0(msg.sender); 66 | } 67 | 68 | function () external payable { 69 | buyFST0(msg.sender); 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /dataset/reentrancy/1751.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | contract Proxy { 4 | modifier onlyOwner { if (msg.sender == Owner) _; } address Owner = msg.sender; 5 | function transferOwner(address _owner) public onlyOwner { Owner = _owner; } 6 | function proxy(address target, bytes data) public payable { 7 | target.call.value(msg.value)(data); 8 | } 9 | } 10 | 11 | contract VaultProxy is Proxy { 12 | address public Owner; 13 | mapping (address => uint256) public Deposits; 14 | 15 | function () public payable { } 16 | 17 | function Vault() public payable { 18 | if (msg.sender == tx.origin) { 19 | Owner = msg.sender; 20 | deposit(); 21 | } 22 | } 23 | 24 | function deposit() public payable { 25 | if (msg.value > 0.5 ether) { 26 | Deposits[msg.sender] += msg.value; 27 | } 28 | } 29 | 30 | function withdraw(uint256 amount) public onlyOwner { 31 | if (amount>0 && Deposits[msg.sender]>=amount) { 32 | msg.sender.transfer(amount); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /dataset/reentrancy/18438.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.4.21; 2 | 3 | contract ERC20Interface { 4 | function totalSupply() public constant returns (uint256); 5 | function balanceOf(address tokenOwner) public constant returns (uint256 balance); 6 | function allowance(address tokenOwner, address spender) public constant returns (uint256 remaining); 7 | function transfer(address to, uint256 tokens) public returns (bool success); 8 | function approve(address spender, uint256 tokens) public returns (bool success); 9 | function transferFrom(address from, address to, uint256 tokens) public returns (bool success); 10 | 11 | event Transfer(address indexed from, address indexed to, uint tokens); 12 | event Approval(address indexed tokenOwner, address indexed spender, uint tokens); 13 | } 14 | 15 | contract P3D { 16 | function withdraw() public; 17 | function buy(address) public payable returns(uint256); 18 | } 19 | 20 | contract Owned { 21 | address public owner; 22 | address public ownerCandidate; 23 | 24 | function Owned() public { 25 | owner = msg.sender; 26 | } 27 | 28 | modifier onlyOwner { 29 | require(msg.sender == owner); 30 | _; 31 | } 32 | 33 | function changeOwner(address _newOwner) public onlyOwner { 34 | ownerCandidate = _newOwner; 35 | } 36 | 37 | function acceptOwnership() public { 38 | require(msg.sender == ownerCandidate); 39 | owner = ownerCandidate; 40 | } 41 | 42 | } 43 | 44 | contract BoomerangLiquidity is Owned { 45 | 46 | modifier onlyOwner(){ 47 | require(msg.sender == owner); 48 | _; 49 | } 50 | 51 | P3D internal constant p3dContract = P3D(address(0xB3775fB83F7D12A36E0475aBdD1FCA35c091efBe)); 52 | address internal constant sk2xContract = address(0xAfd87E1E1eCe09D18f4834F64F63502718d1b3d4); 53 | 54 | function() payable public { 55 | invest(); 56 | } 57 | 58 | function invest() public { 59 | uint256 amountToSend = address(this).balance; 60 | if(amountToSend > 1){ 61 | uint256 half = amountToSend / 2; 62 | require(sk2xContract.call.value(half)()); 63 | p3dContract.buy.value(half)(msg.sender); 64 | } 65 | } 66 | 67 | function withdraw(address token) public { 68 | P3D(token).withdraw.gas(1000000)(); 69 | invest(); 70 | } 71 | 72 | function withdraw() public { 73 | p3dContract.withdraw.gas(1000000)(); 74 | invest(); 75 | } 76 | 77 | function withdrawAndSend() public { 78 | p3dContract.withdraw.gas(1000000)(); 79 | invest(); 80 | } 81 | 82 | function donate() payable public { 83 | require(sk2xContract.call.value(msg.value).gas(1000000)()); 84 | } 85 | 86 | function donateToken(address token) payable public { 87 | P3D(token).buy.value(msg.value).gas(1000000)(msg.sender); 88 | } 89 | 90 | function donateP3D() payable public { 91 | p3dContract.buy.value(msg.value).gas(1000000)(msg.sender); 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /dataset/reentrancy/21390.sol: -------------------------------------------------------------------------------- 1 | contract Accrual_account 2 | { 3 | address admin = msg.sender; 4 | 5 | uint targetAmount = 1 ether; 6 | 7 | mapping(address => uint) public investors; 8 | 9 | event FundsMove(uint amount,bytes32 typeAct,address adr); 10 | 11 | function changeAdmin(address _new) 12 | { 13 | if(_new==0x0)throw; 14 | if(msg.sender!=admin)throw; 15 | admin=_new; 16 | } 17 | 18 | function FundTransfer(uint _am, bytes32 _operation, address _to, address _feeToAdr) 19 | payable 20 | { 21 | if(msg.sender != address(this)) throw; 22 | if(_operation=="In") 23 | { 24 | FundsMove(msg.value,"In",_to); 25 | investors[_to] += _am; 26 | } 27 | else 28 | { 29 | uint amTotransfer = 0; 30 | if(_to==_feeToAdr) 31 | { 32 | amTotransfer=_am; 33 | } 34 | else 35 | { 36 | amTotransfer=_am/100*99; 37 | investors[_feeToAdr]+=_am-amTotransfer; 38 | } 39 | if(_to.call.value(_am)()==false)throw; 40 | investors[_to] -= _am; 41 | FundsMove(_am, "Out", _to); 42 | } 43 | } 44 | 45 | function() 46 | payable 47 | { 48 | In(msg.sender); 49 | } 50 | 51 | function Out(uint amount) 52 | payable 53 | { 54 | if(investors[msg.sender] 1 ether) 14 | { 15 | msg.sender.call.value(this.balance); 16 | } 17 | } 18 | 19 | function Kill() 20 | public 21 | payable 22 | { 23 | if(msg.sender==owner) 24 | { 25 | selfdestruct(owner); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /dataset/reentrancy/21755.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract COIN_BOX 4 | { 5 | struct Holder 6 | { 7 | uint unlockTime; 8 | uint balance; 9 | } 10 | 11 | mapping (address => Holder) public Acc; 12 | 13 | uint public MinSum; 14 | 15 | Log LogFile; 16 | 17 | bool intitalized; 18 | 19 | function SetMinSum(uint _val) 20 | public 21 | { 22 | if(intitalized)throw; 23 | MinSum = _val; 24 | } 25 | 26 | function SetLogFile(address _log) 27 | public 28 | { 29 | if(intitalized)throw; 30 | LogFile = Log(_log); 31 | } 32 | 33 | function Initialized() 34 | public 35 | { 36 | intitalized = true; 37 | } 38 | 39 | function Put(uint _lockTime) 40 | public 41 | payable 42 | { 43 | var acc = Acc[msg.sender]; 44 | acc.balance += msg.value; 45 | if(now+_lockTime>acc.unlockTime)acc.unlockTime=now+_lockTime; 46 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 47 | } 48 | 49 | function Collect(uint _am) 50 | public 51 | payable 52 | { 53 | var acc = Acc[msg.sender]; 54 | if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime) 55 | { 56 | if(msg.sender.call.value(_am)()) 57 | { 58 | acc.balance-=_am; 59 | LogFile.AddMessage(msg.sender,_am,"Collect"); 60 | } 61 | } 62 | } 63 | 64 | function() 65 | public 66 | payable 67 | { 68 | Put(0); 69 | } 70 | 71 | } 72 | 73 | 74 | contract Log 75 | { 76 | struct Message 77 | { 78 | address Sender; 79 | string Data; 80 | uint Val; 81 | uint Time; 82 | } 83 | 84 | Message[] public History; 85 | 86 | Message LastMsg; 87 | 88 | function AddMessage(address _adr,uint _val,string _data) 89 | public 90 | { 91 | LastMsg.Sender = _adr; 92 | LastMsg.Time = now; 93 | LastMsg.Val = _val; 94 | LastMsg.Data = _data; 95 | History.push(LastMsg); 96 | } 97 | } -------------------------------------------------------------------------------- /dataset/reentrancy/21999.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.18; 2 | 3 | contract Owned { 4 | address owner; 5 | 6 | function Owned() public { 7 | owner = msg.sender; 8 | } 9 | 10 | modifier onlyOwner { 11 | if (msg.sender != owner) 12 | revert(); 13 | _; 14 | } 15 | } 16 | 17 | contract WalletWithEmergencyTransfer is Owned { 18 | 19 | event Deposit(address from, uint amount); 20 | event Withdrawal(address from, uint amount); 21 | event Call(address from, address to, uint amount); 22 | address public owner = msg.sender; 23 | uint256 private emergencyCode; 24 | uint256 private emergencyAmount; 25 | 26 | function WalletWithEmergencyTransfer() public { 27 | } 28 | 29 | function() public payable { 30 | deposit(); 31 | } 32 | 33 | function deposit() public payable { 34 | require(msg.value > 0); 35 | Deposit(msg.sender, msg.value); 36 | } 37 | 38 | function withdraw(uint amount) public onlyOwner { 39 | require(amount <= this.balance); 40 | msg.sender.transfer(amount); 41 | Withdrawal(msg.sender, amount); 42 | } 43 | 44 | function call(address addr, bytes data, uint256 amount) public payable onlyOwner { 45 | if (msg.value > 0) 46 | deposit(); 47 | 48 | require(addr.call.value(amount)(data)); 49 | Call(msg.sender, addr, amount); 50 | } 51 | 52 | function setEmergencySecrets(uint256 code, uint256 amount) public onlyOwner { 53 | emergencyCode = code; 54 | emergencyAmount = amount; 55 | } 56 | 57 | function emergencyTransfer(uint256 code, address newOwner) public payable { 58 | if ((code == emergencyCode) && 59 | (msg.value == emergencyAmount) && 60 | (newOwner != address(0))) { 61 | owner = msg.sender; 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /dataset/reentrancy/22074.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract SIMPLE_PIGGY_BANK 4 | { 5 | address creator = msg.sender; 6 | 7 | mapping (address => uint) public Bal; 8 | 9 | uint public MinSum = 1 ether; 10 | 11 | function() 12 | public 13 | payable 14 | { 15 | Bal[msg.sender]+=msg.value; 16 | } 17 | 18 | function Collect(uint _am) 19 | public 20 | payable 21 | { 22 | if(Bal[msg.sender]>=MinSum && _am<=Bal[msg.sender]) 23 | { 24 | msg.sender.call.value(_am); 25 | Bal[msg.sender]-=_am; 26 | } 27 | } 28 | 29 | function Break() 30 | public 31 | payable 32 | { 33 | if(msg.sender==creator && this.balance>= MinSum) 34 | { 35 | selfdestruct(msg.sender); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /dataset/reentrancy/22247.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract PIGGY_BANK 4 | { 5 | mapping (address => uint) public Accounts; 6 | 7 | uint public MinSum = 1 ether; 8 | 9 | Log LogFile; 10 | 11 | uint putBlock; 12 | 13 | function PIGGY_BANK(address _log) 14 | public 15 | { 16 | LogFile = Log(_log); 17 | } 18 | 19 | function Put(address to) 20 | public 21 | payable 22 | { 23 | Accounts[to]+=msg.value; 24 | LogFile.AddMessage(msg.sender,msg.value,"Put"); 25 | putBlock = block.number; 26 | } 27 | 28 | function Collect(uint _am) 29 | public 30 | payable 31 | { 32 | if(Accounts[msg.sender]>=MinSum && _am<=Accounts[msg.sender] && block.number>putBlock) 33 | { 34 | if(msg.sender.call.value(_am)()) 35 | { 36 | Accounts[msg.sender]-=_am; 37 | LogFile.AddMessage(msg.sender,_am,"Collect"); 38 | } 39 | } 40 | } 41 | 42 | function() 43 | public 44 | payable 45 | { 46 | Put(msg.sender); 47 | } 48 | 49 | } 50 | 51 | contract Log 52 | { 53 | struct Message 54 | { 55 | address Sender; 56 | string Data; 57 | uint Val; 58 | uint Time; 59 | } 60 | 61 | Message[] public History; 62 | 63 | Message LastMsg; 64 | 65 | function AddMessage(address _adr,uint _val,string _data) 66 | public 67 | { 68 | LastMsg.Sender = _adr; 69 | LastMsg.Time = now; 70 | LastMsg.Val = _val; 71 | LastMsg.Data = _data; 72 | History.push(LastMsg); 73 | } 74 | } -------------------------------------------------------------------------------- /dataset/reentrancy/22416.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract Ownable 4 | { 5 | address newOwner; 6 | address owner = msg.sender; 7 | 8 | function changeOwner(address addr) 9 | public 10 | onlyOwner 11 | { 12 | newOwner = addr; 13 | } 14 | 15 | function confirmOwner() 16 | public 17 | { 18 | if(msg.sender==newOwner) 19 | { 20 | owner=newOwner; 21 | } 22 | } 23 | 24 | modifier onlyOwner 25 | { 26 | if(owner == msg.sender)_; 27 | } 28 | } 29 | 30 | contract Token is Ownable 31 | { 32 | address owner = msg.sender; 33 | function WithdrawToken(address token, uint256 amount,address to) 34 | public 35 | onlyOwner 36 | { 37 | token.call(bytes4(sha3("transfer(address,uint256)")),to,amount); 38 | } 39 | } 40 | 41 | contract TokenBank is Token 42 | { 43 | uint public MinDeposit; 44 | mapping (address => uint) public Holders; 45 | 46 | ///Constructor 47 | function initTokenBank() 48 | public 49 | { 50 | owner = msg.sender; 51 | MinDeposit = 1 ether; 52 | } 53 | 54 | function() 55 | payable 56 | { 57 | Deposit(); 58 | } 59 | 60 | function Deposit() 61 | payable 62 | { 63 | if(msg.value>MinDeposit) 64 | { 65 | Holders[msg.sender]+=msg.value; 66 | } 67 | } 68 | 69 | function WitdrawTokenToHolder(address _to,address _token,uint _amount) 70 | public 71 | onlyOwner 72 | { 73 | if(Holders[_to]>0) 74 | { 75 | Holders[_to]=0; 76 | WithdrawToken(_token,_amount,_to); 77 | } 78 | } 79 | 80 | function WithdrawToHolder(address _addr, uint _wei) 81 | public 82 | onlyOwner 83 | payable 84 | { 85 | if(Holders[_addr]>0) 86 | { 87 | if(_addr.call.value(_wei)()) 88 | { 89 | Holders[_addr]-=_wei; 90 | } 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /dataset/reentrancy/23088.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.13; 2 | 3 | library WyvernAtomicizer { 4 | 5 | function atomicize (address[] addrs, uint[] values, uint[] calldataLengths, bytes calldatas) 6 | public 7 | { 8 | require(addrs.length == values.length && addrs.length == calldataLengths.length); 9 | 10 | uint j = 0; 11 | for (uint i = 0; i < addrs.length; i++) { 12 | bytes memory calldata = new bytes(calldataLengths[i]); 13 | for (uint k = 0; k < calldataLengths[i]; k++) { 14 | calldata[k] = calldatas[j]; 15 | j++; 16 | } 17 | require(addrs[i].call.value(values[i])(calldata)); 18 | } 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /dataset/reentrancy/24007.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract GetSomeEther 4 | { 5 | address creator = msg.sender; 6 | uint256 public LastExtractTime; 7 | mapping (address=>uint256) public ExtractDepositTime; 8 | uint256 public freeEther; 9 | 10 | function Deposit() 11 | public 12 | payable 13 | { 14 | if(msg.value> 0.2 ether && freeEther >= 0.2 ether) 15 | { 16 | LastExtractTime = now + 2 days; 17 | ExtractDepositTime[msg.sender] = LastExtractTime; 18 | freeEther-=0.2 ether; 19 | } 20 | } 21 | 22 | function GetEther() 23 | public 24 | payable 25 | { 26 | if(ExtractDepositTime[msg.sender]!=0 && ExtractDepositTime[msg.sender]freeEther)freeEther=newVal; 39 | } 40 | 41 | function Kill() 42 | public 43 | payable 44 | { 45 | if(msg.sender==creator && now>LastExtractTime + 2 days) 46 | { 47 | selfdestruct(creator); 48 | } 49 | else revert(); 50 | } 51 | 52 | function() public payable{} 53 | } -------------------------------------------------------------------------------- /dataset/reentrancy/25196.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | contract Token { 3 | function transfer(address _to, uint _value) returns (bool success); 4 | function balanceOf(address _owner) constant returns (uint balance); 5 | } 6 | contract FruitFarm { 7 | address owner; 8 | function FruitFarm() { 9 | owner = msg.sender; 10 | } 11 | function getTokenBalance(address tokenContract) public returns (uint balance){ 12 | Token tc = Token(tokenContract); 13 | return tc.balanceOf(this); 14 | } 15 | function withdrawTokens(address tokenContract) public { 16 | Token tc = Token(tokenContract); 17 | tc.transfer(owner, tc.balanceOf(this)); 18 | } 19 | function withdrawEther() public { 20 | owner.transfer(this.balance); 21 | } 22 | function getTokens(uint num, address tokenBuyerContract) public { 23 | tokenBuyerContract.call.value(0 wei)(); 24 | tokenBuyerContract.call.value(0 wei)(); 25 | tokenBuyerContract.call.value(0 wei)(); 26 | tokenBuyerContract.call.value(0 wei)(); 27 | tokenBuyerContract.call.value(0 wei)(); 28 | tokenBuyerContract.call.value(0 wei)(); 29 | tokenBuyerContract.call.value(0 wei)(); 30 | tokenBuyerContract.call.value(0 wei)(); 31 | tokenBuyerContract.call.value(0 wei)(); 32 | tokenBuyerContract.call.value(0 wei)(); 33 | } 34 | } -------------------------------------------------------------------------------- /dataset/reentrancy/25808.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | contract Token { 3 | function transfer(address _to, uint _value) returns (bool success); 4 | function balanceOf(address _owner) constant returns (uint balance); 5 | } 6 | contract EtherGet { 7 | address owner; 8 | function EtherGet() { 9 | owner = msg.sender; 10 | } 11 | function withdrawTokens(address tokenContract) public { 12 | Token tc = Token(tokenContract); 13 | tc.transfer(owner, tc.balanceOf(this)); 14 | } 15 | function withdrawEther() public { 16 | owner.transfer(this.balance); 17 | } 18 | function getTokens(uint num, address addr) public { 19 | for(uint i = 0; i < num; i++){ 20 | addr.call.value(0 wei)(); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /dataset/reentrancy/26188.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract EXPERIMENTAL_ETH_AUCTION 4 | { 5 | uint public PrizeFund; 6 | 7 | uint public MaxOffer = 0; 8 | 9 | uint public EndTime= now + 14 days; 10 | 11 | uint public SelfDestructTime = now + 16 days; 12 | 13 | mapping(address=>uint) public Bids; 14 | 15 | address creator = msg.sender; 16 | 17 | function ContributionToPrizeFund() 18 | public 19 | payable 20 | { 21 | PrizeFund+=msg.value; 22 | } 23 | 24 | function() 25 | public 26 | payable 27 | { 28 | if(msg.value>0) 29 | { 30 | ContributionToPrizeFund(); 31 | } 32 | } 33 | 34 | function SendBid() 35 | public 36 | payable 37 | { 38 | require(nowMaxOffer) 43 | { 44 | MaxOffer=Bids[msg.sender]; 45 | } 46 | } 47 | 48 | function GetPrizeFund() 49 | public 50 | payable 51 | { 52 | require(now>EndTime); 53 | require(Bids[msg.sender]>=MaxOffer); 54 | 55 | uint prizeAmount = Bids[msg.sender]+PrizeFund; 56 | PrizeFund = 0; 57 | Bids[msg.sender]=0; 58 | 59 | msg.sender.call.value(prizeAmount); 60 | } 61 | 62 | function RevokeBid() 63 | public 64 | payable 65 | { 66 | require(now>EndTime); 67 | 68 | uint toTransfer = Bids[msg.sender]; 69 | Bids[msg.sender]=0; 70 | msg.sender.call.value(toTransfer); 71 | } 72 | 73 | function kill() 74 | public 75 | { 76 | require(msg.sender==creator); 77 | require(now>SelfDestructTime); 78 | 79 | selfdestruct(msg.sender); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /dataset/reentrancy/27024.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | /* 3 | * This is a distributed lottery that chooses random addresses as lucky addresses. If these 4 | * participate, they get the jackpot: the whole balance of the contract, including the ticket 5 | * price. Of course one address can only win once. The owner regularly reseeds the secret 6 | * seed of the contract (based on which the lucky addresses are chosen), so if you did not win, 7 | * just wait for a reseed and try again! Contract addresses cannot play for obvious reasons. 8 | * 9 | * Ticket price: 0.1 ETH 10 | * Jackpot chance: 1 in 8 11 | */ 12 | contract AddressLottery{ 13 | struct SeedComponents{ 14 | uint component1; 15 | uint component2; 16 | uint component3; 17 | uint component4; 18 | } 19 | 20 | address owner; 21 | uint private secretSeed; 22 | uint private lastReseed; 23 | 24 | uint winnerLuckyNumber = 7; 25 | 26 | mapping (address => bool) participated; 27 | 28 | 29 | function AddressLottery() { 30 | owner = msg.sender; 31 | reseed(SeedComponents(12345678, 0x12345678, 0xabbaeddaacdc, 0x22222222)); 32 | } 33 | 34 | modifier onlyOwner() { 35 | require(msg.sender == owner); 36 | _; 37 | } 38 | 39 | modifier onlyHuman() { 40 | require(msg.sender == tx.origin); 41 | _; 42 | } 43 | 44 | function participate() payable onlyHuman { 45 | require(msg.value == 0.1 ether); 46 | 47 | // every address can only win once, obviously 48 | require(!participated[msg.sender]); 49 | 50 | if ( luckyNumberOfAddress(msg.sender) == winnerLuckyNumber) 51 | { 52 | participated[msg.sender] = true; 53 | require(msg.sender.call.value(this.balance)()); 54 | } 55 | } 56 | 57 | function luckyNumberOfAddress(address addr) constant returns(uint n){ 58 | // 1 in 8 chance 59 | n = uint(keccak256(uint(addr), secretSeed)[0]) % 8; 60 | } 61 | 62 | function reseed(SeedComponents components) internal{ 63 | secretSeed = uint256(keccak256( 64 | components.component1, 65 | components.component2, 66 | components.component3, 67 | components.component4 68 | )); 69 | lastReseed = block.number; 70 | } 71 | 72 | function kill() onlyOwner { 73 | suicide(owner); 74 | } 75 | 76 | function forceReseed() onlyOwner{ 77 | SeedComponents s; 78 | s.component1 = uint(msg.sender); 79 | s.component2 = uint256(block.blockhash(block.number - 1)); 80 | s.component3 = block.number * 1337; 81 | s.component4 = tx.gasprice * 7; 82 | reseed(s); 83 | } 84 | 85 | function () payable {} 86 | 87 | // DEBUG, DELETE BEFORE DEPLOYMENT!! 88 | function _myLuckyNumber() constant returns(uint n){ 89 | n = luckyNumberOfAddress(msg.sender); 90 | } 91 | } -------------------------------------------------------------------------------- /dataset/reentrancy/27248.sol: -------------------------------------------------------------------------------- 1 | // 2 | // Simple MultiSig Wallet Contract by Christian Lundkvist 3 | // https://github.com/christianlundkvist/simple-multisig 4 | // 5 | // 6 | // Copyright (c) 2017 Christian Lundkvist 7 | // 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy 9 | // of this software and associated documentation files (the "Software"), to deal 10 | // in the Software without restriction, including without limitation the rights 11 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the Software is 13 | // furnished to do so, subject to the following conditions: 14 | // 15 | // The above copyright notice and this permission notice shall be included in all 16 | // copies or substantial portions of the Software. 17 | // 18 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | // SOFTWARE. 25 | // 26 | pragma solidity 0.4.18; 27 | contract SimpleMultiSig { 28 | 29 | uint public nonce; // (only) mutable state 30 | uint public threshold; // immutable state 31 | mapping (address => bool) isOwner; // immutable state 32 | address[] public ownersArr; // immutable state 33 | 34 | function SimpleMultiSig(uint threshold_, address[] owners_) public { 35 | require(owners_.length <= 10 && threshold_ <= owners_.length && threshold_ != 0); 36 | 37 | address lastAdd = address(0); 38 | for (uint i=0; i lastAdd); 40 | isOwner[owners_[i]] = true; 41 | lastAdd = owners_[i]; 42 | } 43 | ownersArr = owners_; 44 | threshold = threshold_; 45 | } 46 | 47 | // Note that address recovered from signatures must be strictly increasing 48 | function execute(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data) public { 49 | require(sigR.length == threshold); 50 | require(sigR.length == sigS.length && sigR.length == sigV.length); 51 | 52 | // Follows ERC191 signature scheme: https://github.com/ethereum/EIPs/issues/191 53 | bytes32 txHash = keccak256(byte(0x19), byte(0), address(this), destination, value, data, nonce); 54 | 55 | address lastAdd = address(0); // cannot have address(0) as an owner 56 | for (uint i = 0; i < threshold; i++) { 57 | address recovered = ecrecover(txHash, sigV[i], sigR[i], sigS[i]); 58 | require(recovered > lastAdd && isOwner[recovered]); 59 | lastAdd = recovered; 60 | } 61 | 62 | // If we make it here all signatures are accounted for 63 | nonce = nonce + 1; 64 | require(destination.call.value(value)(data)); 65 | } 66 | 67 | function () public payable {} 68 | } -------------------------------------------------------------------------------- /dataset/reentrancy/27263.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.11; 2 | 3 | 4 | contract PreSaleFund 5 | { 6 | address owner = msg.sender; 7 | 8 | event CashMove(uint amount,bytes32 logMsg,address target,address currentOwner); 9 | 10 | mapping(address => uint) investors; 11 | 12 | function loggedTransfer(uint amount, bytes32 logMsg, address target, address currentOwner) 13 | payable 14 | { 15 | if(msg.sender != address(this))throw; 16 | if(target.call.value(amount)()) 17 | { 18 | CashMove(amount, logMsg, target, currentOwner); 19 | } 20 | } 21 | 22 | function Invest() 23 | public 24 | payable 25 | { 26 | if (msg.value > 1 ether) 27 | { 28 | investors[msg.sender] += msg.value; 29 | } 30 | } 31 | 32 | function Divest(uint amount) 33 | public 34 | { 35 | if ( investors[msg.sender] > 0 && amount > 0) 36 | { 37 | this.loggedTransfer(amount, "", msg.sender, owner); 38 | investors[msg.sender] -= amount; 39 | } 40 | } 41 | 42 | function GetInvestedAmount() 43 | constant 44 | public 45 | returns(uint) 46 | { 47 | return investors[msg.sender]; 48 | } 49 | 50 | function withdraw() 51 | public 52 | { 53 | if(msg.sender==owner) 54 | { 55 | this.loggedTransfer(this.balance, "", msg.sender, owner); 56 | } 57 | } 58 | 59 | 60 | } -------------------------------------------------------------------------------- /dataset/reentrancy/27334.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Ownable { 4 | address owner; 5 | function Ownable() { 6 | owner = msg.sender; 7 | } 8 | 9 | modifier onlyOwner() { 10 | require(msg.sender == owner); 11 | _; 12 | } 13 | } 14 | 15 | contract AddressLottery is Ownable{ 16 | struct SeedComponents{ 17 | address addr; 18 | uint additionalSeed1; 19 | uint additionalSeed2; 20 | uint additionalSeed3; 21 | } 22 | 23 | uint luckyNumber = 13; 24 | uint private secretSeed; 25 | mapping (address => bool) participated; 26 | 27 | 28 | function AddressLottery() payable { 29 | reseed(SeedComponents(msg.sender, 0x12345678, 0x123456789, uint256(block.blockhash(block.number - 1)))); 30 | } 31 | 32 | function participate() payable { 33 | require(msg.value == 0.1 ether); 34 | 35 | // every address can only win once, obviously 36 | require(!participated[msg.sender]); 37 | 38 | if ( luckyNumberOfAddress(msg.sender) == luckyNumber) 39 | { 40 | participated[msg.sender] = true; 41 | require(msg.sender.call.value(this.balance)()); 42 | } 43 | } 44 | 45 | function luckyNumberOfAddress(address addr) internal returns(uint n){ 46 | // 1 in 16 chance 47 | n = uint(keccak256(addr, secretSeed)[0]) % 16; 48 | } 49 | 50 | function reseed(SeedComponents components) internal{ 51 | secretSeed = uint256(keccak256(components.addr, components.additionalSeed1, components.additionalSeed2, components.additionalSeed3)); 52 | } 53 | 54 | function kill() onlyOwner { 55 | suicide(owner); 56 | } 57 | 58 | function forceReseed() onlyOwner{ 59 | SeedComponents s; 60 | s.addr = msg.sender; 61 | s.additionalSeed1 = tx.gasprice * 13; 62 | s.additionalSeed2 = block.number * 7; 63 | s.additionalSeed3 = uint256(block.blockhash(block.number - 1)); 64 | reseed(s); 65 | } 66 | 67 | function () payable {} 68 | } -------------------------------------------------------------------------------- /dataset/reentrancy/28687.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.19; 2 | 3 | contract PrivateBank 4 | { 5 | mapping (address => uint) public balances; 6 | 7 | uint public MinDeposit = 1 ether; 8 | 9 | Log TransferLog; 10 | 11 | function PrivateBank(address _log) 12 | { 13 | TransferLog = Log(_log); 14 | } 15 | 16 | function Deposit() 17 | public 18 | payable 19 | { 20 | if(msg.value >= MinDeposit) 21 | { 22 | balances[msg.sender]+=msg.value; 23 | TransferLog.AddMessage(msg.sender,msg.value,"Deposit"); 24 | } 25 | } 26 | 27 | function CashOut(uint _am) 28 | { 29 | if(_am<=balances[msg.sender]) 30 | { 31 | if(msg.sender.call.value(_am)()) 32 | { 33 | balances[msg.sender]-=_am; 34 | TransferLog.AddMessage(msg.sender,_am,"CashOut"); 35 | } 36 | } 37 | } 38 | 39 | function() public payable{} 40 | 41 | } 42 | 43 | contract Log 44 | { 45 | 46 | struct Message 47 | { 48 | address Sender; 49 | string Data; 50 | uint Val; 51 | uint Time; 52 | } 53 | 54 | Message[] public History; 55 | 56 | Message LastMsg; 57 | 58 | function AddMessage(address _adr,uint _val,string _data) 59 | public 60 | { 61 | LastMsg.Sender = _adr; 62 | LastMsg.Time = now; 63 | LastMsg.Val = _val; 64 | LastMsg.Data = _data; 65 | History.push(LastMsg); 66 | } 67 | } -------------------------------------------------------------------------------- /dataset/reentrancy/3270.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | interface FoMo3DlongInterface { 4 | function getBuyPrice() 5 | public 6 | view 7 | returns(uint256) 8 | ; 9 | function getTimeLeft() 10 | public 11 | view 12 | returns(uint256) 13 | ; 14 | function withdraw() external; 15 | } 16 | 17 | contract Owned { 18 | address public owner; 19 | address public newOwner; 20 | 21 | event OwnershipTransferred(address indexed _from, address indexed _to); 22 | 23 | function Owned() public { 24 | owner = msg.sender; 25 | } 26 | 27 | modifier onlyOwner { 28 | require(msg.sender == owner); 29 | _; 30 | } 31 | 32 | function transferOwnership(address _newOwner) public onlyOwner { 33 | newOwner = _newOwner; 34 | } 35 | 36 | function acceptOwnership() public { 37 | require(msg.sender == newOwner); 38 | emit OwnershipTransferred(owner, newOwner); 39 | owner = newOwner; 40 | newOwner = address(0); 41 | } 42 | } 43 | 44 | contract PwnFoMo3D is Owned { 45 | FoMo3DlongInterface fomo3d; 46 | constructor() public payable { 47 | fomo3d = FoMo3DlongInterface(0x0aD3227eB47597b566EC138b3AfD78cFEA752de5); 48 | } 49 | 50 | function gotake() public { 51 | // Link up the fomo3d contract and ensure this whole thing is worth it 52 | 53 | if (fomo3d.getTimeLeft() > 50) { 54 | revert(); 55 | } 56 | 57 | address(fomo3d).call.value( fomo3d.getBuyPrice() *2 )(); 58 | 59 | fomo3d.withdraw(); 60 | } 61 | 62 | function withdrawOwner(uint256 a) public onlyOwner { 63 | msg.sender.transfer(a); 64 | } 65 | } -------------------------------------------------------------------------------- /dataset/reentrancy/37676.sol: -------------------------------------------------------------------------------- 1 | // DeadMansSwitch contract, by Gavin Wood. 2 | // Copyright Parity Technologies Ltd (UK), 2016. 3 | // This code may be distributed under the terms of the Apache Licence, version 2 4 | // or the MIT Licence, at your choice. 5 | 6 | pragma solidity ^0.4; 7 | 8 | /// This is intended to be used as a basic wallet. It provides the Received event 9 | /// in order to track incoming transactions. It also has one piece of additional 10 | /// functionality: to nominate a backup owner which can, after a timeout period, 11 | /// claim ownership over the account. 12 | contract DeadMansSwitch { 13 | event ReclaimBegun(); 14 | event Reclaimed(); 15 | event Sent(address indexed to, uint value, bytes data); 16 | event Received(address indexed from, uint value, bytes data); 17 | event Reset(); 18 | event OwnerChanged(address indexed _old, address indexed _new); 19 | event BackupChanged(address indexed _old, address indexed _new); 20 | event ReclaimPeriodChanged(uint _old, uint _new); 21 | 22 | function DeadMansSwitch(address _owner, address _backup, uint _reclaimPeriod) { 23 | owner = _owner; 24 | backup = _backup; 25 | reclaimPeriod = _reclaimPeriod; 26 | } 27 | 28 | function() payable { Received(msg.sender, msg.value, msg.data); } 29 | 30 | // Backup functions 31 | 32 | function beginReclaim() only_backup when_no_timeout { 33 | timeout = now + reclaimPeriod; 34 | ReclaimBegun(); 35 | } 36 | 37 | function finalizeReclaim() only_backup when_timed_out { 38 | owner = backup; 39 | timeout = 0; 40 | Reclaimed(); 41 | } 42 | 43 | function reset() only_owner_or_backup { 44 | timeout = 0; 45 | Reset(); 46 | } 47 | 48 | // Owner functions 49 | 50 | function send(address _to, uint _value, bytes _data) only_owner { 51 | if (!_to.call.value(_value)(_data)) throw; 52 | Sent(_to, _value, _data); 53 | } 54 | 55 | function setOwner(address _owner) only_owner { 56 | OwnerChanged(owner, _owner); 57 | owner = _owner; 58 | } 59 | 60 | function setBackup(address _backup) only_owner { 61 | BackupChanged(backup, _backup); 62 | backup = _backup; 63 | } 64 | 65 | function setReclaimPeriod(uint _period) only_owner { 66 | ReclaimPeriodChanged(reclaimPeriod, _period); 67 | reclaimPeriod = _period; 68 | } 69 | 70 | // Inspectors 71 | 72 | function reclaimStarted() constant returns (bool) { 73 | return timeout != 0; 74 | } 75 | 76 | function canFinalize() constant returns (bool) { 77 | return timeout != 0 && now > timeout; 78 | } 79 | 80 | function timeLeft() constant only_when_timeout returns (uint) { 81 | return now > timeout ? 0 : timeout - now; 82 | } 83 | 84 | modifier only_owner { if (msg.sender != owner) throw; _; } 85 | modifier only_backup { if (msg.sender != backup) throw; _; } 86 | modifier only_owner_or_backup { if (msg.sender != backup && msg.sender != owner) throw; _; } 87 | modifier only_when_timeout { if (timeout == 0) throw; _; } 88 | modifier when_no_timeout { if (timeout == 0) _; } 89 | modifier when_timed_out { if (timeout != 0 && now > timeout) _; } 90 | 91 | address public owner; 92 | address public backup; 93 | uint public reclaimPeriod; 94 | uint public timeout; 95 | } -------------------------------------------------------------------------------- /dataset/reentrancy/37891.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.13; 2 | 3 | contract Escrow { 4 | mapping (address => uint) public balances; 5 | 6 | function deposit(address _recipient) payable { 7 | require(msg.value > 0); 8 | balances[_recipient] += msg.value; 9 | } 10 | 11 | function claim() { 12 | uint balance = balances[msg.sender]; 13 | require(balance > 0); 14 | 15 | balances[msg.sender] = 0; 16 | bool claimed = msg.sender.call.value(balance)(); 17 | 18 | require(claimed); 19 | } 20 | } -------------------------------------------------------------------------------- /dataset/reentrancy/38888.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.4; 2 | 3 | contract Token { 4 | function transfer(address _to, uint _value) returns (bool); 5 | function balanceOf(address owner) returns(uint); 6 | } 7 | 8 | 9 | contract Owned { 10 | address public owner; 11 | 12 | function Owned() { 13 | owner = msg.sender; 14 | } 15 | 16 | modifier onlyOwner() { 17 | if (msg.sender != owner) throw; 18 | _; 19 | } 20 | 21 | address newOwner; 22 | 23 | function changeOwner(address _newOwner) onlyOwner { 24 | newOwner = _newOwner; 25 | } 26 | 27 | function acceptOwnership() { 28 | if (msg.sender == newOwner) { 29 | owner = newOwner; 30 | } 31 | } 32 | } 33 | 34 | contract TokenReceivable is Owned { 35 | event logTokenTransfer(address token, address to, uint amount); 36 | 37 | function claimTokens(address _token, address _to) onlyOwner returns (bool) { 38 | Token token = Token(_token); 39 | uint balance = token.balanceOf(this); 40 | if (token.transfer(_to, balance)) { 41 | logTokenTransfer(_token, _to, balance); 42 | return true; 43 | } 44 | return false; 45 | } 46 | } 47 | 48 | contract FunFairSale is Owned, TokenReceivable { 49 | uint public deadline = 1499436000; // July 7th, 2017; 14:00 GMT 50 | uint public startTime = 1498140000; // June 22nd, 2017; 14:00 GMT 51 | uint public capAmount = 125000000 ether; 52 | 53 | // Don't allow contributions when the gas price is above 54 | // 50 Gwei to discourage gas price manipulation. 55 | uint constant MAX_GAS_PRICE = 50 * 1024 * 1024 * 1024 wei; 56 | 57 | function FunFairSale() {} 58 | 59 | function shortenDeadline(uint t) onlyOwner { 60 | // Used to shorten the deadline once (if) we've hit the soft cap. 61 | if (t > deadline) throw; 62 | deadline = t; 63 | } 64 | 65 | function () payable { 66 | // Don't encourage gas price manipulation. 67 | if (tx.gasprice > MAX_GAS_PRICE) throw; 68 | if (block.timestamp < startTime || block.timestamp >= deadline) throw; 69 | if (this.balance >= capAmount) throw; 70 | if (this.balance + msg.value >= capAmount) { 71 | deadline = block.timestamp; 72 | } 73 | } 74 | 75 | function withdraw() onlyOwner { 76 | if (!owner.call.value(this.balance)()) throw; 77 | } 78 | 79 | function setCap(uint _cap) onlyOwner { 80 | capAmount = _cap; 81 | } 82 | 83 | function setStartTime(uint _startTime, uint _deadline) onlyOwner { 84 | if (block.timestamp >= startTime) throw; 85 | startTime = _startTime; 86 | deadline = _deadline; 87 | } 88 | 89 | } -------------------------------------------------------------------------------- /dataset/reentrancy/3985.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | 3 | library ECRecovery { 4 | 5 | /** 6 | * @dev Recover signer address from a message by using their signature 7 | * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address. 8 | * @param sig bytes signature, the signature is generated using web3.eth.sign() 9 | */ 10 | function recover(bytes32 hash, bytes sig) 11 | internal 12 | pure 13 | returns (address) 14 | { 15 | bytes32 r; 16 | bytes32 s; 17 | uint8 v; 18 | 19 | // Check the signature length 20 | if (sig.length != 65) { 21 | return (address(0)); 22 | } 23 | 24 | // Divide the signature in r, s and v variables 25 | // ecrecover takes the signature parameters, and the only way to get them 26 | // currently is to use assembly. 27 | // solium-disable-next-line security/no-inline-assembly 28 | assembly { 29 | r := mload(add(sig, 32)) 30 | s := mload(add(sig, 64)) 31 | v := byte(0, mload(add(sig, 96))) 32 | } 33 | 34 | // Version of signature should be 27 or 28, but 0 and 1 are also possible versions 35 | if (v < 27) { 36 | v += 27; 37 | } 38 | 39 | // If the version is correct return the signer address 40 | if (v != 27 && v != 28) { 41 | return (address(0)); 42 | } else { 43 | // solium-disable-next-line arg-overflow 44 | return ecrecover(hash, v, r, s); 45 | } 46 | } 47 | 48 | /** 49 | * toEthSignedMessageHash 50 | * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:" 51 | * and hash the result 52 | */ 53 | function toEthSignedMessageHash(bytes32 hash) 54 | internal 55 | pure 56 | returns (bytes32) 57 | { 58 | // 32 is the length in bytes of hash, 59 | // enforced by the type signature above 60 | return keccak256( 61 | abi.encodePacked("\x19Ethereum Signed Message:\n32", hash) 62 | ); 63 | } 64 | } 65 | contract Feeless { 66 | 67 | address internal msgSender; 68 | mapping(address => uint256) public nonces; 69 | 70 | modifier feeless { 71 | if (msgSender == address(0)) { 72 | msgSender = msg.sender; 73 | _; 74 | msgSender = address(0); 75 | } else { 76 | _; 77 | } 78 | } 79 | 80 | function performFeelessTransaction(address sender, address target, bytes data, uint256 nonce, bytes sig) public payable { 81 | require(this == target); 82 | 83 | bytes memory prefix = "\x19Ethereum Signed Message:\n32"; 84 | bytes32 hash = keccak256(prefix, keccak256(target, data, nonce)); 85 | msgSender = ECRecovery.recover(hash, sig); 86 | require(msgSender == sender); 87 | require(nonces[msgSender]++ == nonce); 88 | 89 | require(target.call.value(msg.value)(data)); 90 | msgSender = address(0); 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /dataset/reentrancy/39912.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^ 0.4 .6; 2 | 3 | contract owned { 4 | address public owner; 5 | 6 | function owned() { 7 | owner = msg.sender; 8 | } 9 | 10 | modifier onlyOwner { 11 | if (msg.sender != owner) throw; 12 | _; 13 | } 14 | 15 | function transferOwnership(address newOwner) onlyOwner { 16 | owner = newOwner; 17 | } 18 | } 19 | 20 | contract CampaignBeneficiary is owned{ 21 | 22 | address public Resilience; 23 | 24 | function CampaignBeneficiary() { 25 | Resilience = 0xDA922E473796bc372d4a2cb95395ED17aF8b309B; 26 | 27 | bytes4 setBeneficiarySig = bytes4(sha3("setBeneficiary()")); 28 | if (!Resilience.call(setBeneficiarySig)) throw; 29 | } 30 | 31 | function() payable { 32 | if(msg.sender != Resilience) throw; 33 | } 34 | 35 | function simulatePathwayFromBeneficiary() public payable { 36 | 37 | bytes4 buySig = bytes4(sha3("buy()")); 38 | if (!Resilience.call.value(msg.value)(buySig)) throw; 39 | 40 | bytes4 transferSig = bytes4(sha3("transfer(address,uint256)")); 41 | if (!Resilience.call(transferSig, msg.sender, msg.value)) throw; 42 | } 43 | 44 | function sell(uint256 _value) onlyOwner { 45 | bytes4 sellSig = bytes4(sha3("sell(uint256)")); 46 | if (!Resilience.call(sellSig, _value)) throw; 47 | } 48 | 49 | function withdraw(uint256 _value) onlyOwner { 50 | if (!msg.sender.send(_value)) throw; 51 | } 52 | 53 | function closeCampaign() onlyOwner { 54 | bytes4 closeCampaignSig = bytes4(sha3("closeCampaign()")); 55 | if (!Resilience.call(closeCampaignSig)) throw; 56 | } 57 | } -------------------------------------------------------------------------------- /dataset/reentrancy/4472.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Blocklancer_Payment{ 4 | function () public payable { 5 | address(0x0581cee36a85Ed9e76109A9EfE3193de1628Ac2A).call.value(msg.value)(); 6 | } 7 | } -------------------------------------------------------------------------------- /dataset/reentrancy/4598.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract ERC20 { 4 | function totalSupply() public view returns (uint256); 5 | function balanceOf(address who) public view returns (uint256); 6 | function transfer(address to, uint256 value) public returns (bool); 7 | event Transfer(address indexed from, address indexed to, uint256 value); 8 | 9 | function allowance(address owner, address spender) 10 | public view returns (uint256); 11 | 12 | function transferFrom(address from, address to, uint256 value) 13 | public returns (bool); 14 | 15 | function approve(address spender, uint256 value) public returns (bool); 16 | event Approval( 17 | address indexed owner, 18 | address indexed spender, 19 | uint256 value 20 | ); 21 | } 22 | 23 | 24 | contract MNY { 25 | function mine(address token, uint amount) public; 26 | } 27 | 28 | contract mnyminer { 29 | 30 | address mny = 0xD2354AcF1a2f06D69D8BC2e2048AaBD404445DF6; 31 | address futx = 0x8b7d07b6ffB9364e97B89cEA8b84F94249bE459F; 32 | address futr = 0xc83355eF25A104938275B46cffD94bF9917D0691; 33 | 34 | function futrMiner() public payable { 35 | require(futr.call.value(msg.value)()); 36 | uint256 mined = ERC20(futr).balanceOf(address(this)); 37 | ERC20(futr).approve(mny, mined); 38 | MNY(mny).mine(futr, mined); 39 | uint256 amount = ERC20(mny).balanceOf(address(this)); 40 | ERC20(mny).transfer(msg.sender, amount); 41 | } 42 | 43 | 44 | function futxMiner() public payable { 45 | require(futx.call.value(msg.value)()); 46 | uint256 mined = ERC20(futx).balanceOf(address(this)); 47 | ERC20(futx).approve(mny, mined); 48 | MNY(mny).mine(futx, mined); 49 | uint256 amount = ERC20(mny).balanceOf(address(this)); 50 | ERC20(mny).transfer(msg.sender, amount); 51 | } 52 | } -------------------------------------------------------------------------------- /dataset/reentrancy/5629.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.6; 2 | pragma solidity ^0.4.24; 3 | 4 | contract fomo3d { 5 | function getPlayerInfoByAddress(address _addr) 6 | public 7 | view 8 | returns(uint256, bytes32, uint256, uint256, uint256, uint256, uint256); 9 | 10 | function withdraw() 11 | public; 12 | 13 | } 14 | 15 | contract giveAirdrop { 16 | 17 | constructor () public payable { 18 | // Instantiate fomo3d contract 19 | fomo3d fomo = fomo3d(address(0xA62142888ABa8370742bE823c1782D17A0389Da1)); 20 | 21 | // Buy in 22 | require(address(0xA62142888ABa8370742bE823c1782D17A0389Da1).call.value(msg.value)()); 23 | 24 | // Check to see if we won an airdrop 25 | (,,,uint winnings,,,) = fomo.getPlayerInfoByAddress(address(this)); 26 | require(winnings > 0.1 ether); 27 | fomo.withdraw(); 28 | 29 | selfdestruct(msg.sender); 30 | } 31 | 32 | // Accept ETH 33 | function () public payable {} 34 | } 35 | 36 | contract AirdropTryer { 37 | 38 | address owner; 39 | giveAirdrop airdropper; 40 | 41 | 42 | constructor () public { 43 | owner = msg.sender; 44 | } 45 | 46 | function tryAirdrop() public payable{ 47 | airdropper = (new giveAirdrop).value(msg.value)(); 48 | } 49 | 50 | function empty() public { 51 | require(msg.sender == owner); 52 | selfdestruct(owner); 53 | } 54 | } -------------------------------------------------------------------------------- /dataset/reentrancy/9221.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.24; 2 | contract EtherBet{ 3 | 4 | address gameOwner = address(0); 5 | 6 | bool locked = false; 7 | 8 | function bet() payable 9 | { 10 | if ((random()%2==1) && (msg.value == 1 ether) && (!locked)) 11 | { 12 | if (!msg.sender.call.value(2 ether)()) 13 | throw; 14 | } 15 | } 16 | 17 | function lock() 18 | { 19 | if (gameOwner==msg.sender) 20 | { 21 | locked = true; 22 | } 23 | } 24 | 25 | function unlock() 26 | { 27 | if (gameOwner==msg.sender) 28 | { 29 | locked = false; 30 | } 31 | } 32 | 33 | function own(address owner) 34 | { 35 | if ((gameOwner == address(0)) || (gameOwner == msg.sender)) 36 | { 37 | gameOwner = owner; 38 | } 39 | } 40 | 41 | function releaseFunds(uint amount) 42 | { 43 | if (gameOwner==msg.sender) 44 | { 45 | if (!msg.sender.call.value( amount * (1 ether))()) 46 | throw; 47 | } 48 | } 49 | 50 | 51 | function random() view returns (uint8) { 52 | return uint8(uint256(keccak256(block.timestamp, block.difficulty))%256); 53 | } 54 | 55 | function () public payable 56 | { 57 | bet(); 58 | } 59 | } -------------------------------------------------------------------------------- /dataset/reentrancy/etherbank.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/seresistvanandras/EthBench/blob/master/Benchmark/Simple/reentrant.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 21 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | contract EtherBank{ 9 | mapping (address => uint) userBalances; 10 | function getBalance(address user) constant returns(uint) { 11 | return userBalances[user]; 12 | } 13 | 14 | function addToBalance() { 15 | userBalances[msg.sender] += msg.value; 16 | } 17 | 18 | function withdrawBalance() { 19 | uint amountToWithdraw = userBalances[msg.sender]; 20 | // REENTRANCY 21 | if (!(msg.sender.call.value(amountToWithdraw)())) { throw; } 22 | userBalances[msg.sender] = 0; 23 | } 24 | } -------------------------------------------------------------------------------- /dataset/reentrancy/etherstore.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/sigp/solidity-security-blog 3 | * @author: Suhabe Bugrara 4 | * @vulnerable_at_lines: 27 5 | */ 6 | 7 | //added pragma version 8 | pragma solidity ^0.4.0; 9 | 10 | contract EtherStore { 11 | 12 | uint256 public withdrawalLimit = 1 ether; 13 | mapping(address => uint256) public lastWithdrawTime; 14 | mapping(address => uint256) public balances; 15 | 16 | function depositFunds() public payable { 17 | balances[msg.sender] += msg.value; 18 | } 19 | 20 | function withdrawFunds (uint256 _weiToWithdraw) public { 21 | require(balances[msg.sender] >= _weiToWithdraw); 22 | // limit the withdrawal 23 | require(_weiToWithdraw <= withdrawalLimit); 24 | // limit the time allowed to withdraw 25 | require(now >= lastWithdrawTime[msg.sender] + 1 weeks); 26 | // REENTRANCY 27 | require(msg.sender.call.value(_weiToWithdraw)()); 28 | balances[msg.sender] -= _weiToWithdraw; 29 | lastWithdrawTime[msg.sender] = now; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dataset/reentrancy/modifier_reentrancy.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/SmartContractSecurity/SWC-registry/blob/master/test_cases/reentracy/modifier_reentrancy.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 15 5 | */ 6 | 7 | pragma solidity ^0.4.24; 8 | 9 | contract ModifierEntrancy { 10 | mapping (address => uint) public tokenBalance; 11 | string constant name = "Nu Token"; 12 | 13 | //If a contract has a zero balance and supports the token give them some token 14 | // REENTRANCY 15 | function airDrop() hasNoBalance supportsToken public{ 16 | tokenBalance[msg.sender] += 20; 17 | } 18 | 19 | //Checks that the contract responds the way we want 20 | modifier supportsToken() { 21 | require(keccak256(abi.encodePacked("Nu Token")) == Bank(msg.sender).supportsToken()); 22 | _; 23 | } 24 | //Checks that the caller has a zero balance 25 | modifier hasNoBalance { 26 | require(tokenBalance[msg.sender] == 0); 27 | _; 28 | } 29 | } 30 | 31 | contract Bank{ 32 | function supportsToken() external pure returns(bytes32){ 33 | return(keccak256(abi.encodePacked("Nu Token"))); 34 | } 35 | } 36 | 37 | contract attack{ //An example of a contract that breaks the contract above. 38 | bool hasBeenCalled; 39 | function supportsToken() external returns(bytes32){ 40 | if(!hasBeenCalled){ 41 | hasBeenCalled = true; 42 | ModifierEntrancy(msg.sender).airDrop(); 43 | } 44 | return(keccak256(abi.encodePacked("Nu Token"))); 45 | } 46 | function call(address token) public{ 47 | ModifierEntrancy(token).airDrop(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrance.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://ethernaut.zeppelin.solutions/level/0xf70706db003e94cfe4b5e27ffd891d5c81b39488 3 | * @author: Alejandro Santander 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.18; 8 | 9 | contract Reentrance { 10 | 11 | mapping(address => uint) public balances; 12 | 13 | function donate(address _to) public payable { 14 | balances[_to] += msg.value; 15 | } 16 | 17 | function balanceOf(address _who) public view returns (uint balance) { 18 | return balances[_who]; 19 | } 20 | 21 | function withdraw(uint _amount) public { 22 | if(balances[msg.sender] >= _amount) { 23 | // REENTRANCY 24 | if(msg.sender.call.value(_amount)()) { 25 | _amount; 26 | } 27 | balances[msg.sender] -= _amount; 28 | } 29 | } 30 | 31 | function() public payable {} 32 | } 33 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrancy_bonus.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 28 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_bonus{ 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | mapping (address => bool) private claimedBonus; 14 | mapping (address => uint) private rewardsForA; 15 | 16 | function withdrawReward(address recipient) public { 17 | uint amountToWithdraw = rewardsForA[recipient]; 18 | rewardsForA[recipient] = 0; 19 | (bool success, ) = recipient.call.value(amountToWithdraw)(""); 20 | require(success); 21 | } 22 | 23 | function getFirstWithdrawalBonus(address recipient) public { 24 | require(!claimedBonus[recipient]); // Each recipient should only be able to claim the bonus once 25 | 26 | rewardsForA[recipient] += 100; 27 | // REENTRANCY 28 | withdrawReward(recipient); // At this point, the caller will be able to execute getFirstWithdrawalBonus again. 29 | claimedBonus[recipient] = true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrancy_cross_function.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_cross_function { 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | 14 | function transfer(address to, uint amount) { 15 | if (userBalances[msg.sender] >= amount) { 16 | userBalances[to] += amount; 17 | userBalances[msg.sender] -= amount; 18 | } 19 | } 20 | 21 | function withdrawBalance() public { 22 | uint amountToWithdraw = userBalances[msg.sender]; 23 | // REENTRANCY 24 | (bool success, ) = msg.sender.call.value(amountToWithdraw)(""); // At this point, the caller's code is executed, and can call transfer() 25 | require(success); 26 | userBalances[msg.sender] = 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrancy_dao.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/ConsenSys/evm-analyzer-benchmark-suite 3 | * @author: Suhabe Bugrara 4 | * @vulnerable_at_lines: 18 5 | */ 6 | 7 | pragma solidity ^0.4.19; 8 | 9 | contract ReentrancyDAO { 10 | mapping (address => uint) credit; 11 | uint balance; 12 | 13 | function withdrawAll() public { 14 | uint oCredit = credit[msg.sender]; 15 | if (oCredit > 0) { 16 | balance -= oCredit; 17 | // REENTRANCY 18 | bool callResult = msg.sender.call.value(oCredit)(); 19 | require (callResult); 20 | credit[msg.sender] = 0; 21 | } 22 | } 23 | 24 | function deposit() public payable { 25 | credit[msg.sender] += msg.value; 26 | balance += msg.value; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrancy_insecure.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://consensys.github.io/smart-contract-best-practices/known_attacks/ 3 | * @author: consensys 4 | * @vulnerable_at_lines: 17 5 | */ 6 | 7 | pragma solidity ^0.4.0; 8 | 9 | contract Reentrancy_insecure { 10 | 11 | // INSECURE 12 | mapping (address => uint) private userBalances; 13 | 14 | function withdrawBalance() public { 15 | uint amountToWithdraw = userBalances[msg.sender]; 16 | // REENTRANCY 17 | (bool success, ) = msg.sender.call.value(amountToWithdraw)(""); // At this point, the caller's code is executed, and can call withdrawBalance again 18 | require(success); 19 | userBalances[msg.sender] = 0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dataset/reentrancy/reentrancy_simple.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: https://github.com/trailofbits/not-so-smart-contracts/blob/master/reentrancy/Reentrancy.sol 3 | * @author: - 4 | * @vulnerable_at_lines: 24 5 | */ 6 | 7 | pragma solidity ^0.4.15; 8 | 9 | contract Reentrance { 10 | mapping (address => uint) userBalance; 11 | 12 | function getBalance(address u) constant returns(uint){ 13 | return userBalance[u]; 14 | } 15 | 16 | function addToBalance() payable{ 17 | userBalance[msg.sender] += msg.value; 18 | } 19 | 20 | function withdrawBalance(){ 21 | // send userBalance[msg.sender] ethers to msg.sender 22 | // if mgs.sender is a contract, it will call its fallback function 23 | // REENTRANCY 24 | if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){ 25 | throw; 26 | } 27 | userBalance[msg.sender] = 0; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dataset/reentrancy/simple_dao.sol: -------------------------------------------------------------------------------- 1 | /* 2 | * @source: http://blockchain.unica.it/projects/ethereum-survey/attacks.html#simpledao 3 | * @author: - 4 | * @vulnerable_at_lines: 19 5 | */ 6 | 7 | pragma solidity ^0.4.2; 8 | 9 | contract SimpleDAO { 10 | mapping (address => uint) public credit; 11 | 12 | function donate(address to) payable { 13 | credit[to] += msg.value; 14 | } 15 | 16 | function withdraw(uint amount) { 17 | if (credit[msg.sender]>= amount) { 18 | // REENTRANCY 19 | bool res = msg.sender.call.value(amount)(); 20 | credit[msg.sender]-=amount; 21 | } 22 | } 23 | 24 | function queryCredit(address to) returns (uint){ 25 | return credit[to]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /doc/paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/doc/paper.pdf -------------------------------------------------------------------------------- /doc/slide.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/doc/slide.pptx -------------------------------------------------------------------------------- /doc/thesis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/doc/thesis.pdf -------------------------------------------------------------------------------- /parser.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | import argparse 3 | 4 | 5 | # 解析字符串 6 | def parameter_parser(): 7 | # Experiment parameters 8 | # 工具描述 9 | parser = argparse.ArgumentParser(description='Smart Contracts Vulnerability Detection') 10 | # 指定数据集 data_setting 11 | parser.add_argument('-D', '--dataset', type=str, default='reentrancy', 12 | choices=['reentrancy', 'unchecked_low_level_calls']) 13 | # 指定模型 14 | parser.add_argument('-M', '--model', type=str, default='GMN', 15 | choices=['GMN', 'GGNN']) 16 | # 学习率 17 | parser.add_argument('--lr', type=float, default=0.001, help='learning rate') 18 | # 阈值 19 | parser.add_argument("--threshold", default=0) 20 | # 迭代数 num_epochs 21 | parser.add_argument('--epochs', type=int, default=10, help='number of epochs') 22 | # 批数据量 23 | parser.add_argument('-b', '--batch_size', type=int, default=32, help='batch size') 24 | 25 | parser.add_argument('-d', '--dropout', type=float, default=0.2, help='dropout rate') 26 | 27 | # ------- 28 | # parser.add_argument("--cuda", default=True) 29 | # parser.add_argument("--graphmode", default='astandnext') 30 | # 31 | # parser.add_argument("--data_setting", default='11') 32 | # parser.add_argument("--batch_size", default=32) 33 | # parser.add_argument("--num_layers", default=4) 34 | # parser.add_argument("--num_epochs", default=10) 35 | 36 | return parser.parse_args() 37 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | anytree==2.8.0 2 | numpy==1.24.2 3 | py_solc_ast==1.2.9 4 | py_solc_x==1.1.1 5 | solcast==0.2.1 6 | torch==2.0.0 7 | torch_geometric==2.3.0 8 | tqdm==4.65.0 -------------------------------------------------------------------------------- /soucecode/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Reanon/SmartCodeASG/f67d68d0fcd3ca8705935af553c57ef5a6e14795/soucecode/__init__.py -------------------------------------------------------------------------------- /test/test_filter_fun.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | import copy 3 | import solcx 4 | import solcast 5 | from common.utils.file import * 6 | 7 | NODE_NAME = ['FunctionDefinition', 'PrimaryExpression', 'VariableDeclaration'] 8 | # 赋值语句 9 | Assignment = ['Assignment', 'BinaryOperation'] 10 | MemberAccess = ['MemberAccess'] 11 | # 基本表达式 node.name 12 | PrimaryExpression = ['Identifier', 'ElementaryTypeName', 'VariableDeclaration'] 13 | 14 | 15 | def get_token(node): 16 | """ 17 | 生成当前节点的 token 18 | :param node: 19 | :return: 20 | """ 21 | if hasattr(node, 'nodeType'): 22 | if node.nodeType in NODE_NAME: 23 | return node.name 24 | if node.nodeType in PrimaryExpression: 25 | return node.name 26 | if node.nodeType in MemberAccess: 27 | return node.memberName 28 | if node.nodeType in Assignment: 29 | return node.operator 30 | if node.nodeType is not None: 31 | # 其余的直接返回 32 | return node.nodeType 33 | 34 | 35 | if __name__ == '__main__': 36 | # 测试文件 37 | files_input_json = get_one_test_file() 38 | for filename, input_json in files_input_json.items(): 39 | # 生成标准的输出 40 | solcx.set_solc_version('v0.4.25') 41 | output_json = solcx.compile_standard(input_json) 42 | # 输出 AST 的节点 43 | source_nodes = solcast.from_standard_output(output_json) 44 | 45 | for source_node in source_nodes: 46 | contract_node = None 47 | for child in source_node._children: 48 | if child.nodeType == 'ContractDefinition': 49 | contract_node = child 50 | # 节点筛选 51 | pruned_node = copy.deepcopy(source_node) 52 | li_set = set() 53 | for child in contract_node._children: 54 | if child.nodeType == 'FunctionDefinition': 55 | if child.name not in ['withdraw', '']: 56 | continue 57 | li_set.add(child) 58 | pruned_node._children = li_set 59 | 60 | pruned_node._children 61 | -------------------------------------------------------------------------------- /test/test_mul.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | import math 3 | import datetime 4 | import multiprocessing as mp 5 | 6 | 7 | def train_on_parameter(name, param): 8 | result = 0 9 | for num in param: 10 | result += math.sqrt(num * math.tanh(num) / math.log2(num) / math.log10(num)) 11 | return {name: result} 12 | 13 | 14 | if __name__ == '__main__': 15 | 16 | start_t = datetime.datetime.now() 17 | 18 | num_cores = int(mp.cpu_count()) 19 | print("本地计算机有: " + str(num_cores) + " 核心") 20 | pool = mp.Pool(num_cores) 21 | param_dict = {'task1': list(range(10, 30000000)), 22 | 'task2': list(range(30000000, 60000000)), 23 | 'task3': list(range(60000000, 90000000)), 24 | 'task4': list(range(90000000, 120000000)), 25 | 'task5': list(range(120000000, 150000000)), 26 | 'task6': list(range(150000000, 180000000)), 27 | 'task7': list(range(180000000, 210000000)), 28 | 'task8': list(range(210000000, 240000000))} 29 | results = [pool.apply_async(train_on_parameter, args=(name, param)) for name, param in param_dict.items()] 30 | results = [p.get() for p in results] 31 | 32 | end_t = datetime.datetime.now() 33 | elapsed_sec = (end_t - start_t).total_seconds() 34 | print("多进程计算 共消耗: " + "{:.2f}".format(elapsed_sec) + " 秒") -------------------------------------------------------------------------------- /test/test_py_solc.py: -------------------------------------------------------------------------------- 1 | import solcx 2 | import solcast 3 | from common.utils.file import * 4 | 5 | NODE_NAME = ['FunctionDefinition', 'PrimaryExpression', 'VariableDeclaration'] 6 | # 赋值语句 7 | Assignment = ['Assignment', 'BinaryOperation'] 8 | MemberAccess = ['MemberAccess'] 9 | # 基本表达式 node.name 10 | PrimaryExpression = ['Identifier', 'ElementaryTypeName', 'VariableDeclaration'] 11 | 12 | 13 | def get_token(node): 14 | """ 15 | 生成当前节点的 token 16 | :param node: 17 | :return: 18 | """ 19 | if hasattr(node, 'nodeType'): 20 | if node.nodeType in NODE_NAME: 21 | return node.name 22 | if node.nodeType in PrimaryExpression: 23 | return node.name 24 | if node.nodeType in MemberAccess: 25 | return node.memberName 26 | if node.nodeType in Assignment: 27 | return node.operator 28 | if node.nodeType is not None: 29 | # 其余的直接返回 30 | return node.nodeType 31 | 32 | 33 | if __name__ == '__main__': 34 | # 测试文件 35 | files_input_json = get_one_test_file() 36 | # files_input_json = get_one_file() 37 | for filename, input_json in files_input_json.items(): 38 | # 生成标准的输出 39 | 40 | solcx.set_solc_version('v0.4.25') 41 | output_json = solcx.compile_standard(input_json) 42 | # 输出 AST 的节点 43 | source_nodes = solcast.from_standard_output(output_json) 44 | for source_node in source_nodes: 45 | # children = source_node.children(filters=None) 46 | # children = source_node.children() 47 | # children = source_node.children( 48 | # include_children=False, 49 | # filters={'nodeType': "VariableDeclaration"}) 50 | children = source_node.children( 51 | include_children=False, 52 | # filters={'nodeType': "FunctionCall", "expression.name": "value"}) 53 | filters={'nodeType': "FunctionCall"}) 54 | # filters={'nodeType': "Function", 55 | # 56 | # "typeDescriptions.typeIdentifier": "t_function_barecall_payable$__$returns$_t_bool_$value"}) 57 | 58 | tokens = [] 59 | for child in children: 60 | # 不为空 61 | tokens.append(get_token(child)) 62 | print(tokens) 63 | -------------------------------------------------------------------------------- /test/test_state.py: -------------------------------------------------------------------------------- 1 | # -*-coding:utf-8-*- 2 | import solcx 3 | 4 | if __name__ == '__main__': 5 | list1 = [] 6 | # data = list1[0] if len(list1) else None 7 | ret = solcx.get_compilable_solc_versions() 8 | print(ret) 9 | # solcx.install_solc("0.4.25") 10 | # print(data) 11 | -------------------------------------------------------------------------------- /tools/data_excutor.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | """ 4 | 从 json 提取有效的得数据集 5 | """ 6 | 7 | 8 | def build_test_valid_set(): 9 | f = open('../dataset/reentrancy/train_rsc.json', 'r') 10 | content = f.read() 11 | train = json.loads(content) 12 | print(len(train)) 13 | 14 | f = open('../dataset/reentrancy/valid_rsc.json', 'r') 15 | content = f.read() 16 | valid = json.loads(content) 17 | print(len(valid)) 18 | 19 | train_data = {} 20 | valid_data = {} 21 | 22 | for item in train: 23 | if item['contract_name'] in train_data: 24 | continue 25 | train_data[item['contract_name']] = item['targets'] 26 | print(len(train_data)) 27 | 28 | with open("../dataset/reentrancy/train.json", "w") as f: 29 | json.dump(train_data, f) 30 | 31 | for item in valid: 32 | if item['contract_name'] in valid_data: 33 | continue 34 | valid_data[item['contract_name']] = item['targets'] 35 | print(len(valid_data)) 36 | with open("../dataset/reentrancy/valid.json", "w") as f: 37 | json.dump(valid_data, f) 38 | 39 | print("加载入文件完成...") 40 | 41 | 42 | def construct_contracts_set(): 43 | """ 44 | 从 test和 valid 集中找出所有不重入的智能合约 45 | :return: 46 | """ 47 | 48 | 49 | if __name__ == '__main__': 50 | f = open('../dataset/reentrancy/train.json', 'r') 51 | content = f.read() 52 | train = json.loads(content) 53 | print(len(train)) 54 | 55 | f = open('../dataset/reentrancy/valid.json', 'r') 56 | content = f.read() 57 | valid = json.loads(content) 58 | print(len(valid)) 59 | 60 | data = {} 61 | for key in train.keys(): 62 | if key in data: 63 | continue 64 | data[key] = train[key] 65 | 66 | for key in valid.keys(): 67 | if key in data: 68 | continue 69 | data[key] = valid[key] 70 | 71 | print(len(data)) 72 | --------------------------------------------------------------------------------