-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverflow
40 lines (33 loc) · 919 Bytes
/
Overflow
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
pragma solidity^0.4.16;
library SafeMath {
function mul(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a * b;
assert(a == 0 || c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a / b;
return c;
}
function sub(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal constant returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract TestOVerflow{
using SafeMath for uint256;
function add(uint8 a, uint8 b) public returns(uint8){
return a + b;
}
function test_uint256(uint256 a) public returns(uint256){
return a*2;
}
function test_uint256_safemath(uint256 a) public returns(uint256){
return a.mul(2);
}
}