-
Notifications
You must be signed in to change notification settings - Fork 3
/
tot_bug.txt
18650 lines (16207 loc) · 686 KB
/
tot_bug.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1 pragma solidity >=0.4.24 <0.6.0;
2 contract ExternalFunctionCall {
3 function foo(uint x) public returns (uint ret) {
4 ret = x + 2;
5 }
6 function testExternalFunctionCall(uint x) public {
7 uint y = this.foo(x);
8 }
9 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity >=0.4.24 <0.6.0;
2 contract B {
3 function funcB() public pure returns (uint) {
4 return 42;
5 }
6 constructor() public {}
7 }
8 contract A {
9 function funcA1() public pure returns (uint) {
10 return 11;
11 }
12 function funcA2(uint x) public pure returns (uint) {
13 return x+1;
14 }
15 function funcA3() public returns (B) {
16 B retVal= new B();
17 return retVal;
18 }
19 constructor() public
20 {
21 }
22 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity >=0.4.24 <0.6.0;
2 // This test passes, but assertion on line 35 is only proved
3 // up to 4 transactions
4 // This result means that ctor A is only called once, for B, as A(x+1)
5 // Compare this test with ConstructorChaining2_fail.sol: no ctor args there,
6 // so the workaround in the compiler doesn't work, and the base ctor is called twice
7 // Example of the trace:
8 // D(x) is called, where x is 716
9 // B(x+3) called, where x is 716, B's arg is 719
10 // A(x+1) called, where x is 720. A's arg is 720
11 // ctor A {a = x} , where a is 720
12 // ctor B {b = x+1 } , where x is 719, b is 720
13 // C(x+4) is called, where x is 716, C's arg is 720
14 // ctor C { c = x + 2}, where x is 720, c is 722
15 contract A {
16 uint a;
17 constructor (uint x) public {
18 a = x;
19 }
20 }
21 contract B is A {
22 uint b;
23 constructor (uint x) A(x+1) public {
24 b = x + 1;
25 }
26 }
27 contract C is A {
28 uint c;
29 //constructor (uint x) A(x+2) public { // no A with ANY args here, otherwise, solc error:
30 // "Base constr args given twice"
31 constructor (uint x) public {
32 c = x + 2;
33 }
34 }
35 contract D is B, C {
36 constructor (uint x) B(x+3) C(x+4) public
37 {
38 }
39 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity >=0.4.24 <0.6.0;
2 contract B {
3 function funcB() public pure returns (uint) {
4 return 42;
5 }
6 constructor() public {}
7 }
8 contract A {
9 function funcA1() public pure returns (uint) {
10 return 11;
11 }
12 function funcA2(uint x) public pure returns (uint) {
13 return x+1;
14 }
15 function funcA3() public returns (B) {
16 B retVal= new B();
17 return retVal;
18 }
19 constructor() public
20 {
21 }
22 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity >=0.4.24 <0.6.0;
2 // This test passes, but assertion on line 35 is only proved
3 // up to 4 transactions
4 // This result means that ctor A is only called once, for B, as A(x+1)
5 // Compare this test with ConstructorChaining2_fail.sol: no ctor args there,
6 // so the workaround in the compiler doesn't work, and the base ctor is called twice
7 // Example of the trace:
8 // D(x) is called, where x is 716
9 // B(x+3) called, where x is 716, B's arg is 719
10 // A(x+1) called, where x is 720. A's arg is 720
11 // ctor A {a = x} , where a is 720
12 // ctor B {b = x+1 } , where x is 719, b is 720
13 // C(x+4) is called, where x is 716, C's arg is 720
14 // ctor C { c = x + 2}, where x is 720, c is 722
15 contract A {
16 uint a;
17 constructor (uint x) public {
18 a = x;
19 }
20 }
21 contract B is A {
22 uint b;
23 constructor (uint x) A(x+1) public {
24 b = x + 1;
25 }
26 }
27 contract C is A {
28 uint c;
29 //constructor (uint x) A(x+2) public { // no A with ANY args here, otherwise, solc error:
30 // "Base constr args given twice"
31 constructor (uint x) public {
32 c = x + 2;
33 // passes, but proved to only 4 transactions
34 }
35 }
36 contract D is B, C {
37 constructor (uint x) B(x+3) C(x+4) public
38 {
39 ;
40 }
41 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity >=0.4.24<0.6.0;
2 import "./Libraries/VeriSolContracts.sol";
3 contract LoopFor {
4 int x;
5 int y;
6 function ContractInvariant () private view {
7 }
8 // test Loop invariant with for loop
9 constructor(int n) public {
10 require (n >= 0);
11 x = n;
12 y = x;
13 }
14 function Foo() public {
15 if ( x > 0 )
16 {
17 x--;
18 y--;
19 }
20 }
21 }
What are the vulnerabilities in the contract?
healthy
<end of text>
pragma solidity >=0.4.24 <0.6.0;
//simple library with no internal state
library Lib {
function add(uint _a, uint _b) public view returns (uint r) {
address x = address(this);
r = _a + _b;
}
}
contract C {
// using Lib for uint;
function foo() public {
uint x = 1;
uint y = 2;
uint z = Lib.add(x, y);
}
}
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity ^0.4.24;
2 import "./../../Libraries/VeriSolContracts.sol";
3 //import "./VeriSolContracts.sol";
4 //import "github.com/microsoft/verisol/blob/master/Libraries/VeriSolContracts.sol";
5 contract LoopFor {
6 // test Loop invariant with for loop
7 constructor(uint n) public {
8 require (n >= 0);
9 uint y = 0;
10 for (uint x = n; x != 0; x --) {
11 y++;
12 }
13 }
14 // test Loop invariant with while loop
15 function Foo(uint n) public {
16 require (n >= 0);
17 uint y = 0;
18 uint x = n;
19 while (x != 0) {
20 y++;
21 x--;
22 }
23 }
24 // test Loop invariant with do-while loop
25 function Bar(uint n) public {
26 require (n > 0);
27 uint y = 0;
28 uint x = n;
29 do {
30 y++;
31 x--;
32 } while (x != 0);
33 }
34 }
What are the vulnerabilities in the contract?
healthy
<end of text>
1 pragma solidity ^0.5.0;
2 import "./IERC20.sol";
3 import "./SafeMath.sol";
4 import "./Libraries/VeriSolContracts.sol"; //change
5 /**
6 * A highly simplified Token to express basic specifications
7 *
8 * - totalSupply() equals the Sum({balanceOf(a) | a is an address })
9 *
10 */
11 contract ERC20 is IERC20 {
12 mapping (address => uint256) private _balances;
13 uint256 private _totalSupply;
14 /**
15 * A dummy constructor
16 */
17 constructor (uint256 totalSupply) public {
18 _totalSupply = totalSupply;
19 _balances[msg.sender] = totalSupply;
20 }
21 /**
22 * @dev See {IERC20-totalSupply}.
23 */
24 function totalSupply() public view returns (uint256) {
25 return _totalSupply;
26 }
27 /**
28 * @dev See {IERC20-balanceOf}.
29 */
30 function balanceOf(address account) public view returns (uint256) {
31 return _balances[account];
32 }
33 /**
34 * @dev See {IERC20-transfer}.
35 *
36 * Requirements:
37 *
38 * - `recipient` cannot be the zero address.
39 * - the caller must have a balance of at least `amount`.
40 */
41 function transfer(address recipient, uint256 amount) public returns (bool) {
42 uint oldBalanceSender = _balances[msg.sender];
43 _transfer(msg.sender, recipient, amount);
44 //assert (/* msg.sender == recipient || */ _balances[msg.sender] == oldBalanceSender - amount);
45 // the following assertion will fail due to overflow when not using safemath
46 // to detect it, run with /modularArith flag
47 // to prove it, run ERC20 with /modularArith flag
48 return true;
49 }
50 /**
51 * @dev Moves tokens `amount` from `sender` to `recipient`.
52 *
53 * This is internal function is equivalent to {transfer}, and can be used to
54 * e.g. implement automatic token fees, slashing mechanisms, etc.
55 *
56 * Emits a {Transfer} event.
57 *
58 * Requirements:
59 *
60 * - `sender` cannot be the zero address.
61 * - `recipient` cannot be the zero address.
62 * - `sender` must have a balance of at least `amount`.
63 */
64 function _transfer(address sender, address recipient, uint256 amount) internal {
65 require(sender != address(0), "ERC20: transfer from the zero address");
66 require(recipient != address(0), "ERC20: transfer to the zero address");
67 _balances[sender] = SafeMath.sub(_balances[sender], amount);
68 _balances[recipient] = _balances[recipient] + amount; // nosafemath //_balances[recipient] = _balances[recipient].add(amount);
69 }
70 }
What are the vulnerabilities in the contract?
incorrect visibility/ownership
business logic flaw
integer overflow/underflow
<end of text>
1 //SPDX-License-Identifier: MIT
2 pragma solidity 0.7.5;
3 contract contrived{
4 function withdraw(uint256 amount) override public nonReentrant updateReward(msg.sender) {
5 _totalSupply = _totalSupply - amount;
6 _balances[msg.sender] = _balances[msg.sender].sub(amount);
7 stakingToken.safeTransfer(msg.sender, amount);
8 emit Withdrawn(msg.sender, amount);
9 }
10 }
What are the vulnerabilities in the contract?
integer over/underflow
<end of text>
1 /**
2 *Submitted for verification at Etherscan.io on 2018-02-09
3 */
4 pragma solidity ^0.4.16;
5 /**
6 * @title SafeMath
7 * @dev Math operations with safety checks that throw on error
8 */
9 library SafeMath {
10 function mul(uint256 a, uint256 b) internal constant returns (uint256) {
11 uint256 c = a * b;
12 return c;
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 function sub(uint256 a, uint256 b) internal constant returns (uint256) {
21 return a - b;
22 }
23 function add(uint256 a, uint256 b) internal constant returns (uint256) {
24 uint256 c = a + b;
25 return c;
26 }
27 }
28 /**
29 * @title ERC20Basic
30 * @dev Simpler version of ERC20 interface
31 * @dev see https://github.com/ethereum/EIPs/issues/179
32 */
33 contract ERC20Basic {
34 uint256 public totalSupply;
35 function balanceOf(address who) public constant returns (uint256);
36 function transfer(address to, uint256 value) public returns (bool);
37 event Transfer(address indexed from, address indexed to, uint256 value);
38 }
39 /**
40 * @title Basic token
41 * @dev Basic version of StandardToken, with no allowances.
42 */
43 contract BasicToken is ERC20Basic {
44 using SafeMath for uint256;
45 mapping(address => uint256) balances;
46 /**
47 * @dev transfer token for a specified address
48 * @param _to The address to transfer to.
49 * @param _value The amount to be transferred.
50 */
51 function transfer(address _to, uint256 _value) public returns (bool) {
52 // SafeMath.sub will throw if there is not enough balance.
53 balances[msg.sender] = balances[msg.sender].sub(_value);
54 balances[_to] = balances[_to].add(_value);
55 Transfer(msg.sender, _to, _value);
56 return true;
57 }
58 /**
59 * @dev Gets the balance of the specified address.
60 * @param _owner The address to query the the balance of.
61 * @return An uint256 representing the amount owned by the passed address.
62 */
63 function balanceOf(address _owner) public constant returns (uint256 balance) {
64 return balances[_owner];
65 }
66 }
67 /**
68 * @title ERC20 interface
69 * @dev see https://github.com/ethereum/EIPs/issues/20
70 */
71 contract ERC20 is ERC20Basic {
72 function allowance(address owner, address spender) public constant returns (uint256);
73 function transferFrom(address from, address to, uint256 value) public returns (bool);
74 function approve(address spender, uint256 value) public returns (bool);
75 event Approval(address indexed owner, address indexed spender, uint256 value);
76 }
77 /**
78 * @title Standard ERC20 token
79 *
80 * @dev Implementation of the basic standard token.
81 * @dev https://github.com/ethereum/EIPs/issues/20
82 * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
83 */
84 contract StandardToken is ERC20, BasicToken {
85 mapping (address => mapping (address => uint256)) internal allowed;
86 /**
87 * @dev Transfer tokens from one address to another
88 * @param _from address The address which you want to send tokens from
89 * @param _to address The address which you want to transfer to
90 * @param _value uint256 the amount of tokens to be transferred
91 */
92 function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
93 require(_to != address(0));
94 require(_value > 0 && _value <= balances[_from]);
95 require(_value <= allowed[_from][msg.sender]);
96 balances[_from] = balances[_from].sub(_value);
97 balances[_to] = balances[_to].add(_value);
98 allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
99 Transfer(_from, _to, _value);
100 return true;
101 }
102 /**
103 * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
104 *
105 * Beware that changing an allowance with this method brings the risk that someone may use both the old
106 * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
107 * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
108 * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
109 * @param _spender The address which will spend the funds.
110 * @param _value The amount of tokens to be spent.
111 */
112 function approve(address _spender, uint256 _value) public returns (bool) {
113 allowed[msg.sender][_spender] = _value;
114 Approval(msg.sender, _spender, _value);
115 return true;
116 }
117 /**
118 * @dev Function to check the amount of tokens that an owner allowed to a spender.
119 * @param _owner address The address which owns the funds.
120 * @param _spender address The address which will spend the funds.
121 * @return A uint256 specifying the amount of tokens still available for the spender.
122 */
123 function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
124 return allowed[_owner][_spender];
125 }
126 }
127 /**
128 * @title Ownable
129 * @dev The Ownable contract has an owner address, and provides basic authorization control
130 * functions, this simplifies the implementation of "user permissions".
131 */
132 contract Ownable {
133 address public owner;
134 event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
135 /**
136 * @dev The Ownable constructor sets the original `owner` of the contract to the sender
137 * account.
138 */
139 function Ownable() {
140 owner = msg.sender;
141 }
142 /**
143 * @dev Throws if called by any account other than the owner.
144 */
145 modifier onlyOwner() {
146 _;
147 }
148 /**
149 * @dev Allows the current owner to transfer control of the contract to a newOwner.
150 * @param newOwner The address to transfer ownership to.
151 */
152 function transferOwnership(address newOwner) onlyOwner public {
153 OwnershipTransferred(owner, newOwner);
154 owner = newOwner;
155 }
156 }
157 /**
158 * @title Pausable
159 * @dev Base contract which allows children to implement an emergency stop mechanism.
160 */
161 contract Pausable is Ownable {
162 event Pause();
163 event Unpause();
164 bool public paused = false;
165 /**
166 * @dev Modifier to make a function callable only when the contract is not paused.
167 */
168 modifier whenNotPaused() {
169 _;
170 }
171 /**
172 * @dev Modifier to make a function callable only when the contract is paused.
173 */
174 modifier whenPaused() {
175 _;
176 }
177 /**
178 * @dev called by the owner to pause, triggers stopped state
179 */
180 function pause() onlyOwner whenNotPaused public {
181 paused = true;
182 Pause();
183 }
184 /**
185 * @dev called by the owner to unpause, returns to normal state
186 */
187 function unpause() onlyOwner whenPaused public {
188 paused = false;
189 Unpause();
190 }
191 }
192 /**
193 * @title Pausable token
194 *
195 * @dev StandardToken modified with pausable transfers.
196 **/
197 contract PausableToken is StandardToken, Pausable {
198 function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
199 return super.transfer(_to, _value);
200 }
201 function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
202 return super.transferFrom(_from, _to, _value);
203 }
204 function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
205 return super.approve(_spender, _value);
206 }
207 function batchTransfer(address[] _receivers, uint256 _value) public whenNotPaused returns (bool) {
208 uint cnt = _receivers.length;
209 uint256 amount = uint256(cnt) * _value;
210 require(cnt > 0 && cnt <= 20);
211 require(_value > 0 && balances[msg.sender] >= amount);
212 balances[msg.sender] = balances[msg.sender].sub(amount);
213 for (uint i = 0; i < cnt; i++) {
214 balances[_receivers[i]] = balances[_receivers[i]].add(_value);
215 Transfer(msg.sender, _receivers[i], _value);
216 }
217 return true;
218 }
219 }
220 /**
221 * @title Bec Token
222 *
223 * @dev Implementation of Bec Token based on the basic standard token.
224 */
225 contract BecToken is PausableToken {
226 /**
227 * Public variables of the token
228 * The following variables are OPTIONAL vanities. One does not have to include them.
229 * They allow one to customise the token contract & in no way influences the core functionality.
230 * Some wallets/interfaces might not even bother to look at this information.
231 */
232 string public name = "BeautyChain";
233 string public symbol = "BEC";
234 string public version = '1.0.0';
235 uint8 public decimals = 18;
236 /**
237 * @dev Function to check the amount of tokens that an owner allowed to a spender.
238 */
239 function BecToken() {
240 totalSupply = 7000000000 * (10**(uint256(decimals)));
241 balances[msg.sender] = totalSupply; // Give the creator all initial tokens
242 }
243 function () {
244 //if ether is sent to this address, send it back.
245 revert();
246 }
247 }
What are the vulnerabilities in the contract?
integer over/underflow
atomicity violation
incorrect visibility/ownership
<end of text>
1 /**
2 *Submitted for verification at Etherscan.io on 2020-10-07
3 */
4 // File: openzeppelin-solidity-2.3.0/contracts/ownership/Ownable.sol
5 pragma solidity ^0.5.0;
6 contract Bank{
7 //reentrant here
8 function work(uint256 id, address goblin, uint256 loan, uint256 maxReturn, bytes calldata data)
9 external payable
10 onlyEOA accrue(msg.value)
11 {
12 // 1. Sanity check the input position, or add a new position of ID is 0.
13 if (id == 0) {
14 id = nextPositionID++;
15 positions[id].goblin = goblin;
16 positions[id].owner = msg.sender;
17 } else {
18 _;
19 }
20 emit Work(id, loan);
21 // 2. Make sure the goblin can accept more debt and remove the existing debt.
22 uint256 debt = _removeDebt(id).add(loan);
23 // 3. Perform the actual work, using a new scope to avoid stack-too-deep errors.
24 uint256 back;
25 {
26 uint256 sendETH = msg.value.add(loan);
27 require(sendETH <= address(this).balance, "insufficient ETH in the bank");
28 uint256 beforeETH = address(this).balance.sub(sendETH);
29 Goblin(goblin).work.value(sendETH)(id, msg.sender, debt, data);
30 back = address(this).balance.sub(beforeETH);
31 }
32 // 4. Check and update position debt.
33 uint256 lessDebt = Math.min(debt, Math.min(back, maxReturn));
34 debt = debt.sub(lessDebt);
35 if (debt > 0) {
36 uint256 health = Goblin(goblin).health(id);
37 uint256 workFactor = config.workFactor(goblin, debt);
38 _addDebt(id, debt);
39 }
40 // 5. Return excess ETH back.
41 if (back > lessDebt) SafeToken.safeTransferETH(msg.sender, back - lessDebt);
42 }
43 }
What are the vulnerabilities in the contract?
reentrancy
<end of text>
1 /**
2 *Submitted for verification at BscScan.com on 2021-07-30
3 */
4 //SPDX-License-Identifier: MIT
5 pragma solidity ^0.8.0;
6 abstract contract ReentrancyGuard {
7 uint256 private constant _NOT_ENTERED = 1;
8 uint256 private constant _ENTERED = 2;
9 uint256 private _status;
10 constructor () {
11 _status = _NOT_ENTERED;
12 }
13 modifier nonReentrant() {
14 _status = _ENTERED;
15 _;
16 _status = _NOT_ENTERED;
17 }
18 }
19 contract surgeToken{
20 /** Sells SURGE Tokens And Deposits the BNB into Seller's Address */
21 function sell(uint256 tokenAmount) public nonReentrant returns (bool) {
22 address seller = msg.sender;
23 // make sure seller has this balance
24 require(_balances[seller] >= tokenAmount, 'cannot sell above token amount');
25 // calculate the sell fee from this transaction
26 uint256 tokensToSwap = tokenAmount.mul(sellFee).div(10**2);
27 // how much BNB are these tokens worth?
28 uint256 amountBNB = tokensToSwap.mul(calculatePrice());
29 //reentrant happens here: during call fallback, the attacker invoked purchase multiple times
30 (bool successful,) = payable(seller).call{value: amountBNB, gas: 40000}("");
31 if (successful) {
32 // subtract full amount from sender
33 _balances[seller] = _balances[seller].sub(tokenAmount, 'sender does not have this amount to sell');
34 // if successful, remove tokens from supply
35 _totalSupply = _totalSupply.sub(tokenAmount);
36 } else {
37 revert();
38 }
39 emit Transfer(seller, address(this), tokenAmount);
40 return true;
41 }
42 function purchase(address buyer, uint256 bnbAmount) internal returns (bool) {
43 // make sure we don't buy more than the bnb in this contract
44 // previous amount of BNB before we received any
45 uint256 prevBNBAmount = (address(this).balance).sub(bnbAmount);
46 // if this is the first purchase, use current balance
47 prevBNBAmount = prevBNBAmount == 0 ? address(this).balance : prevBNBAmount;
48 // find the number of tokens we should mint to keep up with the current price
49 uint256 nShouldPurchase = hyperInflatePrice ? _totalSupply.mul(bnbAmount).div(address(this).balance) : _totalSupply.mul(bnbAmount).div(prevBNBAmount);
50 // apply our spread to tokens to inflate price relative to total supply
51 uint256 tokensToSend = nShouldPurchase.mul(spreadDivisor).div(10**2);
52 // revert if under 1
53 if (tokensToSend < 1) {
54 revert('Must Buy More Than One Surge');
55 }
56 }
57 }
What are the vulnerabilities in the contract?
reentrancy
business logic flaw
<end of text>
1 /**
2 *Submitted for verification at BscScan.com on 2021-07-30
3 */
4 //SPDX-License-Identifier: MIT
5 pragma solidity ^0.8.0;
6 /**
7 *Submitted for verification at FtmScan.com on 2021-08-31
8 */
9 // SPDX-License-Identifier: MIT
10 // File: @openzeppelin/contracts/GSN/Context.sol
11 pragma solidity ^0.5.0;
12 /*
13 * @dev Provides information about the current execution context, including the
14 * sender of the transaction and its data. While these are generally available
15 * via msg.sender and msg.data, they should not be accessed in such a direct
16 * manner, since when dealing with GSN meta-transactions the account sending and
17 * paying for execution may not be the actual sender (as far as an application
18 * is concerned).
19 *
20 * This contract is only required for intermediate, library-like contracts.
21 */
22 abstract contract Context {
23 function _msgSender() internal view virtual returns (address payable) {
24 return msg.sender;
25 }
26 function _msgData() internal view virtual returns (bytes memory) {
27 this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
28 return msg.data;
29 }
30 }
31 // File: @openzeppelin/contracts/token/ERC20/IERC20.sol
32 /**
33 * @dev Interface of the ERC20 standard as defined in the EIP.
34 */
35 interface IERC20 {
36 /**
37 * @dev Returns the amount of tokens in existence.
38 */
39 function totalSupply() external view returns (uint256);
40 /**
41 * @dev Returns the amount of tokens owned by `account`.
42 */
43 function balanceOf(address account) external view returns (uint256);
44 /**
45 * @dev Moves `amount` tokens from the caller's account to `recipient`.
46 *
47 * Returns a boolean value indicating whether the operation succeeded.
48 *
49 * Emits a {Transfer} event.
50 */
51 function transfer(address recipient, uint256 amount) external returns (bool);
52 /**
53 * @dev Returns the remaining number of tokens that `spender` will be
54 * allowed to spend on behalf of `owner` through {transferFrom}. This is
55 * zero by default.
56 *
57 * This value changes when {approve} or {transferFrom} are called.
58 */
59 function allowance(address owner, address spender) external view returns (uint256);
60 /**
61 * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
62 *
63 * Returns a boolean value indicating whether the operation succeeded.
64 *
65 * IMPORTANT: Beware that changing an allowance with this method brings the risk
66 * that someone may use both the old and the new allowance by unfortunate
67 * transaction ordering. One possible solution to mitigate this race
68 * condition is to first reduce the spender's allowance to 0 and set the
69 * desired value afterwards:
70 * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
71 *
72 * Emits an {Approval} event.
73 */
74 function approve(address spender, uint256 amount) external returns (bool);
75 /**
76 * @dev Moves `amount` tokens from `sender` to `recipient` using the
77 * allowance mechanism. `amount` is then deducted from the caller's
78 * allowance.
79 *
80 * Returns a boolean value indicating whether the operation succeeded.
81 *
82 * Emits a {Transfer} event.
83 */
84 function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
85 /**
86 * @dev Emitted when `value` tokens are moved from one account (`from`) to
87 * another (`to`).
88 *
89 * Note that `value` may be zero.
90 */
91 event Transfer(address indexed from, address indexed to, uint256 value);
92 /**
93 * @dev Emitted when the allowance of a `spender` for an `owner` is set by
94 * a call to {approve}. `value` is the new allowance.
95 */
96 event Approval(address indexed owner, address indexed spender, uint256 value);
97 }
98 // File: @openzeppelin/contracts/math/SafeMath.sol
99 /**
100 * @dev Wrappers over Solidity's arithmetic operations with added overflow
101 * checks.
102 *
103 * Arithmetic operations in Solidity wrap on overflow. This can easily result
104 * in bugs, because programmers usually assume that an overflow raises an
105 * error, which is the standard behavior in high level programming languages.
106 * `SafeMath` restores this intuition by reverting the transaction when an
107 * operation overflows.
108 *
109 * Using this library instead of the unchecked operations eliminates an entire
110 * class of bugs, so it's recommended to use it always.
111 */
112 library SafeMath {
113 /**
114 * @dev Returns the addition of two unsigned integers, reverting on
115 * overflow.
116 *
117 * Counterpart to Solidity's `+` operator.
118 *
119 * Requirements:
120 *
121 * - Addition cannot overflow.
122 */
123 function add(uint256 a, uint256 b) internal pure returns (uint256) {
124 uint256 c = a + b;
125 return c;
126 }
127 /**
128 * @dev Returns the subtraction of two unsigned integers, reverting on
129 * overflow (when the result is negative).
130 *
131 * Counterpart to Solidity's `-` operator.
132 *
133 * Requirements:
134 *
135 * - Subtraction cannot overflow.
136 */
137 function sub(uint256 a, uint256 b) internal pure returns (uint256) {
138 _;
139 }
140 /**
141 * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
142 * overflow (when the result is negative).
143 *
144 * Counterpart to Solidity's `-` operator.
145 *
146 * Requirements:
147 *
148 * - Subtraction cannot overflow.
149 */
150 function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
151 uint256 c = a - b;
152 return c;
153 }
154 /**
155 * @dev Returns the multiplication of two unsigned integers, reverting on
156 * overflow.
157 *
158 * Counterpart to Solidity's `*` operator.
159 *
160 * Requirements:
161 *
162 * - Multiplication cannot overflow.
163 */
164 function mul(uint256 a, uint256 b) internal pure returns (uint256) {
165 // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
166 // benefit is lost if 'b' is also tested.
167 // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
168 if (a == 0) {
169 return 0;
170 }
171 uint256 c = a * b;
172 return c;
173 }
174 /**
175 * @dev Returns the integer division of two unsigned integers. Reverts on
176 * division by zero. The result is rounded towards zero.
177 *
178 * Counterpart to Solidity's `/` operator. Note: this function uses a