-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOverUnderflow.sol
34 lines (27 loc) · 1.24 KB
/
OverUnderflow.sol
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
// Deposit to the msg.sender
// send some to other 2 accounts ["0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2","0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db"], 0x8000000000000000000000000000000000000000000000000000000000000000
pragma solidity 0.6.0;
contract Over{
mapping(address=>uint) balances;
uint _amount;
function batchTransfer(address[] memory _receivers, uint _value) public payable returns(bool){
uint cnt = _receivers.length;
uint amount = cnt * _value; // overflow happens here, when 0x8000000000000000000000000000000000000000000000000000000000000000 inserted, this will trigger and amount becomes 0
_amount = amount;
require(_value >0 && balances[msg.sender] > amount); // amount becomes 0, so the check is bypassed.
balances[msg.sender] = balances[msg.sender] - amount;
for(uint i; i<cnt; i++){
balances[_receivers[i]] = balances[_receivers[i]] + _value;
}
return true;
}
function getBalance() public view returns(uint){
return balances[msg.sender];
}
function getAmount() public view returns(uint){
return _amount;
}
function deposit() public payable{
balances[msg.sender] += msg.value;
}
}