Aishwarya Solanki commited on
Commit
ee7776a
·
1 Parent(s): 7b4cf82

initial commit

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. data/CVE/2018-13071.sol +231 -0
  2. data/CVE_clean/2018-13071.sol +171 -0
  3. data/CVE_label/CVE2description.json +0 -0
  4. data/CVE_label/CVE2label.json +21 -0
  5. data_full/CVE/2018-10299.sol +299 -0
  6. data_full/CVE/2018-10376.sol +294 -0
  7. data_full/CVE/2018-10468.sol +146 -0
  8. data_full/CVE/2018-10666.sol +253 -0
  9. data_full/CVE/2018-10705.sol +157 -0
  10. data_full/CVE/2018-10706.sol +404 -0
  11. data_full/CVE/2018-10944.sol +1344 -0
  12. data_full/CVE/2018-11239.sol +102 -0
  13. data_full/CVE/2018-11335.sol +280 -0
  14. data_full/CVE/2018-11411.sol +126 -0
  15. data_full/CVE/2018-11429.sol +165 -0
  16. data_full/CVE/2018-11446.sol +432 -0
  17. data_full/CVE/2018-11561.sol +146 -0
  18. data_full/CVE/2018-11687.sol +99 -0
  19. data_full/CVE/2018-12025-1.sol +165 -0
  20. data_full/CVE/2018-12025-2.sol +165 -0
  21. data_full/CVE/2018-12025-3.sol +150 -0
  22. data_full/CVE/2018-12062.sol +175 -0
  23. data_full/CVE/2018-12063.sol +184 -0
  24. data_full/CVE/2018-12067.sol +175 -0
  25. data_full/CVE/2018-12068.sol +175 -0
  26. data_full/CVE/2018-12070.sol +269 -0
  27. data_full/CVE/2018-12078.sol +145 -0
  28. data_full/CVE/2018-12079.sol +175 -0
  29. data_full/CVE/2018-12080.sol +184 -0
  30. data_full/CVE/2018-12081.sol +175 -0
  31. data_full/CVE/2018-12082.sol +168 -0
  32. data_full/CVE/2018-12083.sol +117 -0
  33. data_full/CVE/2018-12084.sol +153 -0
  34. data_full/CVE/2018-12230.sol +161 -0
  35. data_full/CVE/2018-12454.sol +148 -0
  36. data_full/CVE/2018-12511.sol +175 -0
  37. data_full/CVE/2018-12702.sol +142 -0
  38. data_full/CVE/2018-12703.sol +142 -0
  39. data_full/CVE/2018-12885.sol +1149 -0
  40. data_full/CVE/2018-12959.sol +127 -0
  41. data_full/CVE/2018-12975.sol +1234 -0
  42. data_full/CVE/2018-13041.sol +194 -0
  43. data_full/CVE/2018-13068.sol +166 -0
  44. data_full/CVE/2018-13069.sol +248 -0
  45. data_full/CVE/2018-13070.sol +169 -0
  46. data_full/CVE/2018-13071.sol +231 -0
  47. data_full/CVE/2018-13072.sol +168 -0
  48. data_full/CVE/2018-13073.sol +175 -0
  49. data_full/CVE/2018-13074.sol +227 -0
  50. data_full/CVE/2018-13075.sol +275 -0
data/CVE/2018-13071.sol ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-11-18
3
+ */
4
+
5
+ //ERC20 Token
6
+ pragma solidity ^0.4.17;
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ if (msg.sender != owner) throw;
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
25
+
26
+ contract token {
27
+ /* Public variables of the token */
28
+ string public standard = "T10 1.0";
29
+ string public name;
30
+ string public symbol;
31
+ uint8 public decimals;
32
+ uint256 public totalSupply;
33
+
34
+ /* This creates an array with all balances */
35
+ mapping (address => uint256) public balanceOf;
36
+ mapping (address => mapping (address => uint256)) public allowance;
37
+
38
+ /*************************************************/
39
+ mapping(address=>uint256) public indexes;
40
+ mapping(uint256=>address) public addresses;
41
+ uint256 public lastIndex = 0;
42
+ /*************************************************/
43
+
44
+ /* This generates a public event on the blockchain that will notify clients */
45
+ event Transfer(address indexed from, address indexed to, uint256 value);
46
+
47
+ /* Initializes contract with initial supply tokens to the creator of the contract */
48
+ function token(
49
+ uint256 initialSupply,
50
+ string tokenName,
51
+ uint8 decimalUnits,
52
+ string tokenSymbol
53
+ ) {
54
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
55
+ totalSupply = initialSupply; // Update total supply
56
+ name = tokenName; // Set the name for display purposes
57
+ symbol = tokenSymbol; // Set the symbol for display purposes
58
+ decimals = decimalUnits; // Amount of decimals for display purposes
59
+ /*****************************************/
60
+ addresses[1] = msg.sender;
61
+ indexes[msg.sender] = 1;
62
+ lastIndex = 1;
63
+ /*****************************************/
64
+ }
65
+
66
+ /* Send coins */
67
+ function transfer(address _to, uint256 _value) {
68
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
69
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
70
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
71
+ balanceOf[_to] += _value; // Add the same to the recipient
72
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
73
+ }
74
+
75
+ /* Allow another contract to spend some tokens in your behalf */
76
+ function approve(address _spender, uint256 _value)
77
+ returns (bool success) {
78
+ allowance[msg.sender][_spender] = _value;
79
+ return true;
80
+ }
81
+
82
+ /* Approve and then communicate the approved contract in a single tx */
83
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
84
+ returns (bool success) {
85
+ tokenRecipient spender = tokenRecipient(_spender);
86
+ if (approve(_spender, _value)) {
87
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
88
+ return true;
89
+ }
90
+ }
91
+
92
+ /* A contract attempts _ to get the coins */
93
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
94
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
95
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
96
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
97
+ balanceOf[_from] -= _value; // Subtract from the sender
98
+ balanceOf[_to] += _value; // Add the same to the recipient
99
+ allowance[_from][msg.sender] -= _value;
100
+ Transfer(_from, _to, _value);
101
+ return true;
102
+ }
103
+
104
+ /* This unnamed function is called whenever someone tries to send ether to it */
105
+ function () {
106
+ throw; // Prevents accidental sending of ether
107
+ }
108
+ }
109
+
110
+ contract CCindexToken is owned, token {
111
+
112
+ uint256 public sellPrice;
113
+ uint256 public buyPrice;
114
+
115
+ mapping(address=>bool) public frozenAccount;
116
+
117
+
118
+
119
+ /* This generates a public event on the blockchain that will notify clients */
120
+ event FrozenFunds(address target, bool frozen);
121
+
122
+ /* Initializes contract with initial supply tokens to the creator of the contract */
123
+ uint256 public constant initialSupply = 40000000 * 10**18;
124
+ uint8 public constant decimalUnits = 18;
125
+ string public tokenName = "CCindex10";
126
+ string public tokenSymbol = "T10";
127
+ function CCindexToken() token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
128
+ /* Send coins */
129
+ function transfer(address _to, uint256 _value) {
130
+ // if(!canHolderTransfer()) throw;
131
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
132
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
133
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
134
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
135
+ balanceOf[_to] += _value; // Add the same to the recipient
136
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
137
+ if(_value > 0){
138
+ if(balanceOf[msg.sender] == 0){
139
+ addresses[indexes[msg.sender]] = addresses[lastIndex];
140
+ indexes[addresses[lastIndex]] = indexes[msg.sender];
141
+ indexes[msg.sender] = 0;
142
+ delete addresses[lastIndex];
143
+ lastIndex--;
144
+ }
145
+ if(indexes[_to]==0){
146
+ lastIndex++;
147
+ addresses[lastIndex] = _to;
148
+ indexes[_to] = lastIndex;
149
+ }
150
+ }
151
+ }
152
+
153
+ function getAddresses() constant returns (address[]){
154
+ address[] memory addrs = new address[](lastIndex);
155
+ for(uint i = 0; i < lastIndex; i++){
156
+ addrs[i] = addresses[i+1];
157
+ }
158
+ return addrs;
159
+ }
160
+
161
+ function distributeTokens(uint startIndex,uint endIndex) onlyOwner returns (uint) {
162
+ // if(balanceOf[owner] < _amount) throw;
163
+ uint distributed = 0;
164
+ require(startIndex < endIndex);
165
+
166
+ for(uint i = startIndex; i < lastIndex; i++){
167
+ address holder = addresses[i+1];
168
+ uint reward = balanceOf[holder] * 3 / 100;
169
+ balanceOf[holder] += reward;
170
+ distributed += reward;
171
+ Transfer(0, holder, reward);
172
+ }
173
+
174
+ // balanceOf[owner] -= distributed;
175
+ totalSupply += distributed;
176
+ return distributed;
177
+ }
178
+
179
+ /************************************************************************/
180
+
181
+ /************************************************************************/
182
+
183
+ /* A contract attempts to get the coins */
184
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
185
+ if (frozenAccount[_from]) throw; // Check if frozen
186
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
187
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
188
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
189
+ balanceOf[_from] -= _value; // Subtract from the sender
190
+ balanceOf[_to] += _value; // Add the same to the recipient
191
+ allowance[_from][msg.sender] -= _value;
192
+ Transfer(_from, _to, _value);
193
+ return true;
194
+ }
195
+
196
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
197
+ balanceOf[target] += mintedAmount;
198
+ totalSupply += mintedAmount;
199
+ Transfer(0, this, mintedAmount);
200
+ Transfer(this, target, mintedAmount);
201
+ }
202
+
203
+ function freezeAccount(address target, bool freeze) onlyOwner {
204
+ frozenAccount[target] = freeze;
205
+ FrozenFunds(target, freeze);
206
+ }
207
+
208
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
209
+ sellPrice = newSellPrice;
210
+ buyPrice = newBuyPrice;
211
+ }
212
+
213
+ function buy() payable {
214
+ uint amount = msg.value / buyPrice; // calculates the amount
215
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
216
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
217
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
218
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
219
+ }
220
+
221
+ function sell(uint256 amount) {
222
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
223
+ balanceOf[this] += amount; // adds the amount to owner's balance
224
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
225
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
226
+ throw; // to do this last to avoid recursion attacks
227
+ } else {
228
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
229
+ }
230
+ }
231
+ }
data/CVE_clean/2018-13071.sol ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.17;
2
+ contract owned {
3
+ address public owner;
4
+ function owned() {
5
+ owner = msg.sender;
6
+ }
7
+ modifier onlyOwner {
8
+ if (msg.sender != owner) throw;
9
+ _;
10
+ }
11
+ function transferOwnership(address newOwner) onlyOwner {
12
+ owner = newOwner;
13
+ }
14
+ }
15
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
16
+ contract token {
17
+ string public standard = "T10 1.0";
18
+ string public name;
19
+ string public symbol;
20
+ uint8 public decimals;
21
+ uint256 public totalSupply;
22
+ mapping (address => uint256) public balanceOf;
23
+ mapping (address => mapping (address => uint256)) public allowance;
24
+ mapping(address=>uint256) public indexes;
25
+ mapping(uint256=>address) public addresses;
26
+ uint256 public lastIndex = 0;
27
+ event Transfer(address indexed from, address indexed to, uint256 value);
28
+ function token(
29
+ uint256 initialSupply,
30
+ string tokenName,
31
+ uint8 decimalUnits,
32
+ string tokenSymbol
33
+ ) {
34
+ balanceOf[msg.sender] = initialSupply;
35
+ totalSupply = initialSupply;
36
+ name = tokenName;
37
+ symbol = tokenSymbol;
38
+ decimals = decimalUnits;
39
+ addresses[1] = msg.sender;
40
+ indexes[msg.sender] = 1;
41
+ lastIndex = 1;
42
+ }
43
+ function transfer(address _to, uint256 _value) {
44
+ if (balanceOf[msg.sender] < _value) throw;
45
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw;
46
+ balanceOf[msg.sender] -= _value;
47
+ balanceOf[_to] += _value;
48
+ Transfer(msg.sender, _to, _value);
49
+ }
50
+ function approve(address _spender, uint256 _value)
51
+ returns (bool success) {
52
+ allowance[msg.sender][_spender] = _value;
53
+ return true;
54
+ }
55
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
56
+ returns (bool success) {
57
+ tokenRecipient spender = tokenRecipient(_spender);
58
+ if (approve(_spender, _value)) {
59
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
60
+ return true;
61
+ }
62
+ }
63
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
64
+ if (balanceOf[_from] < _value) throw;
65
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw;
66
+ if (_value > allowance[_from][msg.sender]) throw;
67
+ balanceOf[_from] -= _value;
68
+ balanceOf[_to] += _value;
69
+ allowance[_from][msg.sender] -= _value;
70
+ Transfer(_from, _to, _value);
71
+ return true;
72
+ }
73
+ function () {
74
+ throw;
75
+ }
76
+ }
77
+ contract CCindexToken is owned, token {
78
+ uint256 public sellPrice;
79
+ uint256 public buyPrice;
80
+ mapping(address=>bool) public frozenAccount;
81
+ event FrozenFunds(address target, bool frozen);
82
+ uint256 public constant initialSupply = 40000000 * 10**18;
83
+ uint8 public constant decimalUnits = 18;
84
+ string public tokenName = "CCindex10";
85
+ string public tokenSymbol = "T10";
86
+ function CCindexToken() token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
87
+ function transfer(address _to, uint256 _value) {
88
+ if (balanceOf[msg.sender] < _value) throw;
89
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw;
90
+ if (frozenAccount[msg.sender]) throw;
91
+ balanceOf[msg.sender] -= _value;
92
+ balanceOf[_to] += _value;
93
+ Transfer(msg.sender, _to, _value);
94
+ if(_value > 0){
95
+ if(balanceOf[msg.sender] == 0){
96
+ addresses[indexes[msg.sender]] = addresses[lastIndex];
97
+ indexes[addresses[lastIndex]] = indexes[msg.sender];
98
+ indexes[msg.sender] = 0;
99
+ delete addresses[lastIndex];
100
+ lastIndex--;
101
+ }
102
+ if(indexes[_to]==0){
103
+ lastIndex++;
104
+ addresses[lastIndex] = _to;
105
+ indexes[_to] = lastIndex;
106
+ }
107
+ }
108
+ }
109
+ function getAddresses() constant returns (address[]){
110
+ address[] memory addrs = new address[](lastIndex);
111
+ for(uint i = 0; i < lastIndex; i++){
112
+ addrs[i] = addresses[i+1];
113
+ }
114
+ return addrs;
115
+ }
116
+ function distributeTokens(uint startIndex,uint endIndex) onlyOwner returns (uint) {
117
+ uint distributed = 0;
118
+ require(startIndex < endIndex);
119
+ for(uint i = startIndex; i < lastIndex; i++){
120
+ address holder = addresses[i+1];
121
+ uint reward = balanceOf[holder] * 3 / 100;
122
+ balanceOf[holder] += reward;
123
+ distributed += reward;
124
+ Transfer(0, holder, reward);
125
+ }
126
+ totalSupply += distributed;
127
+ return distributed;
128
+ }
129
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
130
+ if (frozenAccount[_from]) throw;
131
+ if (balanceOf[_from] < _value) throw;
132
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw;
133
+ if (_value > allowance[_from][msg.sender]) throw;
134
+ balanceOf[_from] -= _value;
135
+ balanceOf[_to] += _value;
136
+ allowance[_from][msg.sender] -= _value;
137
+ Transfer(_from, _to, _value);
138
+ return true;
139
+ }
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+ function freezeAccount(address target, bool freeze) onlyOwner {
147
+ frozenAccount[target] = freeze;
148
+ FrozenFunds(target, freeze);
149
+ }
150
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
151
+ sellPrice = newSellPrice;
152
+ buyPrice = newBuyPrice;
153
+ }
154
+ function buy() payable {
155
+ uint amount = msg.value / buyPrice;
156
+ if (balanceOf[this] < amount) throw;
157
+ balanceOf[msg.sender] += amount;
158
+ balanceOf[this] -= amount;
159
+ Transfer(this, msg.sender, amount);
160
+ }
161
+ function sell(uint256 amount) {
162
+ if (balanceOf[msg.sender] < amount ) throw;
163
+ balanceOf[this] += amount;
164
+ balanceOf[msg.sender] -= amount;
165
+ if (!msg.sender.send(amount * sellPrice)) {
166
+ throw;
167
+ } else {
168
+ Transfer(msg.sender, this, amount);
169
+ }
170
+ }
171
+ }
data/CVE_label/CVE2description.json ADDED
The diff for this file is too large to render. See raw diff
 
data/CVE_label/CVE2label.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "CVE-2018-10299": "Integer Overflow",
3
+ "CVE-2018-10376": "Integer Overflow",
4
+ "CVE-2018-11335": "Integer Overflow",
5
+ "CVE-2018-13836": "Integer Overflow",
6
+ "CVE-2018-17882": "Integer Overflow",
7
+ "CVE-2018-10468": "Wrong Logic",
8
+ "CVE-2018-11411": "Wrong Logic",
9
+ "CVE-2018-12025": "Wrong Logic",
10
+ "CVE-2021-3004": "Wrong Logic",
11
+ "CVE-2018-15552": "Bad Randomness",
12
+ "CVE-2018-14715": "Bad Randomness",
13
+ "CVE-2018-17877": "Bad Randomness",
14
+ "CVE-2018-10666": "Access Control",
15
+ "CVE-2018-10705": "Access Control",
16
+ "CVE-2018-19830": "Access Control",
17
+ "CVE-2019-15078": "Typo Constructor",
18
+ "CVE-2019-15079": "Typo Constructor",
19
+ "CVE-2019-15080": "Typo Constructor",
20
+ "CVE-2018-18425": "Token Devalue"
21
+ }
data_full/CVE/2018-10299.sol ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.16;
2
+
3
+ /**
4
+ * @title SafeMath
5
+ * @dev Math operations with safety checks that throw on error
6
+ */
7
+ library SafeMath {
8
+ function mul(uint256 a, uint256 b) internal constant returns (uint256) {
9
+ uint256 c = a * b;
10
+ assert(a == 0 || c / a == b);
11
+ return c;
12
+ }
13
+
14
+ function div(uint256 a, uint256 b) internal constant returns (uint256) {
15
+ // assert(b > 0); // Solidity automatically throws when dividing by 0
16
+ uint256 c = a / b;
17
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
18
+ return c;
19
+ }
20
+
21
+ function sub(uint256 a, uint256 b) internal constant returns (uint256) {
22
+ assert(b <= a);
23
+ return a - b;
24
+ }
25
+
26
+ function add(uint256 a, uint256 b) internal constant returns (uint256) {
27
+ uint256 c = a + b;
28
+ assert(c >= a);
29
+ return c;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * @title ERC20Basic
35
+ * @dev Simpler version of ERC20 interface
36
+ * @dev see https://github.com/ethereum/EIPs/issues/179
37
+ */
38
+ contract ERC20Basic {
39
+ uint256 public totalSupply;
40
+ function balanceOf(address who) public constant returns (uint256);
41
+ function transfer(address to, uint256 value) public returns (bool);
42
+ event Transfer(address indexed from, address indexed to, uint256 value);
43
+ }
44
+
45
+ /**
46
+ * @title Basic token
47
+ * @dev Basic version of StandardToken, with no allowances.
48
+ */
49
+ contract BasicToken is ERC20Basic {
50
+ using SafeMath for uint256;
51
+
52
+ mapping(address => uint256) balances;
53
+
54
+ /**
55
+ * @dev transfer token for a specified address
56
+ * @param _to The address to transfer to.
57
+ * @param _value The amount to be transferred.
58
+ */
59
+ function transfer(address _to, uint256 _value) public returns (bool) {
60
+ require(_to != address(0));
61
+ require(_value > 0 && _value <= balances[msg.sender]);
62
+
63
+ // SafeMath.sub will throw if there is not enough balance.
64
+ balances[msg.sender] = balances[msg.sender].sub(_value);
65
+ balances[_to] = balances[_to].add(_value);
66
+ Transfer(msg.sender, _to, _value);
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * @dev Gets the balance of the specified address.
72
+ * @param _owner The address to query the the balance of.
73
+ * @return An uint256 representing the amount owned by the passed address.
74
+ */
75
+ function balanceOf(address _owner) public constant returns (uint256 balance) {
76
+ return balances[_owner];
77
+ }
78
+ }
79
+
80
+ /**
81
+ * @title ERC20 interface
82
+ * @dev see https://github.com/ethereum/EIPs/issues/20
83
+ */
84
+ contract ERC20 is ERC20Basic {
85
+ function allowance(address owner, address spender) public constant returns (uint256);
86
+ function transferFrom(address from, address to, uint256 value) public returns (bool);
87
+ function approve(address spender, uint256 value) public returns (bool);
88
+ event Approval(address indexed owner, address indexed spender, uint256 value);
89
+ }
90
+
91
+
92
+ /**
93
+ * @title Standard ERC20 token
94
+ *
95
+ * @dev Implementation of the basic standard token.
96
+ * @dev https://github.com/ethereum/EIPs/issues/20
97
+ * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
98
+ */
99
+ contract StandardToken is ERC20, BasicToken {
100
+
101
+ mapping (address => mapping (address => uint256)) internal allowed;
102
+
103
+
104
+ /**
105
+ * @dev Transfer tokens from one address to another
106
+ * @param _from address The address which you want to send tokens from
107
+ * @param _to address The address which you want to transfer to
108
+ * @param _value uint256 the amount of tokens to be transferred
109
+ */
110
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
111
+ require(_to != address(0));
112
+ require(_value > 0 && _value <= balances[_from]);
113
+ require(_value <= allowed[_from][msg.sender]);
114
+
115
+ balances[_from] = balances[_from].sub(_value);
116
+ balances[_to] = balances[_to].add(_value);
117
+ allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
118
+ Transfer(_from, _to, _value);
119
+ return true;
120
+ }
121
+
122
+ /**
123
+ * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
124
+ *
125
+ * Beware that changing an allowance with this method brings the risk that someone may use both the old
126
+ * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
127
+ * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
128
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
129
+ * @param _spender The address which will spend the funds.
130
+ * @param _value The amount of tokens to be spent.
131
+ */
132
+ function approve(address _spender, uint256 _value) public returns (bool) {
133
+ allowed[msg.sender][_spender] = _value;
134
+ Approval(msg.sender, _spender, _value);
135
+ return true;
136
+ }
137
+
138
+ /**
139
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
140
+ * @param _owner address The address which owns the funds.
141
+ * @param _spender address The address which will spend the funds.
142
+ * @return A uint256 specifying the amount of tokens still available for the spender.
143
+ */
144
+ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
145
+ return allowed[_owner][_spender];
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @title Ownable
151
+ * @dev The Ownable contract has an owner address, and provides basic authorization control
152
+ * functions, this simplifies the implementation of "user permissions".
153
+ */
154
+ contract Ownable {
155
+ address public owner;
156
+
157
+
158
+ event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
159
+
160
+
161
+ /**
162
+ * @dev The Ownable constructor sets the original `owner` of the contract to the sender
163
+ * account.
164
+ */
165
+ function Ownable() {
166
+ owner = msg.sender;
167
+ }
168
+
169
+
170
+ /**
171
+ * @dev Throws if called by any account other than the owner.
172
+ */
173
+ modifier onlyOwner() {
174
+ require(msg.sender == owner);
175
+ _;
176
+ }
177
+
178
+
179
+ /**
180
+ * @dev Allows the current owner to transfer control of the contract to a newOwner.
181
+ * @param newOwner The address to transfer ownership to.
182
+ */
183
+ function transferOwnership(address newOwner) onlyOwner public {
184
+ require(newOwner != address(0));
185
+ OwnershipTransferred(owner, newOwner);
186
+ owner = newOwner;
187
+ }
188
+
189
+ }
190
+
191
+ /**
192
+ * @title Pausable
193
+ * @dev Base contract which allows children to implement an emergency stop mechanism.
194
+ */
195
+ contract Pausable is Ownable {
196
+ event Pause();
197
+ event Unpause();
198
+
199
+ bool public paused = false;
200
+
201
+
202
+ /**
203
+ * @dev Modifier to make a function callable only when the contract is not paused.
204
+ */
205
+ modifier whenNotPaused() {
206
+ require(!paused);
207
+ _;
208
+ }
209
+
210
+ /**
211
+ * @dev Modifier to make a function callable only when the contract is paused.
212
+ */
213
+ modifier whenPaused() {
214
+ require(paused);
215
+ _;
216
+ }
217
+
218
+ /**
219
+ * @dev called by the owner to pause, triggers stopped state
220
+ */
221
+ function pause() onlyOwner whenNotPaused public {
222
+ paused = true;
223
+ Pause();
224
+ }
225
+
226
+ /**
227
+ * @dev called by the owner to unpause, returns to normal state
228
+ */
229
+ function unpause() onlyOwner whenPaused public {
230
+ paused = false;
231
+ Unpause();
232
+ }
233
+ }
234
+
235
+ /**
236
+ * @title Pausable token
237
+ *
238
+ * @dev StandardToken modified with pausable transfers.
239
+ **/
240
+
241
+ contract PausableToken is StandardToken, Pausable {
242
+
243
+ function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
244
+ return super.transfer(_to, _value);
245
+ }
246
+
247
+ function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
248
+ return super.transferFrom(_from, _to, _value);
249
+ }
250
+
251
+ function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
252
+ return super.approve(_spender, _value);
253
+ }
254
+
255
+ function batchTransfer(address[] _receivers, uint256 _value) public whenNotPaused returns (bool) {
256
+ uint cnt = _receivers.length;
257
+ uint256 amount = uint256(cnt) * _value;
258
+ require(cnt > 0 && cnt <= 20);
259
+ require(_value > 0 && balances[msg.sender] >= amount);
260
+
261
+ balances[msg.sender] = balances[msg.sender].sub(amount);
262
+ for (uint i = 0; i < cnt; i++) {
263
+ balances[_receivers[i]] = balances[_receivers[i]].add(_value);
264
+ Transfer(msg.sender, _receivers[i], _value);
265
+ }
266
+ return true;
267
+ }
268
+ }
269
+
270
+ /**
271
+ * @title Bec Token
272
+ *
273
+ * @dev Implementation of Bec Token based on the basic standard token.
274
+ */
275
+ contract BecToken is PausableToken {
276
+ /**
277
+ * Public variables of the token
278
+ * The following variables are OPTIONAL vanities. One does not have to include them.
279
+ * They allow one to customise the token contract & in no way influences the core functionality.
280
+ * Some wallets/interfaces might not even bother to look at this information.
281
+ */
282
+ string public name = "BeautyChain";
283
+ string public symbol = "BEC";
284
+ string public version = '1.0.0';
285
+ uint8 public decimals = 18;
286
+
287
+ /**
288
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
289
+ */
290
+ function BecToken() {
291
+ totalSupply = 7000000000 * (10**(uint256(decimals)));
292
+ balances[msg.sender] = totalSupply; // Give the creator all initial tokens
293
+ }
294
+
295
+ function () {
296
+ //if ether is sent to this address, send it back.
297
+ revert();
298
+ }
299
+ }
data_full/CVE/2018-10376.sol ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Abstract contract for the full ERC 20 Token standard
2
+ // https://github.com/ethereum/EIPs/issues/20
3
+ pragma solidity ^0.4.15;
4
+
5
+ contract Token {
6
+ /* This is a slight change to the ERC20 base standard.*/
7
+ /// total amount of tokens
8
+ uint256 public totalSupply;
9
+
10
+ /// @param _owner The address from which the balance will be retrieved
11
+ /// @return The balance
12
+ function balanceOf(address _owner) public constant returns (uint256 balance);
13
+
14
+ /// @notice send `_value` token to `_to` from `msg.sender`
15
+ /// @param _to The address of the recipient
16
+ /// @param _value The amount of token to be transferred
17
+ /// @return Whether the transfer was successful or not
18
+ function transfer(address _to, uint256 _value) public returns (bool success);
19
+
20
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
21
+ /// @param _from The address of the sender
22
+ /// @param _to The address of the recipient
23
+ /// @param _value The amount of token to be transferred
24
+ /// @return Whether the transfer was successful or not
25
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
26
+
27
+ /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
28
+ /// @param _spender The address of the account able to transfer the tokens
29
+ /// @param _value The amount of tokens to be approved for transfer
30
+ /// @return Whether the approval was successful or not
31
+ function approve(address _spender, uint256 _value) public returns (bool success);
32
+
33
+ /// @param _owner The address of the account owning tokens
34
+ /// @param _spender The address of the account able to transfer the tokens
35
+ /// @return Amount of remaining tokens allowed to spent
36
+ function allowance(address _owner, address _spender) public constant returns (uint256 remaining);
37
+
38
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
39
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
40
+ }
41
+
42
+ contract Owned {
43
+
44
+ /// `owner` is the only address that can call a function with this
45
+ /// modifier
46
+ modifier onlyOwner() {
47
+ require(msg.sender == owner);
48
+ _;
49
+ }
50
+
51
+ address public owner;
52
+
53
+ /// @notice The Constructor assigns the message sender to be `owner`
54
+ function Owned() public {
55
+ owner = msg.sender;
56
+ }
57
+
58
+ address newOwner=0x0;
59
+
60
+ event OwnerUpdate(address _prevOwner, address _newOwner);
61
+
62
+ ///change the owner
63
+ function changeOwner(address _newOwner) public onlyOwner {
64
+ require(_newOwner != owner);
65
+ newOwner = _newOwner;
66
+ }
67
+
68
+ /// accept the ownership
69
+ function acceptOwnership() public{
70
+ require(msg.sender == newOwner);
71
+ OwnerUpdate(owner, newOwner);
72
+ owner = newOwner;
73
+ newOwner = 0x0;
74
+ }
75
+ }
76
+
77
+ contract Controlled is Owned{
78
+
79
+ function Controlled() public {
80
+ setExclude(msg.sender);
81
+ }
82
+
83
+ // Flag that determines if the token is transferable or not.
84
+ bool public transferEnabled = false;
85
+
86
+ // flag that makes locked address effect
87
+ bool lockFlag=true;
88
+ mapping(address => bool) locked;
89
+ mapping(address => bool) exclude;
90
+
91
+ function enableTransfer(bool _enable) public onlyOwner{
92
+ transferEnabled=_enable;
93
+ }
94
+
95
+ function disableLock(bool _enable) public onlyOwner returns (bool success){
96
+ lockFlag=_enable;
97
+ return true;
98
+ }
99
+
100
+ function addLock(address _addr) public onlyOwner returns (bool success){
101
+ require(_addr!=msg.sender);
102
+ locked[_addr]=true;
103
+ return true;
104
+ }
105
+
106
+ function setExclude(address _addr) public onlyOwner returns (bool success){
107
+ exclude[_addr]=true;
108
+ return true;
109
+ }
110
+
111
+ function removeLock(address _addr) public onlyOwner returns (bool success){
112
+ locked[_addr]=false;
113
+ return true;
114
+ }
115
+
116
+ modifier transferAllowed(address _addr) {
117
+ if (!exclude[_addr]) {
118
+ assert(transferEnabled);
119
+ if(lockFlag){
120
+ assert(!locked[_addr]);
121
+ }
122
+ }
123
+
124
+ _;
125
+ }
126
+
127
+ }
128
+
129
+ contract StandardToken is Token,Controlled {
130
+
131
+ function transfer(address _to, uint256 _value) public transferAllowed(msg.sender) returns (bool success) {
132
+ //Default assumes totalSupply can't be over max (2^256 - 1).
133
+ //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
134
+ //Replace the if with this one instead.
135
+ if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
136
+ balances[msg.sender] -= _value;
137
+ balances[_to] += _value;
138
+ Transfer(msg.sender, _to, _value);
139
+ return true;
140
+ } else { return false; }
141
+ }
142
+
143
+ function transferFrom(address _from, address _to, uint256 _value) public transferAllowed(_from) returns (bool success) {
144
+ //same as above. Replace this line with the following if you want to protect against wrapping uints.
145
+ if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
146
+ balances[_to] += _value;
147
+ balances[_from] -= _value;
148
+ allowed[_from][msg.sender] -= _value;
149
+ Transfer(_from, _to, _value);
150
+ return true;
151
+ } else { return false; }
152
+ }
153
+
154
+ function balanceOf(address _owner) public constant returns (uint256 balance) {
155
+ return balances[_owner];
156
+ }
157
+
158
+ function approve(address _spender, uint256 _value) public returns (bool success) {
159
+ allowed[msg.sender][_spender] = _value;
160
+ Approval(msg.sender, _spender, _value);
161
+ return true;
162
+ }
163
+
164
+ function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
165
+ return allowed[_owner][_spender];
166
+ }
167
+
168
+ mapping (address => uint256) balances;
169
+ mapping (address => mapping (address => uint256)) allowed;
170
+ }
171
+
172
+ contract SMT is StandardToken {
173
+
174
+ function () public {
175
+ revert();
176
+ }
177
+
178
+ string public name = "SmartMesh Token"; //fancy name
179
+ uint8 public decimals = 18; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
180
+ string public symbol = "SMT"; //An identifier
181
+ string public version = 'v0.1'; //SMT 0.1 standard. Just an arbitrary versioning scheme.
182
+ uint256 public allocateEndTime;
183
+
184
+
185
+ // The nonce for avoid transfer replay attacks
186
+ mapping(address => uint256) nonces;
187
+
188
+ function SMT() public {
189
+ allocateEndTime = now + 1 days;
190
+ }
191
+
192
+ /*
193
+ * Proxy transfer SmartMesh token. When some users of the ethereum account has no ether,
194
+ * he or she can authorize the agent for broadcast transactions, and agents may charge agency fees
195
+ * @param _from
196
+ * @param _to
197
+ * @param _value
198
+ * @param feeSmt
199
+ * @param _v
200
+ * @param _r
201
+ * @param _s
202
+ */
203
+ function transferProxy(address _from, address _to, uint256 _value, uint256 _feeSmt,
204
+ uint8 _v,bytes32 _r, bytes32 _s) public transferAllowed(_from) returns (bool){
205
+
206
+ if(balances[_from] < _feeSmt + _value) revert();
207
+
208
+ uint256 nonce = nonces[_from];
209
+ bytes32 h = keccak256(_from,_to,_value,_feeSmt,nonce);
210
+ if(_from != ecrecover(h,_v,_r,_s)) revert();
211
+
212
+ if(balances[_to] + _value < balances[_to]
213
+ || balances[msg.sender] + _feeSmt < balances[msg.sender]) revert();
214
+ balances[_to] += _value;
215
+ Transfer(_from, _to, _value);
216
+
217
+ balances[msg.sender] += _feeSmt;
218
+ Transfer(_from, msg.sender, _feeSmt);
219
+
220
+ balances[_from] -= _value + _feeSmt;
221
+ nonces[_from] = nonce + 1;
222
+ return true;
223
+ }
224
+
225
+ /*
226
+ * Proxy approve that some one can authorize the agent for broadcast transaction
227
+ * which call approve method, and agents may charge agency fees
228
+ * @param _from The address which should tranfer SMT to others
229
+ * @param _spender The spender who allowed by _from
230
+ * @param _value The value that should be tranfered.
231
+ * @param _v
232
+ * @param _r
233
+ * @param _s
234
+ */
235
+ function approveProxy(address _from, address _spender, uint256 _value,
236
+ uint8 _v,bytes32 _r, bytes32 _s) public returns (bool success) {
237
+
238
+ uint256 nonce = nonces[_from];
239
+ bytes32 hash = keccak256(_from,_spender,_value,nonce);
240
+ if(_from != ecrecover(hash,_v,_r,_s)) revert();
241
+ allowed[_from][_spender] = _value;
242
+ Approval(_from, _spender, _value);
243
+ nonces[_from] = nonce + 1;
244
+ return true;
245
+ }
246
+
247
+
248
+ /*
249
+ * Get the nonce
250
+ * @param _addr
251
+ */
252
+ function getNonce(address _addr) public constant returns (uint256){
253
+ return nonces[_addr];
254
+ }
255
+
256
+ /* Approves and then calls the receiving contract */
257
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
258
+ allowed[msg.sender][_spender] = _value;
259
+ Approval(msg.sender, _spender, _value);
260
+
261
+ //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
262
+ //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
263
+ //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
264
+ if(!_spender.call(bytes4(bytes32(keccak256("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
265
+ return true;
266
+ }
267
+
268
+ /* Approves and then calls the contract code*/
269
+ function approveAndCallcode(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
270
+ allowed[msg.sender][_spender] = _value;
271
+ Approval(msg.sender, _spender, _value);
272
+
273
+ //Call the contract code
274
+ if(!_spender.call(_extraData)) { revert(); }
275
+ return true;
276
+ }
277
+
278
+ // Allocate tokens to the users
279
+ // @param _owners The owners list of the token
280
+ // @param _values The value list of the token
281
+ function allocateTokens(address[] _owners, uint256[] _values) public onlyOwner {
282
+
283
+ if(allocateEndTime < now) revert();
284
+ if(_owners.length != _values.length) revert();
285
+
286
+ for(uint256 i = 0; i < _owners.length ; i++){
287
+ address to = _owners[i];
288
+ uint256 value = _values[i];
289
+ if(totalSupply + value <= totalSupply || balances[to] + value <= balances[to]) revert();
290
+ totalSupply += value;
291
+ balances[to] += value;
292
+ }
293
+ }
294
+ }
data_full/CVE/2018-10468.sol ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.10;
2
+
3
+ contract ForeignToken {
4
+ function balanceOf(address _owner) constant returns (uint256);
5
+ function transfer(address _to, uint256 _value) returns (bool);
6
+ }
7
+
8
+ contract UselessEthereumToken {
9
+ address owner = msg.sender;
10
+
11
+ bool public purchasingAllowed = false;
12
+
13
+ mapping (address => uint256) balances;
14
+ mapping (address => mapping (address => uint256)) allowed;
15
+
16
+ uint256 public totalContribution = 0;
17
+ uint256 public totalBonusTokensIssued = 0;
18
+
19
+ uint256 public totalSupply = 0;
20
+
21
+ function name() constant returns (string) { return "Useless Ethereum Token"; }
22
+ function symbol() constant returns (string) { return "UET"; }
23
+ function decimals() constant returns (uint8) { return 18; }
24
+
25
+ function balanceOf(address _owner) constant returns (uint256) { return balances[_owner]; }
26
+
27
+ function transfer(address _to, uint256 _value) returns (bool success) {
28
+ // mitigates the ERC20 short address attack
29
+ if(msg.data.length < (2 * 32) + 4) { throw; }
30
+
31
+ if (_value == 0) { return false; }
32
+
33
+ uint256 fromBalance = balances[msg.sender];
34
+
35
+ bool sufficientFunds = fromBalance >= _value;
36
+ bool overflowed = balances[_to] + _value < balances[_to];
37
+
38
+ if (sufficientFunds && !overflowed) {
39
+ balances[msg.sender] -= _value;
40
+ balances[_to] += _value;
41
+
42
+ Transfer(msg.sender, _to, _value);
43
+ return true;
44
+ } else { return false; }
45
+ }
46
+
47
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
48
+ // mitigates the ERC20 short address attack
49
+ if(msg.data.length < (3 * 32) + 4) { throw; }
50
+
51
+ if (_value == 0) { return false; }
52
+
53
+ uint256 fromBalance = balances[_from];
54
+ uint256 allowance = allowed[_from][msg.sender];
55
+
56
+ bool sufficientFunds = fromBalance <= _value;
57
+ bool sufficientAllowance = allowance <= _value;
58
+ bool overflowed = balances[_to] + _value > balances[_to];
59
+
60
+ if (sufficientFunds && sufficientAllowance && !overflowed) {
61
+ balances[_to] += _value;
62
+ balances[_from] -= _value;
63
+
64
+ allowed[_from][msg.sender] -= _value;
65
+
66
+ Transfer(_from, _to, _value);
67
+ return true;
68
+ } else { return false; }
69
+ }
70
+
71
+ function approve(address _spender, uint256 _value) returns (bool success) {
72
+ // mitigates the ERC20 spend/approval race condition
73
+ if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; }
74
+
75
+ allowed[msg.sender][_spender] = _value;
76
+
77
+ Approval(msg.sender, _spender, _value);
78
+ return true;
79
+ }
80
+
81
+ function allowance(address _owner, address _spender) constant returns (uint256) {
82
+ return allowed[_owner][_spender];
83
+ }
84
+
85
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
86
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
87
+
88
+ function enablePurchasing() {
89
+ if (msg.sender != owner) { throw; }
90
+
91
+ purchasingAllowed = true;
92
+ }
93
+
94
+ function disablePurchasing() {
95
+ if (msg.sender != owner) { throw; }
96
+
97
+ purchasingAllowed = false;
98
+ }
99
+
100
+ function withdrawForeignTokens(address _tokenContract) returns (bool) {
101
+ if (msg.sender != owner) { throw; }
102
+
103
+ ForeignToken token = ForeignToken(_tokenContract);
104
+
105
+ uint256 amount = token.balanceOf(address(this));
106
+ return token.transfer(owner, amount);
107
+ }
108
+
109
+ function getStats() constant returns (uint256, uint256, uint256, bool) {
110
+ return (totalContribution, totalSupply, totalBonusTokensIssued, purchasingAllowed);
111
+ }
112
+
113
+ function() payable {
114
+ if (!purchasingAllowed) { throw; }
115
+
116
+ if (msg.value == 0) { return; }
117
+
118
+ owner.transfer(msg.value);
119
+ totalContribution += msg.value;
120
+
121
+ uint256 tokensIssued = (msg.value * 100);
122
+
123
+ if (msg.value >= 10 finney) {
124
+ tokensIssued += totalContribution;
125
+
126
+ bytes20 bonusHash = ripemd160(block.coinbase, block.number, block.timestamp);
127
+ if (bonusHash[0] == 0) {
128
+ uint8 bonusMultiplier =
129
+ ((bonusHash[1] & 0x01 != 0) ? 1 : 0) + ((bonusHash[1] & 0x02 != 0) ? 1 : 0) +
130
+ ((bonusHash[1] & 0x04 != 0) ? 1 : 0) + ((bonusHash[1] & 0x08 != 0) ? 1 : 0) +
131
+ ((bonusHash[1] & 0x10 != 0) ? 1 : 0) + ((bonusHash[1] & 0x20 != 0) ? 1 : 0) +
132
+ ((bonusHash[1] & 0x40 != 0) ? 1 : 0) + ((bonusHash[1] & 0x80 != 0) ? 1 : 0);
133
+
134
+ uint256 bonusTokensIssued = (msg.value * 100) * bonusMultiplier;
135
+ tokensIssued += bonusTokensIssued;
136
+
137
+ totalBonusTokensIssued += bonusTokensIssued;
138
+ }
139
+ }
140
+
141
+ totalSupply += tokensIssued;
142
+ balances[msg.sender] += tokensIssued;
143
+
144
+ Transfer(address(this), msg.sender, tokensIssued);
145
+ }
146
+ }
data_full/CVE/2018-10666.sol ADDED
@@ -0,0 +1,253 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-01-17
3
+ */
4
+
5
+ pragma solidity ^0.4.19;
6
+
7
+ /**
8
+ * @title IDXM Contract. IDEX Membership Token contract.
9
+ *
10
+ * @author Ray Pulver, [email protected]
11
+ */
12
+
13
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
14
+
15
+ contract SafeMath {
16
+ function safeMul(uint256 a, uint256 b) returns (uint256) {
17
+ uint256 c = a * b;
18
+ require(a == 0 || c / a == b);
19
+ return c;
20
+ }
21
+ function safeSub(uint256 a, uint256 b) returns (uint256) {
22
+ require(b <= a);
23
+ return a - b;
24
+ }
25
+ function safeAdd(uint256 a, uint256 b) returns (uint256) {
26
+ uint c = a + b;
27
+ require(c >= a && c >= b);
28
+ return c;
29
+ }
30
+ }
31
+
32
+ contract Owned {
33
+ address public owner;
34
+ function Owned() {
35
+ owner = msg.sender;
36
+ }
37
+ function setOwner(address _owner) returns (bool success) {
38
+ owner = _owner;
39
+ return true;
40
+ }
41
+ modifier onlyOwner {
42
+ require(msg.sender == owner);
43
+ _;
44
+ }
45
+ }
46
+
47
+ contract IDXM is Owned, SafeMath {
48
+ uint8 public decimals = 8;
49
+ bytes32 public standard = 'Token 0.1';
50
+ bytes32 public name = 'IDEX Membership';
51
+ bytes32 public symbol = 'IDXM';
52
+ uint256 public totalSupply;
53
+
54
+ event Approval(address indexed from, address indexed spender, uint256 amount);
55
+
56
+ mapping (address => uint256) public balanceOf;
57
+ mapping (address => mapping (address => uint256)) public allowance;
58
+
59
+ event Transfer(address indexed from, address indexed to, uint256 value);
60
+
61
+ uint256 public baseFeeDivisor;
62
+ uint256 public feeDivisor;
63
+ uint256 public singleIDXMQty;
64
+
65
+ function () external {
66
+ throw;
67
+ }
68
+
69
+ uint8 public feeDecimals = 8;
70
+
71
+ struct Validity {
72
+ uint256 last;
73
+ uint256 ts;
74
+ }
75
+
76
+ mapping (address => Validity) public validAfter;
77
+ uint256 public mustHoldFor = 604800;
78
+ mapping (address => uint256) public exportFee;
79
+
80
+ /**
81
+ * Constructor.
82
+ *
83
+ */
84
+ function IDXM() {
85
+ totalSupply = 200000000000;
86
+ balanceOf[msg.sender] = totalSupply;
87
+ exportFee[0x00000000000000000000000000000000000000ff] = 100000000;
88
+ precalculate();
89
+ }
90
+
91
+ bool public balancesLocked = false;
92
+
93
+ function uploadBalances(address[] addresses, uint256[] balances) onlyOwner {
94
+ require(!balancesLocked);
95
+ require(addresses.length == balances.length);
96
+ uint256 sum;
97
+ for (uint256 i = 0; i < uint256(addresses.length); i++) {
98
+ sum = safeAdd(sum, safeSub(balances[i], balanceOf[addresses[i]]));
99
+ balanceOf[addresses[i]] = balances[i];
100
+ }
101
+ balanceOf[owner] = safeSub(balanceOf[owner], sum);
102
+ }
103
+
104
+ function lockBalances() onlyOwner {
105
+ balancesLocked = true;
106
+ }
107
+
108
+ /**
109
+ * @notice Transfer `_amount` from `msg.sender.address()` to `_to`.
110
+ *
111
+ * @param _to Address that will receive.
112
+ * @param _amount Amount to be transferred.
113
+ */
114
+ function transfer(address _to, uint256 _amount) returns (bool success) {
115
+ require(!locked);
116
+ require(balanceOf[msg.sender] >= _amount);
117
+ require(balanceOf[_to] + _amount >= balanceOf[_to]);
118
+ balanceOf[msg.sender] -= _amount;
119
+ uint256 preBalance = balanceOf[_to];
120
+ balanceOf[_to] += _amount;
121
+ bool alreadyMax = preBalance >= singleIDXMQty;
122
+ if (!alreadyMax) {
123
+ if (now >= validAfter[_to].ts + mustHoldFor) validAfter[_to].last = preBalance;
124
+ validAfter[_to].ts = now;
125
+ }
126
+ if (validAfter[msg.sender].last > balanceOf[msg.sender]) validAfter[msg.sender].last = balanceOf[msg.sender];
127
+ Transfer(msg.sender, _to, _amount);
128
+ return true;
129
+ }
130
+
131
+ /**
132
+ * @notice Transfer `_amount` from `_from` to `_to`.
133
+ *
134
+ * @param _from Origin address
135
+ * @param _to Address that will receive
136
+ * @param _amount Amount to be transferred.
137
+ * @return result of the method call
138
+ */
139
+ function transferFrom(address _from, address _to, uint256 _amount) returns (bool success) {
140
+ require(!locked);
141
+ require(balanceOf[_from] >= _amount);
142
+ require(balanceOf[_to] + _amount >= balanceOf[_to]);
143
+ require(_amount <= allowance[_from][msg.sender]);
144
+ balanceOf[_from] -= _amount;
145
+ uint256 preBalance = balanceOf[_to];
146
+ balanceOf[_to] += _amount;
147
+ allowance[_from][msg.sender] -= _amount;
148
+ bool alreadyMax = preBalance >= singleIDXMQty;
149
+ if (!alreadyMax) {
150
+ if (now >= validAfter[_to].ts + mustHoldFor) validAfter[_to].last = preBalance;
151
+ validAfter[_to].ts = now;
152
+ }
153
+ if (validAfter[_from].last > balanceOf[_from]) validAfter[_from].last = balanceOf[_from];
154
+ Transfer(_from, _to, _amount);
155
+ return true;
156
+ }
157
+
158
+ /**
159
+ * @notice Approve spender `_spender` to transfer `_amount` from `msg.sender.address()`
160
+ *
161
+ * @param _spender Address that receives the cheque
162
+ * @param _amount Amount on the cheque
163
+ * @param _extraData Consequential contract to be executed by spender in same transcation.
164
+ * @return result of the method call
165
+ */
166
+ function approveAndCall(address _spender, uint256 _amount, bytes _extraData) returns (bool success) {
167
+ tokenRecipient spender = tokenRecipient(_spender);
168
+ if (approve(_spender, _amount)) {
169
+ spender.receiveApproval(msg.sender, _amount, this, _extraData);
170
+ return true;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * @notice Approve spender `_spender` to transfer `_amount` from `msg.sender.address()`
176
+ *
177
+ * @param _spender Address that receives the cheque
178
+ * @param _amount Amount on the cheque
179
+ * @return result of the method call
180
+ */
181
+ function approve(address _spender, uint256 _amount) returns (bool success) {
182
+ require(!locked);
183
+ allowance[msg.sender][_spender] = _amount;
184
+ Approval(msg.sender, _spender, _amount);
185
+ return true;
186
+ }
187
+
188
+ function setExportFee(address addr, uint256 fee) onlyOwner {
189
+ require(addr != 0x00000000000000000000000000000000000000ff);
190
+ exportFee[addr] = fee;
191
+ }
192
+
193
+ function setHoldingPeriod(uint256 ts) onlyOwner {
194
+ mustHoldFor = ts;
195
+ }
196
+
197
+
198
+ /* --------------- fee calculation method ---------------- */
199
+
200
+ /**
201
+ * @notice 'Returns the fee for a transfer from `from` to `to` on an amount `amount`.
202
+ *
203
+ * Fee's consist of a possible
204
+ * - import fee on transfers to an address
205
+ * - export fee on transfers from an address
206
+ * IDXM ownership on an address
207
+ * - reduces fee on a transfer from this address to an import fee-ed address
208
+ * - reduces the fee on a transfer to this address from an export fee-ed address
209
+ * IDXM discount does not work for addresses that have an import fee or export fee set up against them.
210
+ *
211
+ * IDXM discount goes up to 100%
212
+ *
213
+ * @param from From address
214
+ * @param to To address
215
+ * @param amount Amount for which fee needs to be calculated.
216
+ *
217
+ */
218
+ function feeFor(address from, address to, uint256 amount) constant external returns (uint256 value) {
219
+ uint256 fee = exportFee[from];
220
+ if (fee == 0) return 0;
221
+ uint256 amountHeld;
222
+ if (balanceOf[to] != 0) {
223
+ if (validAfter[to].ts + mustHoldFor < now) amountHeld = balanceOf[to];
224
+ else amountHeld = validAfter[to].last;
225
+ if (amountHeld >= singleIDXMQty) return 0;
226
+ return amount*fee*(singleIDXMQty - amountHeld) / feeDivisor;
227
+ } else return amount*fee / baseFeeDivisor;
228
+ }
229
+
230
+ bool public locked = true;
231
+
232
+ function unlockToken() onlyOwner {
233
+ locked = false;
234
+ }
235
+
236
+ function precalculate() internal returns (bool success) {
237
+ baseFeeDivisor = pow10(1, feeDecimals);
238
+ feeDivisor = pow10(1, feeDecimals + decimals);
239
+ singleIDXMQty = pow10(1, decimals);
240
+ }
241
+ function div10(uint256 a, uint8 b) internal returns (uint256 result) {
242
+ for (uint8 i = 0; i < b; i++) {
243
+ a /= 10;
244
+ }
245
+ return a;
246
+ }
247
+ function pow10(uint256 a, uint8 b) internal returns (uint256 result) {
248
+ for (uint8 i = 0; i < b; i++) {
249
+ a *= 10;
250
+ }
251
+ return a;
252
+ }
253
+ }
data_full/CVE/2018-10705.sol ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-01-17
3
+ */
4
+
5
+ pragma solidity ^0.4.19;
6
+
7
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
8
+
9
+ contract SafeMath {
10
+ function safeMul(uint256 a, uint256 b) returns (uint256) {
11
+ uint256 c = a * b;
12
+ require(a == 0 || c / a == b);
13
+ return c;
14
+ }
15
+ function safeSub(uint256 a, uint256 b) returns (uint256) {
16
+ require(b <= a);
17
+ return a - b;
18
+ }
19
+ function safeAdd(uint256 a, uint256 b) returns (uint256) {
20
+ uint c = a + b;
21
+ require(c >= a && c >= b);
22
+ return c;
23
+ }
24
+ }
25
+
26
+ contract Owned {
27
+ address public owner;
28
+ function Owned() {
29
+ owner = msg.sender;
30
+ }
31
+ function setOwner(address _owner) returns (bool success) {
32
+ owner = _owner;
33
+ return true;
34
+ }
35
+ modifier onlyOwner {
36
+ require(msg.sender == owner);
37
+ _;
38
+ }
39
+ }
40
+
41
+ contract AURA is SafeMath, Owned {
42
+ bool public locked = true;
43
+ string public name = "Aurora DAO";
44
+ string public symbol = "AURA";
45
+ uint8 public decimals = 18;
46
+ uint256 public totalSupply;
47
+ mapping (address => uint256) public balanceOf;
48
+ mapping (address => mapping (address => uint256)) public allowance;
49
+
50
+ event Transfer(address indexed from, address indexed to, uint256 value);
51
+
52
+ /**
53
+ * Constructor function
54
+ *
55
+ * Initializes contract with initial supply tokens to the creator of the contract
56
+ */
57
+ function AURA() public {
58
+ totalSupply = 1000000000000000000000000000;
59
+ balanceOf[msg.sender] = totalSupply;
60
+ }
61
+
62
+ /**
63
+ * Internal transfer, only can be called by this contract
64
+ */
65
+ function _transfer(address _from, address _to, uint _value) internal {
66
+ require(!locked || msg.sender == owner);
67
+ require(_to != 0x0);
68
+ require(balanceOf[_from] >= _value);
69
+ require(balanceOf[_to] + _value > balanceOf[_to]);
70
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
71
+ balanceOf[_from] -= _value;
72
+ balanceOf[_to] += _value;
73
+ Transfer(_from, _to, _value);
74
+ require(balanceOf[_from] + balanceOf[_to] == previousBalances);
75
+ }
76
+
77
+ /**
78
+ * Transfer tokens
79
+ *
80
+ * Send `_value` tokens to `_to` from your account
81
+ *
82
+ * @param _to The address of the recipient
83
+ * @param _value the amount to send
84
+ */
85
+ function transfer(address _to, uint256 _value) public returns (bool success) {
86
+ _transfer(msg.sender, _to, _value);
87
+ return true;
88
+ }
89
+
90
+ /**
91
+ * Transfer tokens from other address
92
+ *
93
+ * Send `_value` tokens to `_to` in behalf of `_from`
94
+ *
95
+ * @param _from The address of the sender
96
+ * @param _to The address of the recipient
97
+ * @param _value the amount to send
98
+ */
99
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
100
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
101
+ allowance[_from][msg.sender] -= _value;
102
+ _transfer(_from, _to, _value);
103
+ return true;
104
+ }
105
+
106
+ /**
107
+ * Set allowance for other address
108
+ *
109
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
110
+ *
111
+ * @param _spender The address authorized to spend
112
+ * @param _value the max amount they can spend
113
+ */
114
+ function approve(address _spender, uint256 _value) public
115
+ returns (bool success) {
116
+ require(!locked);
117
+ allowance[msg.sender][_spender] = _value;
118
+ return true;
119
+ }
120
+
121
+ /**
122
+ * Set allowance for other address and notify
123
+ *
124
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
125
+ *
126
+ * @param _spender The address authorized to spend
127
+ * @param _value the max amount they can spend
128
+ * @param _extraData some extra information to send to the approved contract
129
+ */
130
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
131
+ public
132
+ returns (bool success) {
133
+ tokenRecipient spender = tokenRecipient(_spender);
134
+ if (approve(_spender, _value)) {
135
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
136
+ return true;
137
+ }
138
+ }
139
+
140
+ function unlockToken() onlyOwner {
141
+ locked = false;
142
+ }
143
+
144
+ bool public balancesUploaded = false;
145
+ function uploadBalances(address[] recipients, uint256[] balances) onlyOwner {
146
+ require(!balancesUploaded);
147
+ uint256 sum = 0;
148
+ for (uint256 i = 0; i < recipients.length; i++) {
149
+ balanceOf[recipients[i]] = safeAdd(balanceOf[recipients[i]], balances[i]);
150
+ sum = safeAdd(sum, balances[i]);
151
+ }
152
+ balanceOf[owner] = safeSub(balanceOf[owner], sum);
153
+ }
154
+ function lockBalances() onlyOwner {
155
+ balancesUploaded = true;
156
+ }
157
+ }
data_full/CVE/2018-10706.sol ADDED
@@ -0,0 +1,404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.18;
2
+
3
+ contract ApproveAndCallReceiver {
4
+ function receiveApproval(
5
+ address _from,
6
+ uint256 _amount,
7
+ address _token,
8
+ bytes _data
9
+ ) public;
10
+ }
11
+
12
+ //normal contract. already compiled as bin
13
+ contract Controlled {
14
+ modifier onlyController {
15
+ require(msg.sender == controller);
16
+ _;
17
+ }
18
+ address public controller;
19
+
20
+ function Controlled() public {
21
+ controller = msg.sender;
22
+ }
23
+
24
+ function changeController(address _newController) onlyController public {
25
+ controller = _newController;
26
+ }
27
+ }
28
+
29
+
30
+ contract ERC20Token {
31
+
32
+ /// total amount of tokens
33
+ uint256 public totalSupply;
34
+ //function totalSupply() public constant returns (uint256 balance);
35
+
36
+ /// @param _owner The address from which the balance will be retrieved
37
+ /// @return The balance
38
+ mapping (address => uint256) public balanceOf;
39
+
40
+ // function balanceOf(address _owner) public constant returns (uint256 balance);
41
+
42
+ /// @notice send `_value` token to `_to` from `msg.sender`
43
+ /// @param _to The address of the recipient
44
+ /// @param _value The amount of token to be transferred
45
+ /// @return Whether the transfer was successful or not
46
+ function transfer(address _to, uint256 _value) public returns (bool success);
47
+
48
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
49
+ /// @param _from The address of the sender
50
+ /// @param _to The address of the recipient
51
+ /// @param _value The amount of token to be transferred
52
+ /// @return Whether the transfer was successful or not
53
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
54
+
55
+ /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
56
+ /// @param _spender The address of the account able to transfer the tokens
57
+ /// @param _value The amount of tokens to be approved for transfer
58
+ /// @return Whether the approval was successful or not
59
+ function approve(address _spender, uint256 _value) public returns (bool success);
60
+
61
+ /// @param _owner The address of the account owning tokens
62
+ /// @param _spender The address of the account able to transfer the tokens
63
+ /// @return Amount of remaining tokens allowed to spent
64
+ mapping (address => mapping (address => uint256)) public allowance;
65
+ //function allowance(address _owner, address _spender) public constant returns (uint256 remaining);
66
+
67
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
68
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
69
+ }
70
+
71
+ contract TokenI is ERC20Token, Controlled {
72
+
73
+ string public name; //The Token's name: e.g. DigixDAO Tokens
74
+ uint8 public decimals; //Number of decimals of the smallest unit
75
+ string public symbol; //An identifier: e.g. REP
76
+
77
+
78
+ // ERC20 Methods
79
+
80
+ /// @notice `msg.sender` approves `_spender` to send `_amount` tokens on
81
+ /// its behalf, and then a function is triggered in the contract that is
82
+ /// being approved, `_spender`. This allows users to use their tokens to
83
+ /// interact with contracts in one function call instead of two
84
+ /// @param _spender The address of the contract able to transfer the tokens
85
+ /// @param _amount The amount of tokens to be approved for transfer
86
+ /// @return True if the function call was successful
87
+ function approveAndCall(
88
+ address _spender,
89
+ uint256 _amount,
90
+ bytes _extraData
91
+ ) public returns (bool success);
92
+
93
+
94
+ // Generate and destroy tokens
95
+
96
+ /// @notice Generates `_amount` tokens that are assigned to `_owner`
97
+ /// @param _owner The address that will be assigned the new tokens
98
+ /// @param _amount The quantity of tokens generated
99
+ /// @return True if the tokens are generated correctly
100
+ function generateTokens(address _owner, uint _amount) public returns (bool);
101
+
102
+
103
+ /// @notice Burns `_amount` tokens from `_owner`
104
+ /// @param _owner The address that will lose the tokens
105
+ /// @param _amount The quantity of tokens to burn
106
+ /// @return True if the tokens are burned correctly
107
+ function destroyTokens(address _owner, uint _amount) public returns (bool);
108
+
109
+ }
110
+
111
+ contract Token is TokenI {
112
+
113
+ struct FreezeInfo {
114
+ address user;
115
+ uint256 amount;
116
+ }
117
+ //Key1: step(募资阶段); Key2: user sequence(用户序列)
118
+ mapping (uint8 => mapping (uint8 => FreezeInfo)) public freezeOf; //所有锁仓,key 使用序号向上增加,方便程序查询。
119
+ mapping (uint8 => uint8) public lastFreezeSeq; //最后的 freezeOf 键值。key: step; value: sequence
120
+ mapping (address => uint256) public airdropOf;//空投用户
121
+
122
+ address public owner;
123
+ bool public paused=false;//是否暂停私募
124
+ uint256 public minFunding = 1 ether; //最低起投额度
125
+ uint256 public airdropQty=0;//每个账户空投获得的量
126
+ uint256 public airdropTotalQty=0;//总共发放的���投代币数量
127
+ uint256 public tokensPerEther = 10000;//1eth兑换多少代币
128
+ address private vaultAddress;//存储众筹ETH的地址
129
+ uint256 public totalCollected = 0;//已经募到ETH的总数量
130
+
131
+ /* This generates a public event on the blockchain that will notify clients */
132
+ //event Transfer(address indexed from, address indexed to, uint256 value);
133
+
134
+ /* This notifies clients about the amount burnt */
135
+ event Burn(address indexed from, uint256 value);
136
+
137
+ /* This notifies clients about the amount frozen */
138
+ event Freeze(address indexed from, uint256 value);
139
+
140
+ /* This notifies clients about the amount unfrozen */
141
+ event Unfreeze(address indexed from, uint256 value);
142
+
143
+ event Payment(address sender, uint256 _ethAmount, uint256 _tokenAmount);
144
+
145
+ /* Initializes contract with initial supply tokens to the creator of the contract */
146
+ function Token(
147
+ uint256 initialSupply,
148
+ string tokenName,
149
+ uint8 decimalUnits,
150
+ string tokenSymbol,
151
+ address _vaultAddress
152
+ ) public {
153
+ require(_vaultAddress != 0);
154
+ totalSupply = initialSupply * 10 ** uint256(decimalUnits);
155
+ balanceOf[msg.sender] = totalSupply;
156
+ name = tokenName;
157
+ symbol = tokenSymbol;
158
+ decimals = decimalUnits;
159
+ owner = msg.sender;
160
+ vaultAddress=_vaultAddress;
161
+ }
162
+
163
+ modifier onlyOwner() {
164
+ require(msg.sender == owner);
165
+ _;
166
+ }
167
+
168
+ modifier realUser(address user){
169
+ if(user == 0x0){
170
+ revert();
171
+ }
172
+ _;
173
+ }
174
+
175
+ modifier moreThanZero(uint256 _value){
176
+ if (_value <= 0){
177
+ revert();
178
+ }
179
+ _;
180
+ }
181
+
182
+ /// @dev Internal function to determine if an address is a contract
183
+ /// @param _addr The address being queried
184
+ /// @return True if `_addr` is a contract
185
+ function isContract(address _addr) constant internal returns(bool) {
186
+ uint size;
187
+ if (_addr == 0) {
188
+ return false;
189
+ }
190
+ assembly {
191
+ size := extcodesize(_addr)
192
+ }
193
+ return size>0;
194
+ }
195
+
196
+ /* Send coins */
197
+ function transfer(address _to, uint256 _value) realUser(_to) moreThanZero(_value) public returns (bool) {
198
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
199
+ require(balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
200
+ balanceOf[msg.sender] = balanceOf[msg.sender] - _value; // Subtract from the sender
201
+ balanceOf[_to] = balanceOf[_to] + _value; // Add the same to the recipient
202
+ emit Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
203
+ return true;
204
+ }
205
+
206
+ /* Allow another contract to spend some tokens in your behalf */
207
+ function approve(address _spender, uint256 _value) moreThanZero(_value) public
208
+ returns (bool success) {
209
+ allowance[msg.sender][_spender] = _value;
210
+ return true;
211
+ }
212
+
213
+ /**
214
+ * @notice `msg.sender` approves `_spender` to send `_amount` tokens on
215
+ * its behalf, and then a function is triggered in the contract that is
216
+ * being approved, `_spender`. This allows users to use their tokens to
217
+ * interact with contracts in one function call instead of two
218
+ * @param _spender The address of the contract able to transfer the tokens
219
+ * @param _amount The amount of tokens to be approved for transfer
220
+ * @return True if the function call was successful
221
+ */
222
+ function approveAndCall(address _spender, uint256 _amount, bytes _extraData) public returns (bool success) {
223
+ require(approve(_spender, _amount));
224
+ ApproveAndCallReceiver(_spender).receiveApproval(
225
+ msg.sender,
226
+ _amount,
227
+ this,
228
+ _extraData
229
+ );
230
+
231
+ return true;
232
+ }
233
+
234
+ /* A contract attempts to get the coins */
235
+ function transferFrom(address _from, address _to, uint256 _value) realUser(_from) realUser(_to) moreThanZero(_value) public returns (bool success) {
236
+ require(balanceOf[_from] >= _value); // Check if the sender has enough
237
+ require(balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
238
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
239
+ balanceOf[_from] = balanceOf[_from] - _value; // Subtract from the sender
240
+ balanceOf[_to] = balanceOf[_to] + _value; // Add the same to the recipient
241
+ allowance[_from][msg.sender] = allowance[_from][msg.sender] + _value;
242
+ emit Transfer(_from, _to, _value);
243
+ return true;
244
+ }
245
+
246
+ function transferMulti(address[] _to, uint256[] _value) public returns (uint256 amount){
247
+ require(_to.length == _value.length);
248
+ uint8 len = uint8(_to.length);
249
+ for(uint8 j; j<len; j++){
250
+ amount += _value[j]*10**uint256(decimals);
251
+ }
252
+ require(balanceOf[msg.sender] >= amount);
253
+ for(uint8 i; i<len; i++){
254
+ address _toI = _to[i];
255
+ uint256 _valueI = _value[i]*10**uint256(decimals);
256
+ balanceOf[_toI] += _valueI;
257
+ balanceOf[msg.sender] -= _valueI;
258
+ emit Transfer(msg.sender, _toI, _valueI);
259
+ }
260
+ }
261
+
262
+ //冻结账户
263
+ function freeze(address _user, uint256 _value, uint8 _step) moreThanZero(_value) onlyController public returns (bool success) {
264
+ _value=_value*10**uint256(decimals);
265
+ return _freeze(_user,_value,_step);
266
+ }
267
+
268
+ function _freeze(address _user, uint256 _value, uint8 _step) moreThanZero(_value) private returns (bool success) {
269
+ //info256("balanceOf[_user]", balanceOf[_user]);
270
+ require(balanceOf[_user] >= _value);
271
+ balanceOf[_user] = balanceOf[_user] - _value;
272
+ freezeOf[_step][lastFreezeSeq[_step]] = FreezeInfo({user:_user, amount:_value});
273
+ lastFreezeSeq[_step]++;
274
+ emit Freeze(_user, _value);
275
+ return true;
276
+ }
277
+
278
+
279
+ //为用户解锁账户资金
280
+ function unFreeze(uint8 _step) onlyOwner public returns (bool unlockOver) {
281
+ //_end = length of freezeOf[_step]
282
+ uint8 _end = lastFreezeSeq[_step];
283
+ require(_end > 0);
284
+ unlockOver=false;
285
+ uint8 _start=0;
286
+ for(; _end>_start; _end--){
287
+ FreezeInfo storage fInfo = freezeOf[_step][_end-1];
288
+ uint256 _amount = fInfo.amount;
289
+ balanceOf[fInfo.user] += _amount;
290
+ delete freezeOf[_step][_end-1];
291
+ lastFreezeSeq[_step]--;
292
+ emit Unfreeze(fInfo.user, _amount);
293
+ }
294
+ }
295
+
296
+
297
+ ////////////////
298
+ // Generate and destroy tokens
299
+ ////////////////
300
+
301
+ /// @notice Generates `_amount` tokens that are assigned to `_owner`
302
+ /// @param _user The address that will be assigned the new tokens
303
+ /// @param _amount The quantity of tokens generated
304
+ /// @return True if the tokens are generated correctly
305
+ function generateTokens(address _user, uint _amount) onlyController public returns (bool) {
306
+ _amount=_amount*10**uint256(decimals);
307
+ return _generateTokens(_user,_amount);
308
+ }
309
+
310
+ function _generateTokens(address _user, uint _amount) private returns (bool) {
311
+ require(balanceOf[owner] >= _amount);
312
+ balanceOf[_user] += _amount;
313
+ balanceOf[owner] -= _amount;
314
+ emit Transfer(0, _user, _amount);
315
+ return true;
316
+ }
317
+
318
+ /// @notice Burns `_amount` tokens from `_owner`
319
+ /// @param _user The address that will lose the tokens
320
+ /// @param _amount The quantity of tokens to burn
321
+ /// @return True if the tokens are burned correctly
322
+ function destroyTokens(address _user, uint256 _amount) onlyOwner public returns (bool) {
323
+ _amount=_amount*10**uint256(decimals);
324
+ return _destroyTokens(_user,_amount);
325
+ }
326
+
327
+ function _destroyTokens(address _user, uint256 _amount) private returns (bool) {
328
+ require(balanceOf[_user] >= _amount);
329
+ balanceOf[owner] += _amount;
330
+ balanceOf[_user] -= _amount;
331
+ emit Transfer(_user, 0, _amount);
332
+ emit Burn(_user, _amount);
333
+ return true;
334
+ }
335
+
336
+
337
+ function changeOwner(address newOwner) onlyOwner public returns (bool) {
338
+ balanceOf[newOwner] += balanceOf[owner];
339
+ balanceOf[owner] = 0;
340
+ owner = newOwner;
341
+ return true;
342
+ }
343
+
344
+
345
+ /**
346
+ * 修改token兑换比率,1eth兑换多少代币
347
+ */
348
+ function changeTokensPerEther(uint256 _newRate) onlyController public {
349
+ tokensPerEther = _newRate;
350
+ }
351
+
352
+ /**
353
+ * 修改每个账户可获得的空投量
354
+ */
355
+ function changeAirdropQty(uint256 _airdropQty) onlyController public {
356
+ airdropQty = _airdropQty;
357
+ }
358
+
359
+ /**
360
+ * 修改空投总量
361
+ */
362
+ function changeAirdropTotalQty(uint256 _airdropTotalQty) onlyController public {
363
+ uint256 _token =_airdropTotalQty*10**uint256(decimals);
364
+ require(balanceOf[owner] >= _token);
365
+ airdropTotalQty = _airdropTotalQty;
366
+ }
367
+
368
+ ////////////////
369
+ // 修是否暂停私募
370
+ ////////////////
371
+ function changePaused(bool _paused) onlyController public {
372
+ paused = _paused;
373
+ }
374
+
375
+ //accept ether
376
+ function() payable public {
377
+ require(!paused);
378
+ address _user=msg.sender;
379
+ uint256 tokenValue;
380
+ if(msg.value==0){//空投
381
+ require(airdropQty>0);
382
+ require(airdropTotalQty>=airdropQty);
383
+ require(airdropOf[_user]==0);
384
+ tokenValue=airdropQty*10**uint256(decimals);
385
+ airdropOf[_user]=tokenValue;
386
+ airdropTotalQty-=airdropQty;
387
+ require(_generateTokens(_user, tokenValue));
388
+ emit Payment(_user, msg.value, tokenValue);
389
+ }else{
390
+ require(msg.value >= minFunding);//最低起投
391
+ require(msg.value % 1 ether==0);//只能投整数倍eth
392
+ totalCollected +=msg.value;
393
+ require(vaultAddress.send(msg.value));//Send the ether to the vault
394
+ tokenValue = (msg.value/1 ether)*(tokensPerEther*10 ** uint256(decimals));
395
+ require(_generateTokens(_user, tokenValue));
396
+ uint256 lock1 = tokenValue / 5;
397
+ require(_freeze(_user, lock1, 0));
398
+ _freeze(_user, lock1, 1);
399
+ _freeze(_user, lock1, 2);
400
+ _freeze(_user, lock1, 3);
401
+ emit Payment(_user, msg.value, tokenValue);
402
+ }
403
+ }
404
+ }
data_full/CVE/2018-10944.sol ADDED
@@ -0,0 +1,1344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-01
3
+ */
4
+
5
+ pragma solidity ^0.4.8;
6
+
7
+
8
+
9
+ // <ORACLIZE_API>
10
+ /*
11
+ Copyright (c) 2015-2016 Oraclize SRL
12
+ Copyright (c) 2016 Oraclize LTD
13
+
14
+
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ of this software and associated documentation files (the "Software"), to deal
18
+ in the Software without restriction, including without limitation the rights
19
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ copies of the Software, and to permit persons to whom the Software is
21
+ furnished to do so, subject to the following conditions:
22
+
23
+
24
+
25
+ The above copyright notice and this permission notice shall be included in
26
+ all copies or substantial portions of the Software.
27
+
28
+
29
+
30
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36
+ THE SOFTWARE.
37
+ */
38
+
39
+
40
+
41
+ contract OraclizeI {
42
+ address public cbAddress;
43
+ function query(uint _timestamp, string _datasource, string _arg) payable returns (bytes32 _id);
44
+ function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) payable returns (bytes32 _id);
45
+ function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) payable returns (bytes32 _id);
46
+ function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit) payable returns (bytes32 _id);
47
+ function queryN(uint _timestamp, string _datasource, bytes _argN) payable returns (bytes32 _id);
48
+ function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) payable returns (bytes32 _id);
49
+ function getPrice(string _datasource) returns (uint _dsprice);
50
+ function getPrice(string _datasource, uint gaslimit) returns (uint _dsprice);
51
+ function useCoupon(string _coupon);
52
+ function setProofType(byte _proofType);
53
+ function setConfig(bytes32 _config);
54
+ function setCustomGasPrice(uint _gasPrice);
55
+ function randomDS_getSessionPubKeyHash() returns(bytes32);
56
+ }
57
+ contract OraclizeAddrResolverI {
58
+ function getAddress() returns (address _addr);
59
+ }
60
+ contract usingOraclize {
61
+ uint constant day = 60*60*24;
62
+ uint constant week = 60*60*24*7;
63
+ uint constant month = 60*60*24*30;
64
+ byte constant proofType_NONE = 0x00;
65
+ byte constant proofType_TLSNotary = 0x10;
66
+ byte constant proofType_Android = 0x20;
67
+ byte constant proofType_Ledger = 0x30;
68
+ byte constant proofType_Native = 0xF0;
69
+ byte constant proofStorage_IPFS = 0x01;
70
+ uint8 constant networkID_auto = 0;
71
+ uint8 constant networkID_mainnet = 1;
72
+ uint8 constant networkID_testnet = 2;
73
+ uint8 constant networkID_morden = 2;
74
+ uint8 constant networkID_consensys = 161;
75
+
76
+ OraclizeAddrResolverI OAR;
77
+
78
+ OraclizeI oraclize;
79
+ modifier oraclizeAPI {
80
+ if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto);
81
+ oraclize = OraclizeI(OAR.getAddress());
82
+ _;
83
+ }
84
+ modifier coupon(string code){
85
+ oraclize = OraclizeI(OAR.getAddress());
86
+ oraclize.useCoupon(code);
87
+ _;
88
+ }
89
+
90
+ function oraclize_setNetwork(uint8 networkID) internal returns(bool){
91
+ if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet
92
+ OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed);
93
+ oraclize_setNetworkName("eth_mainnet");
94
+ return true;
95
+ }
96
+ if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet
97
+ OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1);
98
+ oraclize_setNetworkName("eth_ropsten3");
99
+ return true;
100
+ }
101
+ if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet
102
+ OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e);
103
+ oraclize_setNetworkName("eth_kovan");
104
+ return true;
105
+ }
106
+ if (getCodeSize(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48)>0){ //rinkeby testnet
107
+ OAR = OraclizeAddrResolverI(0x146500cfd35B22E4A392Fe0aDc06De1a1368Ed48);
108
+ oraclize_setNetworkName("eth_rinkeby");
109
+ return true;
110
+ }
111
+ if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge
112
+ OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);
113
+ return true;
114
+ }
115
+ if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide
116
+ OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF);
117
+ return true;
118
+ }
119
+ if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity
120
+ OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA);
121
+ return true;
122
+ }
123
+ return false;
124
+ }
125
+
126
+ function __callback(bytes32 myid, string result) {
127
+ __callback(myid, result, new bytes(0));
128
+ }
129
+ function __callback(bytes32 myid, string result, bytes proof) {
130
+ }
131
+
132
+ function oraclize_useCoupon(string code) oraclizeAPI internal {
133
+ oraclize.useCoupon(code);
134
+ }
135
+
136
+ function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){
137
+ return oraclize.getPrice(datasource);
138
+ }
139
+
140
+ function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){
141
+ return oraclize.getPrice(datasource, gaslimit);
142
+ }
143
+
144
+ function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
145
+ uint price = oraclize.getPrice(datasource);
146
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
147
+ return oraclize.query.value(price)(0, datasource, arg);
148
+ }
149
+ function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
150
+ uint price = oraclize.getPrice(datasource);
151
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
152
+ return oraclize.query.value(price)(timestamp, datasource, arg);
153
+ }
154
+ function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
155
+ uint price = oraclize.getPrice(datasource, gaslimit);
156
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
157
+ return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit);
158
+ }
159
+ function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
160
+ uint price = oraclize.getPrice(datasource, gaslimit);
161
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
162
+ return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit);
163
+ }
164
+ function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
165
+ uint price = oraclize.getPrice(datasource);
166
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
167
+ return oraclize.query2.value(price)(0, datasource, arg1, arg2);
168
+ }
169
+ function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
170
+ uint price = oraclize.getPrice(datasource);
171
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
172
+ return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2);
173
+ }
174
+ function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
175
+ uint price = oraclize.getPrice(datasource, gaslimit);
176
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
177
+ return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit);
178
+ }
179
+ function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
180
+ uint price = oraclize.getPrice(datasource, gaslimit);
181
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
182
+ return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit);
183
+ }
184
+ function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){
185
+ uint price = oraclize.getPrice(datasource);
186
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
187
+ bytes memory args = stra2cbor(argN);
188
+ return oraclize.queryN.value(price)(0, datasource, args);
189
+ }
190
+ function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){
191
+ uint price = oraclize.getPrice(datasource);
192
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
193
+ bytes memory args = stra2cbor(argN);
194
+ return oraclize.queryN.value(price)(timestamp, datasource, args);
195
+ }
196
+ function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
197
+ uint price = oraclize.getPrice(datasource, gaslimit);
198
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
199
+ bytes memory args = stra2cbor(argN);
200
+ return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit);
201
+ }
202
+ function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
203
+ uint price = oraclize.getPrice(datasource, gaslimit);
204
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
205
+ bytes memory args = stra2cbor(argN);
206
+ return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit);
207
+ }
208
+ function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) {
209
+ string[] memory dynargs = new string[](1);
210
+ dynargs[0] = args[0];
211
+ return oraclize_query(datasource, dynargs);
212
+ }
213
+ function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) {
214
+ string[] memory dynargs = new string[](1);
215
+ dynargs[0] = args[0];
216
+ return oraclize_query(timestamp, datasource, dynargs);
217
+ }
218
+ function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
219
+ string[] memory dynargs = new string[](1);
220
+ dynargs[0] = args[0];
221
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
222
+ }
223
+ function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
224
+ string[] memory dynargs = new string[](1);
225
+ dynargs[0] = args[0];
226
+ return oraclize_query(datasource, dynargs, gaslimit);
227
+ }
228
+
229
+ function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) {
230
+ string[] memory dynargs = new string[](2);
231
+ dynargs[0] = args[0];
232
+ dynargs[1] = args[1];
233
+ return oraclize_query(datasource, dynargs);
234
+ }
235
+ function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) {
236
+ string[] memory dynargs = new string[](2);
237
+ dynargs[0] = args[0];
238
+ dynargs[1] = args[1];
239
+ return oraclize_query(timestamp, datasource, dynargs);
240
+ }
241
+ function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
242
+ string[] memory dynargs = new string[](2);
243
+ dynargs[0] = args[0];
244
+ dynargs[1] = args[1];
245
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
246
+ }
247
+ function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
248
+ string[] memory dynargs = new string[](2);
249
+ dynargs[0] = args[0];
250
+ dynargs[1] = args[1];
251
+ return oraclize_query(datasource, dynargs, gaslimit);
252
+ }
253
+ function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) {
254
+ string[] memory dynargs = new string[](3);
255
+ dynargs[0] = args[0];
256
+ dynargs[1] = args[1];
257
+ dynargs[2] = args[2];
258
+ return oraclize_query(datasource, dynargs);
259
+ }
260
+ function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) {
261
+ string[] memory dynargs = new string[](3);
262
+ dynargs[0] = args[0];
263
+ dynargs[1] = args[1];
264
+ dynargs[2] = args[2];
265
+ return oraclize_query(timestamp, datasource, dynargs);
266
+ }
267
+ function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
268
+ string[] memory dynargs = new string[](3);
269
+ dynargs[0] = args[0];
270
+ dynargs[1] = args[1];
271
+ dynargs[2] = args[2];
272
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
273
+ }
274
+ function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
275
+ string[] memory dynargs = new string[](3);
276
+ dynargs[0] = args[0];
277
+ dynargs[1] = args[1];
278
+ dynargs[2] = args[2];
279
+ return oraclize_query(datasource, dynargs, gaslimit);
280
+ }
281
+
282
+ function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) {
283
+ string[] memory dynargs = new string[](4);
284
+ dynargs[0] = args[0];
285
+ dynargs[1] = args[1];
286
+ dynargs[2] = args[2];
287
+ dynargs[3] = args[3];
288
+ return oraclize_query(datasource, dynargs);
289
+ }
290
+ function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) {
291
+ string[] memory dynargs = new string[](4);
292
+ dynargs[0] = args[0];
293
+ dynargs[1] = args[1];
294
+ dynargs[2] = args[2];
295
+ dynargs[3] = args[3];
296
+ return oraclize_query(timestamp, datasource, dynargs);
297
+ }
298
+ function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
299
+ string[] memory dynargs = new string[](4);
300
+ dynargs[0] = args[0];
301
+ dynargs[1] = args[1];
302
+ dynargs[2] = args[2];
303
+ dynargs[3] = args[3];
304
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
305
+ }
306
+ function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
307
+ string[] memory dynargs = new string[](4);
308
+ dynargs[0] = args[0];
309
+ dynargs[1] = args[1];
310
+ dynargs[2] = args[2];
311
+ dynargs[3] = args[3];
312
+ return oraclize_query(datasource, dynargs, gaslimit);
313
+ }
314
+ function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) {
315
+ string[] memory dynargs = new string[](5);
316
+ dynargs[0] = args[0];
317
+ dynargs[1] = args[1];
318
+ dynargs[2] = args[2];
319
+ dynargs[3] = args[3];
320
+ dynargs[4] = args[4];
321
+ return oraclize_query(datasource, dynargs);
322
+ }
323
+ function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) {
324
+ string[] memory dynargs = new string[](5);
325
+ dynargs[0] = args[0];
326
+ dynargs[1] = args[1];
327
+ dynargs[2] = args[2];
328
+ dynargs[3] = args[3];
329
+ dynargs[4] = args[4];
330
+ return oraclize_query(timestamp, datasource, dynargs);
331
+ }
332
+ function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
333
+ string[] memory dynargs = new string[](5);
334
+ dynargs[0] = args[0];
335
+ dynargs[1] = args[1];
336
+ dynargs[2] = args[2];
337
+ dynargs[3] = args[3];
338
+ dynargs[4] = args[4];
339
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
340
+ }
341
+ function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
342
+ string[] memory dynargs = new string[](5);
343
+ dynargs[0] = args[0];
344
+ dynargs[1] = args[1];
345
+ dynargs[2] = args[2];
346
+ dynargs[3] = args[3];
347
+ dynargs[4] = args[4];
348
+ return oraclize_query(datasource, dynargs, gaslimit);
349
+ }
350
+ function oraclize_query(string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){
351
+ uint price = oraclize.getPrice(datasource);
352
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
353
+ bytes memory args = ba2cbor(argN);
354
+ return oraclize.queryN.value(price)(0, datasource, args);
355
+ }
356
+ function oraclize_query(uint timestamp, string datasource, bytes[] argN) oraclizeAPI internal returns (bytes32 id){
357
+ uint price = oraclize.getPrice(datasource);
358
+ if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
359
+ bytes memory args = ba2cbor(argN);
360
+ return oraclize.queryN.value(price)(timestamp, datasource, args);
361
+ }
362
+ function oraclize_query(uint timestamp, string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
363
+ uint price = oraclize.getPrice(datasource, gaslimit);
364
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
365
+ bytes memory args = ba2cbor(argN);
366
+ return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit);
367
+ }
368
+ function oraclize_query(string datasource, bytes[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
369
+ uint price = oraclize.getPrice(datasource, gaslimit);
370
+ if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
371
+ bytes memory args = ba2cbor(argN);
372
+ return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit);
373
+ }
374
+ function oraclize_query(string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) {
375
+ bytes[] memory dynargs = new bytes[](1);
376
+ dynargs[0] = args[0];
377
+ return oraclize_query(datasource, dynargs);
378
+ }
379
+ function oraclize_query(uint timestamp, string datasource, bytes[1] args) oraclizeAPI internal returns (bytes32 id) {
380
+ bytes[] memory dynargs = new bytes[](1);
381
+ dynargs[0] = args[0];
382
+ return oraclize_query(timestamp, datasource, dynargs);
383
+ }
384
+ function oraclize_query(uint timestamp, string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
385
+ bytes[] memory dynargs = new bytes[](1);
386
+ dynargs[0] = args[0];
387
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
388
+ }
389
+ function oraclize_query(string datasource, bytes[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
390
+ bytes[] memory dynargs = new bytes[](1);
391
+ dynargs[0] = args[0];
392
+ return oraclize_query(datasource, dynargs, gaslimit);
393
+ }
394
+
395
+ function oraclize_query(string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) {
396
+ bytes[] memory dynargs = new bytes[](2);
397
+ dynargs[0] = args[0];
398
+ dynargs[1] = args[1];
399
+ return oraclize_query(datasource, dynargs);
400
+ }
401
+ function oraclize_query(uint timestamp, string datasource, bytes[2] args) oraclizeAPI internal returns (bytes32 id) {
402
+ bytes[] memory dynargs = new bytes[](2);
403
+ dynargs[0] = args[0];
404
+ dynargs[1] = args[1];
405
+ return oraclize_query(timestamp, datasource, dynargs);
406
+ }
407
+ function oraclize_query(uint timestamp, string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
408
+ bytes[] memory dynargs = new bytes[](2);
409
+ dynargs[0] = args[0];
410
+ dynargs[1] = args[1];
411
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
412
+ }
413
+ function oraclize_query(string datasource, bytes[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
414
+ bytes[] memory dynargs = new bytes[](2);
415
+ dynargs[0] = args[0];
416
+ dynargs[1] = args[1];
417
+ return oraclize_query(datasource, dynargs, gaslimit);
418
+ }
419
+ function oraclize_query(string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) {
420
+ bytes[] memory dynargs = new bytes[](3);
421
+ dynargs[0] = args[0];
422
+ dynargs[1] = args[1];
423
+ dynargs[2] = args[2];
424
+ return oraclize_query(datasource, dynargs);
425
+ }
426
+ function oraclize_query(uint timestamp, string datasource, bytes[3] args) oraclizeAPI internal returns (bytes32 id) {
427
+ bytes[] memory dynargs = new bytes[](3);
428
+ dynargs[0] = args[0];
429
+ dynargs[1] = args[1];
430
+ dynargs[2] = args[2];
431
+ return oraclize_query(timestamp, datasource, dynargs);
432
+ }
433
+ function oraclize_query(uint timestamp, string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
434
+ bytes[] memory dynargs = new bytes[](3);
435
+ dynargs[0] = args[0];
436
+ dynargs[1] = args[1];
437
+ dynargs[2] = args[2];
438
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
439
+ }
440
+ function oraclize_query(string datasource, bytes[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
441
+ bytes[] memory dynargs = new bytes[](3);
442
+ dynargs[0] = args[0];
443
+ dynargs[1] = args[1];
444
+ dynargs[2] = args[2];
445
+ return oraclize_query(datasource, dynargs, gaslimit);
446
+ }
447
+
448
+ function oraclize_query(string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) {
449
+ bytes[] memory dynargs = new bytes[](4);
450
+ dynargs[0] = args[0];
451
+ dynargs[1] = args[1];
452
+ dynargs[2] = args[2];
453
+ dynargs[3] = args[3];
454
+ return oraclize_query(datasource, dynargs);
455
+ }
456
+ function oraclize_query(uint timestamp, string datasource, bytes[4] args) oraclizeAPI internal returns (bytes32 id) {
457
+ bytes[] memory dynargs = new bytes[](4);
458
+ dynargs[0] = args[0];
459
+ dynargs[1] = args[1];
460
+ dynargs[2] = args[2];
461
+ dynargs[3] = args[3];
462
+ return oraclize_query(timestamp, datasource, dynargs);
463
+ }
464
+ function oraclize_query(uint timestamp, string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
465
+ bytes[] memory dynargs = new bytes[](4);
466
+ dynargs[0] = args[0];
467
+ dynargs[1] = args[1];
468
+ dynargs[2] = args[2];
469
+ dynargs[3] = args[3];
470
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
471
+ }
472
+ function oraclize_query(string datasource, bytes[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
473
+ bytes[] memory dynargs = new bytes[](4);
474
+ dynargs[0] = args[0];
475
+ dynargs[1] = args[1];
476
+ dynargs[2] = args[2];
477
+ dynargs[3] = args[3];
478
+ return oraclize_query(datasource, dynargs, gaslimit);
479
+ }
480
+ function oraclize_query(string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) {
481
+ bytes[] memory dynargs = new bytes[](5);
482
+ dynargs[0] = args[0];
483
+ dynargs[1] = args[1];
484
+ dynargs[2] = args[2];
485
+ dynargs[3] = args[3];
486
+ dynargs[4] = args[4];
487
+ return oraclize_query(datasource, dynargs);
488
+ }
489
+ function oraclize_query(uint timestamp, string datasource, bytes[5] args) oraclizeAPI internal returns (bytes32 id) {
490
+ bytes[] memory dynargs = new bytes[](5);
491
+ dynargs[0] = args[0];
492
+ dynargs[1] = args[1];
493
+ dynargs[2] = args[2];
494
+ dynargs[3] = args[3];
495
+ dynargs[4] = args[4];
496
+ return oraclize_query(timestamp, datasource, dynargs);
497
+ }
498
+ function oraclize_query(uint timestamp, string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
499
+ bytes[] memory dynargs = new bytes[](5);
500
+ dynargs[0] = args[0];
501
+ dynargs[1] = args[1];
502
+ dynargs[2] = args[2];
503
+ dynargs[3] = args[3];
504
+ dynargs[4] = args[4];
505
+ return oraclize_query(timestamp, datasource, dynargs, gaslimit);
506
+ }
507
+ function oraclize_query(string datasource, bytes[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
508
+ bytes[] memory dynargs = new bytes[](5);
509
+ dynargs[0] = args[0];
510
+ dynargs[1] = args[1];
511
+ dynargs[2] = args[2];
512
+ dynargs[3] = args[3];
513
+ dynargs[4] = args[4];
514
+ return oraclize_query(datasource, dynargs, gaslimit);
515
+ }
516
+
517
+ function oraclize_cbAddress() oraclizeAPI internal returns (address){
518
+ return oraclize.cbAddress();
519
+ }
520
+ function oraclize_setProof(byte proofP) oraclizeAPI internal {
521
+ return oraclize.setProofType(proofP);
522
+ }
523
+ function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal {
524
+ return oraclize.setCustomGasPrice(gasPrice);
525
+ }
526
+ function oraclize_setConfig(bytes32 config) oraclizeAPI internal {
527
+ return oraclize.setConfig(config);
528
+ }
529
+
530
+ function oraclize_randomDS_getSessionPubKeyHash() oraclizeAPI internal returns (bytes32){
531
+ return oraclize.randomDS_getSessionPubKeyHash();
532
+ }
533
+
534
+ function getCodeSize(address _addr) constant internal returns(uint _size) {
535
+ assembly {
536
+ _size := extcodesize(_addr)
537
+ }
538
+ }
539
+
540
+ function parseAddr(string _a) internal returns (address){
541
+ bytes memory tmp = bytes(_a);
542
+ uint160 iaddr = 0;
543
+ uint160 b1;
544
+ uint160 b2;
545
+ for (uint i=2; i<2+2*20; i+=2){
546
+ iaddr *= 256;
547
+ b1 = uint160(tmp[i]);
548
+ b2 = uint160(tmp[i+1]);
549
+ if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87;
550
+ else if ((b1 >= 65)&&(b1 <= 70)) b1 -= 55;
551
+ else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48;
552
+ if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87;
553
+ else if ((b2 >= 65)&&(b2 <= 70)) b2 -= 55;
554
+ else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48;
555
+ iaddr += (b1*16+b2);
556
+ }
557
+ return address(iaddr);
558
+ }
559
+
560
+ function strCompare(string _a, string _b) internal returns (int) {
561
+ bytes memory a = bytes(_a);
562
+ bytes memory b = bytes(_b);
563
+ uint minLength = a.length;
564
+ if (b.length < minLength) minLength = b.length;
565
+ for (uint i = 0; i < minLength; i ++)
566
+ if (a[i] < b[i])
567
+ return -1;
568
+ else if (a[i] > b[i])
569
+ return 1;
570
+ if (a.length < b.length)
571
+ return -1;
572
+ else if (a.length > b.length)
573
+ return 1;
574
+ else
575
+ return 0;
576
+ }
577
+
578
+ function indexOf(string _haystack, string _needle) internal returns (int) {
579
+ bytes memory h = bytes(_haystack);
580
+ bytes memory n = bytes(_needle);
581
+ if(h.length < 1 || n.length < 1 || (n.length > h.length))
582
+ return -1;
583
+ else if(h.length > (2**128 -1))
584
+ return -1;
585
+ else
586
+ {
587
+ uint subindex = 0;
588
+ for (uint i = 0; i < h.length; i ++)
589
+ {
590
+ if (h[i] == n[0])
591
+ {
592
+ subindex = 1;
593
+ while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex])
594
+ {
595
+ subindex++;
596
+ }
597
+ if(subindex == n.length)
598
+ return int(i);
599
+ }
600
+ }
601
+ return -1;
602
+ }
603
+ }
604
+
605
+ function strConcat(string _a, string _b, string _c, string _d, string _e) internal returns (string) {
606
+ bytes memory _ba = bytes(_a);
607
+ bytes memory _bb = bytes(_b);
608
+ bytes memory _bc = bytes(_c);
609
+ bytes memory _bd = bytes(_d);
610
+ bytes memory _be = bytes(_e);
611
+ string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
612
+ bytes memory babcde = bytes(abcde);
613
+ uint k = 0;
614
+ for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
615
+ for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
616
+ for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
617
+ for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
618
+ for (i = 0; i < _be.length; i++) babcde[k++] = _be[i];
619
+ return string(babcde);
620
+ }
621
+
622
+ function strConcat(string _a, string _b, string _c, string _d) internal returns (string) {
623
+ return strConcat(_a, _b, _c, _d, "");
624
+ }
625
+
626
+ function strConcat(string _a, string _b, string _c) internal returns (string) {
627
+ return strConcat(_a, _b, _c, "", "");
628
+ }
629
+
630
+ function strConcat(string _a, string _b) internal returns (string) {
631
+ return strConcat(_a, _b, "", "", "");
632
+ }
633
+
634
+ // parseInt
635
+ function parseInt(string _a) internal returns (uint) {
636
+ return parseInt(_a, 0);
637
+ }
638
+
639
+ // parseInt(parseFloat*10^_b)
640
+ function parseInt(string _a, uint _b) internal returns (uint) {
641
+ bytes memory bresult = bytes(_a);
642
+ uint mint = 0;
643
+ bool decimals = false;
644
+ for (uint i=0; i<bresult.length; i++){
645
+ if ((bresult[i] >= 48)&&(bresult[i] <= 57)){
646
+ if (decimals){
647
+ if (_b == 0) break;
648
+ else _b--;
649
+ }
650
+ mint *= 10;
651
+ mint += uint(bresult[i]) - 48;
652
+ } else if (bresult[i] == 46) decimals = true;
653
+ }
654
+ if (_b > 0) mint *= 10**_b;
655
+ return mint;
656
+ }
657
+
658
+ function uint2str(uint i) internal returns (string){
659
+ if (i == 0) return "0";
660
+ uint j = i;
661
+ uint len;
662
+ while (j != 0){
663
+ len++;
664
+ j /= 10;
665
+ }
666
+ bytes memory bstr = new bytes(len);
667
+ uint k = len - 1;
668
+ while (i != 0){
669
+ bstr[k--] = byte(48 + i % 10);
670
+ i /= 10;
671
+ }
672
+ return string(bstr);
673
+ }
674
+
675
+ function stra2cbor(string[] arr) internal returns (bytes) {
676
+ uint arrlen = arr.length;
677
+
678
+ // get correct cbor output length
679
+ uint outputlen = 0;
680
+ bytes[] memory elemArray = new bytes[](arrlen);
681
+ for (uint i = 0; i < arrlen; i++) {
682
+ elemArray[i] = (bytes(arr[i]));
683
+ outputlen += elemArray[i].length + (elemArray[i].length - 1)/23 + 3; //+3 accounts for paired identifier types
684
+ }
685
+ uint ctr = 0;
686
+ uint cborlen = arrlen + 0x80;
687
+ outputlen += byte(cborlen).length;
688
+ bytes memory res = new bytes(outputlen);
689
+
690
+ while (byte(cborlen).length > ctr) {
691
+ res[ctr] = byte(cborlen)[ctr];
692
+ ctr++;
693
+ }
694
+ for (i = 0; i < arrlen; i++) {
695
+ res[ctr] = 0x5F;
696
+ ctr++;
697
+ for (uint x = 0; x < elemArray[i].length; x++) {
698
+ // if there's a bug with larger strings, this may be the culprit
699
+ if (x % 23 == 0) {
700
+ uint elemcborlen = elemArray[i].length - x >= 24 ? 23 : elemArray[i].length - x;
701
+ elemcborlen += 0x40;
702
+ uint lctr = ctr;
703
+ while (byte(elemcborlen).length > ctr - lctr) {
704
+ res[ctr] = byte(elemcborlen)[ctr - lctr];
705
+ ctr++;
706
+ }
707
+ }
708
+ res[ctr] = elemArray[i][x];
709
+ ctr++;
710
+ }
711
+ res[ctr] = 0xFF;
712
+ ctr++;
713
+ }
714
+ return res;
715
+ }
716
+
717
+ function ba2cbor(bytes[] arr) internal returns (bytes) {
718
+ uint arrlen = arr.length;
719
+
720
+ // get correct cbor output length
721
+ uint outputlen = 0;
722
+ bytes[] memory elemArray = new bytes[](arrlen);
723
+ for (uint i = 0; i < arrlen; i++) {
724
+ elemArray[i] = (bytes(arr[i]));
725
+ outputlen += elemArray[i].length + (elemArray[i].length - 1)/23 + 3; //+3 accounts for paired identifier types
726
+ }
727
+ uint ctr = 0;
728
+ uint cborlen = arrlen + 0x80;
729
+ outputlen += byte(cborlen).length;
730
+ bytes memory res = new bytes(outputlen);
731
+
732
+ while (byte(cborlen).length > ctr) {
733
+ res[ctr] = byte(cborlen)[ctr];
734
+ ctr++;
735
+ }
736
+ for (i = 0; i < arrlen; i++) {
737
+ res[ctr] = 0x5F;
738
+ ctr++;
739
+ for (uint x = 0; x < elemArray[i].length; x++) {
740
+ // if there's a bug with larger strings, this may be the culprit
741
+ if (x % 23 == 0) {
742
+ uint elemcborlen = elemArray[i].length - x >= 24 ? 23 : elemArray[i].length - x;
743
+ elemcborlen += 0x40;
744
+ uint lctr = ctr;
745
+ while (byte(elemcborlen).length > ctr - lctr) {
746
+ res[ctr] = byte(elemcborlen)[ctr - lctr];
747
+ ctr++;
748
+ }
749
+ }
750
+ res[ctr] = elemArray[i][x];
751
+ ctr++;
752
+ }
753
+ res[ctr] = 0xFF;
754
+ ctr++;
755
+ }
756
+ return res;
757
+ }
758
+
759
+
760
+ string oraclize_network_name;
761
+ function oraclize_setNetworkName(string _network_name) internal {
762
+ oraclize_network_name = _network_name;
763
+ }
764
+
765
+ function oraclize_getNetworkName() internal returns (string) {
766
+ return oraclize_network_name;
767
+ }
768
+
769
+ function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){
770
+ if ((_nbytes == 0)||(_nbytes > 32)) throw;
771
+ bytes memory nbytes = new bytes(1);
772
+ nbytes[0] = byte(_nbytes);
773
+ bytes memory unonce = new bytes(32);
774
+ bytes memory sessionKeyHash = new bytes(32);
775
+ bytes32 sessionKeyHash_bytes32 = oraclize_randomDS_getSessionPubKeyHash();
776
+ assembly {
777
+ mstore(unonce, 0x20)
778
+ mstore(add(unonce, 0x20), xor(blockhash(sub(number, 1)), xor(coinbase, timestamp)))
779
+ mstore(sessionKeyHash, 0x20)
780
+ mstore(add(sessionKeyHash, 0x20), sessionKeyHash_bytes32)
781
+ }
782
+ bytes[3] memory args = [unonce, nbytes, sessionKeyHash];
783
+ bytes32 queryId = oraclize_query(_delay, "random", args, _customGasLimit);
784
+ oraclize_randomDS_setCommitment(queryId, sha3(bytes8(_delay), args[1], sha256(args[0]), args[2]));
785
+ return queryId;
786
+ }
787
+
788
+ function oraclize_randomDS_setCommitment(bytes32 queryId, bytes32 commitment) internal {
789
+ oraclize_randomDS_args[queryId] = commitment;
790
+ }
791
+
792
+ mapping(bytes32=>bytes32) oraclize_randomDS_args;
793
+ mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified;
794
+
795
+ function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){
796
+ bool sigok;
797
+ address signer;
798
+
799
+ bytes32 sigr;
800
+ bytes32 sigs;
801
+
802
+ bytes memory sigr_ = new bytes(32);
803
+ uint offset = 4+(uint(dersig[3]) - 0x20);
804
+ sigr_ = copyBytes(dersig, offset, 32, sigr_, 0);
805
+ bytes memory sigs_ = new bytes(32);
806
+ offset += 32 + 2;
807
+ sigs_ = copyBytes(dersig, offset+(uint(dersig[offset-1]) - 0x20), 32, sigs_, 0);
808
+
809
+ assembly {
810
+ sigr := mload(add(sigr_, 32))
811
+ sigs := mload(add(sigs_, 32))
812
+ }
813
+
814
+
815
+ (sigok, signer) = safer_ecrecover(tosignh, 27, sigr, sigs);
816
+ if (address(sha3(pubkey)) == signer) return true;
817
+ else {
818
+ (sigok, signer) = safer_ecrecover(tosignh, 28, sigr, sigs);
819
+ return (address(sha3(pubkey)) == signer);
820
+ }
821
+ }
822
+
823
+ function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) {
824
+ bool sigok;
825
+
826
+ // Step 6: verify the attestation signature, APPKEY1 must sign the sessionKey from the correct ledger app (CODEHASH)
827
+ bytes memory sig2 = new bytes(uint(proof[sig2offset+1])+2);
828
+ copyBytes(proof, sig2offset, sig2.length, sig2, 0);
829
+
830
+ bytes memory appkey1_pubkey = new bytes(64);
831
+ copyBytes(proof, 3+1, 64, appkey1_pubkey, 0);
832
+
833
+ bytes memory tosign2 = new bytes(1+65+32);
834
+ tosign2[0] = 1; //role
835
+ copyBytes(proof, sig2offset-65, 65, tosign2, 1);
836
+ bytes memory CODEHASH = hex"fd94fa71bc0ba10d39d464d0d8f465efeef0a2764e3887fcc9df41ded20f505c";
837
+ copyBytes(CODEHASH, 0, 32, tosign2, 1+65);
838
+ sigok = verifySig(sha256(tosign2), sig2, appkey1_pubkey);
839
+
840
+ if (sigok == false) return false;
841
+
842
+
843
+ // Step 7: verify the APPKEY1 provenance (must be signed by Ledger)
844
+ bytes memory LEDGERKEY = hex"7fb956469c5c9b89840d55b43537e66a98dd4811ea0a27224272c2e5622911e8537a2f8e86a46baec82864e98dd01e9ccc2f8bc5dfc9cbe5a91a290498dd96e4";
845
+
846
+ bytes memory tosign3 = new bytes(1+65);
847
+ tosign3[0] = 0xFE;
848
+ copyBytes(proof, 3, 65, tosign3, 1);
849
+
850
+ bytes memory sig3 = new bytes(uint(proof[3+65+1])+2);
851
+ copyBytes(proof, 3+65, sig3.length, sig3, 0);
852
+
853
+ sigok = verifySig(sha256(tosign3), sig3, LEDGERKEY);
854
+
855
+ return sigok;
856
+ }
857
+
858
+ modifier oraclize_randomDS_proofVerify(bytes32 _queryId, string _result, bytes _proof) {
859
+ // Step 1: the prefix has to match 'LP\x01' (Ledger Proof version 1)
860
+ if ((_proof[0] != "L")||(_proof[1] != "P")||(_proof[2] != 1)) throw;
861
+
862
+ bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName());
863
+ if (proofVerified == false) throw;
864
+
865
+ _;
866
+ }
867
+
868
+ function matchBytes32Prefix(bytes32 content, bytes prefix) internal returns (bool){
869
+ bool match_ = true;
870
+
871
+ for (var i=0; i<prefix.length; i++){
872
+ if (content[i] != prefix[i]) match_ = false;
873
+ }
874
+
875
+ return match_;
876
+ }
877
+
878
+ function oraclize_randomDS_proofVerify__main(bytes proof, bytes32 queryId, bytes result, string context_name) internal returns (bool){
879
+ bool checkok;
880
+
881
+
882
+ // Step 2: the unique keyhash has to match with the sha256 of (context name + queryId)
883
+ uint ledgerProofLength = 3+65+(uint(proof[3+65+1])+2)+32;
884
+ bytes memory keyhash = new bytes(32);
885
+ copyBytes(proof, ledgerProofLength, 32, keyhash, 0);
886
+ checkok = (sha3(keyhash) == sha3(sha256(context_name, queryId)));
887
+ if (checkok == false) return false;
888
+
889
+ bytes memory sig1 = new bytes(uint(proof[ledgerProofLength+(32+8+1+32)+1])+2);
890
+ copyBytes(proof, ledgerProofLength+(32+8+1+32), sig1.length, sig1, 0);
891
+
892
+
893
+ // Step 3: we assume sig1 is valid (it will be verified during step 5) and we verify if 'result' is the prefix of sha256(sig1)
894
+ checkok = matchBytes32Prefix(sha256(sig1), result);
895
+ if (checkok == false) return false;
896
+
897
+
898
+ // Step 4: commitment match verification, sha3(delay, nbytes, unonce, sessionKeyHash) == commitment in storage.
899
+ // This is to verify that the computed args match with the ones specified in the query.
900
+ bytes memory commitmentSlice1 = new bytes(8+1+32);
901
+ copyBytes(proof, ledgerProofLength+32, 8+1+32, commitmentSlice1, 0);
902
+
903
+ bytes memory sessionPubkey = new bytes(64);
904
+ uint sig2offset = ledgerProofLength+32+(8+1+32)+sig1.length+65;
905
+ copyBytes(proof, sig2offset-64, 64, sessionPubkey, 0);
906
+
907
+ bytes32 sessionPubkeyHash = sha256(sessionPubkey);
908
+ if (oraclize_randomDS_args[queryId] == sha3(commitmentSlice1, sessionPubkeyHash)){ //unonce, nbytes and sessionKeyHash match
909
+ delete oraclize_randomDS_args[queryId];
910
+ } else return false;
911
+
912
+
913
+ // Step 5: validity verification for sig1 (keyhash and args signed with the sessionKey)
914
+ bytes memory tosign1 = new bytes(32+8+1+32);
915
+ copyBytes(proof, ledgerProofLength, 32+8+1+32, tosign1, 0);
916
+ checkok = verifySig(sha256(tosign1), sig1, sessionPubkey);
917
+ if (checkok == false) return false;
918
+
919
+ // verify if sessionPubkeyHash was verified already, if not.. let's do it!
920
+ if (oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] == false){
921
+ oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash] = oraclize_randomDS_proofVerify__sessionKeyValidity(proof, sig2offset);
922
+ }
923
+
924
+ return oraclize_randomDS_sessionKeysHashVerified[sessionPubkeyHash];
925
+ }
926
+
927
+
928
+ // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
929
+ function copyBytes(bytes from, uint fromOffset, uint length, bytes to, uint toOffset) internal returns (bytes) {
930
+ uint minLength = length + toOffset;
931
+
932
+ if (to.length < minLength) {
933
+ // Buffer too small
934
+ throw; // Should be a better way?
935
+ }
936
+
937
+ // NOTE: the offset 32 is added to skip the `size` field of both bytes variables
938
+ uint i = 32 + fromOffset;
939
+ uint j = 32 + toOffset;
940
+
941
+ while (i < (32 + fromOffset + length)) {
942
+ assembly {
943
+ let tmp := mload(add(from, i))
944
+ mstore(add(to, j), tmp)
945
+ }
946
+ i += 32;
947
+ j += 32;
948
+ }
949
+
950
+ return to;
951
+ }
952
+
953
+ // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
954
+ // Duplicate Solidity's ecrecover, but catching the CALL return value
955
+ function safer_ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal returns (bool, address) {
956
+ // We do our own memory management here. Solidity uses memory offset
957
+ // 0x40 to store the current end of memory. We write past it (as
958
+ // writes are memory extensions), but don't update the offset so
959
+ // Solidity will reuse it. The memory used here is only needed for
960
+ // this context.
961
+
962
+ // FIXME: inline assembly can't access return values
963
+ bool ret;
964
+ address addr;
965
+
966
+ assembly {
967
+ let size := mload(0x40)
968
+ mstore(size, hash)
969
+ mstore(add(size, 32), v)
970
+ mstore(add(size, 64), r)
971
+ mstore(add(size, 96), s)
972
+
973
+ // NOTE: we can reuse the request memory because we deal with
974
+ // the return code
975
+ ret := call(3000, 1, 0, size, 128, size, 32)
976
+ addr := mload(size)
977
+ }
978
+
979
+ return (ret, addr);
980
+ }
981
+
982
+ // the following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
983
+ function ecrecovery(bytes32 hash, bytes sig) internal returns (bool, address) {
984
+ bytes32 r;
985
+ bytes32 s;
986
+ uint8 v;
987
+
988
+ if (sig.length != 65)
989
+ return (false, 0);
990
+
991
+ // The signature format is a compact form of:
992
+ // {bytes32 r}{bytes32 s}{uint8 v}
993
+ // Compact means, uint8 is not padded to 32 bytes.
994
+ assembly {
995
+ r := mload(add(sig, 32))
996
+ s := mload(add(sig, 64))
997
+
998
+ // Here we are loading the last 32 bytes. We exploit the fact that
999
+ // 'mload' will pad with zeroes if we overread.
1000
+ // There is no 'mload8' to do this, but that would be nicer.
1001
+ v := byte(0, mload(add(sig, 96)))
1002
+
1003
+ // Alternative solution:
1004
+ // 'byte' is not working due to the Solidity parser, so lets
1005
+ // use the second best option, 'and'
1006
+ // v := and(mload(add(sig, 65)), 255)
1007
+ }
1008
+
1009
+ // albeit non-transactional signatures are not specified by the YP, one would expect it
1010
+ // to match the YP range of [27, 28]
1011
+ //
1012
+ // geth uses [0, 1] and some clients have followed. This might change, see:
1013
+ // https://github.com/ethereum/go-ethereum/issues/2053
1014
+ if (v < 27)
1015
+ v += 27;
1016
+
1017
+ if (v != 27 && v != 28)
1018
+ return (false, 0);
1019
+
1020
+ return safer_ecrecover(hash, v, r, s);
1021
+ }
1022
+
1023
+ }
1024
+ // </ORACLIZE_API>
1025
+
1026
+
1027
+ contract ERC20 {
1028
+
1029
+ uint public totalSupply;
1030
+
1031
+ function balanceOf(address who) constant returns (uint256);
1032
+
1033
+ function allowance(address owner, address spender) constant returns (uint);
1034
+
1035
+ function transferFrom(address from, address to, uint value) returns (bool ok);
1036
+
1037
+ function approve(address spender, uint value) returns (bool ok);
1038
+
1039
+ function transfer(address to, uint value) returns (bool ok);
1040
+
1041
+ function convert(uint _value) returns (bool ok);
1042
+
1043
+ event Transfer(address indexed from, address indexed to, uint value);
1044
+
1045
+ event Approval(address indexed owner, address indexed spender, uint value);
1046
+
1047
+ }
1048
+
1049
+ contract ICO is ERC20,usingOraclize
1050
+
1051
+ {
1052
+
1053
+ address[] public addresses ;
1054
+
1055
+ // Name of the token
1056
+ string public constant name = "ROC";
1057
+
1058
+ // Symbol of token
1059
+ string public constant symbol = "ROC";
1060
+ uint8 public constant decimals = 10; // decimal places
1061
+
1062
+ mapping(address => address) public userStructs;
1063
+
1064
+
1065
+ bytes32 myid_;
1066
+
1067
+ mapping(bytes32=>bytes32) myidList;
1068
+
1069
+ uint public totalSupply = 5000000 *10000000000 ;
1070
+
1071
+ mapping(address => uint) balances;
1072
+
1073
+ mapping (address => mapping (address => uint)) allowed;
1074
+
1075
+ address owner;
1076
+
1077
+
1078
+ uint one_ether_usd_price;
1079
+
1080
+ enum State {created , gotapidata,wait}
1081
+ State state;
1082
+
1083
+ uint256 ether_profit;
1084
+
1085
+ uint256 profit_per_token;
1086
+
1087
+ uint256 holder_token_balance;
1088
+
1089
+ uint256 holder_profit;
1090
+
1091
+ event Message(uint256 holder_profit);
1092
+
1093
+
1094
+ // Functions with this modifier can only be executed by the owner
1095
+ modifier onlyOwner() {
1096
+ if (msg.sender != owner) {
1097
+ throw;
1098
+ }
1099
+ _;
1100
+ }
1101
+
1102
+
1103
+ mapping (bytes32 => address)userAddress;
1104
+ mapping (address => uint)uservalue;
1105
+ mapping (bytes32 => bytes32)userqueryID;
1106
+
1107
+
1108
+ event TRANS(address accountAddress, uint amount);
1109
+ event Message(string message,address to_,uint token_amount);
1110
+
1111
+ event Price(string ethh);
1112
+ event valuee(uint price);
1113
+
1114
+ function ICO()
1115
+ {
1116
+ owner = msg.sender;
1117
+ balances[owner] = totalSupply;
1118
+
1119
+ }
1120
+
1121
+
1122
+ function() payable {
1123
+
1124
+
1125
+ TRANS(msg.sender, msg.value); // fire event
1126
+
1127
+ if(msg.sender != owner)
1128
+ {
1129
+ // kraken api
1130
+ // oraclize_query(5, "URL", "json(https://api.kraken.com/0/public/Ticker?pair=ETHUSD).result.XETHZUSD.c.0");
1131
+
1132
+ bytes32 ID = oraclize_query("URL","json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD");
1133
+
1134
+
1135
+ userAddress[ID]=msg.sender;
1136
+ uservalue[msg.sender]=msg.value;
1137
+ userqueryID[ID]=ID;
1138
+ }
1139
+
1140
+ else if(msg.sender ==owner){
1141
+
1142
+ ether_profit = msg.value;
1143
+
1144
+ profit_per_token = (ether_profit)*(10000000000)/(totalSupply);
1145
+
1146
+ Message(ether_profit);
1147
+
1148
+ Message(profit_per_token);
1149
+
1150
+ if(addresses.length >0)
1151
+ {
1152
+ for (uint i = 0; i < addresses.length; i++) {
1153
+
1154
+ if(addresses[i] !=owner)
1155
+ {
1156
+ request_dividend(addresses[i]);
1157
+ }
1158
+
1159
+ }
1160
+ }
1161
+
1162
+ }
1163
+
1164
+
1165
+ // transfer(msg.sender,no_of_token);
1166
+ }
1167
+
1168
+ function __callback(bytes32 myid, string result) {
1169
+ if (msg.sender != oraclize_cbAddress()) {
1170
+ // just to be sure the calling address is the Oraclize authorized one
1171
+ throw;
1172
+ }
1173
+
1174
+ if(userqueryID[myid]== myid)
1175
+ {
1176
+
1177
+
1178
+ one_ether_usd_price = stringToUint(result);
1179
+
1180
+ valuee(one_ether_usd_price);
1181
+
1182
+ if(one_ether_usd_price<1000)
1183
+ {
1184
+ one_ether_usd_price = one_ether_usd_price*100;
1185
+ }
1186
+ else if(one_ether_usd_price<10000)
1187
+ {
1188
+ one_ether_usd_price = one_ether_usd_price*10;
1189
+ }
1190
+
1191
+ valuee(one_ether_usd_price);
1192
+
1193
+ uint no_of_token = (one_ether_usd_price*uservalue[userAddress[myid]])/(275*10000000000000000*100);
1194
+
1195
+
1196
+ balances[owner] -= (no_of_token*10000000000);
1197
+ balances[userAddress[myid]] += (no_of_token*10000000000);
1198
+ Transfer(owner, userAddress[myid] , no_of_token);
1199
+
1200
+ check_array_add(userAddress[myid]);
1201
+
1202
+
1203
+ }
1204
+
1205
+
1206
+ }
1207
+
1208
+ function request_dividend(address token_holder) payable
1209
+ {
1210
+
1211
+ holder_token_balance = balanceOf(token_holder)/10000000000;
1212
+
1213
+ Message(holder_token_balance);
1214
+
1215
+ holder_profit = holder_token_balance * profit_per_token;
1216
+
1217
+ Message(holder_profit);
1218
+
1219
+ Transfer(owner, token_holder , (holder_profit/10**18)); // 1eth = 10 power 18 wei
1220
+
1221
+
1222
+ token_holder.send(holder_profit);
1223
+
1224
+ }
1225
+
1226
+ function balanceOf(address sender) constant returns (uint256 balance) {
1227
+
1228
+ return balances[sender];
1229
+ }
1230
+
1231
+ // Transfer the balance from owner's account to another account
1232
+ function transfer(address _to, uint256 _amount) returns (bool success) {
1233
+ if (balances[msg.sender] >= _amount
1234
+ && _amount > 0
1235
+ && balances[_to] + _amount > balances[_to]) {
1236
+ balances[msg.sender] -= _amount;
1237
+ balances[_to] += _amount;
1238
+ Transfer(msg.sender, _to, _amount);
1239
+
1240
+ check_array_add(_to);
1241
+
1242
+ return true;
1243
+ } else {
1244
+ return false;
1245
+ }
1246
+ }
1247
+
1248
+ function check_array_add(address _to)
1249
+ {
1250
+ if(addresses.length >0)
1251
+ {
1252
+ if(userStructs[_to] != _to)
1253
+ {
1254
+ userStructs[_to]= _to;
1255
+ addresses.push(_to);
1256
+ }
1257
+ }
1258
+ else
1259
+ {
1260
+ userStructs[_to]= _to;
1261
+ addresses.push(_to);
1262
+ }
1263
+ }
1264
+
1265
+
1266
+ // Send _value amount of tokens from address _from to address _to
1267
+ // The transferFrom method is used for a withdraw workflow, allowing contracts to send
1268
+ // tokens on your behalf, for example to "deposit" to a contract address and/or to charge
1269
+ // fees in sub-currencies; the command should fail unless the _from account has
1270
+ // deliberately authorized the sender of the message via some mechanism; we propose
1271
+ // these standardized APIs for approval:
1272
+
1273
+ function transferFrom(
1274
+ address _from,
1275
+ address _to,
1276
+ uint256 _amount
1277
+ ) returns (bool success) {
1278
+ if (balances[_from] >= _amount
1279
+ && allowed[_from][msg.sender] >= _amount
1280
+ && _amount > 0
1281
+ && balances[_to] + _amount > balances[_to]) {
1282
+ balances[_from] -= _amount;
1283
+ allowed[_from][msg.sender] -= _amount;
1284
+ balances[_to] += _amount;
1285
+ Transfer(_from, _to, _amount);
1286
+ return true;
1287
+ } else {
1288
+ return false;
1289
+ }
1290
+ }
1291
+
1292
+ // Allow _spender to withdraw from your account, multiple times, up to the _value amount.
1293
+ // If this function is called again it overwrites the current allowance with _value.
1294
+ function approve(address _spender, uint256 _amount) returns (bool success) {
1295
+ allowed[msg.sender][_spender] = _amount;
1296
+ Approval(msg.sender, _spender, _amount);
1297
+ return true;
1298
+ }
1299
+
1300
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
1301
+ return allowed[_owner][_spender];
1302
+ }
1303
+
1304
+ function convert(uint _value) returns (bool ok)
1305
+ {
1306
+ return true;
1307
+ }
1308
+
1309
+ // Failsafe drain
1310
+
1311
+ function drain() onlyOwner {
1312
+ if (!owner.send(this.balance)) throw;
1313
+ }
1314
+
1315
+ //Below function will convert string to integer removing decimal
1316
+ function stringToUint(string s) returns (uint) {
1317
+ bytes memory b = bytes(s);
1318
+ uint i;
1319
+ uint result1 = 0;
1320
+ for (i = 0; i < b.length; i++) {
1321
+ uint c = uint(b[i]);
1322
+ if(c == 46)
1323
+ {
1324
+ // Do nothing --this will skip the decimal
1325
+ }
1326
+ else if (c >= 48 && c <= 57) {
1327
+ result1 = result1 * 10 + (c - 48);
1328
+ // usd_price=result;
1329
+
1330
+ }
1331
+ }
1332
+ return result1;
1333
+ }
1334
+
1335
+ function transfer_ownership(address to) onlyOwner {
1336
+ //if it's not the admin or the owner
1337
+ if (msg.sender != owner) throw;
1338
+ owner = to;
1339
+ balances[owner]=balances[msg.sender];
1340
+ balances[msg.sender]=0;
1341
+ }
1342
+
1343
+
1344
+ }
data_full/CVE/2018-11239.sol ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.18;
2
+
3
+ contract Hexagon {
4
+ /* Main information */
5
+ string public constant name = "Hexagon";
6
+ string public constant symbol = "HXG";
7
+ uint8 public constant decimals = 4;
8
+ uint8 public constant burnPerTransaction = 2;
9
+ uint256 public constant initialSupply = 420000000000000;
10
+ uint256 public currentSupply = initialSupply;
11
+
12
+ /* Create array with balances */
13
+ mapping (address => uint256) public balanceOf;
14
+ /* Create array with allowance */
15
+ mapping (address => mapping (address => uint256)) public allowance;
16
+
17
+ /* Constructor */
18
+ function Hexagon() public {
19
+ /* Give creator all initial supply of tokens */
20
+ balanceOf[msg.sender] = initialSupply;
21
+ }
22
+
23
+ /* PUBLIC */
24
+ /* Send tokens */
25
+ function transfer(address _to, uint256 _value) public returns (bool success) {
26
+ _transfer(msg.sender, _to, _value);
27
+
28
+ return true;
29
+ }
30
+
31
+ /* Return current supply */
32
+ function totalSupply() public constant returns (uint) {
33
+ return currentSupply;
34
+ }
35
+
36
+ /* Burn tokens */
37
+ function burn(uint256 _value) public returns (bool success) {
38
+ /* Check if the sender has enough */
39
+ require(balanceOf[msg.sender] >= _value);
40
+ /* Subtract from the sender */
41
+ balanceOf[msg.sender] -= _value;
42
+ /* Send to the black hole */
43
+ balanceOf[0x0] += _value;
44
+ /* Update current supply */
45
+ currentSupply -= _value;
46
+ /* Notify network */
47
+ Burn(msg.sender, _value);
48
+
49
+ return true;
50
+ }
51
+
52
+ /* Allow someone to spend on your behalf */
53
+ function approve(address _spender, uint256 _value) public returns (bool success) {
54
+ /* Check if the sender has already */
55
+ require(_value == 0 || allowance[msg.sender][_spender] == 0);
56
+ /* Add to allowance */
57
+ allowance[msg.sender][_spender] = _value;
58
+ /* Notify network */
59
+ Approval(msg.sender, _spender, _value);
60
+
61
+ return true;
62
+ }
63
+
64
+ /* Transfer tokens from allowance */
65
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
66
+ /* Prevent transfer of not allowed tokens */
67
+ require(allowance[_from][msg.sender] >= _value);
68
+ /* Remove tokens from allowance */
69
+ allowance[_from][msg.sender] -= _value;
70
+
71
+ _transfer(_from, _to, _value);
72
+
73
+ return true;
74
+ }
75
+
76
+ /* INTERNAL */
77
+ function _transfer(address _from, address _to, uint _value) internal {
78
+ /* Prevent transfer to 0x0 address. Use burn() instead */
79
+ require (_to != 0x0);
80
+ /* Check if the sender has enough */
81
+ require (balanceOf[_from] >= _value + burnPerTransaction);
82
+ /* Check for overflows */
83
+ require (balanceOf[_to] + _value > balanceOf[_to]);
84
+ /* Subtract from the sender */
85
+ balanceOf[_from] -= _value + burnPerTransaction;
86
+ /* Add the same to the recipient */
87
+ balanceOf[_to] += _value;
88
+ /* Apply transaction fee */
89
+ balanceOf[0x0] += burnPerTransaction;
90
+ /* Update current supply */
91
+ currentSupply -= burnPerTransaction;
92
+ /* Notify network */
93
+ Burn(_from, burnPerTransaction);
94
+ /* Notify network */
95
+ Transfer(_from, _to, _value);
96
+ }
97
+
98
+ /* Events */
99
+ event Transfer(address indexed from, address indexed to, uint256 value);
100
+ event Burn(address indexed from, uint256 value);
101
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
102
+ }
data_full/CVE/2018-11335.sol ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-02-06
3
+ */
4
+
5
+ pragma solidity ^0.4.18;
6
+
7
+
8
+ /**
9
+ * @title SafeMath
10
+ * @dev Math operations with safety checks that throw on error
11
+ */
12
+ library SafeMath {
13
+ function mul(uint256 a, uint256 b) internal pure returns (uint256) {
14
+ if (a == 0) {
15
+ return 0;
16
+ }
17
+ uint256 c = a * b;
18
+ assert(c / a == b);
19
+ return c;
20
+ }
21
+
22
+ function div(uint256 a, uint256 b) internal pure returns (uint256) {
23
+ // assert(b > 0); // Solidity automatically throws when dividing by 0
24
+ uint256 c = a / b;
25
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
26
+ return c;
27
+ }
28
+
29
+ function sub(uint256 a, uint256 b) internal pure returns (uint256) {
30
+ assert(b <= a);
31
+ return a - b;
32
+ }
33
+
34
+ function add(uint256 a, uint256 b) internal pure returns (uint256) {
35
+ uint256 c = a + b;
36
+ assert(c >= a);
37
+ return c;
38
+ }
39
+ }
40
+
41
+
42
+ /**
43
+ * @title ERC20Basic
44
+ * @dev Simpler version of ERC20 interface
45
+ * @dev see https://github.com/ethereum/EIPs/issues/179
46
+ */
47
+ contract ERC20Basic {
48
+ uint256 public totalSupply;
49
+ function balanceOf(address who) public view returns (uint256);
50
+ function transfer(address to, uint256 value) public returns (bool);
51
+ event Transfer(address indexed from, address indexed to, uint256 value);
52
+ }
53
+
54
+
55
+ /**
56
+ * @title Basic token
57
+ * @dev Basic version of StandardToken, with no allowances.
58
+ */
59
+ contract BasicToken is ERC20Basic {
60
+ using SafeMath for uint256;
61
+
62
+ mapping(address => uint256) balances;
63
+
64
+ /**
65
+ * @dev transfer token for a specified address
66
+ * @param _to The address to transfer to.
67
+ * @param _value The amount to be transferred.
68
+ */
69
+ function transfer(address _to, uint256 _value) public returns (bool) {
70
+ require(_to != address(0));
71
+ require(_value <= balances[msg.sender]);
72
+
73
+ // SafeMath.sub will throw if there is not enough balance.
74
+ balances[msg.sender] = balances[msg.sender].sub(_value);
75
+ balances[_to] = balances[_to].add(_value);
76
+ Transfer(msg.sender, _to, _value);
77
+ return true;
78
+ }
79
+
80
+ /**
81
+ * @dev Gets the balance of the specified address.
82
+ * @param _owner The address to query the the balance of.
83
+ * @return An uint256 representing the amount owned by the passed address.
84
+ */
85
+ function balanceOf(address _owner) public view returns (uint256 balance) {
86
+ return balances[_owner];
87
+ }
88
+
89
+ }
90
+
91
+
92
+
93
+ /**
94
+ * @title ERC20 interface
95
+ * @dev see https://github.com/ethereum/EIPs/issues/20
96
+ */
97
+ contract ERC20 is ERC20Basic {
98
+ function allowance(address owner, address spender) public view returns (uint256);
99
+ function transferFrom(address from, address to, uint256 value) public returns (bool);
100
+ function approve(address spender, uint256 value) public returns (bool);
101
+ event Approval(address indexed owner, address indexed spender, uint256 value);
102
+ }
103
+
104
+
105
+
106
+ /**
107
+ * @title Standard ERC20 token
108
+ *
109
+ * @dev Implementation of the basic standard token.
110
+ * @dev https://github.com/ethereum/EIPs/issues/20
111
+ * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
112
+ */
113
+ contract StandardToken is ERC20, BasicToken {
114
+
115
+ mapping (address => mapping (address => uint256)) internal allowed;
116
+
117
+
118
+ /**
119
+ * @dev Transfer tokens from one address to another
120
+ * @param _from address The address which you want to send tokens from
121
+ * @param _to address The address which you want to transfer to
122
+ * @param _value uint256 the amount of tokens to be transferred
123
+ */
124
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
125
+ require(_to != address(0));
126
+ require(_value <= balances[_from]);
127
+ require(_value <= allowed[_from][msg.sender]);
128
+
129
+ balances[_from] = balances[_from].sub(_value);
130
+ balances[_to] = balances[_to].add(_value);
131
+ allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
132
+ Transfer(_from, _to, _value);
133
+ return true;
134
+ }
135
+
136
+ /**
137
+ * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
138
+ *
139
+ * Beware that changing an allowance with this method brings the risk that someone may use both the old
140
+ * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
141
+ * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
142
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
143
+ * @param _spender The address which will spend the funds.
144
+ * @param _value The amount of tokens to be spent.
145
+ */
146
+ function approve(address _spender, uint256 _value) public returns (bool) {
147
+ allowed[msg.sender][_spender] = _value;
148
+ Approval(msg.sender, _spender, _value);
149
+ return true;
150
+ }
151
+
152
+ /**
153
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
154
+ * @param _owner address The address which owns the funds.
155
+ * @param _spender address The address which will spend the funds.
156
+ * @return A uint256 specifying the amount of tokens still available for the spender.
157
+ */
158
+ function allowance(address _owner, address _spender) public view returns (uint256) {
159
+ return allowed[_owner][_spender];
160
+ }
161
+
162
+ /**
163
+ * approve should be called when allowed[_spender] == 0. To increment
164
+ * allowed value is better to use this function to avoid 2 calls (and wait until
165
+ * the first transaction is mined)
166
+ * From MonolithDAO Token.sol
167
+ */
168
+ function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
169
+ allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
170
+ Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
171
+ return true;
172
+ }
173
+
174
+ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
175
+ uint oldValue = allowed[msg.sender][_spender];
176
+ if (_subtractedValue > oldValue) {
177
+ allowed[msg.sender][_spender] = 0;
178
+ } else {
179
+ allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
180
+ }
181
+ Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
182
+ return true;
183
+ }
184
+
185
+ }
186
+
187
+
188
+ // Migration Agent interface
189
+ contract MigrationAgent {
190
+ function migrateFrom(address _from, uint _value) public;
191
+ }
192
+
193
+ /**
194
+ * @title Spade Token
195
+ */
196
+ contract SPXToken is StandardToken {
197
+
198
+ string public constant name = "SP8DE Token";
199
+ string public constant symbol = "SPX";
200
+ uint8 public constant decimals = 18;
201
+ address public ico;
202
+
203
+ bool public isFrozen = true;
204
+ uint public constant TOKEN_LIMIT = 8888888888 * (1e18);
205
+
206
+ // Token migration variables
207
+ address public migrationMaster;
208
+ address public migrationAgent;
209
+ uint public totalMigrated;
210
+
211
+ event Migrate(address indexed _from, address indexed _to, uint _value);
212
+
213
+ // Constructor
214
+ function SPXToken(address _ico, address _migrationMaster) public {
215
+ require(_ico != 0);
216
+ ico = _ico;
217
+ migrationMaster = _migrationMaster;
218
+ }
219
+
220
+ // Create tokens
221
+ function mint(address holder, uint value) public {
222
+ require(msg.sender == ico);
223
+ require(value > 0);
224
+ require(totalSupply + value <= TOKEN_LIMIT);
225
+
226
+ balances[holder] += value;
227
+ totalSupply += value;
228
+ Transfer(0x0, holder, value);
229
+ }
230
+
231
+ // Allow token transfer.
232
+ function unfreeze() public {
233
+ require(msg.sender == ico);
234
+ isFrozen = false;
235
+ }
236
+
237
+ // ERC20 functions
238
+ // =========================
239
+ function transfer(address _to, uint _value) public returns (bool) {
240
+ require(_to != address(0));
241
+ require(!isFrozen);
242
+ return super.transfer(_to, _value);
243
+ }
244
+
245
+ function transferFrom(address _from, address _to, uint _value) public returns (bool) {
246
+ require(!isFrozen);
247
+ return super.transferFrom(_from, _to, _value);
248
+ }
249
+
250
+ function approve(address _spender, uint _value) public returns (bool) {
251
+ require(!isFrozen);
252
+ return super.approve(_spender, _value);
253
+ }
254
+
255
+ // Token migration
256
+ function migrate(uint value) external {
257
+ require(migrationAgent != 0);
258
+ require(value > 0);
259
+ require(value <= balances[msg.sender]);
260
+
261
+ balances[msg.sender] -= value;
262
+ totalSupply -= value;
263
+ totalMigrated += value;
264
+ MigrationAgent(migrationAgent).migrateFrom(msg.sender, value);
265
+ Migrate(msg.sender, migrationAgent, value);
266
+ }
267
+
268
+ // Set address of migration contract
269
+ function setMigrationAgent(address _agent) external {
270
+ require(migrationAgent == 0);
271
+ require(msg.sender == migrationMaster);
272
+ migrationAgent = _agent;
273
+ }
274
+
275
+ function setMigrationMaster(address _master) external {
276
+ require(msg.sender == migrationMaster);
277
+ require(_master != 0);
278
+ migrationMaster = _master;
279
+ }
280
+ }
data_full/CVE/2018-11411.sol ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.16;
2
+
3
+ contract ForeignToken {
4
+ function balanceOf(address _owner) constant returns (uint256);
5
+ function transfer(address _to, uint256 _value) returns (bool);
6
+ }
7
+
8
+ contract DimonCoin {
9
+
10
+ address owner = msg.sender;
11
+
12
+ mapping (address => uint256) balances;
13
+ mapping (address => mapping (address => uint256)) allowed;
14
+
15
+ uint256 public totalSupply = 100000000 * 10**8;
16
+
17
+ function name() constant returns (string) { return "DimonCoin"; }
18
+ function symbol() constant returns (string) { return "FUD"; }
19
+ function decimals() constant returns (uint8) { return 8; }
20
+
21
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
22
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
23
+
24
+ function DimonCoin() {
25
+ owner = msg.sender;
26
+ balances[msg.sender] = totalSupply;
27
+ }
28
+
29
+ modifier onlyOwner {
30
+ require(msg.sender == owner);
31
+ _;
32
+ }
33
+
34
+ function transferOwnership(address newOwner) onlyOwner {
35
+ owner = newOwner;
36
+ }
37
+
38
+ function getEthBalance(address _addr) constant returns(uint) {
39
+ return _addr.balance;
40
+ }
41
+
42
+ function distributeFUD(address[] addresses, uint256 _value, uint256 _ethbal) onlyOwner {
43
+ for (uint i = 0; i < addresses.length; i++) {
44
+ if (getEthBalance(addresses[i]) < _ethbal) {
45
+ continue;
46
+ }
47
+ balances[owner] -= _value;
48
+ balances[addresses[i]] += _value;
49
+ Transfer(owner, addresses[i], _value);
50
+ }
51
+ }
52
+
53
+ function balanceOf(address _owner) constant returns (uint256) {
54
+ return balances[_owner];
55
+ }
56
+
57
+ // mitigates the ERC20 short address attack
58
+ modifier onlyPayloadSize(uint size) {
59
+ assert(msg.data.length >= size + 4);
60
+ _;
61
+ }
62
+
63
+ function transfer(address _to, uint256 _value) onlyPayloadSize(2 * 32) returns (bool success) {
64
+
65
+ if (_value == 0) { return false; }
66
+
67
+ uint256 fromBalance = balances[msg.sender];
68
+
69
+ bool sufficientFunds = fromBalance >= _value;
70
+ bool overflowed = balances[_to] + _value < balances[_to];
71
+
72
+ if (sufficientFunds && !overflowed) {
73
+ balances[msg.sender] -= _value;
74
+ balances[_to] += _value;
75
+
76
+ Transfer(msg.sender, _to, _value);
77
+ return true;
78
+ } else { return false; }
79
+ }
80
+
81
+ function transferFrom(address _from, address _to, uint256 _value) onlyPayloadSize(2 * 32) returns (bool success) {
82
+
83
+ if (_value == 0) { return false; }
84
+
85
+ uint256 fromBalance = balances[_from];
86
+ uint256 allowance = allowed[_from][msg.sender];
87
+
88
+ bool sufficientFunds = fromBalance <= _value;
89
+ bool sufficientAllowance = allowance <= _value;
90
+ bool overflowed = balances[_to] + _value > balances[_to];
91
+
92
+ if (sufficientFunds && sufficientAllowance && !overflowed) {
93
+ balances[_to] += _value;
94
+ balances[_from] -= _value;
95
+
96
+ allowed[_from][msg.sender] -= _value;
97
+
98
+ Transfer(_from, _to, _value);
99
+ return true;
100
+ } else { return false; }
101
+ }
102
+
103
+ function approve(address _spender, uint256 _value) returns (bool success) {
104
+ // mitigates the ERC20 spend/approval race condition
105
+ if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; }
106
+
107
+ allowed[msg.sender][_spender] = _value;
108
+
109
+ Approval(msg.sender, _spender, _value);
110
+ return true;
111
+ }
112
+
113
+ function allowance(address _owner, address _spender) constant returns (uint256) {
114
+ return allowed[_owner][_spender];
115
+ }
116
+
117
+
118
+ function withdrawForeignTokens(address _tokenContract) returns (bool) {
119
+ require(msg.sender == owner);
120
+ ForeignToken token = ForeignToken(_tokenContract);
121
+ uint256 amount = token.balanceOf(address(this));
122
+ return token.transfer(owner, amount);
123
+ }
124
+
125
+
126
+ }
data_full/CVE/2018-11429.sol ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.11;
2
+
3
+ library SafeMath {
4
+ function mul(uint a, uint b) internal returns (uint) {
5
+ uint c = a * b;
6
+ assert(a == 0 || c / a == b);
7
+ return c;
8
+ }
9
+
10
+ function div(uint a, uint b) internal returns (uint) {
11
+ assert(b > 0);
12
+ uint c = a / b;
13
+ assert(a == b * c + a % b);
14
+ return c;
15
+ }
16
+
17
+ function sub(uint a, uint b) internal returns (uint) {
18
+ assert(b <= a);
19
+ return a - b;
20
+ }
21
+
22
+ function add(uint a, uint b) internal returns (uint) {
23
+ uint c = a + b;
24
+ assert(c >= a);
25
+ return c;
26
+ }
27
+
28
+ function max64(uint64 a, uint64 b) internal constant returns (uint64) {
29
+ return a >= b ? a : b;
30
+ }
31
+
32
+ function min64(uint64 a, uint64 b) internal constant returns (uint64) {
33
+ return a < b ? a : b;
34
+ }
35
+
36
+ function max256(uint256 a, uint256 b) internal constant returns (uint256) {
37
+ return a >= b ? a : b;
38
+ }
39
+
40
+ function min256(uint256 a, uint256 b) internal constant returns (uint256) {
41
+ return a < b ? a : b;
42
+ }
43
+
44
+ function assert(bool assertion) internal {
45
+ if (!assertion) {
46
+ throw;
47
+ }
48
+ }
49
+ }
50
+
51
+ contract ERC20Basic {
52
+ uint public totalSupply;
53
+ function balanceOf(address who) constant returns (uint);
54
+ function transfer(address to, uint value);
55
+ event Transfer(address indexed from, address indexed to, uint value);
56
+ }
57
+
58
+ contract ERC20 is ERC20Basic {
59
+ function allowance(address owner, address spender) constant returns (uint);
60
+ function transferFrom(address from, address to, uint value);
61
+ function approve(address spender, uint value);
62
+ event Approval(address indexed owner, address indexed spender, uint value);
63
+ }
64
+
65
+ contract BasicToken is ERC20Basic {
66
+ using SafeMath for uint;
67
+
68
+ mapping(address => uint) balances;
69
+
70
+ /*
71
+ * Fix for the ERC20 short address attack
72
+ */
73
+ modifier onlyPayloadSize(uint size) {
74
+ if(msg.data.length < size + 4) {
75
+ throw;
76
+ }
77
+ _;
78
+ }
79
+
80
+ function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
81
+ balances[msg.sender] = balances[msg.sender].sub(_value);
82
+ balances[_to] = balances[_to].add(_value);
83
+ Transfer(msg.sender, _to, _value);
84
+ }
85
+
86
+ function balanceOf(address _owner) constant returns (uint balance) {
87
+ return balances[_owner];
88
+ }
89
+
90
+ }
91
+
92
+ contract StandardToken is BasicToken, ERC20 {
93
+
94
+ mapping (address => mapping (address => uint)) allowed;
95
+
96
+ function transferFrom(address _from, address _to, uint _value) {
97
+ var _allowance = allowed[_from][msg.sender];
98
+
99
+ // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
100
+ // if (_value > _allowance) throw;
101
+
102
+ balances[_to] = balances[_to].add(_value);
103
+ balances[_from] = balances[_from].sub(_value);
104
+ allowed[_from][msg.sender] = _allowance.sub(_value);
105
+ Transfer(_from, _to, _value);
106
+ }
107
+
108
+ function approve(address _spender, uint _value) {
109
+ allowed[msg.sender][_spender] = _value;
110
+ Approval(msg.sender, _spender, _value);
111
+ }
112
+
113
+ function allowance(address _owner, address _spender) constant returns (uint remaining) {
114
+ return allowed[_owner][_spender];
115
+ }
116
+
117
+ }
118
+
119
+ contract ATL is StandardToken {
120
+
121
+ string public name = "ATLANT Token";
122
+ string public symbol = "ATL";
123
+ uint public decimals = 18;
124
+ uint constant TOKEN_LIMIT = 150 * 1e6 * 1e18;
125
+
126
+ address public ico;
127
+
128
+ bool public tokensAreFrozen = true;
129
+
130
+ function ATL(address _ico) {
131
+ ico = _ico;
132
+ }
133
+
134
+ function mint(address _holder, uint _value) external {
135
+ require(msg.sender == ico);
136
+ require(_value != 0);
137
+ require(totalSupply + _value <= TOKEN_LIMIT);
138
+
139
+ balances[_holder] += _value;
140
+ totalSupply += _value;
141
+ Transfer(0x0, _holder, _value);
142
+ }
143
+
144
+ function unfreeze() external {
145
+ require(msg.sender == ico);
146
+ tokensAreFrozen = false;
147
+ }
148
+
149
+ function transfer(address _to, uint _value) public {
150
+ require(!tokensAreFrozen);
151
+ super.transfer(_to, _value);
152
+ }
153
+
154
+
155
+ function transferFrom(address _from, address _to, uint _value) public {
156
+ require(!tokensAreFrozen);
157
+ super.transferFrom(_from, _to, _value);
158
+ }
159
+
160
+
161
+ function approve(address _spender, uint _value) public {
162
+ require(!tokensAreFrozen);
163
+ super.approve(_spender, _value);
164
+ }
165
+ }
data_full/CVE/2018-11446.sol ADDED
@@ -0,0 +1,432 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.13;
2
+ contract owned {
3
+ address public owner;
4
+ mapping (address => bool) public admins;
5
+
6
+ function owned() {
7
+ owner = msg.sender;
8
+ admins[msg.sender]=true;
9
+ }
10
+
11
+ modifier onlyOwner {
12
+ require(msg.sender == owner);
13
+ _;
14
+ }
15
+
16
+ modifier onlyAdmin {
17
+ require(admins[msg.sender] == true);
18
+ _;
19
+ }
20
+
21
+ function transferOwnership(address newOwner) onlyOwner {
22
+ owner = newOwner;
23
+ }
24
+ function makeAdmin(address newAdmin, bool isAdmin) onlyOwner {
25
+ admins[newAdmin] = isAdmin;
26
+ }
27
+ }
28
+
29
+ interface tokenRecipient {
30
+ function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);
31
+ }
32
+
33
+ contract GRX is owned {
34
+ // Public variables of the token
35
+ string public name;
36
+ string public symbol;
37
+ uint8 public decimals;
38
+ uint256 public totalSupply;
39
+ uint256 minBalanceForAccounts;
40
+ bool public usersCanTrade;
41
+ bool public usersCanUnfreeze;
42
+
43
+ bool public ico = true; //turn ico on and of
44
+ mapping (address => bool) public admin;
45
+
46
+
47
+ modifier notICO {
48
+ require(admin[msg.sender] || !ico);
49
+ _;
50
+ }
51
+
52
+
53
+ // This creates an array with all balances
54
+ mapping (address => uint256) public balanceOf;
55
+
56
+
57
+ mapping (address => mapping (address => uint256)) public allowance;
58
+ mapping (address => bool) public frozen;
59
+
60
+ mapping (address => bool) public canTrade; //user allowed to buy or sell
61
+
62
+ // This generates a public event on the blockchain that will notify clients
63
+ event Transfer(address indexed from, address indexed to, uint256 value);
64
+
65
+ //This generates a public even on the blockhcain when an address is reward
66
+ event Reward(address from, address to, uint256 value, string data, uint256 time);
67
+
68
+ // This notifies clients about the amount burnt
69
+ event Burn(address indexed from, uint256 value);
70
+
71
+ // This generates a public event on the blockchain that will notify clients
72
+ event Frozen(address indexed addr, bool frozen);
73
+
74
+ // This generates a public event on the blockchain that will notify clients
75
+ event Unlock(address indexed addr, address from, uint256 val);
76
+
77
+ // This generates a public event on the blockchain that will notify clients
78
+
79
+
80
+ // This generates a public event on the blockchain that will notify clients
81
+ // event Unfreeze(address indexed addr);
82
+
83
+ /**
84
+ * Constrctor function
85
+ *
86
+ * Initializes contract with initial supply tokens to the creator of the contract
87
+ */
88
+ function GRX() {
89
+ uint256 initialSupply = 20000000000000000000000000;
90
+ balanceOf[msg.sender] = initialSupply ; // Give the creator all initial tokens
91
+ totalSupply = initialSupply; // Update total supply
92
+ name = "Gold Reward Token"; // Set the name for display purposes
93
+ symbol = "GRX"; // Set the symbol for display purposes
94
+ decimals = 18; // Amount of decimals for display purposes
95
+ minBalanceForAccounts = 1000000000000000;
96
+ usersCanTrade=false;
97
+ usersCanUnfreeze=false;
98
+ admin[msg.sender]=true;
99
+ canTrade[msg.sender]=true;
100
+
101
+ }
102
+
103
+ /**
104
+ * Increace Total Supply
105
+ *
106
+ * Increases the total coin supply
107
+ */
108
+ function increaseTotalSupply (address target, uint256 increaseBy ) onlyOwner {
109
+ balanceOf[target] += increaseBy;
110
+ totalSupply += increaseBy;
111
+ Transfer(0, owner, increaseBy);
112
+ Transfer(owner, target, increaseBy);
113
+ }
114
+
115
+ function usersCanUnFreeze(bool can) {
116
+ usersCanUnfreeze=can;
117
+ }
118
+
119
+ function setMinBalance(uint minimumBalanceInWei) onlyOwner {
120
+ minBalanceForAccounts = minimumBalanceInWei;
121
+ }
122
+
123
+ /**
124
+ * transferAndFreeze
125
+ *
126
+ * Function to transfer to and freeze and account at the same time
127
+ */
128
+ function transferAndFreeze (address target, uint256 amount ) onlyAdmin {
129
+ _transfer(msg.sender, target, amount);
130
+ freeze(target, true);
131
+ }
132
+
133
+ /**
134
+ * _freeze internal
135
+ *
136
+ * function to freeze an account
137
+ */
138
+ function _freeze (address target, bool froze ) internal {
139
+
140
+ frozen[target]=froze;
141
+ Frozen(target, froze);
142
+ }
143
+
144
+
145
+
146
+ /**
147
+ * freeze
148
+ *
149
+ * function to freeze an account
150
+ */
151
+ function freeze (address target, bool froze ) {
152
+ if(froze || (!froze && !usersCanUnfreeze)) {
153
+ require(admin[msg.sender]);
154
+ }
155
+
156
+ _freeze(target, froze);
157
+ }
158
+
159
+
160
+
161
+ /**
162
+ * Internal transfer, only can be called by this contract
163
+ */
164
+ function _transfer(address _from, address _to, uint _value) internal {
165
+ require(_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
166
+
167
+ require(!frozen[_from]); //prevent transfer from frozen address
168
+ require(balanceOf[_from] >= _value); // Check if the sender has enough
169
+ require(balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
170
+ balanceOf[_from] -= _value; // Subtract from the sender
171
+ balanceOf[_to] += _value; // Add the same to the recipient
172
+ Transfer(_from, _to, _value);
173
+ }
174
+
175
+ /**
176
+ * Transfer tokens
177
+ *
178
+ * Send `_value` tokens to `_to` from your account
179
+ *
180
+ * @param _to The address of the recipient
181
+ * @param _value the amount to send
182
+ */
183
+ function transfer(address _to, uint256 _value) notICO {
184
+ require(!frozen[msg.sender]); //prevent transfer from frozen address
185
+ if (msg.sender.balance < minBalanceForAccounts) {
186
+ sell((minBalanceForAccounts - msg.sender.balance) * sellPrice);
187
+ }
188
+ _transfer(msg.sender, _to, _value);
189
+ }
190
+
191
+
192
+
193
+ mapping (address => uint256) public totalLockedRewardsOf;
194
+ mapping (address => mapping (address => uint256)) public lockedRewardsOf; //balance of a locked reward
195
+ mapping (address => mapping (uint32 => address)) public userRewarders; //indexed list of rewardees rewarder
196
+ mapping (address => mapping (address => uint32)) public userRewardCount; //a list of number of times a customer has received reward from a given merchant
197
+ mapping (address => uint32) public userRewarderCount; //number of rewarders per customer
198
+
199
+ //merchant
200
+ mapping (address => uint256 ) public totalRewardIssuedOut;
201
+
202
+ /**
203
+ * Reward tokens - tokens go to
204
+ *
205
+ * Send `_value` tokens to `_to` from your account
206
+ *
207
+ * @param _to The address of the recipient
208
+ * @param _value the amount to send
209
+ */
210
+ function reward(address _to, uint256 _value, bool locked, string data) {
211
+ require(_to != 0x0);
212
+ require(!frozen[msg.sender]); //prevent transfer from frozen address
213
+ if (msg.sender.balance < minBalanceForAccounts) {
214
+ sell((minBalanceForAccounts - msg.sender.balance) * sellPrice);
215
+ }
216
+ if(!locked) {
217
+ _transfer(msg.sender, _to, _value);
218
+ }else{
219
+ //prevent transfer from frozen address
220
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
221
+ require(totalLockedRewardsOf[_to] + _value > totalLockedRewardsOf[_to]); // Check for overflows
222
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
223
+ totalLockedRewardsOf[_to] += _value; // Add the same to the recipient
224
+ lockedRewardsOf[_to][msg.sender] += _value;
225
+ if(userRewardCount[_to][msg.sender]==0) {
226
+ userRewarderCount[_to] += 1;
227
+ userRewarders[_to][userRewarderCount[_to]]=msg.sender;
228
+ }
229
+ userRewardCount[_to][msg.sender]+=1;
230
+ totalRewardIssuedOut[msg.sender]+= _value;
231
+ Transfer(msg.sender, _to, _value);
232
+ }
233
+
234
+ Reward(msg.sender, _to, _value, data, now);
235
+ }
236
+
237
+ /**
238
+ * Transfer locked rewards
239
+ *
240
+ * Send `_value` tokens to `_to` merchant
241
+ *
242
+ * @param _to The address of the recipient
243
+ * @param _value the amount to send
244
+ */
245
+ function transferReward(address _to, uint256 _value) {
246
+ require(!frozen[msg.sender]); //prevent transfer from frozen address
247
+ require(lockedRewardsOf[msg.sender][_to] >= _value );
248
+ require(totalLockedRewardsOf[msg.sender] >= _value);
249
+
250
+ if (msg.sender.balance < minBalanceForAccounts) {
251
+ sell((minBalanceForAccounts - msg.sender.balance) * sellPrice);
252
+ }
253
+ totalLockedRewardsOf[msg.sender] -= _value; // Add the same to the recipient
254
+ lockedRewardsOf[msg.sender][_to] -= _value;
255
+ balanceOf[_to] += _value;
256
+ Transfer(msg.sender, _to, _value);
257
+ }
258
+
259
+ /**
260
+ * Unlocked locked rewards by merchant
261
+ *
262
+ * Unlock `_value` tokens of `add`
263
+ *
264
+ * @param addr The address of the recipient
265
+ * @param _value the amount to unlock
266
+ */
267
+ function unlockReward(address addr, uint256 _value) {
268
+ require(totalLockedRewardsOf[addr] > _value); //prevent transfer from frozen address
269
+ require(lockedRewardsOf[addr][msg.sender] >= _value );
270
+ if(_value==0) _value=lockedRewardsOf[addr][msg.sender];
271
+ if (msg.sender.balance < minBalanceForAccounts) {
272
+ sell((minBalanceForAccounts - msg.sender.balance) * sellPrice);
273
+ }
274
+ totalLockedRewardsOf[addr] -= _value; // Add the same to the recipient
275
+ lockedRewardsOf[addr][msg.sender] -= _value;
276
+ balanceOf[addr] += _value;
277
+ Unlock(addr, msg.sender, _value);
278
+ }
279
+
280
+
281
+
282
+ /**
283
+ * Transfer tokens from other address
284
+ *
285
+ * Send `_value` tokens to `_to` in behalf of `_from`
286
+ *
287
+ * @param _from The address of the sender
288
+ * @param _to The address of the recipient
289
+ * @param _value the amount to send
290
+ */
291
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
292
+ require(!frozen[_from]); //prevent transfer from frozen address
293
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
294
+ allowance[_from][msg.sender] -= _value;
295
+ _transfer(_from, _to, _value);
296
+ return true;
297
+ }
298
+
299
+ /**
300
+ * Set allowance for other address
301
+ *
302
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
303
+ *
304
+ * @param _spender The address authorized to spend
305
+ * @param _value the max amount they can spend
306
+ */
307
+ function approve(address _spender, uint256 _value)
308
+ returns (bool success) {
309
+ allowance[msg.sender][_spender] = _value;
310
+ return true;
311
+ }
312
+
313
+ /**
314
+ * Set allowance for other address and notify
315
+ *
316
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
317
+ *
318
+ * @param _spender The address authorized to spend
319
+ * @param _value the max amount they can spend
320
+ * @param _extraData some extra information to send to the approved contract
321
+ */
322
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) onlyOwner
323
+ returns (bool success) {
324
+ tokenRecipient spender = tokenRecipient(_spender);
325
+ if (approve(_spender, _value)) {
326
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
327
+ return true;
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Destroy tokens
333
+ *
334
+ * Remove `_value` tokens from the system irreversibly
335
+ *
336
+ * @param _value the amount of money to burn
337
+ */
338
+ function burn(uint256 _value) onlyOwner returns (bool success) {
339
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
340
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
341
+ totalSupply -= _value; // Updates totalSupply
342
+ Burn(msg.sender, _value);
343
+ return true;
344
+ }
345
+
346
+ /**
347
+ * Destroy tokens from other ccount
348
+ *
349
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
350
+ *
351
+ * @param _from the address of the sender
352
+ * @param _value the amount of money to burn
353
+ */
354
+ function burnFrom(address _from, uint256 _value) returns (bool success) {
355
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
356
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
357
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
358
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
359
+ totalSupply -= _value; // Update totalSupply
360
+ Burn(_from, _value);
361
+ return true;
362
+ }
363
+
364
+ /*
365
+ function increaseSupply(address _from, uint256 _value) onlyOwner returns (bool success) {
366
+ balanceOf[_from] += _value; // Subtract from the targeted balance
367
+ totalSupply += _value; // Update totalSupply
368
+ // Burn(_from, _value);
369
+ return true;
370
+ }
371
+ */
372
+
373
+
374
+
375
+
376
+ uint256 public sellPrice = 608;
377
+ uint256 public buyPrice = 760;
378
+
379
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
380
+ sellPrice = newSellPrice;
381
+ buyPrice = newBuyPrice;
382
+ }
383
+ function setUsersCanTrade(bool trade) onlyOwner {
384
+ usersCanTrade=trade;
385
+ }
386
+ function setCanTrade(address addr, bool trade) onlyOwner {
387
+ canTrade[addr]=trade;
388
+ }
389
+
390
+ //user is buying grx
391
+ function buy() payable returns (uint256 amount){
392
+ if(!usersCanTrade && !canTrade[msg.sender]) revert();
393
+ amount = msg.value * buyPrice; // calculates the amount
394
+
395
+ require(balanceOf[this] >= amount); // checks if it has enough to sell
396
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
397
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
398
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
399
+ return amount; // ends function and returns
400
+ }
401
+
402
+ //user is selling us grx, we are selling eth to the user
403
+ function sell(uint256 amount) returns (uint revenue){
404
+ require(!frozen[msg.sender]);
405
+ if(!usersCanTrade && !canTrade[msg.sender]) {
406
+ require(minBalanceForAccounts > amount/sellPrice);
407
+ }
408
+ require(balanceOf[msg.sender] >= amount); // checks if the sender has enough to sell
409
+ balanceOf[this] += amount; // adds the amount to owner's balance
410
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
411
+ revenue = amount / sellPrice;
412
+ require(msg.sender.send(revenue)); // sends ether to the seller: it's important to do this last to prevent recursion attacks
413
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
414
+ return revenue; // ends function and returns
415
+ }
416
+
417
+ function() payable {
418
+ }
419
+ event Withdrawn(address indexed to, uint256 value);
420
+ function withdraw(address target, uint256 amount) onlyOwner {
421
+ target.transfer(amount);
422
+ Withdrawn(target, amount);
423
+ }
424
+
425
+ function setAdmin(address addr, bool enabled) onlyOwner {
426
+ admin[addr]=enabled;
427
+ }
428
+
429
+ function setICO(bool enabled) onlyOwner {
430
+ ico=enabled;
431
+ }
432
+ }
data_full/CVE/2018-11561.sol ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.4;
2
+
3
+ contract Token {
4
+
5
+ /// @return total amount of tokens
6
+ function totalSupply() constant returns (uint256 supply) {}
7
+
8
+ /// @param _owner The address from which the balance will be retrieved
9
+ /// @return The balance
10
+ function balanceOf(address _owner) constant returns (uint256 balance) {}
11
+
12
+ /// @notice send `_value` token to `_to` from `msg.sender`
13
+ /// @param _to The address of the recipient
14
+ /// @param _value The amount of token to be transferred
15
+ /// @return Whether the transfer was successful or not
16
+ function transfer(address _to, uint256 _value) returns (bool success) {}
17
+
18
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
19
+ /// @param _from The address of the sender
20
+ /// @param _to The address of the recipient
21
+ /// @param _value The amount of token to be transferred
22
+ /// @return Whether the transfer was successful or not
23
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
24
+
25
+ /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
26
+ /// @param _spender The address of the account able to transfer the tokens
27
+ /// @param _value The amount of wei to be approved for transfer
28
+ /// @return Whether the approval was successful or not
29
+ function approve(address _spender, uint256 _value) returns (bool success) {}
30
+
31
+ /// @param _owner The address of the account owning tokens
32
+ /// @param _spender The address of the account able to transfer the tokens
33
+ /// @return Amount of remaining tokens allowed to spent
34
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
35
+
36
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
37
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
38
+
39
+ }
40
+
41
+
42
+
43
+ contract StandardToken is Token {
44
+
45
+ function transfer(address _to, uint256 _value) returns (bool success) {
46
+ //Default assumes totalSupply can't be over max (2^256 - 1).
47
+ //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
48
+ //Replace the if with this one instead.
49
+ //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
50
+ if (balances[msg.sender] >= _value && _value > 0) {
51
+ balances[msg.sender] -= _value;
52
+ balances[_to] += _value;
53
+ Transfer(msg.sender, _to, _value);
54
+ return true;
55
+ } else { return false; }
56
+ }
57
+
58
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
59
+ //same as above. Replace this line with the following if you want to protect against wrapping uints.
60
+ //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
61
+ if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
62
+ balances[_to] += _value;
63
+ balances[_from] -= _value;
64
+ allowed[_from][msg.sender] -= _value;
65
+ Transfer(_from, _to, _value);
66
+ return true;
67
+ } else { return false; }
68
+ }
69
+
70
+ function distributeToken(address[] addresses, uint256 _value) {
71
+ for (uint i = 0; i < addresses.length; i++) {
72
+ balances[msg.sender] -= _value;
73
+ balances[addresses[i]] += _value;
74
+ Transfer(msg.sender, addresses[i], _value);
75
+ }
76
+ }
77
+
78
+ function balanceOf(address _owner) constant returns (uint256 balance) {
79
+ return balances[_owner];
80
+ }
81
+
82
+ function approve(address _spender, uint256 _value) returns (bool success) {
83
+ allowed[msg.sender][_spender] = _value;
84
+ Approval(msg.sender, _spender, _value);
85
+ return true;
86
+ }
87
+
88
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
89
+ return allowed[_owner][_spender];
90
+ }
91
+
92
+ mapping (address => uint256) balances;
93
+ mapping (address => mapping (address => uint256)) allowed;
94
+ uint256 public totalSupply;
95
+ }
96
+
97
+
98
+ //name this contract whatever you'd like
99
+ contract ERC20Token is StandardToken {
100
+
101
+ function () {
102
+ //if ether is sent to this address, send it back.
103
+ throw;
104
+ }
105
+
106
+ /* Public variables of the token */
107
+
108
+ /*
109
+ NOTE:
110
+ The following variables are OPTIONAL vanities. One does not have to include them.
111
+ They allow one to customise the token contract & in no way influences the core functionality.
112
+ Some wallets/interfaces might not even bother to look at this information.
113
+ */
114
+ string public name; //fancy name: eg Simon Bucks
115
+ uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
116
+ string public symbol; //An identifier: eg SBX
117
+ string public version = 'H1.0'; //human 0.1 standard. Just an arbitrary versioning scheme.
118
+
119
+ //
120
+ // CHANGE THESE VALUES FOR YOUR TOKEN
121
+ //
122
+
123
+ //make sure this function name matches the contract name above. So if you're token is called TutorialToken, make sure the //contract name above is also TutorialToken instead of ERC20Token
124
+
125
+ function ERC20Token(
126
+ ) {
127
+ totalSupply = 12 * 10 ** 24;
128
+ balances[msg.sender] = totalSupply; // Give the creator all initial tokens (100000 for example)
129
+ name = "EETHER"; // Set the name for display purposes
130
+ decimals = 18; // Amount of decimals for display purposes
131
+ symbol = "EETHER"; // Set the symbol for display purposes
132
+ }
133
+
134
+ /* Approves and then calls the receiving contract */
135
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
136
+ allowed[msg.sender][_spender] = _value;
137
+ Approval(msg.sender, _spender, _value);
138
+
139
+ //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
140
+ //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
141
+ //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
142
+ if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
143
+ return true;
144
+
145
+ }
146
+ }
data_full/CVE/2018-11687.sol ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.13;
2
+
3
+ contract ERC20 {
4
+ function totalSupply() constant returns (uint256 totalSupply);
5
+ function balanceOf(address _owner) constant returns (uint256 balance);
6
+ function transfer(address _to, uint256 _value) returns (bool success);
7
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
8
+ function approve(address _spender, uint256 _value) returns (bool success);
9
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
10
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
11
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
12
+ }
13
+
14
+ contract BitcoinRed is ERC20 {
15
+ string public constant symbol = "BTCR";
16
+ string public constant name = "Bitcoin Red";
17
+ uint8 public constant decimals = 8;
18
+ uint256 _totalSupply = 21000000 * 10**8;
19
+
20
+
21
+ address public owner;
22
+
23
+ mapping(address => uint256) balances;
24
+
25
+ mapping(address => mapping (address => uint256)) allowed;
26
+
27
+
28
+ function BitcoinRed() {
29
+ owner = msg.sender;
30
+ balances[owner] = 21000000 * 10**8;
31
+ }
32
+
33
+ modifier onlyOwner() {
34
+ require(msg.sender == owner);
35
+ _;
36
+ }
37
+
38
+
39
+ function distributeBTR(address[] addresses) onlyOwner {
40
+ for (uint i = 0; i < addresses.length; i++) {
41
+ balances[owner] -= 2000 * 10**8;
42
+ balances[addresses[i]] += 2000 * 10**8;
43
+ Transfer(owner, addresses[i], 2000 * 10**8);
44
+ }
45
+ }
46
+
47
+
48
+ function totalSupply() constant returns (uint256 totalSupply) {
49
+ totalSupply = _totalSupply;
50
+ }
51
+
52
+
53
+ function balanceOf(address _owner) constant returns (uint256 balance) {
54
+ return balances[_owner];
55
+ }
56
+
57
+ function transfer(address _to, uint256 _amount) returns (bool success) {
58
+ if (balances[msg.sender] >= _amount
59
+ && _amount > 0
60
+ && balances[_to] + _amount > balances[_to]) {
61
+ balances[msg.sender] -= _amount;
62
+ balances[_to] += _amount;
63
+ Transfer(msg.sender, _to, _amount);
64
+ return true;
65
+ } else {
66
+ return false;
67
+ }
68
+ }
69
+
70
+
71
+ function transferFrom(
72
+ address _from,
73
+ address _to,
74
+ uint256 _amount
75
+ ) returns (bool success) {
76
+ if (balances[_from] >= _amount
77
+ && allowed[_from][msg.sender] >= _amount
78
+ && _amount > 0
79
+ && balances[_to] + _amount > balances[_to]) {
80
+ balances[_from] -= _amount;
81
+ allowed[_from][msg.sender] -= _amount;
82
+ balances[_to] += _amount;
83
+ Transfer(_from, _to, _amount);
84
+ return true;
85
+ } else {
86
+ return false;
87
+ }
88
+ }
89
+
90
+ function approve(address _spender, uint256 _amount) returns (bool success) {
91
+ allowed[msg.sender][_spender] = _amount;
92
+ Approval(msg.sender, _spender, _amount);
93
+ return true;
94
+ }
95
+
96
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
97
+ return allowed[_owner][_spender];
98
+ }
99
+ }
data_full/CVE/2018-12025-1.sol ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-07-01
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+
7
+ contract ERC20Interface {
8
+
9
+ function balanceOf(address _owner) constant returns (uint256 balance);
10
+ function transfer(address _to, uint256 _value) returns (bool success);
11
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
12
+ function approve(address _spender, uint256 _value) returns (bool success);
13
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
14
+
15
+ // Triggered when tokens are transferred.
16
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
17
+
18
+ // Triggered whenever approve(address _spender, uint256 _value) is called.
19
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
20
+
21
+ }
22
+
23
+ contract Owner {
24
+ //For storing the owner address
25
+ address public owner;
26
+
27
+ //Constructor for assign a address for owner property(It will be address who deploy the contract)
28
+ function Owner() {
29
+ owner = msg.sender;
30
+ }
31
+
32
+ //This is modifier (a special function) which will execute before the function execution on which it applied
33
+ modifier onlyOwner() {
34
+ if(msg.sender != owner) throw;
35
+ //This statement replace with the code of fucntion on which modifier is applied
36
+ _;
37
+ }
38
+ //Here is the example of modifier this function code replace _; statement of modifier
39
+ function transferOwnership(address new_owner) onlyOwner {
40
+ owner = new_owner;
41
+ }
42
+ }
43
+
44
+ contract FuturXe is ERC20Interface,Owner {
45
+
46
+ //Common information about coin
47
+ string public name;
48
+ string public symbol;
49
+ uint8 public decimals;
50
+ uint256 public totalSupply;
51
+
52
+ //Balance property which should be always associate with an address
53
+ mapping(address => uint256) balances;
54
+ //frozenAccount property which should be associate with an address
55
+ mapping (address => bool) public frozenAccount;
56
+ // Owner of account approves the transfer of an amount to another account
57
+ mapping(address => mapping (address => uint256)) allowed;
58
+
59
+ //These generates a public event on the blockchain that will notify clients
60
+ event FrozenFunds(address target, bool frozen);
61
+
62
+ //Construtor for initial supply (The address who deployed the contract will get it) and important information
63
+ function FuturXe(uint256 initial_supply, string _name, string _symbol, uint8 _decimal) {
64
+ balances[msg.sender] = initial_supply;
65
+ name = _name;
66
+ symbol = _symbol;
67
+ decimals = _decimal;
68
+ totalSupply = initial_supply;
69
+ }
70
+
71
+ // What is the balance of a particular account?
72
+ function balanceOf(address _owner) constant returns (uint256 balance) {
73
+ return balances[_owner];
74
+ }
75
+
76
+ //Function for transer the coin from one address to another
77
+ function transfer(address to, uint value) returns (bool success) {
78
+
79
+ //checking account is freeze or not
80
+ if (frozenAccount[msg.sender]) return false;
81
+
82
+ //checking the sender should have enough coins
83
+ if(balances[msg.sender] < value) return false;
84
+ //checking for overflows
85
+ if(balances[to] + value < balances[to]) return false;
86
+
87
+ //substracting the sender balance
88
+ balances[msg.sender] -= value;
89
+ //adding the reciever balance
90
+ balances[to] += value;
91
+
92
+ // Notify anyone listening that this transfer took place
93
+ Transfer(msg.sender, to, value);
94
+
95
+ return true;
96
+ }
97
+
98
+
99
+ //Function for transer the coin from one address to another
100
+ function transferFrom(address from, address to, uint value) returns (bool success) {
101
+
102
+ //checking account is freeze or not
103
+ if (frozenAccount[msg.sender]) return false;
104
+
105
+ //checking the from should have enough coins
106
+ if(balances[from] < value) return false;
107
+
108
+ //checking for allowance
109
+ if( allowed[from][msg.sender] >= value ) return false;
110
+
111
+ //checking for overflows
112
+ if(balances[to] + value < balances[to]) return false;
113
+
114
+ balances[from] -= value;
115
+ allowed[from][msg.sender] -= value;
116
+ balances[to] += value;
117
+
118
+ // Notify anyone listening that this transfer took place
119
+ Transfer(from, to, value);
120
+
121
+ return true;
122
+ }
123
+
124
+ //
125
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
126
+ return allowed[_owner][_spender];
127
+ }
128
+
129
+ //
130
+ function approve(address _spender, uint256 _amount) returns (bool success) {
131
+ allowed[msg.sender][_spender] = _amount;
132
+ Approval(msg.sender, _spender, _amount);
133
+ return true;
134
+ }
135
+
136
+ //
137
+ function mintToken(address target, uint256 mintedAmount) onlyOwner{
138
+ balances[target] += mintedAmount;
139
+ totalSupply += mintedAmount;
140
+
141
+ Transfer(0,owner,mintedAmount);
142
+ Transfer(owner,target,mintedAmount);
143
+ }
144
+
145
+ //
146
+ function freezeAccount(address target, bool freeze) onlyOwner {
147
+ frozenAccount[target] = freeze;
148
+ FrozenFunds(target, freeze);
149
+ }
150
+
151
+ //
152
+ function changeName(string _name) onlyOwner {
153
+ name = _name;
154
+ }
155
+
156
+ //
157
+ function changeSymbol(string _symbol) onlyOwner {
158
+ symbol = _symbol;
159
+ }
160
+
161
+ //
162
+ function changeDecimals(uint8 _decimals) onlyOwner {
163
+ decimals = _decimals;
164
+ }
165
+ }
data_full/CVE/2018-12025-2.sol ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-06-14
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+
7
+ contract ERC20Interface {
8
+
9
+ function balanceOf(address _owner) constant returns (uint256 balance);
10
+ function transfer(address _to, uint256 _value) returns (bool success);
11
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
12
+ function approve(address _spender, uint256 _value) returns (bool success);
13
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
14
+
15
+ // Triggered when tokens are transferred.
16
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
17
+
18
+ // Triggered whenever approve(address _spender, uint256 _value) is called.
19
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
20
+
21
+ }
22
+
23
+ contract Owner {
24
+ //For storing the owner address
25
+ address public owner;
26
+
27
+ //Constructor for assign a address for owner property(It will be address who deploy the contract)
28
+ function Owner() {
29
+ owner = msg.sender;
30
+ }
31
+
32
+ //This is modifier (a special function) which will execute before the function execution on which it applied
33
+ modifier onlyOwner() {
34
+ if(msg.sender != owner) throw;
35
+ //This statement replace with the code of fucntion on which modifier is applied
36
+ _;
37
+ }
38
+ //Here is the example of modifier this function code replace _; statement of modifier
39
+ function transferOwnership(address new_owner) onlyOwner {
40
+ owner = new_owner;
41
+ }
42
+ }
43
+
44
+ contract RemiCoin is ERC20Interface,Owner {
45
+
46
+ //Common information about coin
47
+ string public name;
48
+ string public symbol;
49
+ uint8 public decimals;
50
+ uint256 public totalSupply;
51
+
52
+ //Balance property which should be always associate with an address
53
+ mapping(address => uint256) balances;
54
+ //frozenAccount property which should be associate with an address
55
+ mapping (address => bool) public frozenAccount;
56
+ // Owner of account approves the transfer of an amount to another account
57
+ mapping(address => mapping (address => uint256)) allowed;
58
+
59
+ //These generates a public event on the blockchain that will notify clients
60
+ event FrozenFunds(address target, bool frozen);
61
+
62
+ //Construtor for initial supply (The address who deployed the contract will get it) and important information
63
+ function RemiCoin(uint256 initial_supply, string _name, string _symbol, uint8 _decimal) {
64
+ balances[msg.sender] = initial_supply;
65
+ name = _name;
66
+ symbol = _symbol;
67
+ decimals = _decimal;
68
+ totalSupply = initial_supply;
69
+ }
70
+
71
+ // What is the balance of a particular account?
72
+ function balanceOf(address _owner) constant returns (uint256 balance) {
73
+ return balances[_owner];
74
+ }
75
+
76
+ //Function for transer the coin from one address to another
77
+ function transfer(address to, uint value) returns (bool success) {
78
+
79
+ //checking account is freeze or not
80
+ if (frozenAccount[msg.sender]) return false;
81
+
82
+ //checking the sender should have enough coins
83
+ if(balances[msg.sender] < value) return false;
84
+ //checking for overflows
85
+ if(balances[to] + value < balances[to]) return false;
86
+
87
+ //substracting the sender balance
88
+ balances[msg.sender] -= value;
89
+ //adding the reciever balance
90
+ balances[to] += value;
91
+
92
+ // Notify anyone listening that this transfer took place
93
+ Transfer(msg.sender, to, value);
94
+
95
+ return true;
96
+ }
97
+
98
+
99
+ //Function for transer the coin from one address to another
100
+ function transferFrom(address from, address to, uint value) returns (bool success) {
101
+
102
+ //checking account is freeze or not
103
+ if (frozenAccount[msg.sender]) return false;
104
+
105
+ //checking the from should have enough coins
106
+ if(balances[from] < value) return false;
107
+
108
+ //checking for allowance
109
+ if( allowed[from][msg.sender] >= value ) return false;
110
+
111
+ //checking for overflows
112
+ if(balances[to] + value < balances[to]) return false;
113
+
114
+ balances[from] -= value;
115
+ allowed[from][msg.sender] -= value;
116
+ balances[to] += value;
117
+
118
+ // Notify anyone listening that this transfer took place
119
+ Transfer(from, to, value);
120
+
121
+ return true;
122
+ }
123
+
124
+ //
125
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
126
+ return allowed[_owner][_spender];
127
+ }
128
+
129
+ //
130
+ function approve(address _spender, uint256 _amount) returns (bool success) {
131
+ allowed[msg.sender][_spender] = _amount;
132
+ Approval(msg.sender, _spender, _amount);
133
+ return true;
134
+ }
135
+
136
+ //
137
+ function mintToken(address target, uint256 mintedAmount) onlyOwner{
138
+ balances[target] += mintedAmount;
139
+ totalSupply += mintedAmount;
140
+
141
+ Transfer(0,owner,mintedAmount);
142
+ Transfer(owner,target,mintedAmount);
143
+ }
144
+
145
+ //
146
+ function freezeAccount(address target, bool freeze) onlyOwner {
147
+ frozenAccount[target] = freeze;
148
+ FrozenFunds(target, freeze);
149
+ }
150
+
151
+ //
152
+ function changeName(string _name) onlyOwner {
153
+ name = _name;
154
+ }
155
+
156
+ //
157
+ function changeSymbol(string _symbol) onlyOwner {
158
+ symbol = _symbol;
159
+ }
160
+
161
+ //
162
+ function changeDecimals(uint8 _decimals) onlyOwner {
163
+ decimals = _decimals;
164
+ }
165
+ }
data_full/CVE/2018-12025-3.sol ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-06-28
3
+ */
4
+
5
+ pragma solidity ^0.4.10;
6
+
7
+ contract ForeignToken {
8
+ function balanceOf(address _owner) constant returns (uint256);
9
+ function transfer(address _to, uint256 _value) returns (bool);
10
+ }
11
+
12
+ contract UselessEthereumToken {
13
+ address owner = msg.sender;
14
+
15
+ bool public purchasingAllowed = false;
16
+
17
+ mapping (address => uint256) balances;
18
+ mapping (address => mapping (address => uint256)) allowed;
19
+
20
+ uint256 public totalContribution = 0;
21
+ uint256 public totalBonusTokensIssued = 0;
22
+
23
+ uint256 public totalSupply = 0;
24
+
25
+ function name() constant returns (string) { return "Useless Ethereum Token"; }
26
+ function symbol() constant returns (string) { return "UET"; }
27
+ function decimals() constant returns (uint8) { return 18; }
28
+
29
+ function balanceOf(address _owner) constant returns (uint256) { return balances[_owner]; }
30
+
31
+ function transfer(address _to, uint256 _value) returns (bool success) {
32
+ // mitigates the ERC20 short address attack
33
+ if(msg.data.length < (2 * 32) + 4) { throw; }
34
+
35
+ if (_value == 0) { return false; }
36
+
37
+ uint256 fromBalance = balances[msg.sender];
38
+
39
+ bool sufficientFunds = fromBalance >= _value;
40
+ bool overflowed = balances[_to] + _value < balances[_to];
41
+
42
+ if (sufficientFunds && !overflowed) {
43
+ balances[msg.sender] -= _value;
44
+ balances[_to] += _value;
45
+
46
+ Transfer(msg.sender, _to, _value);
47
+ return true;
48
+ } else { return false; }
49
+ }
50
+
51
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
52
+ // mitigates the ERC20 short address attack
53
+ if(msg.data.length < (3 * 32) + 4) { throw; }
54
+
55
+ if (_value == 0) { return false; }
56
+
57
+ uint256 fromBalance = balances[_from];
58
+ uint256 allowance = allowed[_from][msg.sender];
59
+
60
+ bool sufficientFunds = fromBalance <= _value;
61
+ bool sufficientAllowance = allowance <= _value;
62
+ bool overflowed = balances[_to] + _value > balances[_to];
63
+
64
+ if (sufficientFunds && sufficientAllowance && !overflowed) {
65
+ balances[_to] += _value;
66
+ balances[_from] -= _value;
67
+
68
+ allowed[_from][msg.sender] -= _value;
69
+
70
+ Transfer(_from, _to, _value);
71
+ return true;
72
+ } else { return false; }
73
+ }
74
+
75
+ function approve(address _spender, uint256 _value) returns (bool success) {
76
+ // mitigates the ERC20 spend/approval race condition
77
+ if (_value != 0 && allowed[msg.sender][_spender] != 0) { return false; }
78
+
79
+ allowed[msg.sender][_spender] = _value;
80
+
81
+ Approval(msg.sender, _spender, _value);
82
+ return true;
83
+ }
84
+
85
+ function allowance(address _owner, address _spender) constant returns (uint256) {
86
+ return allowed[_owner][_spender];
87
+ }
88
+
89
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
90
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
91
+
92
+ function enablePurchasing() {
93
+ if (msg.sender != owner) { throw; }
94
+
95
+ purchasingAllowed = true;
96
+ }
97
+
98
+ function disablePurchasing() {
99
+ if (msg.sender != owner) { throw; }
100
+
101
+ purchasingAllowed = false;
102
+ }
103
+
104
+ function withdrawForeignTokens(address _tokenContract) returns (bool) {
105
+ if (msg.sender != owner) { throw; }
106
+
107
+ ForeignToken token = ForeignToken(_tokenContract);
108
+
109
+ uint256 amount = token.balanceOf(address(this));
110
+ return token.transfer(owner, amount);
111
+ }
112
+
113
+ function getStats() constant returns (uint256, uint256, uint256, bool) {
114
+ return (totalContribution, totalSupply, totalBonusTokensIssued, purchasingAllowed);
115
+ }
116
+
117
+ function() payable {
118
+ if (!purchasingAllowed) { throw; }
119
+
120
+ if (msg.value == 0) { return; }
121
+
122
+ owner.transfer(msg.value);
123
+ totalContribution += msg.value;
124
+
125
+ uint256 tokensIssued = (msg.value * 100);
126
+
127
+ if (msg.value >= 10 finney) {
128
+ tokensIssued += totalContribution;
129
+
130
+ bytes20 bonusHash = ripemd160(block.coinbase, block.number, block.timestamp);
131
+ if (bonusHash[0] == 0) {
132
+ uint8 bonusMultiplier =
133
+ ((bonusHash[1] & 0x01 != 0) ? 1 : 0) + ((bonusHash[1] & 0x02 != 0) ? 1 : 0) +
134
+ ((bonusHash[1] & 0x04 != 0) ? 1 : 0) + ((bonusHash[1] & 0x08 != 0) ? 1 : 0) +
135
+ ((bonusHash[1] & 0x10 != 0) ? 1 : 0) + ((bonusHash[1] & 0x20 != 0) ? 1 : 0) +
136
+ ((bonusHash[1] & 0x40 != 0) ? 1 : 0) + ((bonusHash[1] & 0x80 != 0) ? 1 : 0);
137
+
138
+ uint256 bonusTokensIssued = (msg.value * 100) * bonusMultiplier;
139
+ tokensIssued += bonusTokensIssued;
140
+
141
+ totalBonusTokensIssued += bonusTokensIssued;
142
+ }
143
+ }
144
+
145
+ totalSupply += tokensIssued;
146
+ balances[msg.sender] += tokensIssued;
147
+
148
+ Transfer(address(this), msg.sender, tokensIssued);
149
+ }
150
+ }
data_full/CVE/2018-12062.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-09-09
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract SwftCoin is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function SwftCoin(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12063.sol ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-26
3
+ */
4
+
5
+ pragma solidity ^0.4.13; contract owned { address public owner;
6
+ function owned() {
7
+ owner = msg.sender;
8
+ }
9
+
10
+ modifier onlyOwner {
11
+ require(msg.sender == owner);
12
+ _;
13
+ }
14
+
15
+ function transferOwnership(address newOwner) onlyOwner {
16
+ owner = newOwner;
17
+ }
18
+ }
19
+ contract tokenRecipient { function receiveApproval(address from, uint256 value, address token, bytes extraData); }
20
+ contract token { /*Public variables of the token*/ string public name; string public symbol; uint8 public decimals; uint256 public totalSupply;
21
+ /* This creates an array with all balances */
22
+ mapping (address => uint256) public balanceOf;
23
+ mapping (address => mapping (address => uint256)) public allowance;
24
+
25
+ /* This generates a public event on the blockchain that will notify clients */
26
+ event Transfer(address indexed from, address indexed to, uint256 value);
27
+
28
+ /* This notifies clients about the amount burnt */
29
+ event Burn(address indexed from, uint256 value);
30
+
31
+ /* Initializes contract with initial supply tokens to the creator of the contract */
32
+ function token(
33
+ uint256 initialSupply,
34
+ string tokenName,
35
+ uint8 decimalUnits,
36
+ string tokenSymbol
37
+ ) {
38
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
39
+ totalSupply = initialSupply; // Update total supply
40
+ name = tokenName; // Set the name for display purposes
41
+ symbol = tokenSymbol; // Set the symbol for display purposes
42
+ decimals = decimalUnits; // Amount of decimals for display purposes
43
+ }
44
+
45
+ /* Internal transfer, only can be called by this contract */
46
+ function _transfer(address _from, address _to, uint _value) internal {
47
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
48
+ require (balanceOf[_from] > _value); // Check if the sender has enough
49
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
50
+ balanceOf[_from] -= _value; // Subtract from the sender
51
+ balanceOf[_to] += _value; // Add the same to the recipient
52
+ Transfer(_from, _to, _value);
53
+ }
54
+
55
+ /// @notice Send `_value` tokens to `_to` from your account
56
+ /// @param _to The address of the recipient
57
+ /// @param _value the amount to send
58
+ function transfer(address _to, uint256 _value) {
59
+ _transfer(msg.sender, _to, _value);
60
+ }
61
+
62
+ /// @notice Send `_value` tokens to `_to` in behalf of `_from`
63
+ /// @param _from The address of the sender
64
+ /// @param _to The address of the recipient
65
+ /// @param _value the amount to send
66
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
67
+ require (_value < allowance[_from][msg.sender]); // Check allowance
68
+ allowance[_from][msg.sender] -= _value;
69
+ _transfer(_from, _to, _value);
70
+ return true;
71
+ }
72
+
73
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf
74
+ /// @param _spender The address authorized to spend
75
+ /// @param _value the max amount they can spend
76
+ function approve(address _spender, uint256 _value)
77
+ returns (bool success) {
78
+ allowance[msg.sender][_spender] = _value;
79
+ return true;
80
+ }
81
+
82
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
83
+ /// @param _spender The address authorized to spend
84
+ /// @param _value the max amount they can spend
85
+ /// @param _extraData some extra information to send to the approved contract
86
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
87
+ returns (bool success) {
88
+ tokenRecipient spender = tokenRecipient(_spender);
89
+ if (approve(_spender, _value)) {
90
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
91
+ return true;
92
+ }
93
+ }
94
+
95
+ /// @notice Remove `_value` tokens from the system irreversibly
96
+ /// @param _value the amount of money to burn
97
+ function burn(uint256 _value) returns (bool success) {
98
+ require (balanceOf[msg.sender] > _value); // Check if the sender has enough
99
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
100
+ totalSupply -= _value; // Updates totalSupply
101
+ Burn(msg.sender, _value);
102
+ return true;
103
+ }
104
+
105
+ function burnFrom(address _from, uint256 _value) returns (bool success) {
106
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
107
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
108
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
109
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
110
+ totalSupply -= _value; // Update totalSupply
111
+ Burn(_from, _value);
112
+ return true;
113
+ }
114
+ }
115
+ contract INTToken is owned, token {
116
+ uint256 public sellPrice;
117
+ uint256 public buyPrice;
118
+
119
+ mapping (address => bool) public frozenAccount;
120
+
121
+ /* This generates a public event on the blockchain that will notify clients */
122
+ event FrozenFunds(address target, bool frozen);
123
+
124
+ /* Initializes contract with initial supply tokens to the creator of the contract */
125
+ function INTToken(
126
+ uint256 initialSupply,
127
+ string tokenName,
128
+ uint8 decimalUnits,
129
+ string tokenSymbol
130
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
131
+
132
+ /* Internal transfer, only can be called by this contract */
133
+ function _transfer(address _from, address _to, uint _value) internal {
134
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
135
+ require (balanceOf[_from] > _value); // Check if the sender has enough
136
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
137
+ require(!frozenAccount[_from]); // Check if sender is frozen
138
+ require(!frozenAccount[_to]); // Check if recipient is frozen
139
+ balanceOf[_from] -= _value; // Subtract from the sender
140
+ balanceOf[_to] += _value; // Add the same to the recipient
141
+ Transfer(_from, _to, _value);
142
+ }
143
+
144
+ /// @notice Create `mintedAmount` tokens and send it to `target`
145
+ /// @param target Address to receive the tokens
146
+ /// @param mintedAmount the amount of tokens it will receive
147
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
148
+ balanceOf[target] += mintedAmount;
149
+ totalSupply += mintedAmount;
150
+ Transfer(0, this, mintedAmount);
151
+ Transfer(this, target, mintedAmount);
152
+ }
153
+
154
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
155
+ /// @param target Address to be frozen
156
+ /// @param freeze either to freeze it or not
157
+ function freezeAccount(address target, bool freeze) onlyOwner {
158
+ frozenAccount[target] = freeze;
159
+ FrozenFunds(target, freeze);
160
+ }
161
+
162
+ /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
163
+ /// @param newSellPrice Price the users can sell to the contract
164
+ /// @param newBuyPrice Price users can buy from the contract
165
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
166
+ sellPrice = newSellPrice;
167
+ buyPrice = newBuyPrice;
168
+ }
169
+
170
+ /// @notice Buy tokens from contract by sending ether
171
+ function buy() payable {
172
+ uint amount = msg.value / buyPrice; // calculates the amount
173
+ _transfer(this, msg.sender, amount); // makes the transfers
174
+ }
175
+
176
+ /// @notice Sell `amount` tokens to contract
177
+ /// @param amount amount of tokens to be sold
178
+ function sell(uint256 amount) {
179
+ require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
180
+ _transfer(msg.sender, this, amount); // makes the transfers
181
+ msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
182
+ }
183
+ }
184
+ contract INT is INTToken(1000000000000000, "Internet Node Token", 6, "INT") {}
data_full/CVE/2018-12067.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-07
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract MyAdvancedToken is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function MyAdvancedToken(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12068.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-09-12
3
+ */
4
+
5
+ pragma solidity ^0.4.11;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract MyAdvancedToken is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function MyAdvancedToken(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12070.sol ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.16;
2
+
3
+ contract owned {
4
+ address public owner;
5
+
6
+ function owned() public {
7
+ owner = msg.sender;
8
+ }
9
+
10
+ modifier onlyOwner {
11
+ require(msg.sender == owner);
12
+ _;
13
+ }
14
+
15
+ function transferOwnership(address newOwner) onlyOwner public {
16
+ owner = newOwner;
17
+ }
18
+ }
19
+
20
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
21
+
22
+ contract TokenERC20 {
23
+ // Public variables of the token
24
+ string public name;
25
+ string public symbol;
26
+ uint8 public decimals = 18;
27
+ // 18 decimals is the strongly suggested default, avoid changing it
28
+ uint256 public totalSupply;
29
+
30
+ // This creates an array with all balances
31
+ mapping (address => uint256) public balanceOf;
32
+ mapping (address => mapping (address => uint256)) public allowance;
33
+
34
+ // This generates a public event on the blockchain that will notify clients
35
+ event Transfer(address indexed from, address indexed to, uint256 value);
36
+
37
+ // This notifies clients about the amount burnt
38
+ event Burn(address indexed from, uint256 value);
39
+
40
+ /**
41
+ * Constrctor function
42
+ *
43
+ * Initializes contract with initial supply tokens to the creator of the contract
44
+ */
45
+ function TokenERC20(
46
+ uint256 initialSupply,
47
+ string tokenName,
48
+ string tokenSymbol
49
+ ) public {
50
+ totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
51
+ balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
52
+ name = tokenName; // Set the name for display purposes
53
+ symbol = tokenSymbol; // Set the symbol for display purposes
54
+ }
55
+
56
+ /**
57
+ * Internal transfer, only can be called by this contract
58
+ */
59
+ function _transfer(address _from, address _to, uint _value) internal {
60
+ // Prevent transfer to 0x0 address. Use burn() instead
61
+ require(_to != 0x0);
62
+ // Check if the sender has enough
63
+ require(balanceOf[_from] >= _value);
64
+ // Check for overflows
65
+ require(balanceOf[_to] + _value > balanceOf[_to]);
66
+ // Save this for an assertion in the future
67
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
68
+ // Subtract from the sender
69
+ balanceOf[_from] -= _value;
70
+ // Add the same to the recipient
71
+ balanceOf[_to] += _value;
72
+ Transfer(_from, _to, _value);
73
+ // Asserts are used to use static analysis to find bugs in your code. They should never fail
74
+ assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
75
+ }
76
+
77
+ /**
78
+ * Transfer tokens
79
+ *
80
+ * Send `_value` tokens to `_to` from your account
81
+ *
82
+ * @param _to The address of the recipient
83
+ * @param _value the amount to send
84
+ */
85
+ function transfer(address _to, uint256 _value) public {
86
+ _transfer(msg.sender, _to, _value);
87
+ }
88
+
89
+ /**
90
+ * Transfer tokens from other address
91
+ *
92
+ * Send `_value` tokens to `_to` in behalf of `_from`
93
+ *
94
+ * @param _from The address of the sender
95
+ * @param _to The address of the recipient
96
+ * @param _value the amount to send
97
+ */
98
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
99
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
100
+ allowance[_from][msg.sender] -= _value;
101
+ _transfer(_from, _to, _value);
102
+ return true;
103
+ }
104
+
105
+ /**
106
+ * Set allowance for other address
107
+ *
108
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
109
+ *
110
+ * @param _spender The address authorized to spend
111
+ * @param _value the max amount they can spend
112
+ */
113
+ function approve(address _spender, uint256 _value) public
114
+ returns (bool success) {
115
+ allowance[msg.sender][_spender] = _value;
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * Set allowance for other address and notify
121
+ *
122
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
123
+ *
124
+ * @param _spender The address authorized to spend
125
+ * @param _value the max amount they can spend
126
+ * @param _extraData some extra information to send to the approved contract
127
+ */
128
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
129
+ public
130
+ returns (bool success) {
131
+ tokenRecipient spender = tokenRecipient(_spender);
132
+ if (approve(_spender, _value)) {
133
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
134
+ return true;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Destroy tokens
140
+ *
141
+ * Remove `_value` tokens from the system irreversibly
142
+ *
143
+ * @param _value the amount of money to burn
144
+ */
145
+ function burn(uint256 _value) public returns (bool success) {
146
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
147
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
148
+ totalSupply -= _value; // Updates totalSupply
149
+ Burn(msg.sender, _value);
150
+ return true;
151
+ }
152
+
153
+ /**
154
+ * Destroy tokens from other account
155
+ *
156
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
157
+ *
158
+ * @param _from the address of the sender
159
+ * @param _value the amount of money to burn
160
+ */
161
+ function burnFrom(address _from, uint256 _value) public returns (bool success) {
162
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
163
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
164
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
165
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
166
+ totalSupply -= _value; // Update totalSupply
167
+ Burn(_from, _value);
168
+ return true;
169
+ }
170
+ }
171
+
172
+ /******************************************/
173
+ /* ADVANCED TOKEN STARTS HERE */
174
+ /******************************************/
175
+
176
+ contract SECToken is owned, TokenERC20 {
177
+
178
+ uint256 public sellPrice;
179
+ uint256 public buyPrice;
180
+
181
+ mapping (address => bool) public frozenAccount;
182
+
183
+ /* This generates a public event on the blockchain that will notify clients */
184
+ event FrozenFunds(address target, bool frozen);
185
+
186
+ /* Initializes contract with initial supply tokens to the creator of the contract */
187
+ function SECToken(
188
+ uint256 initialSupply,
189
+ string tokenName,
190
+ string tokenSymbol
191
+ ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
192
+
193
+ /* Internal transfer, only can be called by this contract */
194
+ function _transfer(address _from, address _to, uint _value) internal {
195
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
196
+ require (balanceOf[_from] >= _value); // Check if the sender has enough
197
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
198
+ require(!frozenAccount[_from]); // Check if sender is frozen
199
+ require(!frozenAccount[_to]); // Check if recipient is frozen
200
+
201
+ //about lock coins
202
+ uint start = 1520956799;
203
+ uint256 SECtotalAmount = 1500000000 * 10 ** 18;
204
+ address teamaccount = 0xC32b1519A0d4E883FE136AbB3198cbC402b5503F;
205
+
206
+ uint256 amount = _value;
207
+ address sender = _from;
208
+ uint256 balance = balanceOf[_from];
209
+
210
+
211
+ if(teamaccount == sender){
212
+ if (now < start + 365 * 1 days) {
213
+ require((balance - amount) >= SECtotalAmount/10 * 3/4);
214
+
215
+ } else if (now < start + (2*365+1) * 1 days){
216
+ require((balance - amount) >= SECtotalAmount/10 * 2/4);
217
+
218
+ }else if (now < start + (3*365+1) * 1 days){
219
+ require((balance - amount) >= SECtotalAmount/10 * 1/4);
220
+
221
+ }
222
+ }
223
+
224
+ balanceOf[_from] -= _value; // Subtract from the sender
225
+ balanceOf[_to] += _value; // Add the same to the recipient
226
+ Transfer(_from, _to, _value);
227
+ }
228
+
229
+ /// @notice Create `mintedAmount` tokens and send it to `target`
230
+ /// @param target Address to receive the tokens
231
+ /// @param mintedAmount the amount of tokens it will receive
232
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
233
+ balanceOf[target] += mintedAmount;
234
+ totalSupply += mintedAmount;
235
+ Transfer(0, this, mintedAmount);
236
+ Transfer(this, target, mintedAmount);
237
+ }
238
+
239
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
240
+ /// @param target Address to be frozen
241
+ /// @param freeze either to freeze it or not
242
+ function freezeAccount(address target, bool freeze) onlyOwner public {
243
+ frozenAccount[target] = freeze;
244
+ FrozenFunds(target, freeze);
245
+ }
246
+
247
+ /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
248
+ /// @param newSellPrice Price the users can sell to the contract
249
+ /// @param newBuyPrice Price users can buy from the contract
250
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
251
+ sellPrice = newSellPrice;
252
+ buyPrice = newBuyPrice;
253
+ }
254
+
255
+ /// @notice Buy tokens from contract by sending ether
256
+ function buy() payable public {
257
+ uint amount = msg.value / buyPrice; // calculates the amount
258
+ _transfer(this, msg.sender, amount); // makes the transfers
259
+ }
260
+
261
+ /// @notice Sell `amount` tokens to contract
262
+ /// @param amount amount of tokens to be sold
263
+ function sell(uint256 amount) public {
264
+ require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
265
+ _transfer(msg.sender, this, amount); // makes the transfers
266
+ msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
267
+ }
268
+ }
269
+ contract SEC is SECToken(1500000000, "SEC", "SEC") {}
data_full/CVE/2018-12078.sol ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-10-03
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) revert();
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public name;
28
+ string public symbol;
29
+ uint8 public decimals;
30
+ uint256 public totalSupply;
31
+
32
+ /* This creates an array with all balances */
33
+ mapping (address => uint256) public balanceOf;
34
+ mapping (address => mapping (address => uint256)) public allowance;
35
+
36
+ /* This generates a public event on the blockchain that will notify clients */
37
+ event Transfer(address indexed from, address indexed to, uint256 value);
38
+
39
+ /* Initializes contract with initial supply tokens to the creator of the contract */
40
+ function token(
41
+ uint256 initialSupply,
42
+ string tokenName,
43
+ uint8 decimalUnits,
44
+ string tokenSymbol
45
+ ) {
46
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
47
+ totalSupply = initialSupply; // Update total supply
48
+ name = tokenName; // Set the name for display purposes
49
+ symbol = tokenSymbol; // Set the symbol for display purposes
50
+ decimals = decimalUnits; // Amount of decimals for display purposes
51
+ }
52
+
53
+ /* Send coins */
54
+ function transfer(address _to, uint256 _value) {
55
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
56
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
57
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
58
+ balanceOf[_to] += _value; // Add the same to the recipient
59
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
60
+ }
61
+
62
+ /* Allow another contract to spend some tokens in your behalf */
63
+ function approve(address _spender, uint256 _value)
64
+ returns (bool success) {
65
+ allowance[msg.sender][_spender] = _value;
66
+ return true;
67
+ }
68
+
69
+ /* Approve and then communicate the approved contract in a single tx */
70
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
71
+ returns (bool success) {
72
+ tokenRecipient spender = tokenRecipient(_spender);
73
+ if (approve(_spender, _value)) {
74
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
75
+ return true;
76
+ }
77
+ }
78
+
79
+ /* A contract attempts to get the coins */
80
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
81
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
82
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
83
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
84
+ balanceOf[_from] -= _value; // Subtract from the sender
85
+ balanceOf[_to] += _value; // Add the same to the recipient
86
+ allowance[_from][msg.sender] -= _value;
87
+ Transfer(_from, _to, _value);
88
+ return true;
89
+ }
90
+
91
+ /* This unnamed function is called whenever someone tries to send ether to it */
92
+ function () {
93
+ revert(); // Prevents accidental sending of ether
94
+ }
95
+ }
96
+
97
+ contract PolyAi is owned, token {
98
+
99
+ mapping (address => bool) public frozenAccount;
100
+
101
+ /* This generates a public event on the blockchain that will notify clients */
102
+ event FrozenFunds(address target, bool frozen);
103
+
104
+ /* Initializes contract with initial supply tokens to the creator of the contract */
105
+ function PolyAi(
106
+ uint256 initialSupply,
107
+ string tokenName,
108
+ uint8 decimalUnits,
109
+ string tokenSymbol
110
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
111
+
112
+ /* Send coins */
113
+ function transfer(address _to, uint256 _value) {
114
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
115
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
116
+ if (frozenAccount[msg.sender]) revert(); // Check if frozen
117
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
118
+ balanceOf[_to] += _value; // Add the same to the recipient
119
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
120
+ }
121
+
122
+ /* A contract attempts to get the coins */
123
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
124
+ if (frozenAccount[_from]) revert(); // Check if frozen
125
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
126
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
127
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
128
+ balanceOf[_from] -= _value; // Subtract from the sender
129
+ balanceOf[_to] += _value; // Add the same to the recipient
130
+ allowance[_from][msg.sender] -= _value;
131
+ Transfer(_from, _to, _value);
132
+ return true;
133
+ }
134
+
135
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
136
+ balanceOf[target] += mintedAmount;
137
+ Transfer(0, owner, mintedAmount);
138
+ Transfer(owner, target, mintedAmount);
139
+ }
140
+
141
+ function freezeAccount(address target, bool freeze) onlyOwner {
142
+ frozenAccount[target] = freeze;
143
+ FrozenFunds(target, freeze);
144
+ }
145
+ }
data_full/CVE/2018-12079.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-07
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract MyAdvancedToken is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function MyAdvancedToken(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12080.sol ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-26
3
+ */
4
+
5
+ pragma solidity ^0.4.13; contract owned { address public owner;
6
+ function owned() {
7
+ owner = msg.sender;
8
+ }
9
+
10
+ modifier onlyOwner {
11
+ require(msg.sender == owner);
12
+ _;
13
+ }
14
+
15
+ function transferOwnership(address newOwner) onlyOwner {
16
+ owner = newOwner;
17
+ }
18
+ }
19
+ contract tokenRecipient { function receiveApproval(address from, uint256 value, address token, bytes extraData); }
20
+ contract token { /*Public variables of the token*/ string public name; string public symbol; uint8 public decimals; uint256 public totalSupply;
21
+ /* This creates an array with all balances */
22
+ mapping (address => uint256) public balanceOf;
23
+ mapping (address => mapping (address => uint256)) public allowance;
24
+
25
+ /* This generates a public event on the blockchain that will notify clients */
26
+ event Transfer(address indexed from, address indexed to, uint256 value);
27
+
28
+ /* This notifies clients about the amount burnt */
29
+ event Burn(address indexed from, uint256 value);
30
+
31
+ /* Initializes contract with initial supply tokens to the creator of the contract */
32
+ function token(
33
+ uint256 initialSupply,
34
+ string tokenName,
35
+ uint8 decimalUnits,
36
+ string tokenSymbol
37
+ ) {
38
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
39
+ totalSupply = initialSupply; // Update total supply
40
+ name = tokenName; // Set the name for display purposes
41
+ symbol = tokenSymbol; // Set the symbol for display purposes
42
+ decimals = decimalUnits; // Amount of decimals for display purposes
43
+ }
44
+
45
+ /* Internal transfer, only can be called by this contract */
46
+ function _transfer(address _from, address _to, uint _value) internal {
47
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
48
+ require (balanceOf[_from] > _value); // Check if the sender has enough
49
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
50
+ balanceOf[_from] -= _value; // Subtract from the sender
51
+ balanceOf[_to] += _value; // Add the same to the recipient
52
+ Transfer(_from, _to, _value);
53
+ }
54
+
55
+ /// @notice Send `_value` tokens to `_to` from your account
56
+ /// @param _to The address of the recipient
57
+ /// @param _value the amount to send
58
+ function transfer(address _to, uint256 _value) {
59
+ _transfer(msg.sender, _to, _value);
60
+ }
61
+
62
+ /// @notice Send `_value` tokens to `_to` in behalf of `_from`
63
+ /// @param _from The address of the sender
64
+ /// @param _to The address of the recipient
65
+ /// @param _value the amount to send
66
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
67
+ require (_value < allowance[_from][msg.sender]); // Check allowance
68
+ allowance[_from][msg.sender] -= _value;
69
+ _transfer(_from, _to, _value);
70
+ return true;
71
+ }
72
+
73
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf
74
+ /// @param _spender The address authorized to spend
75
+ /// @param _value the max amount they can spend
76
+ function approve(address _spender, uint256 _value)
77
+ returns (bool success) {
78
+ allowance[msg.sender][_spender] = _value;
79
+ return true;
80
+ }
81
+
82
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
83
+ /// @param _spender The address authorized to spend
84
+ /// @param _value the max amount they can spend
85
+ /// @param _extraData some extra information to send to the approved contract
86
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
87
+ returns (bool success) {
88
+ tokenRecipient spender = tokenRecipient(_spender);
89
+ if (approve(_spender, _value)) {
90
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
91
+ return true;
92
+ }
93
+ }
94
+
95
+ /// @notice Remove `_value` tokens from the system irreversibly
96
+ /// @param _value the amount of money to burn
97
+ function burn(uint256 _value) returns (bool success) {
98
+ require (balanceOf[msg.sender] > _value); // Check if the sender has enough
99
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
100
+ totalSupply -= _value; // Updates totalSupply
101
+ Burn(msg.sender, _value);
102
+ return true;
103
+ }
104
+
105
+ function burnFrom(address _from, uint256 _value) returns (bool success) {
106
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
107
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
108
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
109
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
110
+ totalSupply -= _value; // Update totalSupply
111
+ Burn(_from, _value);
112
+ return true;
113
+ }
114
+ }
115
+ contract INTToken is owned, token {
116
+ uint256 public sellPrice;
117
+ uint256 public buyPrice;
118
+
119
+ mapping (address => bool) public frozenAccount;
120
+
121
+ /* This generates a public event on the blockchain that will notify clients */
122
+ event FrozenFunds(address target, bool frozen);
123
+
124
+ /* Initializes contract with initial supply tokens to the creator of the contract */
125
+ function INTToken(
126
+ uint256 initialSupply,
127
+ string tokenName,
128
+ uint8 decimalUnits,
129
+ string tokenSymbol
130
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
131
+
132
+ /* Internal transfer, only can be called by this contract */
133
+ function _transfer(address _from, address _to, uint _value) internal {
134
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
135
+ require (balanceOf[_from] > _value); // Check if the sender has enough
136
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
137
+ require(!frozenAccount[_from]); // Check if sender is frozen
138
+ require(!frozenAccount[_to]); // Check if recipient is frozen
139
+ balanceOf[_from] -= _value; // Subtract from the sender
140
+ balanceOf[_to] += _value; // Add the same to the recipient
141
+ Transfer(_from, _to, _value);
142
+ }
143
+
144
+ /// @notice Create `mintedAmount` tokens and send it to `target`
145
+ /// @param target Address to receive the tokens
146
+ /// @param mintedAmount the amount of tokens it will receive
147
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
148
+ balanceOf[target] += mintedAmount;
149
+ totalSupply += mintedAmount;
150
+ Transfer(0, this, mintedAmount);
151
+ Transfer(this, target, mintedAmount);
152
+ }
153
+
154
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
155
+ /// @param target Address to be frozen
156
+ /// @param freeze either to freeze it or not
157
+ function freezeAccount(address target, bool freeze) onlyOwner {
158
+ frozenAccount[target] = freeze;
159
+ FrozenFunds(target, freeze);
160
+ }
161
+
162
+ /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
163
+ /// @param newSellPrice Price the users can sell to the contract
164
+ /// @param newBuyPrice Price users can buy from the contract
165
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
166
+ sellPrice = newSellPrice;
167
+ buyPrice = newBuyPrice;
168
+ }
169
+
170
+ /// @notice Buy tokens from contract by sending ether
171
+ function buy() payable {
172
+ uint amount = msg.value / buyPrice; // calculates the amount
173
+ _transfer(this, msg.sender, amount); // makes the transfers
174
+ }
175
+
176
+ /// @notice Sell `amount` tokens to contract
177
+ /// @param amount amount of tokens to be sold
178
+ function sell(uint256 amount) {
179
+ require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
180
+ _transfer(msg.sender, this, amount); // makes the transfers
181
+ msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
182
+ }
183
+ }
184
+ contract INT is INTToken(1000000000000000, "Internet Node Token", 6, "INT") {}
data_full/CVE/2018-12081.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-09-12
3
+ */
4
+
5
+ pragma solidity ^0.4.11;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract MyAdvancedToken is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function MyAdvancedToken(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12082.sol ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-04
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) revert();
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public name;
28
+ string public symbol;
29
+ uint8 public decimals;
30
+ uint256 public totalSupply;
31
+
32
+ /* This creates an array with all balances */
33
+ mapping (address => uint256) public balanceOf;
34
+ mapping (address => mapping (address => uint256)) public allowance;
35
+
36
+ /* This generates a public event on the blockchain that will notify clients */
37
+ event Transfer(address indexed from, address indexed to, uint256 value);
38
+
39
+ /* Initializes contract with initial supply tokens to the creator of the contract */
40
+ function token(
41
+ uint256 initialSupply,
42
+ string tokenName,
43
+ uint8 decimalUnits,
44
+ string tokenSymbol
45
+ ) {
46
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
47
+ totalSupply = initialSupply; // Update total supply
48
+ name = tokenName; // Set the name for display purposes
49
+ symbol = tokenSymbol; // Set the symbol for display purposes
50
+ decimals = decimalUnits; // Amount of decimals for display purposes
51
+ }
52
+
53
+ /* Send coins */
54
+ function transfer(address _to, uint256 _value) {
55
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
56
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
57
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
58
+ balanceOf[_to] += _value; // Add the same to the recipient
59
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
60
+ }
61
+
62
+ /* Allow another contract to spend some tokens in your behalf */
63
+ function approve(address _spender, uint256 _value)
64
+ returns (bool success) {
65
+ allowance[msg.sender][_spender] = _value;
66
+ return true;
67
+ }
68
+
69
+ /* Approve and then communicate the approved contract in a single tx */
70
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
71
+ returns (bool success) {
72
+ tokenRecipient spender = tokenRecipient(_spender);
73
+ if (approve(_spender, _value)) {
74
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
75
+ return true;
76
+ }
77
+ }
78
+
79
+ /* A contract attempts to get the coins */
80
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
81
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
82
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
83
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
84
+ balanceOf[_from] -= _value; // Subtract from the sender
85
+ balanceOf[_to] += _value; // Add the same to the recipient
86
+ allowance[_from][msg.sender] -= _value;
87
+ Transfer(_from, _to, _value);
88
+ return true;
89
+ }
90
+
91
+ /* This unnamed function is called whenever someone tries to send ether to it */
92
+ function () {
93
+ revert(); // Prevents accidental sending of ether
94
+ }
95
+ }
96
+
97
+ contract FujintoToken is owned, token {
98
+
99
+ uint public buyRate = 4000; // price of one token
100
+ bool public isSelling = true;
101
+
102
+ mapping (address => bool) public frozenAccount;
103
+
104
+ /* This generates a public event on the blockchain that will notify clients */
105
+ event FrozenFunds(address target, bool frozen);
106
+
107
+ /* Initializes contract with initial supply tokens to the creator of the contract */
108
+ function FujintoToken(
109
+ uint256 initialSupply,
110
+ string tokenName,
111
+ uint8 decimalUnits,
112
+ string tokenSymbol
113
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
114
+
115
+ /* Send coins */
116
+ function transfer(address _to, uint256 _value) {
117
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
118
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
119
+ if (frozenAccount[msg.sender]) revert(); // Check if frozen
120
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
121
+ balanceOf[_to] += _value; // Add the same to the recipient
122
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
123
+ }
124
+
125
+ /* A contract attempts to get the coins */
126
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
127
+ if (frozenAccount[_from]) revert(); // Check if frozen
128
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
129
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
130
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
131
+ balanceOf[_from] -= _value; // Subtract from the sender
132
+ balanceOf[_to] += _value; // Add the same to the recipient
133
+ allowance[_from][msg.sender] -= _value;
134
+ Transfer(_from, _to, _value);
135
+ return true;
136
+ }
137
+
138
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
139
+ balanceOf[target] += mintedAmount;
140
+ Transfer(0, owner, mintedAmount);
141
+ Transfer(owner, target, mintedAmount);
142
+ }
143
+
144
+ function freezeAccount(address target, bool freeze) onlyOwner {
145
+ frozenAccount[target] = freeze;
146
+ FrozenFunds(target, freeze);
147
+ }
148
+
149
+ function setBuyRate(uint newBuyRate) onlyOwner {
150
+ buyRate = newBuyRate;
151
+ }
152
+
153
+ function setSelling(bool newStatus) onlyOwner {
154
+ isSelling = newStatus;
155
+ }
156
+
157
+ function buy() payable {
158
+ if(isSelling == false) revert();
159
+ uint amount = msg.value * buyRate; // calculates the amount
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[owner] -= amount; // subtracts amount from seller's balance
162
+ Transfer(owner, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function withdrawToOwner(uint256 amountWei) onlyOwner {
166
+ owner.transfer(amountWei);
167
+ }
168
+ }
data_full/CVE/2018-12083.sol ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-11-14
3
+ */
4
+
5
+ pragma solidity ^0.4.18;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ function changeOwner(address newOwner) onlyOwner {
15
+ owner = newOwner;
16
+ }
17
+
18
+ modifier onlyOwner {
19
+ require(msg.sender == owner);
20
+ _;
21
+ }
22
+ }
23
+
24
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
25
+
26
+ contract GoalToken is owned {
27
+ /* Public variables of the token */
28
+ string public name = "GOAL Bonanza";
29
+ string public symbol = "GOAL";
30
+ uint8 public decimals = 18;
31
+ uint256 public totalSupply = 0;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ event Burn(address indexed from, uint256 value);
41
+
42
+ /* Internal transfer, only can be called by this contract */
43
+ function _transfer(address _from, address _to, uint _value) internal {
44
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
45
+ require (balanceOf[_from] > _value); // Check if the sender has enough
46
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
47
+ balanceOf[_from] -= _value; // Subtract from the sender
48
+ balanceOf[_to] += _value; // Add the same to the recipient
49
+ Transfer(_from, _to, _value);
50
+ }
51
+
52
+ /// @notice Send `_value` tokens to `_to` from your account
53
+ /// @param _to The address of the recipient
54
+ /// @param _value the amount to send
55
+ function transfer(address _to, uint256 _value) {
56
+ _transfer(msg.sender, _to, _value);
57
+ }
58
+
59
+ /// @notice Send `_value` tokens to `_to` in behalf of `_from`
60
+ /// @param _from The address of the sender
61
+ /// @param _to The address of the recipient
62
+ /// @param _value the amount to send
63
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
64
+ require (_value <= allowance[_from][msg.sender]); // Check allowance
65
+ allowance[_from][msg.sender] -= _value;
66
+ _transfer(_from, _to, _value);
67
+ return true;
68
+ }
69
+
70
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf
71
+ /// @param _spender The address authorized to spend
72
+ /// @param _value the max amount they can spend
73
+ function approve(address _spender, uint256 _value)
74
+ returns (bool success) {
75
+ allowance[msg.sender][_spender] = _value;
76
+ return true;
77
+ }
78
+
79
+ /// @notice Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
80
+ /// @param _spender The address authorized to spend
81
+ /// @param _value the max amount they can spend
82
+ /// @param _extraData some extra information to send to the approved contract
83
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
84
+ returns (bool success) {
85
+ tokenRecipient spender = tokenRecipient(_spender);
86
+ if (approve(_spender, _value)) {
87
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
88
+ return true;
89
+ }
90
+ }
91
+
92
+ /// @notice Remove `_value` tokens from the system irreversibly
93
+ /// @param _value the amount of money to burn
94
+ function burn(uint256 _value) returns (bool success) {
95
+ require (balanceOf[msg.sender] > _value); // Check if the sender has enough
96
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
97
+ totalSupply -= _value; // Updates totalSupply
98
+ Burn(msg.sender, _value);
99
+ return true;
100
+ }
101
+
102
+ function burnFrom(address _from, uint256 _value) returns (bool success) {
103
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
104
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
105
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
106
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
107
+ totalSupply -= _value; // Update totalSupply
108
+ Burn(_from, _value);
109
+ return true;
110
+ }
111
+
112
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
113
+ balanceOf[target] += mintedAmount;
114
+ totalSupply += mintedAmount;
115
+ Transfer(this, target, mintedAmount);
116
+ }
117
+ }
data_full/CVE/2018-12084.sol ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-07-25
3
+ */
4
+
5
+ pragma solidity ^0.4.13;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ if (msg.sender != owner) revert();
16
+ _;
17
+ }
18
+
19
+ }
20
+
21
+ contract tokenRecipient {
22
+
23
+ function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData);
24
+
25
+ }
26
+
27
+ contract token {
28
+
29
+ /* Public variables of the token */
30
+ string public name;
31
+ string public symbol;
32
+ uint8 public decimals;
33
+ uint256 public totalSupply;
34
+
35
+ /* This creates an array with all balances */
36
+ mapping (address => uint256) public balanceOf;
37
+ mapping (address => mapping (address => uint256)) public allowance;
38
+
39
+ /* This generates a public event on the blockchain that will notify clients */
40
+ event Transfer(address indexed from, address indexed to, uint256 value);
41
+
42
+ /* Initializes contract with initial supply tokens to the creator of the contract */
43
+ function token(
44
+ uint256 initialSupply,
45
+ string tokenName,
46
+ uint8 decimalUnits,
47
+ string tokenSymbol
48
+ ) {
49
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
50
+ totalSupply = initialSupply; // Update total supply
51
+ name = tokenName; // Set the name for display purposes
52
+ symbol = tokenSymbol; // Set the symbol for display purposes
53
+ decimals = decimalUnits; // Amount of decimals for display purposes
54
+ }
55
+
56
+ /* Send coins */
57
+ function transfer(address _to, uint256 _value) {
58
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
59
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
60
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
61
+ balanceOf[_to] += _value; // Add the same to the recipient
62
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
63
+ }
64
+
65
+ /* Allow another contract to spend some tokens in your behalf */
66
+ function approve(address _spender, uint256 _value)
67
+ returns (bool success) {
68
+ allowance[msg.sender][_spender] = _value;
69
+ return true;
70
+ }
71
+
72
+ /* Approve and then communicate the approved contract in a single tx */
73
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
74
+ returns (bool success) {
75
+ tokenRecipient spender = tokenRecipient(_spender);
76
+ if (approve(_spender, _value)) {
77
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
78
+ return true;
79
+ }
80
+ }
81
+
82
+ /* A contract attempts to get the coins e.g. exchange transfer our token */
83
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
84
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
85
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
86
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
87
+ balanceOf[_from] -= _value; // Subtract from the sender
88
+ balanceOf[_to] += _value; // Add the same to the recipient
89
+ allowance[_from][msg.sender] -= _value;
90
+ Transfer(_from, _to, _value);
91
+ return true;
92
+ }
93
+
94
+ /* This unnamed function is called whenever someone tries to send ether to it */
95
+ function () {
96
+ revert(); // Prevents accidental sending of ether
97
+ }
98
+ }
99
+
100
+ contract BitAseanToken is owned, token {
101
+
102
+ mapping (address => bool) public frozenAccount;
103
+
104
+ /* This generates a public event on the blockchain that will notify clients */
105
+ event FrozenFunds(address target, bool frozen);
106
+
107
+ /* Initializes contract with initial supply tokens to the creator of the contract */
108
+ function BitAseanToken(
109
+ uint256 initialSupply,
110
+ string tokenName,
111
+ uint8 decimalUnits,
112
+ string tokenSymbol
113
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {
114
+ }
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
120
+ if (frozenAccount[msg.sender]) revert(); // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) revert(); // Check if frozen
130
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+
153
+ }
data_full/CVE/2018-12230.sol ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pragma solidity ^0.4.2;
2
+
3
+ contract ERC20Interface {
4
+
5
+ function balanceOf(address _owner) constant returns (uint256 balance);
6
+ function transfer(address _to, uint256 _value) returns (bool success);
7
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
8
+ function approve(address _spender, uint256 _value) returns (bool success);
9
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
10
+
11
+ // Triggered when tokens are transferred.
12
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
13
+
14
+ // Triggered whenever approve(address _spender, uint256 _value) is called.
15
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
16
+
17
+ }
18
+
19
+ contract Owner {
20
+ //For storing the owner address
21
+ address public owner;
22
+
23
+ //Constructor for assign a address for owner property(It will be address who deploy the contract)
24
+ function Owner() {
25
+ owner = msg.sender;
26
+ }
27
+
28
+ //This is modifier (a special function) which will execute before the function execution on which it applied
29
+ modifier onlyOwner() {
30
+ if(msg.sender != owner) throw;
31
+ //This statement replace with the code of fucntion on which modifier is applied
32
+ _;
33
+ }
34
+ //Here is the example of modifier this function code replace _; statement of modifier
35
+ function transferOwnership(address new_owner) onlyOwner {
36
+ owner = new_owner;
37
+ }
38
+ }
39
+
40
+ contract RemiCoin is ERC20Interface,Owner {
41
+
42
+ //Common information about coin
43
+ string public name;
44
+ string public symbol;
45
+ uint8 public decimals;
46
+ uint256 public totalSupply;
47
+
48
+ //Balance property which should be always associate with an address
49
+ mapping(address => uint256) balances;
50
+ //frozenAccount property which should be associate with an address
51
+ mapping (address => bool) public frozenAccount;
52
+ // Owner of account approves the transfer of an amount to another account
53
+ mapping(address => mapping (address => uint256)) allowed;
54
+
55
+ //These generates a public event on the blockchain that will notify clients
56
+ event FrozenFunds(address target, bool frozen);
57
+
58
+ //Construtor for initial supply (The address who deployed the contract will get it) and important information
59
+ function RemiCoin(uint256 initial_supply, string _name, string _symbol, uint8 _decimal) {
60
+ balances[msg.sender] = initial_supply;
61
+ name = _name;
62
+ symbol = _symbol;
63
+ decimals = _decimal;
64
+ totalSupply = initial_supply;
65
+ }
66
+
67
+ // What is the balance of a particular account?
68
+ function balanceOf(address _owner) constant returns (uint256 balance) {
69
+ return balances[_owner];
70
+ }
71
+
72
+ //Function for transer the coin from one address to another
73
+ function transfer(address to, uint value) returns (bool success) {
74
+
75
+ //checking account is freeze or not
76
+ if (frozenAccount[msg.sender]) return false;
77
+
78
+ //checking the sender should have enough coins
79
+ if(balances[msg.sender] < value) return false;
80
+ //checking for overflows
81
+ if(balances[to] + value < balances[to]) return false;
82
+
83
+ //substracting the sender balance
84
+ balances[msg.sender] -= value;
85
+ //adding the reciever balance
86
+ balances[to] += value;
87
+
88
+ // Notify anyone listening that this transfer took place
89
+ Transfer(msg.sender, to, value);
90
+
91
+ return true;
92
+ }
93
+
94
+
95
+ //Function for transer the coin from one address to another
96
+ function transferFrom(address from, address to, uint value) returns (bool success) {
97
+
98
+ //checking account is freeze or not
99
+ if (frozenAccount[msg.sender]) return false;
100
+
101
+ //checking the from should have enough coins
102
+ if(balances[from] < value) return false;
103
+
104
+ //checking for allowance
105
+ if( allowed[from][msg.sender] >= value ) return false;
106
+
107
+ //checking for overflows
108
+ if(balances[to] + value < balances[to]) return false;
109
+
110
+ balances[from] -= value;
111
+ allowed[from][msg.sender] -= value;
112
+ balances[to] += value;
113
+
114
+ // Notify anyone listening that this transfer took place
115
+ Transfer(from, to, value);
116
+
117
+ return true;
118
+ }
119
+
120
+ //
121
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
122
+ return allowed[_owner][_spender];
123
+ }
124
+
125
+ //
126
+ function approve(address _spender, uint256 _amount) returns (bool success) {
127
+ allowed[msg.sender][_spender] = _amount;
128
+ Approval(msg.sender, _spender, _amount);
129
+ return true;
130
+ }
131
+
132
+ //
133
+ function mintToken(address target, uint256 mintedAmount) onlyOwner{
134
+ balances[target] += mintedAmount;
135
+ totalSupply += mintedAmount;
136
+
137
+ Transfer(0,owner,mintedAmount);
138
+ Transfer(owner,target,mintedAmount);
139
+ }
140
+
141
+ //
142
+ function freezeAccount(address target, bool freeze) onlyOwner {
143
+ frozenAccount[target] = freeze;
144
+ FrozenFunds(target, freeze);
145
+ }
146
+
147
+ //
148
+ function changeName(string _name) onlyOwner {
149
+ name = _name;
150
+ }
151
+
152
+ //
153
+ function changeSymbol(string _symbol) onlyOwner {
154
+ symbol = _symbol;
155
+ }
156
+
157
+ //
158
+ function changeDecimals(uint8 _decimals) onlyOwner {
159
+ decimals = _decimals;
160
+ }
161
+ }
data_full/CVE/2018-12454.sol ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-11-25
3
+ */
4
+
5
+ pragma solidity ^0.4.11;
6
+ contract simplelottery {
7
+ enum State { Started, Locked }
8
+ State public state = State.Started;
9
+ struct Guess{
10
+ address addr;
11
+ //uint guess;
12
+ }
13
+ uint arraysize=1000;
14
+ uint constant maxguess=1000000;
15
+ uint bettingprice = 1 ether;
16
+ Guess[1000] guesses;
17
+ uint numguesses = 0;
18
+ bytes32 curhash = '';
19
+ uint _gameindex = 1;
20
+ uint _starttime = 0;
21
+ modifier inState(State _state) {
22
+ require(state == _state);
23
+ _;
24
+ }
25
+ address developer = 0x0;
26
+ address _winner = 0x0;
27
+ event SentPrizeToWinner(address winner, uint money, uint gameindex, uint lotterynumber, uint starttime, uint finishtime);
28
+ event SentDeveloperFee(uint amount, uint balance);
29
+
30
+ function simplelottery()
31
+ {
32
+ if(developer==address(0)){
33
+ developer = msg.sender;
34
+ state = State.Started;
35
+ _starttime = block.timestamp;
36
+ }
37
+ }
38
+
39
+ function setBettingCondition(uint _contenders, uint _bettingprice)
40
+ {
41
+ if(msg.sender != developer)
42
+ return;
43
+ arraysize = _contenders;
44
+ if(arraysize>1000)
45
+ arraysize = 1000;
46
+ bettingprice = _bettingprice;
47
+ }
48
+
49
+ function findWinner(uint value)
50
+ {
51
+ uint i = value % numguesses;
52
+ _winner = guesses[i].addr;
53
+ }
54
+
55
+ function getMaxContenders() constant returns(uint){
56
+ return arraysize;
57
+ }
58
+
59
+ function getBettingPrice() constant returns(uint){
60
+ return bettingprice;
61
+ }
62
+
63
+ function getDeveloperAddress() constant returns(address)
64
+ {
65
+ return developer;
66
+ }
67
+
68
+ function getDeveloperFee() constant returns(uint)
69
+ {
70
+ uint developerfee = this.balance/100;
71
+ return developerfee;
72
+ }
73
+
74
+ function getBalance() constant returns(uint)
75
+ {
76
+ return this.balance;
77
+ }
78
+
79
+ function getLotteryMoney() constant returns(uint)
80
+ {
81
+ uint developerfee = getDeveloperFee();
82
+ uint prize = (this.balance - developerfee);
83
+ return prize;
84
+ }
85
+
86
+ function getBettingStatus()
87
+ constant
88
+ returns (uint, uint, uint, uint, uint, uint, uint)
89
+ {
90
+ return ((uint)(state), _gameindex, _starttime, numguesses, getLotteryMoney(), this.balance, bettingprice);
91
+ }
92
+
93
+
94
+
95
+ function finish()
96
+ {
97
+ if(msg.sender != developer)
98
+ return;
99
+ _finish();
100
+ }
101
+
102
+ function _finish() private
103
+ {
104
+ state = State.Locked;
105
+ uint block_timestamp = block.timestamp;
106
+ uint lotterynumber = (uint(curhash)+block_timestamp)%(maxguess+1);
107
+ findWinner(lotterynumber);
108
+ uint prize = getLotteryMoney();
109
+ uint numwinners = 1;
110
+ uint remain = this.balance - (prize*numwinners);
111
+
112
+ _winner.transfer(prize);
113
+ SentPrizeToWinner(_winner, prize, _gameindex, lotterynumber, _starttime, block_timestamp);
114
+
115
+ // give delveoper the money left behind
116
+ developer.transfer(remain);
117
+ SentDeveloperFee(remain, this.balance);
118
+ numguesses = 0;
119
+ _gameindex++;
120
+ state = State.Started;
121
+ _starttime = block.timestamp;
122
+ }
123
+
124
+ function () payable
125
+ {
126
+ _addguess();
127
+ }
128
+
129
+ function addguess()
130
+ inState(State.Started)
131
+ payable
132
+ {
133
+ _addguess();
134
+ }
135
+
136
+ function _addguess() private
137
+ inState(State.Started)
138
+ {
139
+ require(msg.value >= bettingprice);
140
+ curhash = sha256(block.timestamp, block.coinbase, block.difficulty, curhash);
141
+ if((uint)(numguesses+1)<=arraysize) {
142
+ guesses[numguesses++].addr = msg.sender;
143
+ if((uint)(numguesses)>=arraysize){
144
+ _finish();
145
+ }
146
+ }
147
+ }
148
+ }
data_full/CVE/2018-12511.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-07
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) throw;
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public standard = 'Token 0.1';
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals;
31
+ uint256 public totalSupply;
32
+
33
+ /* This creates an array with all balances */
34
+ mapping (address => uint256) public balanceOf;
35
+ mapping (address => mapping (address => uint256)) public allowance;
36
+
37
+ /* This generates a public event on the blockchain that will notify clients */
38
+ event Transfer(address indexed from, address indexed to, uint256 value);
39
+
40
+ /* Initializes contract with initial supply tokens to the creator of the contract */
41
+ function token(
42
+ uint256 initialSupply,
43
+ string tokenName,
44
+ uint8 decimalUnits,
45
+ string tokenSymbol
46
+ ) {
47
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
48
+ totalSupply = initialSupply; // Update total supply
49
+ name = tokenName; // Set the name for display purposes
50
+ symbol = tokenSymbol; // Set the symbol for display purposes
51
+ decimals = decimalUnits; // Amount of decimals for display purposes
52
+ }
53
+
54
+ /* Send coins */
55
+ function transfer(address _to, uint256 _value) {
56
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
57
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
58
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
59
+ balanceOf[_to] += _value; // Add the same to the recipient
60
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
61
+ }
62
+
63
+ /* Allow another contract to spend some tokens in your behalf */
64
+ function approve(address _spender, uint256 _value)
65
+ returns (bool success) {
66
+ allowance[msg.sender][_spender] = _value;
67
+ return true;
68
+ }
69
+
70
+ /* Approve and then communicate the approved contract in a single tx */
71
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
72
+ returns (bool success) {
73
+ tokenRecipient spender = tokenRecipient(_spender);
74
+ if (approve(_spender, _value)) {
75
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
76
+ return true;
77
+ }
78
+ }
79
+
80
+ /* A contract attempts to get the coins */
81
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
82
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
83
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
84
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
85
+ balanceOf[_from] -= _value; // Subtract from the sender
86
+ balanceOf[_to] += _value; // Add the same to the recipient
87
+ allowance[_from][msg.sender] -= _value;
88
+ Transfer(_from, _to, _value);
89
+ return true;
90
+ }
91
+
92
+ /* This unnamed function is called whenever someone tries to send ether to it */
93
+ function () {
94
+ throw; // Prevents accidental sending of ether
95
+ }
96
+ }
97
+
98
+ contract MyAdvancedToken is owned, token {
99
+
100
+ uint256 public sellPrice;
101
+ uint256 public buyPrice;
102
+
103
+ mapping (address => bool) public frozenAccount;
104
+
105
+ /* This generates a public event on the blockchain that will notify clients */
106
+ event FrozenFunds(address target, bool frozen);
107
+
108
+ /* Initializes contract with initial supply tokens to the creator of the contract */
109
+ function MyAdvancedToken(
110
+ uint256 initialSupply,
111
+ string tokenName,
112
+ uint8 decimalUnits,
113
+ string tokenSymbol
114
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
115
+
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-12702.sol ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-12-26
3
+ */
4
+
5
+ // Abstract contract for the full ERC 20 Token standard
6
+ // https://github.com/ethereum/EIPs/issues/20
7
+ pragma solidity ^0.4.16;
8
+
9
+ contract Token {
10
+ /* This is a slight change to the ERC20 base standard.
11
+ function totalSupply() constant returns (uint256 supply);
12
+ is replaced with:
13
+ uint256 public totalSupply;
14
+ This automatically creates a getter function for the totalSupply.
15
+ This is moved to the base contract since public getter functions are not
16
+ currently recognised as an implementation of the matching abstract
17
+ function by the compiler.
18
+ */
19
+ /// total amount of tokens
20
+ uint256 public totalSupply;
21
+
22
+ /// @param _owner The address from which the balance will be retrieved
23
+ /// @return The balance
24
+ function balanceOf(address _owner) constant returns (uint256 balance);
25
+
26
+ /// @notice send `_value` token to `_to` from `msg.sender`
27
+ /// @param _to The address of the recipient
28
+ /// @param _value The amount of token to be transferred
29
+ /// @return Whether the transfer was successful or not
30
+ function transfer(address _to, uint256 _value) returns (bool success);
31
+
32
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
33
+ /// @param _from The address of the sender
34
+ /// @param _to The address of the recipient
35
+ /// @param _value The amount of token to be transferred
36
+ /// @return Whether the transfer was successful or not
37
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
38
+
39
+ /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
40
+ /// @param _spender The address of the account able to transfer the tokens
41
+ /// @param _value The amount of tokens to be approved for transfer
42
+ /// @return Whether the approval was successful or not
43
+ function approve(address _spender, uint256 _value) returns (bool success);
44
+
45
+ /// @param _owner The address of the account owning tokens
46
+ /// @param _spender The address of the account able to transfer the tokens
47
+ /// @return Amount of remaining tokens allowed to spent
48
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
49
+
50
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
51
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
52
+ }
53
+
54
+
55
+ contract StandardToken is Token {
56
+
57
+ function transfer(address _to, uint256 _value) returns (bool success) {
58
+ require(_to != address(0));
59
+ require(_value <= balances[msg.sender]);
60
+ //Default assumes totalSupply can't be over max (2^256 - 1).
61
+ //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
62
+ //Replace the if with this one instead.
63
+ require(balances[_to] + _value > balances[_to]);
64
+ balances[msg.sender] -= _value;
65
+ balances[_to] += _value;
66
+ Transfer(msg.sender, _to, _value);
67
+ return true;
68
+ }
69
+
70
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
71
+ require(_to != address(0));
72
+ require(_value <= balances[_from]);
73
+ require(_value <= allowed[_from][msg.sender]);
74
+ //same as above. Replace this line with the following if you want to protect against wrapping uints.
75
+ require(balances[_to] + _value > balances[_to]);
76
+ balances[_to] += _value;
77
+ balances[_from] -= _value;
78
+ allowed[_from][msg.sender] -= _value;
79
+ Transfer(_from, _to, _value);
80
+ return true;
81
+ }
82
+
83
+ function balanceOf(address _owner) constant returns (uint256 balance) {
84
+ return balances[_owner];
85
+ }
86
+
87
+ function approve(address _spender, uint256 _value) returns (bool success) {
88
+ allowed[msg.sender][_spender] = _value;
89
+ Approval(msg.sender, _spender, _value);
90
+ return true;
91
+ }
92
+
93
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
94
+ return allowed[_owner][_spender];
95
+ }
96
+
97
+ mapping (address => uint256) balances;
98
+ mapping (address => mapping (address => uint256)) allowed;
99
+ }
100
+
101
+ contract GVE is StandardToken {
102
+
103
+ function () {
104
+ //if ether is sent to this address, send it back.
105
+ revert();
106
+ }
107
+
108
+ string public name = "Globalvillage ecosystem"; //fancy name: eg Simon Bucks
109
+ uint8 public decimals = 18; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
110
+ string public symbol = "GVE"; //An identifier: eg SBX
111
+ string public version = 'v0.1'; //gve 0.1 standard. Just an arbitrary versioning scheme.
112
+
113
+ address public founder; // The address of the founder
114
+
115
+ function GVE() {
116
+ founder = msg.sender;
117
+ totalSupply = 1000000000 * 10 ** uint256(decimals);
118
+ balances[founder] = totalSupply;
119
+ }
120
+
121
+ /* Approves and then calls the receiving contract */
122
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
123
+ allowed[msg.sender][_spender] = _value;
124
+ Approval(msg.sender, _spender, _value);
125
+
126
+ //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
127
+ //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
128
+ //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
129
+ if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
130
+ return true;
131
+ }
132
+
133
+ /* Approves and then calls the contract code*/
134
+ function approveAndCallcode(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
135
+ allowed[msg.sender][_spender] = _value;
136
+ Approval(msg.sender, _spender, _value);
137
+
138
+ //Call the contract code
139
+ if(!_spender.call(_extraData)) { revert(); }
140
+ return true;
141
+ }
142
+ }
data_full/CVE/2018-12703.sol ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-01-04
3
+ */
4
+
5
+ // Abstract contract for the full ERC 20 Token standard
6
+ // https://github.com/ethereum/EIPs/issues/20
7
+ pragma solidity ^0.4.16;
8
+
9
+ contract Token {
10
+ /* This is a slight change to the ERC20 base standard.
11
+ function totalSupply() constant returns (uint256 supply);
12
+ is replaced with:
13
+ uint256 public totalSupply;
14
+ This automatically creates a getter function for the totalSupply.
15
+ This is moved to the base contract since public getter functions are not
16
+ currently recognised as an implementation of the matching abstract
17
+ function by the compiler.
18
+ */
19
+ /// total amount of tokens
20
+ uint256 public totalSupply;
21
+
22
+ /// @param _owner The address from which the balance will be retrieved
23
+ /// @return The balance
24
+ function balanceOf(address _owner) constant returns (uint256 balance);
25
+
26
+ /// @notice send `_value` token to `_to` from `msg.sender`
27
+ /// @param _to The address of the recipient
28
+ /// @param _value The amount of token to be transferred
29
+ /// @return Whether the transfer was successful or not
30
+ function transfer(address _to, uint256 _value) returns (bool success);
31
+
32
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
33
+ /// @param _from The address of the sender
34
+ /// @param _to The address of the recipient
35
+ /// @param _value The amount of token to be transferred
36
+ /// @return Whether the transfer was successful or not
37
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success);
38
+
39
+ /// @notice `msg.sender` approves `_spender` to spend `_value` tokens
40
+ /// @param _spender The address of the account able to transfer the tokens
41
+ /// @param _value The amount of tokens to be approved for transfer
42
+ /// @return Whether the approval was successful or not
43
+ function approve(address _spender, uint256 _value) returns (bool success);
44
+
45
+ /// @param _owner The address of the account owning tokens
46
+ /// @param _spender The address of the account able to transfer the tokens
47
+ /// @return Amount of remaining tokens allowed to spent
48
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining);
49
+
50
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
51
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
52
+ }
53
+
54
+
55
+ contract StandardToken is Token {
56
+
57
+ function transfer(address _to, uint256 _value) returns (bool success) {
58
+ require(_to != address(0));
59
+ require(_value <= balances[msg.sender]);
60
+ //Default assumes totalSupply can't be over max (2^256 - 1).
61
+ //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
62
+ //Replace the if with this one instead.
63
+ require(balances[_to] + _value > balances[_to]);
64
+ balances[msg.sender] -= _value;
65
+ balances[_to] += _value;
66
+ Transfer(msg.sender, _to, _value);
67
+ return true;
68
+ }
69
+
70
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
71
+ require(_to != address(0));
72
+ require(_value <= balances[_from]);
73
+ require(_value <= allowed[_from][msg.sender]);
74
+ //same as above. Replace this line with the following if you want to protect against wrapping uints.
75
+ require(balances[_to] + _value > balances[_to]);
76
+ balances[_to] += _value;
77
+ balances[_from] -= _value;
78
+ allowed[_from][msg.sender] -= _value;
79
+ Transfer(_from, _to, _value);
80
+ return true;
81
+ }
82
+
83
+ function balanceOf(address _owner) constant returns (uint256 balance) {
84
+ return balances[_owner];
85
+ }
86
+
87
+ function approve(address _spender, uint256 _value) returns (bool success) {
88
+ allowed[msg.sender][_spender] = _value;
89
+ Approval(msg.sender, _spender, _value);
90
+ return true;
91
+ }
92
+
93
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
94
+ return allowed[_owner][_spender];
95
+ }
96
+
97
+ mapping (address => uint256) balances;
98
+ mapping (address => mapping (address => uint256)) allowed;
99
+ }
100
+
101
+ contract EightteenToken is StandardToken {
102
+
103
+ function () {
104
+ //if ether is sent to this address, send it back.
105
+ revert();
106
+ }
107
+
108
+ string public name = "Block 18"; //fancy name: eg Simon Bucks
109
+ uint8 public decimals = 18; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
110
+ string public symbol = "18T"; //An identifier: eg SBX
111
+ string public version = 'v0.1'; //18t 0.1 standard. Just an arbitrary versioning scheme.
112
+
113
+ address public founder; // The address of the founder
114
+
115
+ function EightteenToken() {
116
+ founder = msg.sender;
117
+ totalSupply = 1000000000 * 10 ** uint256(decimals);
118
+ balances[founder] = totalSupply;
119
+ }
120
+
121
+ /* Approves and then calls the receiving contract */
122
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
123
+ allowed[msg.sender][_spender] = _value;
124
+ Approval(msg.sender, _spender, _value);
125
+
126
+ //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
127
+ //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
128
+ //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
129
+ if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { revert(); }
130
+ return true;
131
+ }
132
+
133
+ /* Approves and then calls the contract code*/
134
+ function approveAndCallcode(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
135
+ allowed[msg.sender][_spender] = _value;
136
+ Approval(msg.sender, _spender, _value);
137
+
138
+ //Call the contract code
139
+ if(!_spender.call(_extraData)) { revert(); }
140
+ return true;
141
+ }
142
+ }
data_full/CVE/2018-12885.sol ADDED
@@ -0,0 +1,1149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-05-14
3
+ */
4
+
5
+ pragma solidity 0.4.23;
6
+
7
+
8
+ /**
9
+ * @title SafeMath
10
+ * @dev Math operations with safety checks that throw on error
11
+ */
12
+ library SafeMath {
13
+ /**
14
+ * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
15
+ */
16
+ function sub(uint256 a, uint256 b) internal pure returns (uint256) {
17
+ assert(b <= a);
18
+ return a - b;
19
+ }
20
+
21
+ /**
22
+ * @dev Adds two numbers, throws on overflow.
23
+ */
24
+ function add(uint256 a, uint256 b) internal pure returns (uint256) {
25
+ uint256 c = a + b;
26
+ assert(c >= a);
27
+ return c;
28
+ }
29
+ }
30
+
31
+
32
+ /**
33
+ * @title Ownable
34
+ * @dev The Ownable contract has an owner address, and provides basic authorization control
35
+ * functions, this simplifies the implementation of "user permissions".
36
+ */
37
+ contract Ownable {
38
+ address internal contractOwner;
39
+
40
+ constructor () internal {
41
+ if(contractOwner == address(0)){
42
+ contractOwner = msg.sender;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * @dev Throws if called by any account other than the owner.
48
+ */
49
+ modifier onlyOwner() {
50
+ require(msg.sender == contractOwner);
51
+ _;
52
+ }
53
+
54
+
55
+ /**
56
+ * @dev Allows the current owner to transfer control of the contract to a newOwner.
57
+ * @param newOwner The address to transfer ownership to.
58
+ */
59
+ function transferOwnership(address newOwner) public onlyOwner {
60
+ require(newOwner != address(0));
61
+ contractOwner = newOwner;
62
+ }
63
+
64
+ }
65
+
66
+
67
+ /**
68
+ * @title Pausable
69
+ * @dev Base contract which allows children to implement an emergency stop mechanism.
70
+ */
71
+ contract Pausable is Ownable {
72
+ bool private paused = false;
73
+
74
+ /**
75
+ * @dev Modifier to allow actions only when the contract IS paused
76
+ @dev If is paused msg.value is send back
77
+ */
78
+ modifier whenNotPaused() {
79
+ if(paused == true && msg.value > 0){
80
+ msg.sender.transfer(msg.value);
81
+ }
82
+ require(!paused);
83
+ _;
84
+ }
85
+
86
+
87
+ /**
88
+ * @dev Called by the owner to pause, triggers stopped state
89
+ */
90
+ function triggerPause() onlyOwner external {
91
+ paused = !paused;
92
+ }
93
+
94
+ }
95
+
96
+
97
+ /// @title A contract for creating new champs and making withdrawals
98
+ contract ChampFactory is Pausable{
99
+
100
+ event NewChamp(uint256 champID, address owner);
101
+
102
+ using SafeMath for uint; //SafeMath for overflow prevention
103
+
104
+ /*
105
+ * Variables
106
+ */
107
+ struct Champ {
108
+ uint256 id; //same as position in Champ[]
109
+ uint256 attackPower;
110
+ uint256 defencePower;
111
+ uint256 cooldownTime; //how long does it take to be ready attack again
112
+ uint256 readyTime; //if is smaller than block.timestamp champ is ready to fight
113
+ uint256 winCount;
114
+ uint256 lossCount;
115
+ uint256 position; //position in leaderboard. subtract 1 and you got position in leaderboard[]
116
+ uint256 price; //selling price
117
+ uint256 withdrawCooldown; //if you one of the 800 best champs and withdrawCooldown is less as block.timestamp then you get ETH reward
118
+ uint256 eq_sword;
119
+ uint256 eq_shield;
120
+ uint256 eq_helmet;
121
+ bool forSale; //is champ for sale?
122
+ }
123
+
124
+ struct AddressInfo {
125
+ uint256 withdrawal;
126
+ uint256 champsCount;
127
+ uint256 itemsCount;
128
+ string name;
129
+ }
130
+
131
+ //Item struct
132
+ struct Item {
133
+ uint8 itemType; // 1 - Sword | 2 - Shield | 3 - Helmet
134
+ uint8 itemRarity; // 1 - Common | 2 - Uncommon | 3 - Rare | 4 - Epic | 5 - Legendery | 6 - Forged
135
+ uint256 attackPower;
136
+ uint256 defencePower;
137
+ uint256 cooldownReduction;
138
+ uint256 price;
139
+ uint256 onChampId; //can not be used to decide if item is on champ, because champ's id can be 0, 'bool onChamp' solves it.
140
+ bool onChamp;
141
+ bool forSale; //is item for sale?
142
+ }
143
+
144
+ mapping (address => AddressInfo) public addressInfo;
145
+ mapping (uint256 => address) public champToOwner;
146
+ mapping (uint256 => address) public itemToOwner;
147
+ mapping (uint256 => string) public champToName;
148
+
149
+ Champ[] public champs;
150
+ Item[] public items;
151
+ uint256[] public leaderboard;
152
+
153
+ uint256 internal createChampFee = 5 finney;
154
+ uint256 internal lootboxFee = 5 finney;
155
+ uint256 internal pendingWithdrawal = 0;
156
+ uint256 private randNonce = 0; //being used in generating random numbers
157
+ uint256 public champsForSaleCount;
158
+ uint256 public itemsForSaleCount;
159
+
160
+
161
+ /*
162
+ * Modifiers
163
+ */
164
+ /// @dev Checks if msg.sender is owner of champ
165
+ modifier onlyOwnerOfChamp(uint256 _champId) {
166
+ require(msg.sender == champToOwner[_champId]);
167
+ _;
168
+ }
169
+
170
+
171
+ /// @dev Checks if msg.sender is NOT owner of champ
172
+ modifier onlyNotOwnerOfChamp(uint256 _champId) {
173
+ require(msg.sender != champToOwner[_champId]);
174
+ _;
175
+ }
176
+
177
+
178
+ /// @notice Checks if amount was sent
179
+ modifier isPaid(uint256 _price){
180
+ require(msg.value >= _price);
181
+ _;
182
+ }
183
+
184
+
185
+ /// @notice People are allowed to withdraw only if min. balance (0.01 gwei) is reached
186
+ modifier contractMinBalanceReached(){
187
+ require( (address(this).balance).sub(pendingWithdrawal) > 1000000 );
188
+ _;
189
+ }
190
+
191
+
192
+ /// @notice Checks if withdraw cooldown passed
193
+ modifier isChampWithdrawReady(uint256 _id){
194
+ require(champs[_id].withdrawCooldown < block.timestamp);
195
+ _;
196
+ }
197
+
198
+
199
+ /// @notice Distribute input funds between contract owner and players
200
+ modifier distributeInput(address _affiliateAddress){
201
+
202
+ //contract owner
203
+ uint256 contractOwnerWithdrawal = (msg.value / 100) * 50; // 50%
204
+ addressInfo[contractOwner].withdrawal += contractOwnerWithdrawal;
205
+ pendingWithdrawal += contractOwnerWithdrawal;
206
+
207
+ //affiliate
208
+ //checks if _affiliateAddress is set & if affiliate address is not buying player
209
+ if(_affiliateAddress != address(0) && _affiliateAddress != msg.sender){
210
+ uint256 affiliateBonus = (msg.value / 100) * 25; //provision is 25%
211
+ addressInfo[_affiliateAddress].withdrawal += affiliateBonus;
212
+ pendingWithdrawal += affiliateBonus;
213
+ }
214
+
215
+ _;
216
+ }
217
+
218
+
219
+
220
+ /*
221
+ * View
222
+ */
223
+ /// @notice Gets champs by address
224
+ /// @param _owner Owner address
225
+ function getChampsByOwner(address _owner) external view returns(uint256[]) {
226
+ uint256[] memory result = new uint256[](addressInfo[_owner].champsCount);
227
+ uint256 counter = 0;
228
+ for (uint256 i = 0; i < champs.length; i++) {
229
+ if (champToOwner[i] == _owner) {
230
+ result[counter] = i;
231
+ counter++;
232
+ }
233
+ }
234
+ return result;
235
+ }
236
+
237
+
238
+ /// @notice Gets total champs count
239
+ function getChampsCount() external view returns(uint256){
240
+ return champs.length;
241
+ }
242
+
243
+
244
+ /// @notice Gets champ's reward in wei
245
+ function getChampReward(uint256 _position) public view returns(uint256) {
246
+ if(_position <= 800){
247
+ //percentageMultipier = 10,000
248
+ //maxReward = 2000 = .2% * percentageMultipier
249
+ //subtractPerPosition = 2 = .0002% * percentageMultipier
250
+ //2000 - (2 * (_position - 1))
251
+ uint256 rewardPercentage = uint256(2000).sub(2 * (_position - 1));
252
+
253
+ //available funds are all funds - already pending
254
+ uint256 availableWithdrawal = address(this).balance.sub(pendingWithdrawal);
255
+
256
+ //calculate reward for champ's position
257
+ //1000000 = percentageMultipier * 100
258
+ return availableWithdrawal / 1000000 * rewardPercentage;
259
+ }else{
260
+ return uint256(0);
261
+ }
262
+ }
263
+
264
+
265
+ /*
266
+ * Internal
267
+ */
268
+ /// @notice Generates random modulus
269
+ /// @param _modulus Max random modulus
270
+ function randMod(uint256 _modulus) internal returns(uint256) {
271
+ randNonce++;
272
+ return uint256(keccak256(randNonce, blockhash(block.number - 1))) % _modulus;
273
+ }
274
+
275
+
276
+
277
+ /*
278
+ * External
279
+ */
280
+ /// @notice Creates new champ
281
+ /// @param _affiliateAddress Affiliate address (optional)
282
+ function createChamp(address _affiliateAddress) external payable
283
+ whenNotPaused
284
+ isPaid(createChampFee)
285
+ distributeInput(_affiliateAddress)
286
+ {
287
+
288
+ /*
289
+ Champ memory champ = Champ({
290
+ id: 0,
291
+ attackPower: 2 + randMod(4),
292
+ defencePower: 1 + randMod(4),
293
+ cooldownTime: uint256(1 days) - uint256(randMod(9) * 1 hours),
294
+ readyTime: 0,
295
+ winCount: 0,
296
+ lossCount: 0,
297
+ position: leaderboard.length + 1, //Last place in leaderboard is new champ's position. Used in new champ struct bellow. +1 to avoid zero position.
298
+ price: 0,
299
+ withdrawCooldown: uint256(block.timestamp),
300
+ eq_sword: 0,
301
+ eq_shield: 0,
302
+ eq_helmet: 0,
303
+ forSale: false
304
+ });
305
+ */
306
+
307
+ // This line bellow is about 30k gas cheaper than lines above. They are the same. Lines above are just more readable.
308
+ uint256 id = champs.push(Champ(0, 2 + randMod(4), 1 + randMod(4), uint256(1 days) - uint256(randMod(9) * 1 hours), 0, 0, 0, leaderboard.length + 1, 0, uint256(block.timestamp), 0,0,0, false)) - 1;
309
+
310
+
311
+ champs[id].id = id; //sets id in Champ struct
312
+ leaderboard.push(id); //push champ on the last place in leaderboard
313
+ champToOwner[id] = msg.sender; //sets owner of this champ - msg.sender
314
+ addressInfo[msg.sender].champsCount++;
315
+
316
+ emit NewChamp(id, msg.sender);
317
+
318
+ }
319
+
320
+
321
+ /// @notice Change "CreateChampFee". If ETH price will grow up it can expensive to create new champ.
322
+ /// @param _fee New "CreateChampFee"
323
+ /// @dev Only owner of contract can change "CreateChampFee"
324
+ function setCreateChampFee(uint256 _fee) external onlyOwner {
325
+ createChampFee = _fee;
326
+ }
327
+
328
+
329
+ /// @notice Change champ's name
330
+ function changeChampsName(uint _champId, string _name) external
331
+ onlyOwnerOfChamp(_champId){
332
+ champToName[_champId] = _name;
333
+ }
334
+
335
+
336
+ /// @notice Change players's name
337
+ function changePlayersName(string _name) external {
338
+ addressInfo[msg.sender].name = _name;
339
+ }
340
+
341
+
342
+ /// @notice Withdraw champ's reward
343
+ /// @param _id Champ id
344
+ /// @dev Move champ reward to pending withdrawal to his wallet.
345
+ function withdrawChamp(uint _id) external
346
+ onlyOwnerOfChamp(_id)
347
+ contractMinBalanceReached
348
+ isChampWithdrawReady(_id)
349
+ whenNotPaused {
350
+ Champ storage champ = champs[_id];
351
+ require(champ.position <= 800);
352
+
353
+ champ.withdrawCooldown = block.timestamp + 1 days; //one withdrawal 1 per day
354
+
355
+ uint256 withdrawal = getChampReward(champ.position);
356
+ addressInfo[msg.sender].withdrawal += withdrawal;
357
+ pendingWithdrawal += withdrawal;
358
+ }
359
+
360
+
361
+ /// @dev Send all pending funds of caller's address
362
+ function withdrawToAddress(address _address) external
363
+ whenNotPaused {
364
+ address playerAddress = _address;
365
+ if(playerAddress == address(0)){ playerAddress = msg.sender; }
366
+ uint256 share = addressInfo[playerAddress].withdrawal; //gets pending funds
367
+ require(share > 0); //is it more than 0?
368
+
369
+ //first sets players withdrawal pending to 0 and subtract amount from playerWithdrawals then transfer funds to avoid reentrancy
370
+ addressInfo[playerAddress].withdrawal = 0; //set player's withdrawal pendings to 0
371
+ pendingWithdrawal = pendingWithdrawal.sub(share); //subtract share from total pendings
372
+
373
+ playerAddress.transfer(share); //transfer
374
+ }
375
+
376
+ }
377
+
378
+
379
+
380
+ /// @title Moderates items and creates new ones
381
+ contract Items is ChampFactory {
382
+
383
+ event NewItem(uint256 itemID, address owner);
384
+
385
+ constructor () internal {
386
+ //item -> nothing
387
+ items.push(Item(0, 0, 0, 0, 0, 0, 0, false, false));
388
+ }
389
+
390
+ /*
391
+ * Modifiers
392
+ */
393
+ /// @notice Checks if sender is owner of item
394
+ modifier onlyOwnerOfItem(uint256 _itemId) {
395
+ require(_itemId != 0);
396
+ require(msg.sender == itemToOwner[_itemId]);
397
+ _;
398
+ }
399
+
400
+
401
+ /// @notice Checks if sender is NOT owner of item
402
+ modifier onlyNotOwnerOfItem(uint256 _itemId) {
403
+ require(msg.sender != itemToOwner[_itemId]);
404
+ _;
405
+ }
406
+
407
+
408
+ /*
409
+ * View
410
+ */
411
+ ///@notice Check if champ has something on
412
+ ///@param _type Sword, shield or helmet
413
+ function hasChampSomethingOn(uint _champId, uint8 _type) internal view returns(bool){
414
+ Champ storage champ = champs[_champId];
415
+ if(_type == 1){
416
+ return (champ.eq_sword == 0) ? false : true;
417
+ }
418
+ if(_type == 2){
419
+ return (champ.eq_shield == 0) ? false : true;
420
+ }
421
+ if(_type == 3){
422
+ return (champ.eq_helmet == 0) ? false : true;
423
+ }
424
+ }
425
+
426
+
427
+ /// @notice Gets items by address
428
+ /// @param _owner Owner address
429
+ function getItemsByOwner(address _owner) external view returns(uint256[]) {
430
+ uint256[] memory result = new uint256[](addressInfo[_owner].itemsCount);
431
+ uint256 counter = 0;
432
+ for (uint256 i = 0; i < items.length; i++) {
433
+ if (itemToOwner[i] == _owner) {
434
+ result[counter] = i;
435
+ counter++;
436
+ }
437
+ }
438
+ return result;
439
+ }
440
+
441
+
442
+ /*
443
+ * Public
444
+ */
445
+ ///@notice Takes item off champ
446
+ function takeOffItem(uint _champId, uint8 _type) public
447
+ onlyOwnerOfChamp(_champId) {
448
+ uint256 itemId;
449
+ Champ storage champ = champs[_champId];
450
+ if(_type == 1){
451
+ itemId = champ.eq_sword; //Get item ID
452
+ if (itemId > 0) { //0 = nothing
453
+ champ.eq_sword = 0; //take off sword
454
+ }
455
+ }
456
+ if(_type == 2){
457
+ itemId = champ.eq_shield; //Get item ID
458
+ if(itemId > 0) {//0 = nothing
459
+ champ.eq_shield = 0; //take off shield
460
+ }
461
+ }
462
+ if(_type == 3){
463
+ itemId = champ.eq_helmet; //Get item ID
464
+ if(itemId > 0) { //0 = nothing
465
+ champ.eq_helmet = 0; //take off
466
+ }
467
+ }
468
+ if(itemId > 0){
469
+ items[itemId].onChamp = false; //item is free to use, is not on champ
470
+ }
471
+ }
472
+
473
+
474
+
475
+ /*
476
+ * External
477
+ */
478
+ ///@notice Puts item on champ
479
+ function putOn(uint256 _champId, uint256 _itemId) external
480
+ onlyOwnerOfChamp(_champId)
481
+ onlyOwnerOfItem(_itemId) {
482
+ Champ storage champ = champs[_champId];
483
+ Item storage item = items[_itemId];
484
+
485
+ //checks if items is on some other champ
486
+ if(item.onChamp){
487
+ takeOffItem(item.onChampId, item.itemType); //take off from champ
488
+ }
489
+
490
+ item.onChamp = true; //item is on champ
491
+ item.onChampId = _champId; //champ's id
492
+
493
+ //put on
494
+ if(item.itemType == 1){
495
+ //take off actual sword
496
+ if(champ.eq_sword > 0){
497
+ takeOffItem(champ.id, 1);
498
+ }
499
+ champ.eq_sword = _itemId; //put on sword
500
+ }
501
+ if(item.itemType == 2){
502
+ //take off actual shield
503
+ if(champ.eq_shield > 0){
504
+ takeOffItem(champ.id, 2);
505
+ }
506
+ champ.eq_shield = _itemId; //put on shield
507
+ }
508
+ if(item.itemType == 3){
509
+ //take off actual helmet
510
+ if(champ.eq_helmet > 0){
511
+ takeOffItem(champ.id, 3);
512
+ }
513
+ champ.eq_helmet = _itemId; //put on helmet
514
+ }
515
+ }
516
+
517
+
518
+
519
+ /// @notice Opens loot box and generates new item
520
+ function openLootbox(address _affiliateAddress) external payable
521
+ whenNotPaused
522
+ isPaid(lootboxFee)
523
+ distributeInput(_affiliateAddress) {
524
+
525
+ uint256 pointToCooldownReduction;
526
+ uint256 randNum = randMod(1001); //random number <= 1000
527
+ uint256 pointsToShare; //total points given
528
+ uint256 itemID;
529
+
530
+ //sets up item
531
+ Item memory item = Item({
532
+ itemType: uint8(uint256(randMod(3) + 1)), //generates item type - max num is 2 -> 0 + 1 SWORD | 1 + 1 SHIELD | 2 + 1 HELMET;
533
+ itemRarity: uint8(0),
534
+ attackPower: 0,
535
+ defencePower: 0,
536
+ cooldownReduction: 0,
537
+ price: 0,
538
+ onChampId: 0,
539
+ onChamp: false,
540
+ forSale: false
541
+ });
542
+
543
+ // Gets Rarity of item
544
+ // 45% common
545
+ // 27% uncommon
546
+ // 19% rare
547
+ // 7% epic
548
+ // 2% legendary
549
+ if(450 > randNum){
550
+ pointsToShare = 25 + randMod(9); //25 basic + random number max to 8
551
+ item.itemRarity = uint8(1);
552
+ }else if(720 > randNum){
553
+ pointsToShare = 42 + randMod(17); //42 basic + random number max to 16
554
+ item.itemRarity = uint8(2);
555
+ }else if(910 > randNum){
556
+ pointsToShare = 71 + randMod(25); //71 basic + random number max to 24
557
+ item.itemRarity = uint8(3);
558
+ }else if(980 > randNum){
559
+ pointsToShare = 119 + randMod(33); //119 basic + random number max to 32
560
+ item.itemRarity = uint8(4);
561
+ }else{
562
+ pointsToShare = 235 + randMod(41); //235 basic + random number max to 40
563
+ item.itemRarity = uint8(5);
564
+ }
565
+
566
+
567
+ //Gets type of item
568
+ if(item.itemType == uint8(1)){ //ITEM IS SWORDS
569
+ item.attackPower = pointsToShare / 10 * 7; //70% attackPower
570
+ pointsToShare -= item.attackPower; //points left;
571
+
572
+ item.defencePower = pointsToShare / 10 * randMod(6); //up to 15% defencePower
573
+ pointsToShare -= item.defencePower; //points left;
574
+
575
+ item.cooldownReduction = pointsToShare * uint256(1 minutes); //rest of points is cooldown reduction
576
+ item.itemType = uint8(1);
577
+ }
578
+
579
+ if(item.itemType == uint8(2)){ //ITEM IS SHIELD
580
+ item.defencePower = pointsToShare / 10 * 7; //70% defencePower
581
+ pointsToShare -= item.defencePower; //points left;
582
+
583
+ item.attackPower = pointsToShare / 10 * randMod(6); //up to 15% attackPowerPower
584
+ pointsToShare -= item.attackPower; //points left;
585
+
586
+ item.cooldownReduction = pointsToShare * uint256(1 minutes); //rest of points is cooldown reduction
587
+ item.itemType = uint8(2);
588
+ }
589
+
590
+ if(item.itemType == uint8(3)){ //ITEM IS HELMET
591
+ pointToCooldownReduction = pointsToShare / 10 * 7; //70% cooldown reduction
592
+ item.cooldownReduction = pointToCooldownReduction * uint256(1 minutes); //points to time
593
+ pointsToShare -= pointToCooldownReduction; //points left;
594
+
595
+ item.attackPower = pointsToShare / 10 * randMod(6); //up to 15% attackPower
596
+ pointsToShare -= item.attackPower; //points left;
597
+
598
+ item.defencePower = pointsToShare; //rest of points is defencePower
599
+ item.itemType = uint8(3);
600
+ }
601
+
602
+ itemID = items.push(item) - 1;
603
+
604
+ itemToOwner[itemID] = msg.sender; //sets owner of this item - msg.sender
605
+ addressInfo[msg.sender].itemsCount++; //every address has count of items
606
+
607
+ emit NewItem(itemID, msg.sender);
608
+
609
+ }
610
+
611
+ /// @notice Change "lootboxFee".
612
+ /// @param _fee New "lootboxFee"
613
+ /// @dev Only owner of contract can change "lootboxFee"
614
+ function setLootboxFee(uint _fee) external onlyOwner {
615
+ lootboxFee = _fee;
616
+ }
617
+ }
618
+
619
+
620
+
621
+ /// @title Moderates buying and selling items
622
+ contract ItemMarket is Items {
623
+
624
+ event TransferItem(address from, address to, uint256 itemID);
625
+
626
+ /*
627
+ * Modifiers
628
+ */
629
+ ///@notice Checks if item is for sale
630
+ modifier itemIsForSale(uint256 _id){
631
+ require(items[_id].forSale);
632
+ _;
633
+ }
634
+
635
+ ///@notice Checks if item is NOT for sale
636
+ modifier itemIsNotForSale(uint256 _id){
637
+ require(items[_id].forSale == false);
638
+ _;
639
+ }
640
+
641
+ ///@notice If item is for sale then cancel sale
642
+ modifier ifItemForSaleThenCancelSale(uint256 _itemID){
643
+ Item storage item = items[_itemID];
644
+ if(item.forSale){
645
+ _cancelItemSale(item);
646
+ }
647
+ _;
648
+ }
649
+
650
+
651
+ ///@notice Distribute sale eth input
652
+ modifier distributeSaleInput(address _owner) {
653
+ uint256 contractOwnerCommision; //1%
654
+ uint256 playerShare; //99%
655
+
656
+ if(msg.value > 100){
657
+ contractOwnerCommision = (msg.value / 100);
658
+ playerShare = msg.value - contractOwnerCommision;
659
+ }else{
660
+ contractOwnerCommision = 0;
661
+ playerShare = msg.value;
662
+ }
663
+
664
+ addressInfo[_owner].withdrawal += playerShare;
665
+ addressInfo[contractOwner].withdrawal += contractOwnerCommision;
666
+ pendingWithdrawal += playerShare + contractOwnerCommision;
667
+ _;
668
+ }
669
+
670
+
671
+
672
+ /*
673
+ * View
674
+ */
675
+ function getItemsForSale() view external returns(uint256[]){
676
+ uint256[] memory result = new uint256[](itemsForSaleCount);
677
+ if(itemsForSaleCount > 0){
678
+ uint256 counter = 0;
679
+ for (uint256 i = 0; i < items.length; i++) {
680
+ if (items[i].forSale == true) {
681
+ result[counter]=i;
682
+ counter++;
683
+ }
684
+ }
685
+ }
686
+ return result;
687
+ }
688
+
689
+ /*
690
+ * Private
691
+ */
692
+ ///@notice Cancel sale. Should not be called without checking if item is really for sale.
693
+ function _cancelItemSale(Item storage item) private {
694
+ //No need to overwrite item's price
695
+ item.forSale = false;
696
+ itemsForSaleCount--;
697
+ }
698
+
699
+
700
+ /*
701
+ * Internal
702
+ */
703
+ /// @notice Transfer item
704
+ function transferItem(address _from, address _to, uint256 _itemID) internal
705
+ ifItemForSaleThenCancelSale(_itemID) {
706
+ Item storage item = items[_itemID];
707
+
708
+ //take off
709
+ if(item.onChamp && _to != champToOwner[item.onChampId]){
710
+ takeOffItem(item.onChampId, item.itemType);
711
+ }
712
+
713
+ addressInfo[_to].itemsCount++;
714
+ addressInfo[_from].itemsCount--;
715
+ itemToOwner[_itemID] = _to;
716
+
717
+ emit TransferItem(_from, _to, _itemID);
718
+ }
719
+
720
+
721
+
722
+ /*
723
+ * Public
724
+ */
725
+ /// @notice Calls transfer item
726
+ /// @notice Address _from is msg.sender. Cannot be used is market, bc msg.sender is buyer
727
+ function giveItem(address _to, uint256 _itemID) public
728
+ onlyOwnerOfItem(_itemID) {
729
+ transferItem(msg.sender, _to, _itemID);
730
+ }
731
+
732
+
733
+ /// @notice Calcels item's sale
734
+ function cancelItemSale(uint256 _id) public
735
+ itemIsForSale(_id)
736
+ onlyOwnerOfItem(_id){
737
+ Item storage item = items[_id];
738
+ _cancelItemSale(item);
739
+ }
740
+
741
+
742
+ /*
743
+ * External
744
+ */
745
+ /// @notice Sets item for sale
746
+ function setItemForSale(uint256 _id, uint256 _price) external
747
+ onlyOwnerOfItem(_id)
748
+ itemIsNotForSale(_id) {
749
+ Item storage item = items[_id];
750
+ item.forSale = true;
751
+ item.price = _price;
752
+ itemsForSaleCount++;
753
+ }
754
+
755
+
756
+ /// @notice Buys item
757
+ function buyItem(uint256 _id) external payable
758
+ whenNotPaused
759
+ onlyNotOwnerOfItem(_id)
760
+ itemIsForSale(_id)
761
+ isPaid(items[_id].price)
762
+ distributeSaleInput(itemToOwner[_id])
763
+ {
764
+ transferItem(itemToOwner[_id], msg.sender, _id);
765
+ }
766
+
767
+ }
768
+
769
+
770
+
771
+ /// @title Manages forging
772
+ contract ItemForge is ItemMarket {
773
+
774
+ event Forge(uint256 forgedItemID);
775
+
776
+ ///@notice Forge items together
777
+ function forgeItems(uint256 _parentItemID, uint256 _childItemID) external
778
+ onlyOwnerOfItem(_parentItemID)
779
+ onlyOwnerOfItem(_childItemID)
780
+ ifItemForSaleThenCancelSale(_parentItemID)
781
+ ifItemForSaleThenCancelSale(_childItemID) {
782
+
783
+ //checks if items are not the same
784
+ require(_parentItemID != _childItemID);
785
+
786
+ Item storage parentItem = items[_parentItemID];
787
+ Item storage childItem = items[_childItemID];
788
+
789
+ //take child item off, because child item will be burned
790
+ if(childItem.onChamp){
791
+ takeOffItem(childItem.onChampId, childItem.itemType);
792
+ }
793
+
794
+ //update parent item
795
+ parentItem.attackPower = (parentItem.attackPower > childItem.attackPower) ? parentItem.attackPower : childItem.attackPower;
796
+ parentItem.defencePower = (parentItem.defencePower > childItem.defencePower) ? parentItem.defencePower : childItem.defencePower;
797
+ parentItem.cooldownReduction = (parentItem.cooldownReduction > childItem.cooldownReduction) ? parentItem.cooldownReduction : childItem.cooldownReduction;
798
+ parentItem.itemRarity = uint8(6);
799
+
800
+ //burn child item
801
+ transferItem(msg.sender, address(0), _childItemID);
802
+
803
+ emit Forge(_parentItemID);
804
+ }
805
+
806
+ }
807
+
808
+
809
+ /// @title Manages attacks in game
810
+ contract ChampAttack is ItemForge {
811
+
812
+ event Attack(uint256 winnerChampID, uint256 defeatedChampID, bool didAttackerWin);
813
+
814
+ /*
815
+ * Modifiers
816
+ */
817
+ /// @notice Is champ ready to fight again?
818
+ modifier isChampReady(uint256 _champId) {
819
+ require (champs[_champId].readyTime <= block.timestamp);
820
+ _;
821
+ }
822
+
823
+
824
+ /// @notice Prevents from self-attack
825
+ modifier notSelfAttack(uint256 _champId, uint256 _targetId) {
826
+ require(_champId != _targetId);
827
+ _;
828
+ }
829
+
830
+
831
+ /// @notice Checks if champ does exist
832
+ modifier targetExists(uint256 _targetId){
833
+ require(champToOwner[_targetId] != address(0));
834
+ _;
835
+ }
836
+
837
+
838
+ /*
839
+ * View
840
+ */
841
+ /// @notice Gets champ's attack power, defence power and cooldown reduction with items on
842
+ function getChampStats(uint256 _champId) public view returns(uint256,uint256,uint256){
843
+ Champ storage champ = champs[_champId];
844
+ Item storage sword = items[champ.eq_sword];
845
+ Item storage shield = items[champ.eq_shield];
846
+ Item storage helmet = items[champ.eq_helmet];
847
+
848
+ //AP
849
+ uint256 totalAttackPower = champ.attackPower + sword.attackPower + shield.attackPower + helmet.attackPower; //Gets champs AP
850
+
851
+ //DP
852
+ uint256 totalDefencePower = champ.defencePower + sword.defencePower + shield.defencePower + helmet.defencePower; //Gets champs DP
853
+
854
+ //CR
855
+ uint256 totalCooldownReduction = sword.cooldownReduction + shield.cooldownReduction + helmet.cooldownReduction; //Gets CR
856
+
857
+ return (totalAttackPower, totalDefencePower, totalCooldownReduction);
858
+ }
859
+
860
+
861
+ /*
862
+ * Pure
863
+ */
864
+ /// @notice Subtracts ability points. Helps to not cross minimal attack ability points -> 2
865
+ /// @param _playerAttackPoints Actual player's attack points
866
+ /// @param _x Amount to subtract
867
+ function subAttack(uint256 _playerAttackPoints, uint256 _x) internal pure returns (uint256) {
868
+ return (_playerAttackPoints <= _x + 2) ? 2 : _playerAttackPoints - _x;
869
+ }
870
+
871
+
872
+ /// @notice Subtracts ability points. Helps to not cross minimal defence ability points -> 1
873
+ /// @param _playerDefencePoints Actual player's defence points
874
+ /// @param _x Amount to subtract
875
+ function subDefence(uint256 _playerDefencePoints, uint256 _x) internal pure returns (uint256) {
876
+ return (_playerDefencePoints <= _x) ? 1 : _playerDefencePoints - _x;
877
+ }
878
+
879
+
880
+ /*
881
+ * Private
882
+ */
883
+ /// @dev Is called from from Attack function after the winner is already chosen
884
+ /// @dev Updates abilities, champ's stats and swaps positions
885
+ function _attackCompleted(Champ storage _winnerChamp, Champ storage _defeatedChamp, uint256 _pointsGiven, uint256 _pointsToAttackPower) private {
886
+ /*
887
+ * Updates abilities after fight
888
+ */
889
+ //winner abilities update
890
+ _winnerChamp.attackPower += _pointsToAttackPower; //increase attack power
891
+ _winnerChamp.defencePower += _pointsGiven - _pointsToAttackPower; //max point that was given - already given to AP
892
+
893
+ //defeated champ's abilities update
894
+ //checks for not cross minimal AP & DP points
895
+ _defeatedChamp.attackPower = subAttack(_defeatedChamp.attackPower, _pointsToAttackPower); //decrease attack power
896
+ _defeatedChamp.defencePower = subDefence(_defeatedChamp.defencePower, _pointsGiven - _pointsToAttackPower); // decrease defence power
897
+
898
+
899
+
900
+ /*
901
+ * Update champs' wins and losses
902
+ */
903
+ _winnerChamp.winCount++;
904
+ _defeatedChamp.lossCount++;
905
+
906
+
907
+
908
+ /*
909
+ * Swap positions
910
+ */
911
+ if(_winnerChamp.position > _defeatedChamp.position) { //require loser to has better (lower) postion than attacker
912
+ uint256 winnerPosition = _winnerChamp.position;
913
+ uint256 loserPosition = _defeatedChamp.position;
914
+
915
+ _defeatedChamp.position = winnerPosition;
916
+ _winnerChamp.position = loserPosition;
917
+
918
+ //position in champ struct is always one point bigger than in leaderboard array
919
+ leaderboard[winnerPosition - 1] = _defeatedChamp.id;
920
+ leaderboard[loserPosition - 1] = _winnerChamp.id;
921
+ }
922
+ }
923
+
924
+
925
+ /// @dev Gets pointsGiven and pointsToAttackPower
926
+ function _getPoints(uint256 _pointsGiven) private returns (uint256 pointsGiven, uint256 pointsToAttackPower){
927
+ return (_pointsGiven, randMod(_pointsGiven+1));
928
+ }
929
+
930
+
931
+
932
+ /*
933
+ * External
934
+ */
935
+ /// @notice Attack function
936
+ /// @param _champId Attacker champ
937
+ /// @param _targetId Target champ
938
+ function attack(uint256 _champId, uint256 _targetId) external
939
+ onlyOwnerOfChamp(_champId)
940
+ isChampReady(_champId)
941
+ notSelfAttack(_champId, _targetId)
942
+ targetExists(_targetId) {
943
+ Champ storage myChamp = champs[_champId];
944
+ Champ storage enemyChamp = champs[_targetId];
945
+ uint256 pointsGiven; //total points that will be divided between AP and DP
946
+ uint256 pointsToAttackPower; //part of points that will be added to attack power, the rest of points go to defence power
947
+ uint256 myChampAttackPower;
948
+ uint256 enemyChampDefencePower;
949
+ uint256 myChampCooldownReduction;
950
+
951
+ (myChampAttackPower,,myChampCooldownReduction) = getChampStats(_champId);
952
+ (,enemyChampDefencePower,) = getChampStats(_targetId);
953
+
954
+
955
+ //if attacker's AP is more than target's DP then attacker wins
956
+ if (myChampAttackPower > enemyChampDefencePower) {
957
+
958
+ //this should demotivate players from farming on way weaker champs than they are
959
+ //the bigger difference between AP & DP is, the reward is smaller
960
+ if(myChampAttackPower - enemyChampDefencePower < 5){
961
+
962
+ //big experience - 3 ability points
963
+ (pointsGiven, pointsToAttackPower) = _getPoints(3);
964
+
965
+
966
+ }else if(myChampAttackPower - enemyChampDefencePower < 10){
967
+
968
+ //medium experience - 2 ability points
969
+ (pointsGiven, pointsToAttackPower) = _getPoints(2);
970
+
971
+ }else{
972
+
973
+ //small experience - 1 ability point to random ability (attack power or defence power)
974
+ (pointsGiven, pointsToAttackPower) = _getPoints(1);
975
+
976
+ }
977
+
978
+ _attackCompleted(myChamp, enemyChamp, pointsGiven, pointsToAttackPower);
979
+
980
+ emit Attack(myChamp.id, enemyChamp.id, true);
981
+
982
+ } else {
983
+
984
+ //1 ability point to random ability (attack power or defence power)
985
+ (pointsGiven, pointsToAttackPower) = _getPoints(1);
986
+
987
+ _attackCompleted(enemyChamp, myChamp, pointsGiven, pointsToAttackPower);
988
+
989
+ emit Attack(enemyChamp.id, myChamp.id, false);
990
+
991
+ }
992
+
993
+ //Trigger cooldown for attacker
994
+ myChamp.readyTime = uint256(block.timestamp + myChamp.cooldownTime - myChampCooldownReduction);
995
+
996
+ }
997
+
998
+ }
999
+
1000
+
1001
+ /// @title Moderates buying and selling champs
1002
+ contract ChampMarket is ChampAttack {
1003
+
1004
+ event TransferChamp(address from, address to, uint256 champID);
1005
+
1006
+ /*
1007
+ * Modifiers
1008
+ */
1009
+ ///@notice Require champ to be sale
1010
+ modifier champIsForSale(uint256 _id){
1011
+ require(champs[_id].forSale);
1012
+ _;
1013
+ }
1014
+
1015
+
1016
+ ///@notice Require champ NOT to be for sale
1017
+ modifier champIsNotForSale(uint256 _id){
1018
+ require(champs[_id].forSale == false);
1019
+ _;
1020
+ }
1021
+
1022
+
1023
+ ///@notice If champ is for sale then cancel sale
1024
+ modifier ifChampForSaleThenCancelSale(uint256 _champID){
1025
+ Champ storage champ = champs[_champID];
1026
+ if(champ.forSale){
1027
+ _cancelChampSale(champ);
1028
+ }
1029
+ _;
1030
+ }
1031
+
1032
+
1033
+ /*
1034
+ * View
1035
+ */
1036
+ ///@notice Gets all champs for sale
1037
+ function getChampsForSale() view external returns(uint256[]){
1038
+ uint256[] memory result = new uint256[](champsForSaleCount);
1039
+ if(champsForSaleCount > 0){
1040
+ uint256 counter = 0;
1041
+ for (uint256 i = 0; i < champs.length; i++) {
1042
+ if (champs[i].forSale == true) {
1043
+ result[counter]=i;
1044
+ counter++;
1045
+ }
1046
+ }
1047
+ }
1048
+ return result;
1049
+ }
1050
+
1051
+
1052
+ /*
1053
+ * Private
1054
+ */
1055
+ ///@dev Cancel sale. Should not be called without checking if champ is really for sale.
1056
+ function _cancelChampSale(Champ storage champ) private {
1057
+ //cancel champ's sale
1058
+ //no need waste gas to overwrite his price.
1059
+ champ.forSale = false;
1060
+ champsForSaleCount--;
1061
+ }
1062
+
1063
+
1064
+ /*
1065
+ * Internal
1066
+ */
1067
+ /// @notice Transfer champ
1068
+ function transferChamp(address _from, address _to, uint256 _champId) internal ifChampForSaleThenCancelSale(_champId){
1069
+ Champ storage champ = champs[_champId];
1070
+
1071
+ //transfer champ
1072
+ addressInfo[_to].champsCount++;
1073
+ addressInfo[_from].champsCount--;
1074
+ champToOwner[_champId] = _to;
1075
+
1076
+ //transfer items
1077
+ if(champ.eq_sword != 0) { transferItem(_from, _to, champ.eq_sword); }
1078
+ if(champ.eq_shield != 0) { transferItem(_from, _to, champ.eq_shield); }
1079
+ if(champ.eq_helmet != 0) { transferItem(_from, _to, champ.eq_helmet); }
1080
+
1081
+ emit TransferChamp(_from, _to, _champId);
1082
+ }
1083
+
1084
+
1085
+
1086
+ /*
1087
+ * Public
1088
+ */
1089
+ /// @notice Champ is no more for sale
1090
+ function cancelChampSale(uint256 _id) public
1091
+ champIsForSale(_id)
1092
+ onlyOwnerOfChamp(_id) {
1093
+ Champ storage champ = champs[_id];
1094
+ _cancelChampSale(champ);
1095
+ }
1096
+
1097
+
1098
+ /*
1099
+ * External
1100
+ */
1101
+ /// @notice Gift champ
1102
+ /// @dev Address _from is msg.sender
1103
+ function giveChamp(address _to, uint256 _champId) external
1104
+ onlyOwnerOfChamp(_champId) {
1105
+ transferChamp(msg.sender, _to, _champId);
1106
+ }
1107
+
1108
+
1109
+ /// @notice Sets champ for sale
1110
+ function setChampForSale(uint256 _id, uint256 _price) external
1111
+ onlyOwnerOfChamp(_id)
1112
+ champIsNotForSale(_id) {
1113
+ Champ storage champ = champs[_id];
1114
+ champ.forSale = true;
1115
+ champ.price = _price;
1116
+ champsForSaleCount++;
1117
+ }
1118
+
1119
+
1120
+ /// @notice Buys champ
1121
+ function buyChamp(uint256 _id) external payable
1122
+ whenNotPaused
1123
+ onlyNotOwnerOfChamp(_id)
1124
+ champIsForSale(_id)
1125
+ isPaid(champs[_id].price)
1126
+ distributeSaleInput(champToOwner[_id]) {
1127
+ transferChamp(champToOwner[_id], msg.sender, _id);
1128
+ }
1129
+
1130
+ }
1131
+
1132
+
1133
+
1134
+ /// @title Only used for deploying all contracts
1135
+ contract MyCryptoChampCore is ChampMarket {
1136
+ /*
1137
+ © Copyright 2018 - Patrik Mojzis
1138
+ Redistributing and modifying is prohibited.
1139
+
1140
+ https://mycryptochamp.io/
1141
+
1142
+ What is MyCryptoChamp?
1143
+ - Blockchain game about upgrading champs by fighting, getting better items,
1144
+ trading them and the best 800 champs are daily rewarded by real Ether.
1145
+
1146
+ Feel free to ask any questions
1147
1148
+ */
1149
+ }
data_full/CVE/2018-12959.sol ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-12-27
3
+ */
4
+
5
+ pragma solidity ^0.4.4;
6
+
7
+ contract Token {
8
+
9
+ /// @return total amount of tokens
10
+ function totalSupply() constant returns (uint256 supply) {}
11
+
12
+ /// @param _owner The address from which the balance will be retrieved
13
+ /// @return The balance
14
+ function balanceOf(address _owner) constant returns (uint256 balance) {}
15
+
16
+ /// @notice send `_value` token to `_to` from `msg.sender`
17
+ /// @param _to The address of the recipient
18
+ /// @param _value The amount of token to be transferred
19
+ /// @return Whether the transfer was successful or not
20
+ function transfer(address _to, uint256 _value) returns (bool success) {}
21
+
22
+ /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
23
+ /// @param _from The address of the sender
24
+ /// @param _to The address of the recipient
25
+ /// @param _value The amount of token to be transferred
26
+ /// @return Whether the transfer was successful or not
27
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
28
+
29
+ /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
30
+ /// @param _spender The address of the account able to transfer the tokens
31
+ /// @param _value The amount of wei to be approved for transfer
32
+ /// @return Whether the approval was successful or not
33
+ function approve(address _spender, uint256 _value) returns (bool success) {}
34
+
35
+ /// @param _owner The address of the account owning tokens
36
+ /// @param _spender The address of the account able to transfer the tokens
37
+ /// @return Amount of remaining tokens allowed to spent
38
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
39
+
40
+ event Transfer(address indexed _from, address indexed _to, uint256 _value);
41
+ event Approval(address indexed _owner, address indexed _spender, uint256 _value);
42
+
43
+ }
44
+
45
+
46
+
47
+ contract StandardToken is Token {
48
+
49
+ function transfer(address _to, uint256 _value) returns (bool success) {
50
+ //Default assumes totalSupply can't be over max (2^256 - 1).
51
+ //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
52
+ //Replace the if with this one instead.
53
+ //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
54
+ if (balances[msg.sender] >= _value && _value > 0) {
55
+ balances[msg.sender] -= _value;
56
+ balances[_to] += _value;
57
+ Transfer(msg.sender, _to, _value);
58
+ return true;
59
+ } else { return false; }
60
+ }
61
+
62
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
63
+ //same as above. Replace this line with the following if you want to protect against wrapping uints.
64
+ //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
65
+ if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
66
+ balances[_to] += _value;
67
+ balances[_from] -= _value;
68
+ allowed[_from][msg.sender] -= _value;
69
+ Transfer(_from, _to, _value);
70
+ return true;
71
+ } else { return false; }
72
+ }
73
+
74
+ function balanceOf(address _owner) constant returns (uint256 balance) {
75
+ return balances[_owner];
76
+ }
77
+
78
+ function approve(address _spender, uint256 _value) returns (bool success) {
79
+ allowed[msg.sender][_spender] = _value;
80
+ Approval(msg.sender, _spender, _value);
81
+ return true;
82
+ }
83
+
84
+ function allowance(address _owner, address _spender) constant returns (uint256 remaining) {
85
+ return allowed[_owner][_spender];
86
+ }
87
+
88
+ mapping (address => uint256) balances;
89
+ mapping (address => mapping (address => uint256)) allowed;
90
+ uint256 public totalSupply;
91
+ }
92
+
93
+ contract AditusToken is StandardToken {
94
+
95
+ function () {
96
+ //if ether is sent to this address, send it back.
97
+ throw;
98
+ }
99
+
100
+ /* Public variables of the token */
101
+
102
+ string public name;
103
+ uint8 public decimals;
104
+ string public symbol;
105
+ string public version = 'A1.0';
106
+
107
+ function AditusToken(
108
+ ) {
109
+ balances[msg.sender] = 1000000000000000000000000000; // Give the creator all initial tokens (100000 for example)
110
+ totalSupply = 1000000000000000000000000000; // Update total supply (100000 for example)
111
+ name = "Aditus"; // Set the name for display purposes
112
+ decimals = 18; // Amount of decimals for display purposes
113
+ symbol = "ADI"; // Set the symbol for display purposes
114
+ }
115
+
116
+ /* Approves and then calls the receiving contract */
117
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
118
+ allowed[msg.sender][_spender] = _value;
119
+ Approval(msg.sender, _spender, _value);
120
+
121
+ //call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
122
+ //receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
123
+ //it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
124
+ if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
125
+ return true;
126
+ }
127
+ }
data_full/CVE/2018-12975.sol ADDED
@@ -0,0 +1,1234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-02-14
3
+ */
4
+
5
+ pragma solidity ^0.4.18;
6
+
7
+ /**
8
+ * @title Ownable
9
+ * @dev The Ownable contract has an owner address, and provides basic authorization control
10
+ * functions, this simplifies the implementation of "user permissions".
11
+ */
12
+ contract Ownable {
13
+ address public owner;
14
+
15
+
16
+ event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
17
+
18
+
19
+ /**
20
+ * @dev The Ownable constructor sets the original `owner` of the contract to the sender
21
+ * account.
22
+ */
23
+ function Ownable() public {
24
+ owner = msg.sender;
25
+ }
26
+
27
+ /**
28
+ * @dev Throws if called by any account other than the owner.
29
+ */
30
+ modifier onlyOwner() {
31
+ require(msg.sender == owner);
32
+ _;
33
+ }
34
+
35
+ /**
36
+ * @dev Allows the current owner to transfer control of the contract to a newOwner.
37
+ * @param newOwner The address to transfer ownership to.
38
+ */
39
+ function transferOwnership(address newOwner) public onlyOwner {
40
+ require(newOwner != address(0));
41
+ OwnershipTransferred(owner, newOwner);
42
+ owner = newOwner;
43
+ }
44
+
45
+ }
46
+
47
+
48
+ /**
49
+ * @title Claimable
50
+ * @dev Extension for the Ownable contract, where the ownership needs to be claimed.
51
+ * This allows the new owner to accept the transfer.
52
+ */
53
+ contract Claimable is Ownable {
54
+ address public pendingOwner;
55
+
56
+ /**
57
+ * @dev Modifier throws if called by any account other than the pendingOwner.
58
+ */
59
+ modifier onlyPendingOwner() {
60
+ require(msg.sender == pendingOwner);
61
+ _;
62
+ }
63
+
64
+ /**
65
+ * @dev Allows the current owner to set the pendingOwner address.
66
+ * @param newOwner The address to transfer ownership to.
67
+ */
68
+ function transferOwnership(address newOwner) onlyOwner public {
69
+ pendingOwner = newOwner;
70
+ }
71
+
72
+ /**
73
+ * @dev Allows the pendingOwner address to finalize the transfer.
74
+ */
75
+ function claimOwnership() onlyPendingOwner public {
76
+ OwnershipTransferred(owner, pendingOwner);
77
+ owner = pendingOwner;
78
+ pendingOwner = address(0);
79
+ }
80
+ }
81
+
82
+
83
+ /**
84
+ * @title Pausable
85
+ * @dev Base contract which allows children to implement an emergency stop mechanism.
86
+ */
87
+ contract Pausable is Ownable {
88
+ event Pause();
89
+ event Unpause();
90
+
91
+ bool public paused = false;
92
+
93
+
94
+ /**
95
+ * @dev Modifier to make a function callable only when the contract is not paused.
96
+ */
97
+ modifier whenNotPaused() {
98
+ require(!paused);
99
+ _;
100
+ }
101
+
102
+ /**
103
+ * @dev Modifier to make a function callable only when the contract is paused.
104
+ */
105
+ modifier whenPaused() {
106
+ require(paused);
107
+ _;
108
+ }
109
+
110
+ /**
111
+ * @dev called by the owner to pause, triggers stopped state
112
+ */
113
+ function pause() onlyOwner whenNotPaused public {
114
+ paused = true;
115
+ Pause();
116
+ }
117
+
118
+ /**
119
+ * @dev called by the owner to unpause, returns to normal state
120
+ */
121
+ function unpause() onlyOwner whenPaused public {
122
+ paused = false;
123
+ Unpause();
124
+ }
125
+ }
126
+
127
+
128
+ /**
129
+ * @title AccessDeploy
130
+ * @dev Adds grant/revoke functions to the contract.
131
+ */
132
+ contract AccessDeploy is Claimable {
133
+
134
+ // Access for deploying heroes.
135
+ mapping(address => bool) private deployAccess;
136
+
137
+ // Modifier for accessibility to deploy a hero on a location.
138
+ modifier onlyAccessDeploy {
139
+ require(msg.sender == owner || deployAccess[msg.sender] == true);
140
+ _;
141
+ }
142
+
143
+ // @dev Grant acess to deploy heroes.
144
+ function grantAccessDeploy(address _address)
145
+ onlyOwner
146
+ public
147
+ {
148
+ deployAccess[_address] = true;
149
+ }
150
+
151
+ // @dev Revoke acess to deploy heroes.
152
+ function revokeAccessDeploy(address _address)
153
+ onlyOwner
154
+ public
155
+ {
156
+ deployAccess[_address] = false;
157
+ }
158
+
159
+ }
160
+
161
+
162
+ /**
163
+ * @title AccessDeposit
164
+ * @dev Adds grant/revoke functions to the contract.
165
+ */
166
+ contract AccessDeposit is Claimable {
167
+
168
+ // Access for adding deposit.
169
+ mapping(address => bool) private depositAccess;
170
+
171
+ // Modifier for accessibility to add deposit.
172
+ modifier onlyAccessDeposit {
173
+ require(msg.sender == owner || depositAccess[msg.sender] == true);
174
+ _;
175
+ }
176
+
177
+ // @dev Grant acess to deposit heroes.
178
+ function grantAccessDeposit(address _address)
179
+ onlyOwner
180
+ public
181
+ {
182
+ depositAccess[_address] = true;
183
+ }
184
+
185
+ // @dev Revoke acess to deposit heroes.
186
+ function revokeAccessDeposit(address _address)
187
+ onlyOwner
188
+ public
189
+ {
190
+ depositAccess[_address] = false;
191
+ }
192
+
193
+ }
194
+
195
+
196
+ /**
197
+ * @title AccessMint
198
+ * @dev Adds grant/revoke functions to the contract.
199
+ */
200
+ contract AccessMint is Claimable {
201
+
202
+ // Access for minting new tokens.
203
+ mapping(address => bool) private mintAccess;
204
+
205
+ // Modifier for accessibility to define new hero types.
206
+ modifier onlyAccessMint {
207
+ require(msg.sender == owner || mintAccess[msg.sender] == true);
208
+ _;
209
+ }
210
+
211
+ // @dev Grant acess to mint heroes.
212
+ function grantAccessMint(address _address)
213
+ onlyOwner
214
+ public
215
+ {
216
+ mintAccess[_address] = true;
217
+ }
218
+
219
+ // @dev Revoke acess to mint heroes.
220
+ function revokeAccessMint(address _address)
221
+ onlyOwner
222
+ public
223
+ {
224
+ mintAccess[_address] = false;
225
+ }
226
+
227
+ }
228
+
229
+
230
+ /**
231
+ * @title ERC721 interface
232
+ * @dev see https://github.com/ethereum/eips/issues/721
233
+ */
234
+ contract ERC721 {
235
+ event Transfer(address indexed _from, address indexed _to, uint256 _tokenId);
236
+ event Approval(address indexed _owner, address indexed _approved, uint256 _tokenId);
237
+
238
+ function balanceOf(address _owner) public view returns (uint256 _balance);
239
+ function ownerOf(uint256 _tokenId) public view returns (address _owner);
240
+ function transfer(address _to, uint256 _tokenId) public;
241
+ function approve(address _to, uint256 _tokenId) public;
242
+ function takeOwnership(uint256 _tokenId) public;
243
+ }
244
+
245
+
246
+ /**
247
+ * @title ERC721Token
248
+ * Generic implementation for the required functionality of the ERC721 standard
249
+ */
250
+ contract ERC721Token is ERC721 {
251
+ using SafeMath for uint256;
252
+
253
+ // Total amount of tokens
254
+ uint256 private totalTokens;
255
+
256
+ // Mapping from token ID to owner
257
+ mapping (uint256 => address) private tokenOwner;
258
+
259
+ // Mapping from token ID to approved address
260
+ mapping (uint256 => address) private tokenApprovals;
261
+
262
+ // Mapping from owner to list of owned token IDs
263
+ mapping (address => uint256[]) private ownedTokens;
264
+
265
+ // Mapping from token ID to index of the owner tokens list
266
+ mapping(uint256 => uint256) private ownedTokensIndex;
267
+
268
+ /**
269
+ * @dev Guarantees msg.sender is owner of the given token
270
+ * @param _tokenId uint256 ID of the token to validate its ownership belongs to msg.sender
271
+ */
272
+ modifier onlyOwnerOf(uint256 _tokenId) {
273
+ require(ownerOf(_tokenId) == msg.sender);
274
+ _;
275
+ }
276
+
277
+ /**
278
+ * @dev Gets the total amount of tokens stored by the contract
279
+ * @return uint256 representing the total amount of tokens
280
+ */
281
+ function totalSupply() public view returns (uint256) {
282
+ return totalTokens;
283
+ }
284
+
285
+ /**
286
+ * @dev Gets the balance of the specified address
287
+ * @param _owner address to query the balance of
288
+ * @return uint256 representing the amount owned by the passed address
289
+ */
290
+ function balanceOf(address _owner) public view returns (uint256) {
291
+ return ownedTokens[_owner].length;
292
+ }
293
+
294
+ /**
295
+ * @dev Gets the list of tokens owned by a given address
296
+ * @param _owner address to query the tokens of
297
+ * @return uint256[] representing the list of tokens owned by the passed address
298
+ */
299
+ function tokensOf(address _owner) public view returns (uint256[]) {
300
+ return ownedTokens[_owner];
301
+ }
302
+
303
+ /**
304
+ * @dev Gets the owner of the specified token ID
305
+ * @param _tokenId uint256 ID of the token to query the owner of
306
+ * @return owner address currently marked as the owner of the given token ID
307
+ */
308
+ function ownerOf(uint256 _tokenId) public view returns (address) {
309
+ address owner = tokenOwner[_tokenId];
310
+ require(owner != address(0));
311
+ return owner;
312
+ }
313
+
314
+ /**
315
+ * @dev Gets the approved address to take ownership of a given token ID
316
+ * @param _tokenId uint256 ID of the token to query the approval of
317
+ * @return address currently approved to take ownership of the given token ID
318
+ */
319
+ function approvedFor(uint256 _tokenId) public view returns (address) {
320
+ return tokenApprovals[_tokenId];
321
+ }
322
+
323
+ /**
324
+ * @dev Transfers the ownership of a given token ID to another address
325
+ * @param _to address to receive the ownership of the given token ID
326
+ * @param _tokenId uint256 ID of the token to be transferred
327
+ */
328
+ function transfer(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
329
+ clearApprovalAndTransfer(msg.sender, _to, _tokenId);
330
+ }
331
+
332
+ /**
333
+ * @dev Approves another address to claim for the ownership of the given token ID
334
+ * @param _to address to be approved for the given token ID
335
+ * @param _tokenId uint256 ID of the token to be approved
336
+ */
337
+ function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
338
+ address owner = ownerOf(_tokenId);
339
+ require(_to != owner);
340
+ if (approvedFor(_tokenId) != 0 || _to != 0) {
341
+ tokenApprovals[_tokenId] = _to;
342
+ Approval(owner, _to, _tokenId);
343
+ }
344
+ }
345
+
346
+ /**
347
+ * @dev Claims the ownership of a given token ID
348
+ * @param _tokenId uint256 ID of the token being claimed by the msg.sender
349
+ */
350
+ function takeOwnership(uint256 _tokenId) public {
351
+ require(isApprovedFor(msg.sender, _tokenId));
352
+ clearApprovalAndTransfer(ownerOf(_tokenId), msg.sender, _tokenId);
353
+ }
354
+
355
+ /**
356
+ * @dev Mint token function
357
+ * @param _to The address that will own the minted token
358
+ * @param _tokenId uint256 ID of the token to be minted by the msg.sender
359
+ */
360
+ function _mint(address _to, uint256 _tokenId) internal {
361
+ require(_to != address(0));
362
+ addToken(_to, _tokenId);
363
+ Transfer(0x0, _to, _tokenId);
364
+ }
365
+
366
+ /**
367
+ * @dev Burns a specific token
368
+ * @param _tokenId uint256 ID of the token being burned by the msg.sender
369
+ */
370
+ function _burn(uint256 _tokenId) onlyOwnerOf(_tokenId) internal {
371
+ if (approvedFor(_tokenId) != 0) {
372
+ clearApproval(msg.sender, _tokenId);
373
+ }
374
+ removeToken(msg.sender, _tokenId);
375
+ Transfer(msg.sender, 0x0, _tokenId);
376
+ }
377
+
378
+ /**
379
+ * @dev Tells whether the msg.sender is approved for the given token ID or not
380
+ * This function is not private so it can be extended in further implementations like the operatable ERC721
381
+ * @param _owner address of the owner to query the approval of
382
+ * @param _tokenId uint256 ID of the token to query the approval of
383
+ * @return bool whether the msg.sender is approved for the given token ID or not
384
+ */
385
+ function isApprovedFor(address _owner, uint256 _tokenId) internal view returns (bool) {
386
+ return approvedFor(_tokenId) == _owner;
387
+ }
388
+
389
+ /**
390
+ * @dev Internal function to clear current approval and transfer the ownership of a given token ID
391
+ * @param _from address which you want to send tokens from
392
+ * @param _to address which you want to transfer the token to
393
+ * @param _tokenId uint256 ID of the token to be transferred
394
+ */
395
+ function clearApprovalAndTransfer(address _from, address _to, uint256 _tokenId) internal {
396
+ require(_to != address(0));
397
+ require(_to != ownerOf(_tokenId));
398
+ require(ownerOf(_tokenId) == _from);
399
+
400
+ clearApproval(_from, _tokenId);
401
+ removeToken(_from, _tokenId);
402
+ addToken(_to, _tokenId);
403
+ Transfer(_from, _to, _tokenId);
404
+ }
405
+
406
+ /**
407
+ * @dev Internal function to clear current approval of a given token ID
408
+ * @param _tokenId uint256 ID of the token to be transferred
409
+ */
410
+ function clearApproval(address _owner, uint256 _tokenId) private {
411
+ require(ownerOf(_tokenId) == _owner);
412
+ tokenApprovals[_tokenId] = 0;
413
+ Approval(_owner, 0, _tokenId);
414
+ }
415
+
416
+ /**
417
+ * @dev Internal function to add a token ID to the list of a given address
418
+ * @param _to address representing the new owner of the given token ID
419
+ * @param _tokenId uint256 ID of the token to be added to the tokens list of the given address
420
+ */
421
+ function addToken(address _to, uint256 _tokenId) private {
422
+ require(tokenOwner[_tokenId] == address(0));
423
+ tokenOwner[_tokenId] = _to;
424
+ uint256 length = balanceOf(_to);
425
+ ownedTokens[_to].push(_tokenId);
426
+ ownedTokensIndex[_tokenId] = length;
427
+ totalTokens = totalTokens.add(1);
428
+ }
429
+
430
+ /**
431
+ * @dev Internal function to remove a token ID from the list of a given address
432
+ * @param _from address representing the previous owner of the given token ID
433
+ * @param _tokenId uint256 ID of the token to be removed from the tokens list of the given address
434
+ */
435
+ function removeToken(address _from, uint256 _tokenId) private {
436
+ require(ownerOf(_tokenId) == _from);
437
+
438
+ uint256 tokenIndex = ownedTokensIndex[_tokenId];
439
+ uint256 lastTokenIndex = balanceOf(_from).sub(1);
440
+ uint256 lastToken = ownedTokens[_from][lastTokenIndex];
441
+
442
+ tokenOwner[_tokenId] = 0;
443
+ ownedTokens[_from][tokenIndex] = lastToken;
444
+ ownedTokens[_from][lastTokenIndex] = 0;
445
+ // Note that this will handle single-element arrays. In that case, both tokenIndex and lastTokenIndex are going to
446
+ // be zero. Then we can make sure that we will remove _tokenId from the ownedTokens list since we are first swapping
447
+ // the lastToken to the first position, and then dropping the element placed in the last position of the list
448
+
449
+ ownedTokens[_from].length--;
450
+ ownedTokensIndex[_tokenId] = 0;
451
+ ownedTokensIndex[lastToken] = tokenIndex;
452
+ totalTokens = totalTokens.sub(1);
453
+ }
454
+ }
455
+
456
+
457
+ /**
458
+ * @title ERC20Basic
459
+ * @dev Simpler version of ERC20 interface
460
+ * @dev see https://github.com/ethereum/EIPs/issues/179
461
+ */
462
+ contract ERC20Basic {
463
+ function totalSupply() public view returns (uint256);
464
+ function balanceOf(address who) public view returns (uint256);
465
+ function transfer(address to, uint256 value) public returns (bool);
466
+ event Transfer(address indexed from, address indexed to, uint256 value);
467
+ }
468
+
469
+
470
+ /**
471
+ * @title ERC20 interface
472
+ * @dev see https://github.com/ethereum/EIPs/issues/20
473
+ */
474
+ contract ERC20 is ERC20Basic {
475
+ function allowance(address owner, address spender) public view returns (uint256);
476
+ function transferFrom(address from, address to, uint256 value) public returns (bool);
477
+ function approve(address spender, uint256 value) public returns (bool);
478
+ event Approval(address indexed owner, address indexed spender, uint256 value);
479
+ }
480
+
481
+
482
+ /**
483
+ * @title SafeMath
484
+ * @dev Math operations with safety checks that throw on error
485
+ */
486
+ library SafeMath {
487
+
488
+ /**
489
+ * @dev Multiplies two numbers, throws on overflow.
490
+ */
491
+ function mul(uint256 a, uint256 b) internal pure returns (uint256) {
492
+ if (a == 0) {
493
+ return 0;
494
+ }
495
+ uint256 c = a * b;
496
+ assert(c / a == b);
497
+ return c;
498
+ }
499
+
500
+ /**
501
+ * @dev Integer division of two numbers, truncating the quotient.
502
+ */
503
+ function div(uint256 a, uint256 b) internal pure returns (uint256) {
504
+ // assert(b > 0); // Solidity automatically throws when dividing by 0
505
+ uint256 c = a / b;
506
+ // assert(a == b * c + a % b); // There is no case in which this doesn't hold
507
+ return c;
508
+ }
509
+
510
+ /**
511
+ * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
512
+ */
513
+ function sub(uint256 a, uint256 b) internal pure returns (uint256) {
514
+ assert(b <= a);
515
+ return a - b;
516
+ }
517
+
518
+ /**
519
+ * @dev Adds two numbers, throws on overflow.
520
+ */
521
+ function add(uint256 a, uint256 b) internal pure returns (uint256) {
522
+ uint256 c = a + b;
523
+ assert(c >= a);
524
+ return c;
525
+ }
526
+ }
527
+
528
+
529
+ /**
530
+ * @title Basic token
531
+ * @dev Basic version of StandardToken, with no allowances.
532
+ */
533
+ contract BasicToken is ERC20Basic {
534
+ using SafeMath for uint256;
535
+
536
+ mapping(address => uint256) balances;
537
+
538
+ uint256 totalSupply_;
539
+
540
+ /**
541
+ * @dev total number of tokens in existence
542
+ */
543
+ function totalSupply() public view returns (uint256) {
544
+ return totalSupply_;
545
+ }
546
+
547
+ /**
548
+ * @dev transfer token for a specified address
549
+ * @param _to The address to transfer to.
550
+ * @param _value The amount to be transferred.
551
+ */
552
+ function transfer(address _to, uint256 _value) public returns (bool) {
553
+ require(_to != address(0));
554
+ require(_value <= balances[msg.sender]);
555
+
556
+ // SafeMath.sub will throw if there is not enough balance.
557
+ balances[msg.sender] = balances[msg.sender].sub(_value);
558
+ balances[_to] = balances[_to].add(_value);
559
+ Transfer(msg.sender, _to, _value);
560
+ return true;
561
+ }
562
+
563
+ /**
564
+ * @dev Gets the balance of the specified address.
565
+ * @param _owner The address to query the the balance of.
566
+ * @return An uint256 representing the amount owned by the passed address.
567
+ */
568
+ function balanceOf(address _owner) public view returns (uint256 balance) {
569
+ return balances[_owner];
570
+ }
571
+
572
+ }
573
+
574
+
575
+ /**
576
+ * @title Standard ERC20 token
577
+ *
578
+ * @dev Implementation of the basic standard token.
579
+ * @dev https://github.com/ethereum/EIPs/issues/20
580
+ * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
581
+ */
582
+ contract StandardToken is ERC20, BasicToken {
583
+
584
+ mapping (address => mapping (address => uint256)) internal allowed;
585
+
586
+
587
+ /**
588
+ * @dev Transfer tokens from one address to another
589
+ * @param _from address The address which you want to send tokens from
590
+ * @param _to address The address which you want to transfer to
591
+ * @param _value uint256 the amount of tokens to be transferred
592
+ */
593
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
594
+ require(_to != address(0));
595
+ require(_value <= balances[_from]);
596
+ require(_value <= allowed[_from][msg.sender]);
597
+
598
+ balances[_from] = balances[_from].sub(_value);
599
+ balances[_to] = balances[_to].add(_value);
600
+ allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
601
+ Transfer(_from, _to, _value);
602
+ return true;
603
+ }
604
+
605
+ /**
606
+ * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
607
+ *
608
+ * Beware that changing an allowance with this method brings the risk that someone may use both the old
609
+ * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
610
+ * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
611
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
612
+ * @param _spender The address which will spend the funds.
613
+ * @param _value The amount of tokens to be spent.
614
+ */
615
+ function approve(address _spender, uint256 _value) public returns (bool) {
616
+ allowed[msg.sender][_spender] = _value;
617
+ Approval(msg.sender, _spender, _value);
618
+ return true;
619
+ }
620
+
621
+ /**
622
+ * @dev Function to check the amount of tokens that an owner allowed to a spender.
623
+ * @param _owner address The address which owns the funds.
624
+ * @param _spender address The address which will spend the funds.
625
+ * @return A uint256 specifying the amount of tokens still available for the spender.
626
+ */
627
+ function allowance(address _owner, address _spender) public view returns (uint256) {
628
+ return allowed[_owner][_spender];
629
+ }
630
+
631
+ /**
632
+ * @dev Increase the amount of tokens that an owner allowed to a spender.
633
+ *
634
+ * approve should be called when allowed[_spender] == 0. To increment
635
+ * allowed value is better to use this function to avoid 2 calls (and wait until
636
+ * the first transaction is mined)
637
+ * From MonolithDAO Token.sol
638
+ * @param _spender The address which will spend the funds.
639
+ * @param _addedValue The amount of tokens to increase the allowance by.
640
+ */
641
+ function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
642
+ allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
643
+ Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
644
+ return true;
645
+ }
646
+
647
+ /**
648
+ * @dev Decrease the amount of tokens that an owner allowed to a spender.
649
+ *
650
+ * approve should be called when allowed[_spender] == 0. To decrement
651
+ * allowed value is better to use this function to avoid 2 calls (and wait until
652
+ * the first transaction is mined)
653
+ * From MonolithDAO Token.sol
654
+ * @param _spender The address which will spend the funds.
655
+ * @param _subtractedValue The amount of tokens to decrease the allowance by.
656
+ */
657
+ function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
658
+ uint oldValue = allowed[msg.sender][_spender];
659
+ if (_subtractedValue > oldValue) {
660
+ allowed[msg.sender][_spender] = 0;
661
+ } else {
662
+ allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
663
+ }
664
+ Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
665
+ return true;
666
+ }
667
+
668
+ }
669
+
670
+
671
+ /**
672
+ * @title Gold
673
+ * @dev ERC20 Token that can be minted.
674
+ */
675
+ contract Gold is StandardToken, Claimable, AccessMint {
676
+
677
+ string public constant name = "Gold";
678
+ string public constant symbol = "G";
679
+ uint8 public constant decimals = 18;
680
+
681
+ // Event that is fired when minted.
682
+ event Mint(
683
+ address indexed _to,
684
+ uint256 indexed _tokenId
685
+ );
686
+
687
+ // @dev Mint tokens with _amount to the address.
688
+ function mint(address _to, uint256 _amount)
689
+ onlyAccessMint
690
+ public
691
+ returns (bool)
692
+ {
693
+ totalSupply_ = totalSupply_.add(_amount);
694
+ balances[_to] = balances[_to].add(_amount);
695
+ Mint(_to, _amount);
696
+ Transfer(address(0), _to, _amount);
697
+ return true;
698
+ }
699
+
700
+ }
701
+
702
+
703
+ /**
704
+ * @title CryptoSagaHero
705
+ * @dev The token contract for the hero.
706
+ * Also a superset of the ERC721 standard that allows for the minting
707
+ * of the non-fungible tokens.
708
+ */
709
+ contract CryptoSagaHero is ERC721Token, Claimable, Pausable, AccessMint, AccessDeploy, AccessDeposit {
710
+
711
+ string public constant name = "CryptoSaga Hero";
712
+ string public constant symbol = "HERO";
713
+
714
+ struct HeroClass {
715
+ // ex) Soldier, Knight, Fighter...
716
+ string className;
717
+ // 0: Common, 1: Uncommon, 2: Rare, 3: Heroic, 4: Legendary.
718
+ uint8 classRank;
719
+ // 0: Human, 1: Celestial, 2: Demon, 3: Elf, 4: Dark Elf, 5: Yogoe, 6: Furry, 7: Dragonborn, 8: Undead, 9: Goblin, 10: Troll, 11: Slime, and more to come.
720
+ uint8 classRace;
721
+ // How old is this hero class?
722
+ uint32 classAge;
723
+ // 0: Fighter, 1: Rogue, 2: Mage.
724
+ uint8 classType;
725
+
726
+ // Possible max level of this class.
727
+ uint32 maxLevel;
728
+ // 0: Water, 1: Fire, 2: Nature, 3: Light, 4: Darkness.
729
+ uint8 aura;
730
+
731
+ // Base stats of this hero type.
732
+ // 0: ATK 1: DEF 2: AGL 3: LUK 4: HP.
733
+ uint32[5] baseStats;
734
+ // Minimum IVs for stats.
735
+ // 0: ATK 1: DEF 2: AGL 3: LUK 4: HP.
736
+ uint32[5] minIVForStats;
737
+ // Maximum IVs for stats.
738
+ // 0: ATK 1: DEF 2: AGL 3: LUK 4: HP.
739
+ uint32[5] maxIVForStats;
740
+
741
+ // Number of currently instanced heroes.
742
+ uint32 currentNumberOfInstancedHeroes;
743
+ }
744
+
745
+ struct HeroInstance {
746
+ // What is this hero's type? ex) John, Sally, Mark...
747
+ uint32 heroClassId;
748
+
749
+ // Individual hero's name.
750
+ string heroName;
751
+
752
+ // Current level of this hero.
753
+ uint32 currentLevel;
754
+ // Current exp of this hero.
755
+ uint32 currentExp;
756
+
757
+ // Where has this hero been deployed? (0: Never depolyed ever.) ex) Dungeon Floor #1, Arena #5...
758
+ uint32 lastLocationId;
759
+ // When a hero is deployed, it takes time for the hero to return to the base. This is in Unix epoch.
760
+ uint256 availableAt;
761
+
762
+ // Current stats of this hero.
763
+ // 0: ATK 1: DEF 2: AGL 3: LUK 4: HP.
764
+ uint32[5] currentStats;
765
+ // The individual value for this hero's stats.
766
+ // This will affect the current stats of heroes.
767
+ // 0: ATK 1: DEF 2: AGL 3: LUK 4: HP.
768
+ uint32[5] ivForStats;
769
+ }
770
+
771
+ // Required exp for level up will increase when heroes level up.
772
+ // This defines how the value will increase.
773
+ uint32 public requiredExpIncreaseFactor = 100;
774
+
775
+ // Required Gold for level up will increase when heroes level up.
776
+ // This defines how the value will increase.
777
+ uint256 public requiredGoldIncreaseFactor = 1000000000000000000;
778
+
779
+ // Existing hero classes.
780
+ mapping(uint32 => HeroClass) public heroClasses;
781
+ // The number of hero classes ever defined.
782
+ uint32 public numberOfHeroClasses;
783
+
784
+ // Existing hero instances.
785
+ // The key is _tokenId.
786
+ mapping(uint256 => HeroInstance) public tokenIdToHeroInstance;
787
+ // The number of tokens ever minted. This works as the serial number.
788
+ uint256 public numberOfTokenIds;
789
+
790
+ // Gold contract.
791
+ Gold public goldContract;
792
+
793
+ // Deposit of players (in Gold).
794
+ mapping(address => uint256) public addressToGoldDeposit;
795
+
796
+ // Random seed.
797
+ uint32 private seed = 0;
798
+
799
+ // Event that is fired when a hero type defined.
800
+ event DefineType(
801
+ address indexed _by,
802
+ uint32 indexed _typeId,
803
+ string _className
804
+ );
805
+
806
+ // Event that is fired when a hero is upgraded.
807
+ event LevelUp(
808
+ address indexed _by,
809
+ uint256 indexed _tokenId,
810
+ uint32 _newLevel
811
+ );
812
+
813
+ // Event that is fired when a hero is deployed.
814
+ event Deploy(
815
+ address indexed _by,
816
+ uint256 indexed _tokenId,
817
+ uint32 _locationId,
818
+ uint256 _duration
819
+ );
820
+
821
+ // @dev Get the class's entire infomation.
822
+ function getClassInfo(uint32 _classId)
823
+ external view
824
+ returns (string className, uint8 classRank, uint8 classRace, uint32 classAge, uint8 classType, uint32 maxLevel, uint8 aura, uint32[5] baseStats, uint32[5] minIVs, uint32[5] maxIVs)
825
+ {
826
+ var _cl = heroClasses[_classId];
827
+ return (_cl.className, _cl.classRank, _cl.classRace, _cl.classAge, _cl.classType, _cl.maxLevel, _cl.aura, _cl.baseStats, _cl.minIVForStats, _cl.maxIVForStats);
828
+ }
829
+
830
+ // @dev Get the class's name.
831
+ function getClassName(uint32 _classId)
832
+ external view
833
+ returns (string)
834
+ {
835
+ return heroClasses[_classId].className;
836
+ }
837
+
838
+ // @dev Get the class's rank.
839
+ function getClassRank(uint32 _classId)
840
+ external view
841
+ returns (uint8)
842
+ {
843
+ return heroClasses[_classId].classRank;
844
+ }
845
+
846
+ // @dev Get the heroes ever minted for the class.
847
+ function getClassMintCount(uint32 _classId)
848
+ external view
849
+ returns (uint32)
850
+ {
851
+ return heroClasses[_classId].currentNumberOfInstancedHeroes;
852
+ }
853
+
854
+ // @dev Get the hero's entire infomation.
855
+ function getHeroInfo(uint256 _tokenId)
856
+ external view
857
+ returns (uint32 classId, string heroName, uint32 currentLevel, uint32 currentExp, uint32 lastLocationId, uint256 availableAt, uint32[5] currentStats, uint32[5] ivs, uint32 bp)
858
+ {
859
+ HeroInstance memory _h = tokenIdToHeroInstance[_tokenId];
860
+ var _bp = _h.currentStats[0] + _h.currentStats[1] + _h.currentStats[2] + _h.currentStats[3] + _h.currentStats[4];
861
+ return (_h.heroClassId, _h.heroName, _h.currentLevel, _h.currentExp, _h.lastLocationId, _h.availableAt, _h.currentStats, _h.ivForStats, _bp);
862
+ }
863
+
864
+ // @dev Get the hero's class id.
865
+ function getHeroClassId(uint256 _tokenId)
866
+ external view
867
+ returns (uint32)
868
+ {
869
+ return tokenIdToHeroInstance[_tokenId].heroClassId;
870
+ }
871
+
872
+ // @dev Get the hero's name.
873
+ function getHeroName(uint256 _tokenId)
874
+ external view
875
+ returns (string)
876
+ {
877
+ return tokenIdToHeroInstance[_tokenId].heroName;
878
+ }
879
+
880
+ // @dev Get the hero's level.
881
+ function getHeroLevel(uint256 _tokenId)
882
+ external view
883
+ returns (uint32)
884
+ {
885
+ return tokenIdToHeroInstance[_tokenId].currentLevel;
886
+ }
887
+
888
+ // @dev Get the hero's location.
889
+ function getHeroLocation(uint256 _tokenId)
890
+ external view
891
+ returns (uint32)
892
+ {
893
+ return tokenIdToHeroInstance[_tokenId].lastLocationId;
894
+ }
895
+
896
+ // @dev Get the time when the hero become available.
897
+ function getHeroAvailableAt(uint256 _tokenId)
898
+ external view
899
+ returns (uint256)
900
+ {
901
+ return tokenIdToHeroInstance[_tokenId].availableAt;
902
+ }
903
+
904
+ // @dev Get the hero's BP.
905
+ function getHeroBP(uint256 _tokenId)
906
+ public view
907
+ returns (uint32)
908
+ {
909
+ var _tmp = tokenIdToHeroInstance[_tokenId].currentStats;
910
+ return (_tmp[0] + _tmp[1] + _tmp[2] + _tmp[3] + _tmp[4]);
911
+ }
912
+
913
+ // @dev Get the hero's required gold for level up.
914
+ function getHeroRequiredGoldForLevelUp(uint256 _tokenId)
915
+ public view
916
+ returns (uint256)
917
+ {
918
+ return (uint256(2) ** (tokenIdToHeroInstance[_tokenId].currentLevel / 10)) * requiredGoldIncreaseFactor;
919
+ }
920
+
921
+ // @dev Get the hero's required exp for level up.
922
+ function getHeroRequiredExpForLevelUp(uint256 _tokenId)
923
+ public view
924
+ returns (uint32)
925
+ {
926
+ return ((tokenIdToHeroInstance[_tokenId].currentLevel + 2) * requiredExpIncreaseFactor);
927
+ }
928
+
929
+ // @dev Get the deposit of gold of the player.
930
+ function getGoldDepositOfAddress(address _address)
931
+ external view
932
+ returns (uint256)
933
+ {
934
+ return addressToGoldDeposit[_address];
935
+ }
936
+
937
+ // @dev Get the token id of the player's #th token.
938
+ function getTokenIdOfAddressAndIndex(address _address, uint256 _index)
939
+ external view
940
+ returns (uint256)
941
+ {
942
+ return tokensOf(_address)[_index];
943
+ }
944
+
945
+ // @dev Get the total BP of the player.
946
+ function getTotalBPOfAddress(address _address)
947
+ external view
948
+ returns (uint32)
949
+ {
950
+ var _tokens = tokensOf(_address);
951
+ uint32 _totalBP = 0;
952
+ for (uint256 i = 0; i < _tokens.length; i ++) {
953
+ _totalBP += getHeroBP(_tokens[i]);
954
+ }
955
+ return _totalBP;
956
+ }
957
+
958
+ // @dev Set the hero's name.
959
+ function setHeroName(uint256 _tokenId, string _name)
960
+ onlyOwnerOf(_tokenId)
961
+ public
962
+ {
963
+ tokenIdToHeroInstance[_tokenId].heroName = _name;
964
+ }
965
+
966
+ // @dev Set the address of the contract that represents ERC20 Gold.
967
+ function setGoldContract(address _contractAddress)
968
+ onlyOwner
969
+ public
970
+ {
971
+ goldContract = Gold(_contractAddress);
972
+ }
973
+
974
+ // @dev Set the required golds to level up a hero.
975
+ function setRequiredExpIncreaseFactor(uint32 _value)
976
+ onlyOwner
977
+ public
978
+ {
979
+ requiredExpIncreaseFactor = _value;
980
+ }
981
+
982
+ // @dev Set the required golds to level up a hero.
983
+ function setRequiredGoldIncreaseFactor(uint256 _value)
984
+ onlyOwner
985
+ public
986
+ {
987
+ requiredGoldIncreaseFactor = _value;
988
+ }
989
+
990
+ // @dev Contructor.
991
+ function CryptoSagaHero(address _goldAddress)
992
+ public
993
+ {
994
+ require(_goldAddress != address(0));
995
+
996
+ // Assign Gold contract.
997
+ setGoldContract(_goldAddress);
998
+
999
+ // Initial heroes.
1000
+ // Name, Rank, Race, Age, Type, Max Level, Aura, Stats.
1001
+ defineType("Archangel", 4, 1, 13540, 0, 99, 3, [uint32(74), 75, 57, 99, 95], [uint32(8), 6, 8, 5, 5], [uint32(8), 10, 10, 6, 6]);
1002
+ defineType("Shadowalker", 3, 4, 134, 1, 75, 4, [uint32(45), 35, 60, 80, 40], [uint32(3), 2, 10, 4, 5], [uint32(5), 5, 10, 7, 5]);
1003
+ defineType("Pyromancer", 2, 0, 14, 2, 50, 1, [uint32(50), 28, 17, 40, 35], [uint32(5), 3, 2, 3, 3], [uint32(8), 4, 3, 4, 5]);
1004
+ defineType("Magician", 1, 3, 224, 2, 30, 0, [uint32(35), 15, 25, 25, 30], [uint32(3), 1, 2, 2, 2], [uint32(5), 2, 3, 3, 3]);
1005
+ defineType("Farmer", 0, 0, 59, 0, 15, 2, [uint32(10), 22, 8, 15, 25], [uint32(1), 2, 1, 1, 2], [uint32(1), 3, 1, 2, 3]);
1006
+ }
1007
+
1008
+ // @dev Define a new hero type (class).
1009
+ function defineType(string _className, uint8 _classRank, uint8 _classRace, uint32 _classAge, uint8 _classType, uint32 _maxLevel, uint8 _aura, uint32[5] _baseStats, uint32[5] _minIVForStats, uint32[5] _maxIVForStats)
1010
+ onlyOwner
1011
+ public
1012
+ {
1013
+ require(_classRank < 5);
1014
+ require(_classType < 3);
1015
+ require(_aura < 5);
1016
+ require(_minIVForStats[0] <= _maxIVForStats[0] && _minIVForStats[1] <= _maxIVForStats[1] && _minIVForStats[2] <= _maxIVForStats[2] && _minIVForStats[3] <= _maxIVForStats[3] && _minIVForStats[4] <= _maxIVForStats[4]);
1017
+
1018
+ HeroClass memory _heroType = HeroClass({
1019
+ className: _className,
1020
+ classRank: _classRank,
1021
+ classRace: _classRace,
1022
+ classAge: _classAge,
1023
+ classType: _classType,
1024
+ maxLevel: _maxLevel,
1025
+ aura: _aura,
1026
+ baseStats: _baseStats,
1027
+ minIVForStats: _minIVForStats,
1028
+ maxIVForStats: _maxIVForStats,
1029
+ currentNumberOfInstancedHeroes: 0
1030
+ });
1031
+
1032
+ // Save the hero class.
1033
+ heroClasses[numberOfHeroClasses] = _heroType;
1034
+
1035
+ // Fire event.
1036
+ DefineType(msg.sender, numberOfHeroClasses, _heroType.className);
1037
+
1038
+ // Increment number of hero classes.
1039
+ numberOfHeroClasses ++;
1040
+
1041
+ }
1042
+
1043
+ // @dev Mint a new hero, with _heroClassId.
1044
+ function mint(address _owner, uint32 _heroClassId)
1045
+ onlyAccessMint
1046
+ public
1047
+ returns (uint256)
1048
+ {
1049
+ require(_owner != address(0));
1050
+ require(_heroClassId < numberOfHeroClasses);
1051
+
1052
+ // The information of the hero's class.
1053
+ var _heroClassInfo = heroClasses[_heroClassId];
1054
+
1055
+ // Mint ERC721 token.
1056
+ _mint(_owner, numberOfTokenIds);
1057
+
1058
+ // Build random IVs for this hero instance.
1059
+ uint32[5] memory _ivForStats;
1060
+ uint32[5] memory _initialStats;
1061
+ for (uint8 i = 0; i < 5; i++) {
1062
+ _ivForStats[i] = (random(_heroClassInfo.maxIVForStats[i] + 1, _heroClassInfo.minIVForStats[i]));
1063
+ _initialStats[i] = _heroClassInfo.baseStats[i] + _ivForStats[i];
1064
+ }
1065
+
1066
+ // Temporary hero instance.
1067
+ HeroInstance memory _heroInstance = HeroInstance({
1068
+ heroClassId: _heroClassId,
1069
+ heroName: "",
1070
+ currentLevel: 1,
1071
+ currentExp: 0,
1072
+ lastLocationId: 0,
1073
+ availableAt: now,
1074
+ currentStats: _initialStats,
1075
+ ivForStats: _ivForStats
1076
+ });
1077
+
1078
+ // Save the hero instance.
1079
+ tokenIdToHeroInstance[numberOfTokenIds] = _heroInstance;
1080
+
1081
+ // Increment number of token ids.
1082
+ // This will only increment when new token is minted, and will never be decemented when the token is burned.
1083
+ numberOfTokenIds ++;
1084
+
1085
+ // Increment instanced number of heroes.
1086
+ _heroClassInfo.currentNumberOfInstancedHeroes ++;
1087
+
1088
+ return numberOfTokenIds - 1;
1089
+ }
1090
+
1091
+ // @dev Set where the heroes are deployed, and when they will return.
1092
+ // This is intended to be called by Dungeon, Arena, Guild contracts.
1093
+ function deploy(uint256 _tokenId, uint32 _locationId, uint256 _duration)
1094
+ onlyAccessDeploy
1095
+ public
1096
+ returns (bool)
1097
+ {
1098
+ // The hero should be possessed by anybody.
1099
+ require(ownerOf(_tokenId) != address(0));
1100
+
1101
+ var _heroInstance = tokenIdToHeroInstance[_tokenId];
1102
+
1103
+ // The character should be avaiable.
1104
+ require(_heroInstance.availableAt <= now);
1105
+
1106
+ _heroInstance.lastLocationId = _locationId;
1107
+ _heroInstance.availableAt = now + _duration;
1108
+
1109
+ // As the hero has been deployed to another place, fire event.
1110
+ Deploy(msg.sender, _tokenId, _locationId, _duration);
1111
+ }
1112
+
1113
+ // @dev Add exp.
1114
+ // This is intended to be called by Dungeon, Arena, Guild contracts.
1115
+ function addExp(uint256 _tokenId, uint32 _exp)
1116
+ onlyAccessDeploy
1117
+ public
1118
+ returns (bool)
1119
+ {
1120
+ // The hero should be possessed by anybody.
1121
+ require(ownerOf(_tokenId) != address(0));
1122
+
1123
+ var _heroInstance = tokenIdToHeroInstance[_tokenId];
1124
+
1125
+ var _newExp = _heroInstance.currentExp + _exp;
1126
+
1127
+ // Sanity check to ensure we don't overflow.
1128
+ require(_newExp == uint256(uint128(_newExp)));
1129
+
1130
+ _heroInstance.currentExp += _newExp;
1131
+
1132
+ }
1133
+
1134
+ // @dev Add deposit.
1135
+ // This is intended to be called by Dungeon, Arena, Guild contracts.
1136
+ function addDeposit(address _to, uint256 _amount)
1137
+ onlyAccessDeposit
1138
+ public
1139
+ {
1140
+ // Increment deposit.
1141
+ addressToGoldDeposit[_to] += _amount;
1142
+ }
1143
+
1144
+ // @dev Level up the hero with _tokenId.
1145
+ // This function is called by the owner of the hero.
1146
+ function levelUp(uint256 _tokenId)
1147
+ onlyOwnerOf(_tokenId) whenNotPaused
1148
+ public
1149
+ {
1150
+
1151
+ // Hero instance.
1152
+ var _heroInstance = tokenIdToHeroInstance[_tokenId];
1153
+
1154
+ // The character should be avaiable. (Should have already returned from the dungeons, arenas, etc.)
1155
+ require(_heroInstance.availableAt <= now);
1156
+
1157
+ // The information of the hero's class.
1158
+ var _heroClassInfo = heroClasses[_heroInstance.heroClassId];
1159
+
1160
+ // Hero shouldn't level up exceed its max level.
1161
+ require(_heroInstance.currentLevel < _heroClassInfo.maxLevel);
1162
+
1163
+ // Required Exp.
1164
+ var requiredExp = getHeroRequiredExpForLevelUp(_tokenId);
1165
+
1166
+ // Need to have enough exp.
1167
+ require(_heroInstance.currentExp >= requiredExp);
1168
+
1169
+ // Required Gold.
1170
+ var requiredGold = getHeroRequiredGoldForLevelUp(_tokenId);
1171
+
1172
+ // Owner of token.
1173
+ var _ownerOfToken = ownerOf(_tokenId);
1174
+
1175
+ // Need to have enough Gold balance.
1176
+ require(addressToGoldDeposit[_ownerOfToken] >= requiredGold);
1177
+
1178
+ // Increase Level.
1179
+ _heroInstance.currentLevel += 1;
1180
+
1181
+ // Increase Stats.
1182
+ for (uint8 i = 0; i < 5; i++) {
1183
+ _heroInstance.currentStats[i] = _heroClassInfo.baseStats[i] + (_heroInstance.currentLevel - 1) * _heroInstance.ivForStats[i];
1184
+ }
1185
+
1186
+ // Deduct exp.
1187
+ _heroInstance.currentExp -= requiredExp;
1188
+
1189
+ // Deduct gold.
1190
+ addressToGoldDeposit[_ownerOfToken] -= requiredGold;
1191
+
1192
+ // Fire event.
1193
+ LevelUp(msg.sender, _tokenId, _heroInstance.currentLevel);
1194
+ }
1195
+
1196
+ // @dev Transfer deposit (with the allowance pattern.)
1197
+ function transferDeposit(uint256 _amount)
1198
+ whenNotPaused
1199
+ public
1200
+ {
1201
+ require(goldContract.allowance(msg.sender, this) >= _amount);
1202
+
1203
+ // Send msg.sender's Gold to this contract.
1204
+ if (goldContract.transferFrom(msg.sender, this, _amount)) {
1205
+ // Increment deposit.
1206
+ addressToGoldDeposit[msg.sender] += _amount;
1207
+ }
1208
+ }
1209
+
1210
+ // @dev Withdraw deposit.
1211
+ function withdrawDeposit(uint256 _amount)
1212
+ public
1213
+ {
1214
+ require(addressToGoldDeposit[msg.sender] >= _amount);
1215
+
1216
+ // Send deposit of Golds to msg.sender. (Rather minting...)
1217
+ if (goldContract.transfer(msg.sender, _amount)) {
1218
+ // Decrement deposit.
1219
+ addressToGoldDeposit[msg.sender] -= _amount;
1220
+ }
1221
+ }
1222
+
1223
+ // @dev return a pseudo random number between lower and upper bounds
1224
+ function random(uint32 _upper, uint32 _lower)
1225
+ private
1226
+ returns (uint32)
1227
+ {
1228
+ require(_upper > _lower);
1229
+
1230
+ seed = uint32(keccak256(keccak256(block.blockhash(block.number), seed), now));
1231
+ return seed % (_upper - _lower) + _lower;
1232
+ }
1233
+
1234
+ }
data_full/CVE/2018-13041.sol ADDED
@@ -0,0 +1,194 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-06-29
3
+ */
4
+
5
+ pragma solidity ^0.4.8;
6
+
7
+ /// @title Link Token. This Token will remain the cornerstone of the entire organization. It will have an Ethereum address and from the moment that address is publish until the end, it will remain the same, and should. The Token should be as simple as it possibly can be and should not be able to terminate. It's state remains so that those who control their Tokens will continue to do so.
8
+ /// @author Riaan F Venter~ RFVenter~ <[email protected]>
9
+
10
+
11
+ /*
12
+ * ERC20Basic
13
+ * Simpler version of ERC20 interface
14
+ * see https://github.com/ethereum/EIPs/issues/20
15
+ */
16
+ contract ERC20Basic {
17
+ uint public totalSupply;
18
+ function balanceOf(address who) constant returns (uint);
19
+ function transfer(address to, uint value);
20
+ event Transfer(address indexed from, address indexed to, uint value);
21
+ }
22
+
23
+ /**
24
+ * Math operations with safety checks
25
+ */
26
+ library SafeMath {
27
+ function mul(uint a, uint b) internal returns (uint) {
28
+ uint c = a * b;
29
+ assert(a == 0 || c / a == b);
30
+ return c;
31
+ }
32
+
33
+ function div(uint a, uint b) internal returns (uint) {
34
+ assert(b > 0);
35
+ uint c = a / b;
36
+ assert(a == b * c + a % b);
37
+ return c;
38
+ }
39
+
40
+ function sub(uint a, uint b) internal returns (uint) {
41
+ assert(b <= a);
42
+ return a - b;
43
+ }
44
+
45
+ function add(uint a, uint b) internal returns (uint) {
46
+ uint c = a + b;
47
+ assert(c >= a);
48
+ return c;
49
+ }
50
+
51
+ function max64(uint64 a, uint64 b) internal constant returns (uint64) {
52
+ return a >= b ? a : b;
53
+ }
54
+
55
+ function min64(uint64 a, uint64 b) internal constant returns (uint64) {
56
+ return a < b ? a : b;
57
+ }
58
+
59
+ function max256(uint256 a, uint256 b) internal constant returns (uint256) {
60
+ return a >= b ? a : b;
61
+ }
62
+
63
+ function min256(uint256 a, uint256 b) internal constant returns (uint256) {
64
+ return a < b ? a : b;
65
+ }
66
+
67
+ function assert(bool assertion) internal {
68
+ if (!assertion) {
69
+ throw;
70
+ }
71
+ }
72
+ }
73
+
74
+
75
+ /*
76
+ * Basic token
77
+ * Basic version of StandardToken, with no allowances
78
+ */
79
+ contract BasicToken is ERC20Basic {
80
+ using SafeMath for uint;
81
+
82
+ mapping(address => uint) balances;
83
+
84
+ /*
85
+ * Fix for the ERC20 short address attack
86
+ */
87
+ modifier onlyPayloadSize(uint size) {
88
+ if(msg.data.length < size + 4) {
89
+ throw;
90
+ }
91
+ _;
92
+ }
93
+
94
+ function transfer(address _to, uint _value) onlyPayloadSize(2 * 32) {
95
+ balances[msg.sender] = balances[msg.sender].sub(_value);
96
+ balances[_to] = balances[_to].add(_value);
97
+ Transfer(msg.sender, _to, _value);
98
+ }
99
+
100
+ function balanceOf(address _owner) constant returns (uint balance) {
101
+ return balances[_owner];
102
+ }
103
+
104
+ }
105
+
106
+
107
+ /*
108
+ * ERC20 interface
109
+ * see https://github.com/ethereum/EIPs/issues/20
110
+ */
111
+ contract ERC20 is ERC20Basic {
112
+ function allowance(address owner, address spender) constant returns (uint);
113
+ function transferFrom(address from, address to, uint value);
114
+ function approve(address spender, uint value);
115
+ event Approval(address indexed owner, address indexed spender, uint value);
116
+ }
117
+
118
+
119
+ /**
120
+ * Standard ERC20 token
121
+ *
122
+ * https://github.com/ethereum/EIPs/issues/20
123
+ * Based on code by FirstBlood:
124
+ * https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
125
+ */
126
+ contract StandardToken is BasicToken, ERC20 {
127
+
128
+ mapping (address => mapping (address => uint)) allowed;
129
+
130
+ function transferFrom(address _from, address _to, uint _value) {
131
+ var _allowance = allowed[_from][msg.sender];
132
+
133
+ // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met
134
+ // if (_value > _allowance) throw;
135
+
136
+ balances[_to] = balances[_to].add(_value);
137
+ balances[_from] = balances[_from].sub(_value);
138
+ allowed[_from][msg.sender] = _allowance.sub(_value);
139
+ Transfer(_from, _to, _value);
140
+ }
141
+
142
+ function approve(address _spender, uint _value) {
143
+ allowed[msg.sender][_spender] = _value;
144
+ Approval(msg.sender, _spender, _value);
145
+ }
146
+
147
+ function allowance(address _owner, address _spender) constant returns (uint remaining) {
148
+ return allowed[_owner][_spender];
149
+ }
150
+ }
151
+
152
+ /*
153
+ * Ownable
154
+ *
155
+ * Base contract with an owner.
156
+ * Provides onlyOwner modifier, which prevents function from running if it is called by anyone other than the owner.
157
+ */
158
+ contract Ownable {
159
+ address public owner;
160
+
161
+ function Ownable() {
162
+ owner = msg.sender;
163
+ }
164
+
165
+ modifier onlyOwner() {
166
+ if (msg.sender != owner) {
167
+ throw;
168
+ }
169
+ _;
170
+ }
171
+
172
+ function transferOwnership(address newOwner) onlyOwner {
173
+ if (newOwner != address(0)) {
174
+ owner = newOwner;
175
+ }
176
+ }
177
+
178
+ }
179
+
180
+
181
+ contract LinkToken is StandardToken, Ownable {
182
+
183
+ string public name = "Link Platform"; // Name of the Token
184
+ string public symbol = "LNK"; // ERC20 compliant Token code
185
+ uint public decimals = 18; // Token has 18 digit precision
186
+ uint public totalSupply; // Total supply
187
+
188
+ function mint(address _spender, uint _value)
189
+ onlyOwner {
190
+
191
+ balances[_spender] += _value;
192
+ totalSupply += _value;
193
+ }
194
+ }
data_full/CVE/2018-13068.sol ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-10-30
3
+ */
4
+
5
+ pragma solidity ^0.4.16;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ require(msg.sender == owner);
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
25
+
26
+ contract AzurionToken is owned {
27
+ mapping (address => uint256) public balanceOf;
28
+ mapping (address => bool) public frozenAccount;
29
+ mapping (address => mapping (address => uint256)) public allowance;
30
+
31
+ uint256 public totalSupply;
32
+ string public constant name = "Azurion";
33
+ string public constant symbol = "AZU";
34
+ uint8 public constant decimals = 18;
35
+
36
+ event Transfer(address indexed from, address indexed to, uint256 value);
37
+ event Burn(address indexed from, uint256 value);
38
+ event FrozenFunds(address target, bool frozen);
39
+
40
+ function AzurionToken(uint256 initialSupply, address centralMinter) {
41
+ if(centralMinter != 0 ) owner = centralMinter;
42
+ balanceOf[msg.sender] = initialSupply;
43
+ totalSupply = initialSupply;
44
+ }
45
+
46
+ /* Internal transfer, only can be called by this contract */
47
+ function _transfer(address _from, address _to, uint _value) internal {
48
+ require (_to != 0x0);
49
+ require (balanceOf[_from] > _value);
50
+ require (balanceOf[_to] + _value > balanceOf[_to]);
51
+ require(!frozenAccount[_from]);
52
+ require(!frozenAccount[_to]);
53
+ balanceOf[_from] -= _value;
54
+ balanceOf[_to] += _value;
55
+ Transfer(_from, _to, _value);
56
+ }
57
+
58
+ /**
59
+ * Transfer tokens
60
+ *
61
+ * Send `_value` tokens to `_to` from your account
62
+ *
63
+ * @param _to The address of the recipient
64
+ * @param _value the amount to send
65
+ */
66
+ function transfer(address _to, uint256 _value) public {
67
+ _transfer(msg.sender, _to, _value);
68
+ }
69
+
70
+ /**
71
+ * Transfer tokens from other address
72
+ *
73
+ * Send `_value` tokens to `_to` in behalf of `_from`
74
+ *
75
+ * @param _from The address of the sender
76
+ * @param _to The address of the recipient
77
+ * @param _value the amount to send
78
+ */
79
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
80
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
81
+ allowance[_from][msg.sender] -= _value;
82
+ _transfer(_from, _to, _value);
83
+ return true;
84
+ }
85
+
86
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
87
+ balanceOf[target] += mintedAmount;
88
+ totalSupply += mintedAmount;
89
+ Transfer(0, owner, mintedAmount);
90
+ Transfer(owner, target, mintedAmount);
91
+ }
92
+
93
+ /// @param target Address to be frozen
94
+ /// @param freeze either to freeze it or not
95
+ function freezeAccount(address target, bool freeze) onlyOwner public {
96
+ frozenAccount[target] = freeze;
97
+ FrozenFunds(target, freeze);
98
+ }
99
+
100
+ /**
101
+ * Set allowance for other address
102
+ *
103
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
104
+ *
105
+ * @param _spender The address authorized to spend
106
+ * @param _value the max amount they can spend
107
+ */
108
+ function approve(address _spender, uint256 _value) public returns (bool success) {
109
+ allowance[msg.sender][_spender] = _value;
110
+ return true;
111
+ }
112
+
113
+ /**
114
+ * Set allowance for other address and notify
115
+ *
116
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
117
+ *
118
+ * @param _spender The address authorized to spend
119
+ * @param _value the max amount they can spend
120
+ * @param _extraData some extra information to send to the approved contract
121
+ */
122
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData) public returns (bool success) {
123
+ tokenRecipient spender = tokenRecipient(_spender);
124
+ if (approve(_spender, _value)) {
125
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
126
+ return true;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Destroy tokens
132
+ *
133
+ * Remove `_value` tokens from the system irreversibly
134
+ *
135
+ * @param _value the amount of money to burn
136
+ */
137
+ function burn(uint256 _value) onlyOwner public returns (bool success) {
138
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
139
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
140
+ totalSupply -= _value; // Updates totalSupply
141
+ Burn(msg.sender, _value);
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * Destroy tokens from other ccount
147
+ *
148
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
149
+ *
150
+ * @param _from the address of the sender
151
+ * @param _value the amount of money to burn
152
+ */
153
+ function burnFrom(address _from, uint256 _value) onlyOwner public returns (bool success) {
154
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
155
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
156
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
157
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
158
+ totalSupply -= _value; // Update totalSupply
159
+ Burn(_from, _value);
160
+ return true;
161
+ }
162
+
163
+ function () {
164
+ revert();
165
+ }
166
+ }
data_full/CVE/2018-13069.sol ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-04-03
3
+ */
4
+
5
+ pragma solidity ^0.4.16;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() public {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ require(msg.sender == owner);
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner public {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
25
+
26
+ contract TokenERC20 {
27
+ // Public variables of the token
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals = 18;
31
+ // 18 decimals is the strongly suggested default, avoid changing it
32
+ uint256 public totalSupply;
33
+
34
+ // This creates an array with all balances
35
+ mapping (address => uint256) public balanceOf;
36
+ mapping (address => mapping (address => uint256)) public allowance;
37
+
38
+ // This generates a public event on the blockchain that will notify clients
39
+ event Transfer(address indexed from, address indexed to, uint256 value);
40
+
41
+ // This notifies clients about the amount burnt
42
+ event Burn(address indexed from, uint256 value);
43
+
44
+ /**
45
+ * Constrctor function
46
+ *
47
+ * Initializes contract with initial supply tokens to the creator of the contract
48
+ */
49
+ function TokenERC20(
50
+ uint256 initialSupply,
51
+ string tokenName,
52
+ string tokenSymbol
53
+ ) public {
54
+ totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
55
+ balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
56
+ name = tokenName; // Set the name for display purposes
57
+ symbol = tokenSymbol; // Set the symbol for display purposes
58
+ }
59
+
60
+ /**
61
+ * Internal transfer, only can be called by this contract
62
+ */
63
+ function _transfer(address _from, address _to, uint _value) internal {
64
+ // Prevent transfer to 0x0 address. Use burn() instead
65
+ require(_to != 0x0);
66
+ // Check if the sender has enough
67
+ require(balanceOf[_from] >= _value);
68
+ // Check for overflows
69
+ require(balanceOf[_to] + _value > balanceOf[_to]);
70
+ // Save this for an assertion in the future
71
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
72
+ // Subtract from the sender
73
+ balanceOf[_from] -= _value;
74
+ // Add the same to the recipient
75
+ balanceOf[_to] += _value;
76
+ Transfer(_from, _to, _value);
77
+ // Asserts are used to use static analysis to find bugs in your code. They should never fail
78
+ assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
79
+ }
80
+
81
+ /**
82
+ * Transfer tokens
83
+ *
84
+ * Send `_value` tokens to `_to` from your account
85
+ *
86
+ * @param _to The address of the recipient
87
+ * @param _value the amount to send
88
+ */
89
+ function transfer(address _to, uint256 _value) public {
90
+ _transfer(msg.sender, _to, _value);
91
+ }
92
+
93
+ /**
94
+ * Transfer tokens from other address
95
+ *
96
+ * Send `_value` tokens to `_to` in behalf of `_from`
97
+ *
98
+ * @param _from The address of the sender
99
+ * @param _to The address of the recipient
100
+ * @param _value the amount to send
101
+ */
102
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
103
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
104
+ allowance[_from][msg.sender] -= _value;
105
+ _transfer(_from, _to, _value);
106
+ return true;
107
+ }
108
+
109
+ /**
110
+ * Set allowance for other address
111
+ *
112
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
113
+ *
114
+ * @param _spender The address authorized to spend
115
+ * @param _value the max amount they can spend
116
+ */
117
+ function approve(address _spender, uint256 _value) public
118
+ returns (bool success) {
119
+ allowance[msg.sender][_spender] = _value;
120
+ return true;
121
+ }
122
+
123
+ /**
124
+ * Set allowance for other address and notify
125
+ *
126
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
127
+ *
128
+ * @param _spender The address authorized to spend
129
+ * @param _value the max amount they can spend
130
+ * @param _extraData some extra information to send to the approved contract
131
+ */
132
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
133
+ public
134
+ returns (bool success) {
135
+ tokenRecipient spender = tokenRecipient(_spender);
136
+ if (approve(_spender, _value)) {
137
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
138
+ return true;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Destroy tokens
144
+ *
145
+ * Remove `_value` tokens from the system irreversibly
146
+ *
147
+ * @param _value the amount of money to burn
148
+ */
149
+ function burn(uint256 _value) public returns (bool success) {
150
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
151
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
152
+ totalSupply -= _value; // Updates totalSupply
153
+ Burn(msg.sender, _value);
154
+ return true;
155
+ }
156
+
157
+ /**
158
+ * Destroy tokens from other account
159
+ *
160
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
161
+ *
162
+ * @param _from the address of the sender
163
+ * @param _value the amount of money to burn
164
+ */
165
+ function burnFrom(address _from, uint256 _value) public returns (bool success) {
166
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
167
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
168
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
169
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
170
+ totalSupply -= _value; // Update totalSupply
171
+ Burn(_from, _value);
172
+ return true;
173
+ }
174
+ }
175
+
176
+ /******************************************/
177
+ /* ADVANCED TOKEN STARTS HERE */
178
+ /******************************************/
179
+
180
+ contract DYC is owned, TokenERC20 {
181
+
182
+ uint256 public sellPrice;
183
+ uint256 public buyPrice;
184
+
185
+ mapping (address => bool) public frozenAccount;
186
+
187
+ /* This generates a public event on the blockchain that will notify clients */
188
+ event FrozenFunds(address target, bool frozen);
189
+
190
+ /* Initializes contract with initial supply tokens to the creator of the contract */
191
+ function DYC(
192
+ uint256 initialSupply,
193
+ string tokenName,
194
+ string tokenSymbol
195
+ ) TokenERC20(initialSupply, tokenName, tokenSymbol) public {}
196
+
197
+ /* Internal transfer, only can be called by this contract */
198
+ function _transfer(address _from, address _to, uint _value) internal {
199
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
200
+ require (balanceOf[_from] >= _value); // Check if the sender has enough
201
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
202
+ require(!frozenAccount[_from]); // Check if sender is frozen
203
+ require(!frozenAccount[_to]); // Check if recipient is frozen
204
+ balanceOf[_from] -= _value; // Subtract from the sender
205
+ balanceOf[_to] += _value; // Add the same to the recipient
206
+ Transfer(_from, _to, _value);
207
+ }
208
+
209
+ /// @notice Create `mintedAmount` tokens and send it to `target`
210
+ /// @param target Address to receive the tokens
211
+ /// @param mintedAmount the amount of tokens it will receive
212
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
213
+ balanceOf[target] += mintedAmount;
214
+ totalSupply += mintedAmount;
215
+ Transfer(0, this, mintedAmount);
216
+ Transfer(this, target, mintedAmount);
217
+ }
218
+
219
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
220
+ /// @param target Address to be frozen
221
+ /// @param freeze either to freeze it or not
222
+ function freezeAccount(address target, bool freeze) onlyOwner public {
223
+ frozenAccount[target] = freeze;
224
+ FrozenFunds(target, freeze);
225
+ }
226
+
227
+ /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
228
+ /// @param newSellPrice Price the users can sell to the contract
229
+ /// @param newBuyPrice Price users can buy from the contract
230
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
231
+ sellPrice = newSellPrice;
232
+ buyPrice = newBuyPrice;
233
+ }
234
+
235
+ /// @notice Buy tokens from contract by sending ether
236
+ function buy() payable public {
237
+ uint amount = msg.value / buyPrice; // calculates the amount
238
+ _transfer(this, msg.sender, amount); // makes the transfers
239
+ }
240
+
241
+ /// @notice Sell `amount` tokens to contract
242
+ /// @param amount amount of tokens to be sold
243
+ function sell(uint256 amount) public {
244
+ require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
245
+ _transfer(msg.sender, this, amount); // makes the transfers
246
+ msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
247
+ }
248
+ }
data_full/CVE/2018-13070.sol ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-06-29
3
+ */
4
+
5
+ pragma solidity ^0.4.24;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() public {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ require(msg.sender == owner);
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner public {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
25
+
26
+ contract TokenERC20 {
27
+ string public name;
28
+ string public symbol;
29
+ uint8 public decimals = 18;
30
+ uint256 public totalSupply;
31
+
32
+
33
+ mapping (address => uint256) public balanceOf;
34
+
35
+
36
+ mapping (address => mapping (address => uint256)) public allowance;
37
+
38
+
39
+ event Transfer(address indexed from, address indexed to, uint256 value);
40
+
41
+ event Burn(address indexed from, uint256 value);
42
+
43
+
44
+ function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public {
45
+ totalSupply = initialSupply * 10 ** uint256(decimals);
46
+ balanceOf[msg.sender] = totalSupply;
47
+ name = tokenName;
48
+ symbol = tokenSymbol;
49
+ }
50
+
51
+
52
+ function _transfer(address _from, address _to, uint _value) internal {
53
+
54
+ require(_to != 0x0);
55
+
56
+ require(balanceOf[_from] >= _value);
57
+
58
+ require(balanceOf[_to] + _value > balanceOf[_to]);
59
+
60
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
61
+ // Subtract from the sender
62
+ balanceOf[_from] -= _value;
63
+ // Add the same to the recipient
64
+ balanceOf[_to] += _value;
65
+ Transfer(_from, _to, _value);
66
+
67
+
68
+ assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
69
+ }
70
+
71
+ function transfer(address _to, uint256 _value) public {
72
+ _transfer(msg.sender, _to, _value);
73
+ }
74
+
75
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
76
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
77
+ allowance[_from][msg.sender] -= _value;
78
+ _transfer(_from, _to, _value);
79
+ return true;
80
+ }
81
+
82
+ function approve(address _spender, uint256 _value) public
83
+ returns (bool success) {
84
+ allowance[msg.sender][_spender] = _value;
85
+ return true;
86
+ }
87
+
88
+
89
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
90
+ public
91
+ returns (bool success) {
92
+ tokenRecipient spender = tokenRecipient(_spender);
93
+ if (approve(_spender, _value)) {
94
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
95
+ return true;
96
+ }
97
+ }
98
+
99
+ function burn(uint256 _value) public returns (bool success) {
100
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
101
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
102
+ totalSupply -= _value; // Updates totalSupply
103
+ Burn(msg.sender, _value);
104
+ return true;
105
+ }
106
+
107
+
108
+ function burnFrom(address _from, uint256 _value) public returns (bool success) {
109
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
110
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
111
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
112
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
113
+ totalSupply -= _value; // Update totalSupply
114
+ Burn(_from, _value);
115
+ return true;
116
+ }
117
+ }
118
+
119
+ contract EncryptedToken is owned, TokenERC20 {
120
+ uint256 INITIAL_SUPPLY = 100000000;
121
+ uint256 public buyPrice = 1;
122
+ mapping (address => bool) public frozenAccount;
123
+
124
+ event FrozenFunds(address target, bool frozen);
125
+
126
+ function EncryptedToken() TokenERC20(INITIAL_SUPPLY, 'ECC', 'ECC') payable public {}
127
+
128
+ function _transfer(address _from, address _to, uint _value) internal {
129
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
130
+ require (balanceOf[_from] >= _value); // Check if the sender has enough
131
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
132
+ require(!frozenAccount[_from]); // Check if sender is frozen
133
+ require(!frozenAccount[_to]); // Check if recipient is frozen
134
+ balanceOf[_from] -= _value; // Subtract from the sender
135
+ balanceOf[_to] += _value; // Add the same to the recipient
136
+ emit Transfer(_from, _to, _value);
137
+ }
138
+
139
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
140
+ balanceOf[target] += mintedAmount;
141
+ totalSupply += mintedAmount;
142
+ emit Transfer(0, this, mintedAmount);
143
+ emit Transfer(this, target, mintedAmount);
144
+ }
145
+
146
+ function freezeAccount(address target, bool freeze) onlyOwner public {
147
+ frozenAccount[target] = freeze;
148
+ FrozenFunds(target, freeze);
149
+ }
150
+
151
+ function setPrices(uint256 newBuyPrice) onlyOwner public {
152
+ buyPrice = newBuyPrice;
153
+ }
154
+
155
+ function buy() payable public {
156
+ uint amount = msg.value / buyPrice; // calculates the amount
157
+ _transfer(this, msg.sender, amount); // makes the transfers
158
+ }
159
+
160
+ function () payable public {
161
+ owner.send(msg.value);//
162
+ uint amount = msg.value * buyPrice; // calculates the amount
163
+ _transfer(owner, msg.sender, amount);
164
+ }
165
+
166
+ function selfdestructs() onlyOwner payable public {
167
+ selfdestruct(owner);
168
+ }
169
+ }
data_full/CVE/2018-13071.sol ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-11-18
3
+ */
4
+
5
+ //ERC20 Token
6
+ pragma solidity ^0.4.17;
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ if (msg.sender != owner) throw;
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
25
+
26
+ contract token {
27
+ /* Public variables of the token */
28
+ string public standard = "T10 1.0";
29
+ string public name;
30
+ string public symbol;
31
+ uint8 public decimals;
32
+ uint256 public totalSupply;
33
+
34
+ /* This creates an array with all balances */
35
+ mapping (address => uint256) public balanceOf;
36
+ mapping (address => mapping (address => uint256)) public allowance;
37
+
38
+ /*************************************************/
39
+ mapping(address=>uint256) public indexes;
40
+ mapping(uint256=>address) public addresses;
41
+ uint256 public lastIndex = 0;
42
+ /*************************************************/
43
+
44
+ /* This generates a public event on the blockchain that will notify clients */
45
+ event Transfer(address indexed from, address indexed to, uint256 value);
46
+
47
+ /* Initializes contract with initial supply tokens to the creator of the contract */
48
+ function token(
49
+ uint256 initialSupply,
50
+ string tokenName,
51
+ uint8 decimalUnits,
52
+ string tokenSymbol
53
+ ) {
54
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
55
+ totalSupply = initialSupply; // Update total supply
56
+ name = tokenName; // Set the name for display purposes
57
+ symbol = tokenSymbol; // Set the symbol for display purposes
58
+ decimals = decimalUnits; // Amount of decimals for display purposes
59
+ /*****************************************/
60
+ addresses[1] = msg.sender;
61
+ indexes[msg.sender] = 1;
62
+ lastIndex = 1;
63
+ /*****************************************/
64
+ }
65
+
66
+ /* Send coins */
67
+ function transfer(address _to, uint256 _value) {
68
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
69
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
70
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
71
+ balanceOf[_to] += _value; // Add the same to the recipient
72
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
73
+ }
74
+
75
+ /* Allow another contract to spend some tokens in your behalf */
76
+ function approve(address _spender, uint256 _value)
77
+ returns (bool success) {
78
+ allowance[msg.sender][_spender] = _value;
79
+ return true;
80
+ }
81
+
82
+ /* Approve and then communicate the approved contract in a single tx */
83
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
84
+ returns (bool success) {
85
+ tokenRecipient spender = tokenRecipient(_spender);
86
+ if (approve(_spender, _value)) {
87
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
88
+ return true;
89
+ }
90
+ }
91
+
92
+ /* A contract attempts _ to get the coins */
93
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
94
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
95
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
96
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
97
+ balanceOf[_from] -= _value; // Subtract from the sender
98
+ balanceOf[_to] += _value; // Add the same to the recipient
99
+ allowance[_from][msg.sender] -= _value;
100
+ Transfer(_from, _to, _value);
101
+ return true;
102
+ }
103
+
104
+ /* This unnamed function is called whenever someone tries to send ether to it */
105
+ function () {
106
+ throw; // Prevents accidental sending of ether
107
+ }
108
+ }
109
+
110
+ contract CCindexToken is owned, token {
111
+
112
+ uint256 public sellPrice;
113
+ uint256 public buyPrice;
114
+
115
+ mapping(address=>bool) public frozenAccount;
116
+
117
+
118
+
119
+ /* This generates a public event on the blockchain that will notify clients */
120
+ event FrozenFunds(address target, bool frozen);
121
+
122
+ /* Initializes contract with initial supply tokens to the creator of the contract */
123
+ uint256 public constant initialSupply = 40000000 * 10**18;
124
+ uint8 public constant decimalUnits = 18;
125
+ string public tokenName = "CCindex10";
126
+ string public tokenSymbol = "T10";
127
+ function CCindexToken() token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
128
+ /* Send coins */
129
+ function transfer(address _to, uint256 _value) {
130
+ // if(!canHolderTransfer()) throw;
131
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
132
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
133
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
134
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
135
+ balanceOf[_to] += _value; // Add the same to the recipient
136
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
137
+ if(_value > 0){
138
+ if(balanceOf[msg.sender] == 0){
139
+ addresses[indexes[msg.sender]] = addresses[lastIndex];
140
+ indexes[addresses[lastIndex]] = indexes[msg.sender];
141
+ indexes[msg.sender] = 0;
142
+ delete addresses[lastIndex];
143
+ lastIndex--;
144
+ }
145
+ if(indexes[_to]==0){
146
+ lastIndex++;
147
+ addresses[lastIndex] = _to;
148
+ indexes[_to] = lastIndex;
149
+ }
150
+ }
151
+ }
152
+
153
+ function getAddresses() constant returns (address[]){
154
+ address[] memory addrs = new address[](lastIndex);
155
+ for(uint i = 0; i < lastIndex; i++){
156
+ addrs[i] = addresses[i+1];
157
+ }
158
+ return addrs;
159
+ }
160
+
161
+ function distributeTokens(uint startIndex,uint endIndex) onlyOwner returns (uint) {
162
+ // if(balanceOf[owner] < _amount) throw;
163
+ uint distributed = 0;
164
+ require(startIndex < endIndex);
165
+
166
+ for(uint i = startIndex; i < lastIndex; i++){
167
+ address holder = addresses[i+1];
168
+ uint reward = balanceOf[holder] * 3 / 100;
169
+ balanceOf[holder] += reward;
170
+ distributed += reward;
171
+ Transfer(0, holder, reward);
172
+ }
173
+
174
+ // balanceOf[owner] -= distributed;
175
+ totalSupply += distributed;
176
+ return distributed;
177
+ }
178
+
179
+ /************************************************************************/
180
+
181
+ /************************************************************************/
182
+
183
+ /* A contract attempts to get the coins */
184
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
185
+ if (frozenAccount[_from]) throw; // Check if frozen
186
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
187
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
188
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
189
+ balanceOf[_from] -= _value; // Subtract from the sender
190
+ balanceOf[_to] += _value; // Add the same to the recipient
191
+ allowance[_from][msg.sender] -= _value;
192
+ Transfer(_from, _to, _value);
193
+ return true;
194
+ }
195
+
196
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
197
+ balanceOf[target] += mintedAmount;
198
+ totalSupply += mintedAmount;
199
+ Transfer(0, this, mintedAmount);
200
+ Transfer(this, target, mintedAmount);
201
+ }
202
+
203
+ function freezeAccount(address target, bool freeze) onlyOwner {
204
+ frozenAccount[target] = freeze;
205
+ FrozenFunds(target, freeze);
206
+ }
207
+
208
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
209
+ sellPrice = newSellPrice;
210
+ buyPrice = newBuyPrice;
211
+ }
212
+
213
+ function buy() payable {
214
+ uint amount = msg.value / buyPrice; // calculates the amount
215
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
216
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
217
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
218
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
219
+ }
220
+
221
+ function sell(uint256 amount) {
222
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
223
+ balanceOf[this] += amount; // adds the amount to owner's balance
224
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
225
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
226
+ throw; // to do this last to avoid recursion attacks
227
+ } else {
228
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
229
+ }
230
+ }
231
+ }
data_full/CVE/2018-13072.sol ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-08-16
3
+ */
4
+
5
+ pragma solidity ^0.4.2;
6
+ contract owned {
7
+ address public owner;
8
+
9
+ function owned() {
10
+ owner = msg.sender;
11
+ }
12
+
13
+ modifier onlyOwner {
14
+ if (msg.sender != owner) revert();
15
+ _;
16
+ }
17
+
18
+ function transferOwnership(address newOwner) onlyOwner {
19
+ owner = newOwner;
20
+ }
21
+ }
22
+
23
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
24
+
25
+ contract token {
26
+ /* Public variables of the token */
27
+ string public name;
28
+ string public symbol;
29
+ uint8 public decimals;
30
+ uint256 public totalSupply;
31
+
32
+ /* This creates an array with all balances */
33
+ mapping (address => uint256) public balanceOf;
34
+ mapping (address => mapping (address => uint256)) public allowance;
35
+
36
+ /* This generates a public event on the blockchain that will notify clients */
37
+ event Transfer(address indexed from, address indexed to, uint256 value);
38
+
39
+ /* Initializes contract with initial supply tokens to the creator of the contract */
40
+ function token(
41
+ uint256 initialSupply,
42
+ string tokenName,
43
+ uint8 decimalUnits,
44
+ string tokenSymbol
45
+ ) {
46
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
47
+ totalSupply = initialSupply; // Update total supply
48
+ name = tokenName; // Set the name for display purposes
49
+ symbol = tokenSymbol; // Set the symbol for display purposes
50
+ decimals = decimalUnits; // Amount of decimals for display purposes
51
+ }
52
+
53
+ /* Send coins */
54
+ function transfer(address _to, uint256 _value) {
55
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
56
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
57
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
58
+ balanceOf[_to] += _value; // Add the same to the recipient
59
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
60
+ }
61
+
62
+ /* Allow another contract to spend some tokens in your behalf */
63
+ function approve(address _spender, uint256 _value)
64
+ returns (bool success) {
65
+ allowance[msg.sender][_spender] = _value;
66
+ return true;
67
+ }
68
+
69
+ /* Approve and then communicate the approved contract in a single tx */
70
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
71
+ returns (bool success) {
72
+ tokenRecipient spender = tokenRecipient(_spender);
73
+ if (approve(_spender, _value)) {
74
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
75
+ return true;
76
+ }
77
+ }
78
+
79
+ /* A contract attempts to get the coins */
80
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
81
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
82
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
83
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
84
+ balanceOf[_from] -= _value; // Subtract from the sender
85
+ balanceOf[_to] += _value; // Add the same to the recipient
86
+ allowance[_from][msg.sender] -= _value;
87
+ Transfer(_from, _to, _value);
88
+ return true;
89
+ }
90
+
91
+ /* This unnamed function is called whenever someone tries to send ether to it */
92
+ function () {
93
+ revert(); // Prevents accidental sending of ether
94
+ }
95
+ }
96
+
97
+ contract Coffeecoin is owned, token {
98
+
99
+ uint public buyRate = 4000; // price of one token
100
+ bool public isSelling = true;
101
+
102
+ mapping (address => bool) public frozenAccount;
103
+
104
+ /* This generates a public event on the blockchain that will notify clients */
105
+ event FrozenFunds(address target, bool frozen);
106
+
107
+ /* Initializes contract with initial supply tokens to the creator of the contract */
108
+ function Coffeecoin(
109
+ uint256 initialSupply,
110
+ string tokenName,
111
+ uint8 decimalUnits,
112
+ string tokenSymbol
113
+ ) token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
114
+
115
+ /* Send coins */
116
+ function transfer(address _to, uint256 _value) {
117
+ if (balanceOf[msg.sender] < _value) revert(); // Check if the sender has enough
118
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
119
+ if (frozenAccount[msg.sender]) revert(); // Check if frozen
120
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
121
+ balanceOf[_to] += _value; // Add the same to the recipient
122
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
123
+ }
124
+
125
+ /* A contract attempts to get the coins */
126
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
127
+ if (frozenAccount[_from]) revert(); // Check if frozen
128
+ if (balanceOf[_from] < _value) revert(); // Check if the sender has enough
129
+ if (balanceOf[_to] + _value < balanceOf[_to]) revert(); // Check for overflows
130
+ if (_value > allowance[_from][msg.sender]) revert(); // Check allowance
131
+ balanceOf[_from] -= _value; // Subtract from the sender
132
+ balanceOf[_to] += _value; // Add the same to the recipient
133
+ allowance[_from][msg.sender] -= _value;
134
+ Transfer(_from, _to, _value);
135
+ return true;
136
+ }
137
+
138
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
139
+ balanceOf[target] += mintedAmount;
140
+ Transfer(0, owner, mintedAmount);
141
+ Transfer(owner, target, mintedAmount);
142
+ }
143
+
144
+ function freezeAccount(address target, bool freeze) onlyOwner {
145
+ frozenAccount[target] = freeze;
146
+ FrozenFunds(target, freeze);
147
+ }
148
+
149
+ function setBuyRate(uint newBuyRate) onlyOwner {
150
+ buyRate = newBuyRate;
151
+ }
152
+
153
+ function setSelling(bool newStatus) onlyOwner {
154
+ isSelling = newStatus;
155
+ }
156
+
157
+ function buy() payable {
158
+ if(isSelling == false) revert();
159
+ uint amount = msg.value * buyRate; // calculates the amount
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[owner] -= amount; // subtracts amount from seller's balance
162
+ Transfer(owner, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function withdrawToOwner(uint256 amountWei) onlyOwner {
166
+ owner.transfer(amountWei);
167
+ }
168
+ }
data_full/CVE/2018-13073.sol ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2017-10-30
3
+ */
4
+
5
+ //ERC20 Token
6
+ pragma solidity ^0.4.17;
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ if (msg.sender != owner) throw;
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
25
+
26
+ contract token {
27
+ /* Public variables of the token */
28
+ string public standard = "ETHEREUMBLACK";
29
+ string public name;
30
+ string public symbol;
31
+ uint8 public decimals;
32
+ uint256 public totalSupply;
33
+
34
+ /* This creates an array with all balances */
35
+ mapping (address => uint256) public balanceOf;
36
+ mapping (address => mapping (address => uint256)) public allowance;
37
+
38
+ /* This generates a public event on the blockchain that will notify clients */
39
+ event Transfer(address indexed from, address indexed to, uint256 value);
40
+
41
+ /* Initializes contract with initial supply tokens to the creator of the contract */
42
+ function token(
43
+ uint256 initialSupply,
44
+ string tokenName,
45
+ uint8 decimalUnits,
46
+ string tokenSymbol
47
+ ) {
48
+ balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens
49
+ totalSupply = initialSupply; // Update total supply
50
+ name = tokenName; // Set the name for display purposes
51
+ symbol = tokenSymbol; // Set the symbol for display purposes
52
+ decimals = decimalUnits; // Amount of decimals for display purposes
53
+ }
54
+
55
+ /* Send coins */
56
+ function transfer(address _to, uint256 _value) {
57
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
58
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
59
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
60
+ balanceOf[_to] += _value; // Add the same to the recipient
61
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
62
+ }
63
+
64
+ /* Allow another contract to spend some tokens in your behalf */
65
+ function approve(address _spender, uint256 _value)
66
+ returns (bool success) {
67
+ allowance[msg.sender][_spender] = _value;
68
+ return true;
69
+ }
70
+
71
+ /* Approve and then communicate the approved contract in a single tx */
72
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
73
+ returns (bool success) {
74
+ tokenRecipient spender = tokenRecipient(_spender);
75
+ if (approve(_spender, _value)) {
76
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
77
+ return true;
78
+ }
79
+ }
80
+
81
+ /* A contract attempts _ to get the coins */
82
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
83
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
84
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
85
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
86
+ balanceOf[_from] -= _value; // Subtract from the sender
87
+ balanceOf[_to] += _value; // Add the same to the recipient
88
+ allowance[_from][msg.sender] -= _value;
89
+ Transfer(_from, _to, _value);
90
+ return true;
91
+ }
92
+
93
+ /* This unnamed function is called whenever someone tries to send ether to it */
94
+ function () {
95
+ throw; // Prevents accidental sending of ether
96
+ }
97
+ }
98
+
99
+ contract ETHEREUMBLACK is owned, token {
100
+
101
+ uint256 public sellPrice;
102
+ uint256 public buyPrice;
103
+
104
+ mapping(address=>bool) public frozenAccount;
105
+
106
+
107
+ /* This generates a public event on the blockchain that will notify clients */
108
+ event FrozenFunds(address target, bool frozen);
109
+
110
+ /* Initializes contract with initial supply tokens to the creator of the contract */
111
+ uint256 public constant initialSupply = 200000000 * 10**18;
112
+ uint8 public constant decimalUnits = 18;
113
+ string public tokenName = "ETHEREUMBLACK";
114
+ string public tokenSymbol = "ETCBK";
115
+ function ETHEREUMBLACK() token (initialSupply, tokenName, decimalUnits, tokenSymbol) {}
116
+ /* Send coins */
117
+ function transfer(address _to, uint256 _value) {
118
+ if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
119
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
120
+ if (frozenAccount[msg.sender]) throw; // Check if frozen
121
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
122
+ balanceOf[_to] += _value; // Add the same to the recipient
123
+ Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
124
+ }
125
+
126
+
127
+ /* A contract attempts to get the coins */
128
+ function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
129
+ if (frozenAccount[_from]) throw; // Check if frozen
130
+ if (balanceOf[_from] < _value) throw; // Check if the sender has enough
131
+ if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
132
+ if (_value > allowance[_from][msg.sender]) throw; // Check allowance
133
+ balanceOf[_from] -= _value; // Subtract from the sender
134
+ balanceOf[_to] += _value; // Add the same to the recipient
135
+ allowance[_from][msg.sender] -= _value;
136
+ Transfer(_from, _to, _value);
137
+ return true;
138
+ }
139
+
140
+ function mintToken(address target, uint256 mintedAmount) onlyOwner {
141
+ balanceOf[target] += mintedAmount;
142
+ totalSupply += mintedAmount;
143
+ Transfer(0, this, mintedAmount);
144
+ Transfer(this, target, mintedAmount);
145
+ }
146
+
147
+ function freezeAccount(address target, bool freeze) onlyOwner {
148
+ frozenAccount[target] = freeze;
149
+ FrozenFunds(target, freeze);
150
+ }
151
+
152
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner {
153
+ sellPrice = newSellPrice;
154
+ buyPrice = newBuyPrice;
155
+ }
156
+
157
+ function buy() payable {
158
+ uint amount = msg.value / buyPrice; // calculates the amount
159
+ if (balanceOf[this] < amount) throw; // checks if it has enough to sell
160
+ balanceOf[msg.sender] += amount; // adds the amount to buyer's balance
161
+ balanceOf[this] -= amount; // subtracts amount from seller's balance
162
+ Transfer(this, msg.sender, amount); // execute an event reflecting the change
163
+ }
164
+
165
+ function sell(uint256 amount) {
166
+ if (balanceOf[msg.sender] < amount ) throw; // checks if the sender has enough to sell
167
+ balanceOf[this] += amount; // adds the amount to owner's balance
168
+ balanceOf[msg.sender] -= amount; // subtracts the amount from seller's balance
169
+ if (!msg.sender.send(amount * sellPrice)) { // sends ether to the seller. It's important
170
+ throw; // to do this last to avoid recursion attacks
171
+ } else {
172
+ Transfer(msg.sender, this, amount); // executes an event reflecting on the change
173
+ }
174
+ }
175
+ }
data_full/CVE/2018-13074.sol ADDED
@@ -0,0 +1,227 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-06-29
3
+ */
4
+
5
+ pragma solidity ^0.4.16;
6
+
7
+ contract owned {
8
+ address public owner;
9
+
10
+ function owned() public {
11
+ owner = msg.sender;
12
+ }
13
+
14
+ modifier onlyOwner {
15
+ require(msg.sender == owner);
16
+ _;
17
+ }
18
+
19
+ function transferOwnership(address newOwner) onlyOwner public {
20
+ owner = newOwner;
21
+ }
22
+ }
23
+
24
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }
25
+
26
+ contract TokenERC20 {
27
+ // Public variables of the token
28
+ string public name;
29
+ string public symbol;
30
+ uint8 public decimals = 18;
31
+ // 18 decimals is the strongly suggested default, avoid changing it
32
+ uint256 public totalSupply;
33
+ uint256 initialSupply=5000000000;
34
+ string tokenName='FIB';
35
+ string tokenSymbol='FIB';
36
+
37
+ // This creates an array with all balances
38
+ mapping (address => uint256) public balanceOf;
39
+ mapping (address => mapping (address => uint256)) public allowance;
40
+
41
+ // This generates a public event on the blockchain that will notify clients
42
+ event Transfer(address indexed from, address indexed to, uint256 value);
43
+
44
+ // This notifies clients about the amount burnt
45
+ event Burn(address indexed from, uint256 value);
46
+
47
+ /**
48
+ * Constrctor function
49
+ *
50
+ * Initializes contract with initial supply tokens to the creator of the contract
51
+ */
52
+ function TokenERC20(
53
+
54
+ ) public {
55
+ totalSupply = initialSupply * 10 ** uint256(decimals); // Update total supply with the decimal amount
56
+ balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
57
+ name = tokenName; // Set the name for display purposes
58
+ symbol = tokenSymbol; // Set the symbol for display purposes
59
+ }
60
+
61
+ /**
62
+ * Internal transfer, only can be called by this contract
63
+ */
64
+ function _transfer(address _from, address _to, uint _value) internal {
65
+ // Prevent transfer to 0x0 address. Use burn() instead
66
+ require(_to != 0x0);
67
+ // Check if the sender has enough
68
+ require(balanceOf[_from] >= _value);
69
+ // Check for overflows
70
+ require(balanceOf[_to] + _value > balanceOf[_to]);
71
+ // Save this for an assertion in the future
72
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
73
+ // Subtract from the sender
74
+ balanceOf[_from] -= _value;
75
+ // Add the same to the recipient
76
+ balanceOf[_to] += _value;
77
+ emit Transfer(_from, _to, _value);
78
+ // Asserts are used to use static analysis to find bugs in your code. They should never fail
79
+ assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
80
+ }
81
+
82
+ /**
83
+ * Transfer tokens
84
+ *
85
+ * Send `_value` tokens to `_to` from your account
86
+ *
87
+ * @param _to The address of the recipient
88
+ * @param _value the amount to send
89
+ */
90
+ function transfer(address _to, uint256 _value) public {
91
+ _transfer(msg.sender, _to, _value);
92
+ }
93
+
94
+ /**
95
+ * Transfer tokens from other address
96
+ *
97
+ * Send `_value` tokens to `_to` in behalf of `_from`
98
+ *
99
+ * @param _from The address of the sender
100
+ * @param _to The address of the recipient
101
+ * @param _value the amount to send
102
+ */
103
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
104
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
105
+ allowance[_from][msg.sender] -= _value;
106
+ _transfer(_from, _to, _value);
107
+ return true;
108
+ }
109
+
110
+ /**
111
+ * Set allowance for other address
112
+ *
113
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
114
+ *
115
+ * @param _spender The address authorized to spend
116
+ * @param _value the max amount they can spend
117
+ */
118
+ function approve(address _spender, uint256 _value) public
119
+ returns (bool success) {
120
+ allowance[msg.sender][_spender] = _value;
121
+ return true;
122
+ }
123
+
124
+ /**
125
+ * Set allowance for other address and notify
126
+ *
127
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
128
+ *
129
+ * @param _spender The address authorized to spend
130
+ * @param _value the max amount they can spend
131
+ * @param _extraData some extra information to send to the approved contract
132
+ */
133
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
134
+ public
135
+ returns (bool success) {
136
+ tokenRecipient spender = tokenRecipient(_spender);
137
+ if (approve(_spender, _value)) {
138
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
139
+ return true;
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Destroy tokens
145
+ *
146
+ * Remove `_value` tokens from the system irreversibly
147
+ *
148
+ * @param _value the amount of money to burn
149
+ */
150
+ function burn(uint256 _value) public returns (bool success) {
151
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
152
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
153
+ totalSupply -= _value; // Updates totalSupply
154
+ emit Burn(msg.sender, _value);
155
+ return true;
156
+ }
157
+
158
+ /**
159
+ * Destroy tokens from other account
160
+ *
161
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
162
+ *
163
+ * @param _from the address of the sender
164
+ * @param _value the amount of money to burn
165
+ */
166
+ function burnFrom(address _from, uint256 _value) public returns (bool success) {
167
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
168
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
169
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
170
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
171
+ totalSupply -= _value; // Update totalSupply
172
+ emit Burn(_from, _value);
173
+ return true;
174
+ }
175
+ }
176
+
177
+ /******************************************/
178
+ /* ADVANCED TOKEN STARTS HERE */
179
+ /******************************************/
180
+
181
+ contract FIBToken is owned, TokenERC20 {
182
+
183
+ uint256 public sellPrice;
184
+ uint256 public buyPrice;
185
+
186
+ mapping (address => bool) public frozenAccount;
187
+
188
+ /* This generates a public event on the blockchain that will notify clients */
189
+ event FrozenFunds(address target, bool frozen);
190
+
191
+ /* Initializes contract with initial supply tokens to the creator of the contract */
192
+ function FIBToken(
193
+
194
+ ) TokenERC20() public {}
195
+
196
+ /* Internal transfer, only can be called by this contract */
197
+ function _transfer(address _from, address _to, uint _value) internal {
198
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
199
+ require (balanceOf[_from] >= _value); // Check if the sender has enough
200
+ require (balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
201
+ require(!frozenAccount[_from]); // Check if sender is frozen
202
+ require(!frozenAccount[_to]); // Check if recipient is frozen
203
+ balanceOf[_from] -= _value; // Subtract from the sender
204
+ balanceOf[_to] += _value; // Add the same to the recipient
205
+ emit Transfer(_from, _to, _value);
206
+ }
207
+
208
+ /// @notice Create `mintedAmount` tokens and send it to `target`
209
+ /// @param target Address to receive the tokens
210
+ /// @param mintedAmount the amount of tokens it will receive
211
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
212
+ balanceOf[target] += mintedAmount;
213
+ totalSupply += mintedAmount;
214
+ emit Transfer(0, this, mintedAmount);
215
+ emit Transfer(this, target, mintedAmount);
216
+ }
217
+
218
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
219
+ /// @param target Address to be frozen
220
+ /// @param freeze either to freeze it or not
221
+ function freezeAccount(address target, bool freeze) onlyOwner public {
222
+ frozenAccount[target] = freeze;
223
+ emit FrozenFunds(target, freeze);
224
+ }
225
+
226
+
227
+ }
data_full/CVE/2018-13075.sol ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *Submitted for verification at Etherscan.io on 2018-03-22
3
+ */
4
+
5
+ /** 官方高級token */
6
+
7
+
8
+ pragma solidity ^0.4.18;
9
+
10
+ contract owned {
11
+ address public owner;
12
+
13
+ function owned() public {
14
+ owner = msg.sender;
15
+ }
16
+
17
+ modifier onlyOwner {
18
+ require(msg.sender == owner);
19
+ _;
20
+ }
21
+
22
+ function transferOwnership(address newOwner) onlyOwner public {
23
+ owner = newOwner;
24
+ }
25
+
26
+ function destruct() public onlyOwner {
27
+ selfdestruct(owner);
28
+ }
29
+ }
30
+
31
+ interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }
32
+
33
+ contract TokenERC20 {
34
+ // Public variables of the token
35
+ string public name;
36
+ string public symbol;
37
+ uint8 public decimals = 18;
38
+ // 18 decimals is the strongly suggested default, avoid changing it
39
+ uint256 public totalSupply;
40
+
41
+ // This creates an array with all balances
42
+ mapping (address => uint256) public balanceOf;
43
+ mapping (address => mapping (address => uint256)) public allowance;
44
+
45
+ // This generates a public event on the blockchain that will notify clients
46
+ event Transfer(address indexed from, address indexed to, uint256 value);
47
+
48
+ // This notifies clients about the amount burnt
49
+ event Burn(address indexed from, uint256 value);
50
+
51
+ /**
52
+ * Constrctor function
53
+ *
54
+ * Initializes contract with initial supply tokens to the creator of the contract
55
+ */
56
+ function TokenERC20() public {
57
+ totalSupply = 500000000000 * 10 ** uint256(decimals); // Update total supply with the decimal amount
58
+ balanceOf[msg.sender] = totalSupply; // Give the creator all initial tokens
59
+ name = "Carbon Exchange Coin Token"; // Set the name for display purposes
60
+ symbol = "CEC"; // Set the symbol for display purposes
61
+ }
62
+
63
+ /**
64
+ * Internal transfer, only can be called by this contract
65
+ */
66
+ function _transfer(address _from, address _to, uint _value) internal {
67
+ // Prevent transfer to 0x0 address. Use burn() instead
68
+ require(_to != 0x0);
69
+ // Check if the sender has enough
70
+ require(balanceOf[_from] >= _value);
71
+ // Check for overflows
72
+ require(balanceOf[_to] + _value > balanceOf[_to]);
73
+ // Save this for an assertion in the future
74
+ uint previousBalances = balanceOf[_from] + balanceOf[_to];
75
+ // Subtract from the sender
76
+ balanceOf[_from] -= _value;
77
+ // Add the same to the recipient
78
+ balanceOf[_to] += _value;
79
+ Transfer(_from, _to, _value);
80
+ // Asserts are used to use static analysis to find bugs in your code. They should never fail
81
+ assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
82
+ }
83
+
84
+ /**
85
+ * Transfer tokens
86
+ *
87
+ * Send `_value` tokens to `_to` from your account
88
+ *
89
+ * @param _to The address of the recipient
90
+ * @param _value the amount to send
91
+ */
92
+ function transfer(address _to, uint256 _value) public {
93
+ _transfer(msg.sender, _to, _value);
94
+ }
95
+
96
+ /**
97
+ * Transfer tokens from other address
98
+ *
99
+ * Send `_value` tokens to `_to` in behalf of `_from`
100
+ *
101
+ * @param _from The address of the sender
102
+ * @param _to The address of the recipient
103
+ * @param _value the amount to send
104
+ */
105
+ function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
106
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
107
+ allowance[_from][msg.sender] -= _value;
108
+ _transfer(_from, _to, _value);
109
+ return true;
110
+ }
111
+
112
+ /**
113
+ * Set allowance for other address
114
+ *
115
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf
116
+ *
117
+ * @param _spender The address authorized to spend
118
+ * @param _value the max amount they can spend
119
+ */
120
+ function approve(address _spender, uint256 _value) public
121
+ returns (bool success) {
122
+ allowance[msg.sender][_spender] = _value;
123
+ return true;
124
+ }
125
+
126
+ /**
127
+ * Set allowance for other address and notify
128
+ *
129
+ * Allows `_spender` to spend no more than `_value` tokens in your behalf, and then ping the contract about it
130
+ *
131
+ * @param _spender The address authorized to spend
132
+ * @param _value the max amount they can spend
133
+ * @param _extraData some extra information to send to the approved contract
134
+ */
135
+ function approveAndCall(address _spender, uint256 _value, bytes _extraData)
136
+ public
137
+ returns (bool success) {
138
+ tokenRecipient spender = tokenRecipient(_spender);
139
+ if (approve(_spender, _value)) {
140
+ spender.receiveApproval(msg.sender, _value, this, _extraData);
141
+ return true;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Destroy tokens
147
+ *
148
+ * Remove `_value` tokens from the system irreversibly
149
+ *
150
+ * @param _value the amount of money to burn
151
+ */
152
+ function burn(uint256 _value) public returns (bool success) {
153
+ require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
154
+ balanceOf[msg.sender] -= _value; // Subtract from the sender
155
+ totalSupply -= _value; // Updates totalSupply
156
+ Burn(msg.sender, _value);
157
+ return true;
158
+ }
159
+
160
+ /**
161
+ * Destroy tokens from other account
162
+ *
163
+ * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
164
+ *
165
+ * @param _from the address of the sender
166
+ * @param _value the amount of money to burn
167
+ */
168
+ function burnFrom(address _from, uint256 _value) public returns (bool success) {
169
+ require(balanceOf[_from] >= _value); // Check if the targeted balance is enough
170
+ require(_value <= allowance[_from][msg.sender]); // Check allowance
171
+ balanceOf[_from] -= _value; // Subtract from the targeted balance
172
+ allowance[_from][msg.sender] -= _value; // Subtract from the sender's allowance
173
+ totalSupply -= _value; // Update totalSupply
174
+ Burn(_from, _value);
175
+ return true;
176
+ }
177
+ }
178
+
179
+ /******************************************/
180
+ /* ADVANCED TOKEN STARTS HERE */
181
+ /******************************************/
182
+
183
+ contract CarbonExchangeCoinToken is owned, TokenERC20 {
184
+
185
+ uint256 public sellPrice;
186
+ uint256 public buyPrice;
187
+ uint256 public decimals = 18;
188
+ string public tokenName;
189
+ string public tokenSymbol;
190
+ uint minBalanceForAccounts ; //threshold amount
191
+
192
+ mapping (address => bool) public frozenAccount;
193
+
194
+ /* This generates a public event on the blockchain that will notify clients */
195
+ event FrozenFunds(address target, bool frozen);
196
+
197
+ /* Initializes contract with initial supply tokens to the creator of the contract */
198
+
199
+
200
+ function CarbonExchangeCoinToken() public {
201
+ owner = msg.sender;
202
+ totalSupply = 50000000000000000000000000000;
203
+ balanceOf[owner]=totalSupply;
204
+ tokenName="Carbon Exchange Coin Token";
205
+ tokenSymbol="CEC";
206
+ }
207
+
208
+
209
+ /* Internal transfer, only can be called by this contract */
210
+ function _transfer(address _from, address _to, uint _value) internal {
211
+ require (_to != 0x0); // Prevent transfer to 0x0 address. Use burn() instead
212
+ require (balanceOf[_from] >= _value); // Check if the sender has enough
213
+ require (balanceOf[_to] + _value > balanceOf[_to]); // Check for overflows
214
+ require(!frozenAccount[_from]); // Check if sender is frozen
215
+ require(!frozenAccount[_to]); // Check if recipient is frozen
216
+ balanceOf[_from] -= _value; // Subtract from the sender
217
+ balanceOf[_to] += _value; // Add the same to the recipient
218
+ Transfer(_from, _to, _value);
219
+ }
220
+
221
+ /// @notice Create `mintedAmount` tokens and send it to `target`
222
+ /// @param target Address to receive the tokens
223
+ /// @param mintedAmount the amount of tokens it will receive
224
+ function mintToken(address target, uint256 mintedAmount) onlyOwner public {
225
+ balanceOf[target] += mintedAmount;
226
+ totalSupply += mintedAmount;
227
+ Transfer(0, this, mintedAmount);
228
+ Transfer(this, target, mintedAmount);
229
+ }
230
+
231
+ /// @notice `freeze? Prevent | Allow` `target` from sending & receiving tokens
232
+ /// @param target Address to be frozen
233
+ /// @param freeze either to freeze it or not
234
+ function freezeAccount(address target, bool freeze) onlyOwner public {
235
+ frozenAccount[target] = freeze;
236
+ FrozenFunds(target, freeze);
237
+ }
238
+
239
+ /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
240
+ /// @param newSellPrice Price the users can sell to the contract
241
+ /// @param newBuyPrice Price users can buy from the contract
242
+ function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner public {
243
+ sellPrice = newSellPrice;
244
+ buyPrice = newBuyPrice;
245
+ }
246
+
247
+ /// @notice Buy tokens from contract by sending ether
248
+ function buy() payable public {
249
+ uint amount = msg.value / buyPrice; // calculates the amount
250
+ _transfer(this, msg.sender, amount); // makes the transfers
251
+ }
252
+
253
+ /// @notice Sell `amount` tokens to contract
254
+ ///@param amount amount of tokens to be sold
255
+ function sell(uint256 amount) public {
256
+ require(this.balance >= amount * sellPrice); // checks if the contract has enough ether to buy
257
+ _transfer(msg.sender, this, amount); // makes the transfers
258
+ msg.sender.transfer(amount * sellPrice); // sends ether to the seller. It's important to do this last to avoid recursion attacks
259
+ }
260
+
261
+
262
+ /* 设置自动补充gas的阈值信息 201803202232 james */
263
+ function setMinBalance(uint minimumBalanceInFinney) public onlyOwner {
264
+ minBalanceForAccounts = minimumBalanceInFinney * 1 finney;
265
+ }
266
+
267
+ /* 设置tokenname */
268
+ function setTokenName(string newTokenName) public onlyOwner{
269
+ tokenName = newTokenName;
270
+ }
271
+ /* 设置tokenSymbol */
272
+ function setTokenSymbol(string newTokenSymbol) public onlyOwner{
273
+ tokenSymbol = newTokenSymbol;
274
+ }
275
+ }