pragma solidity 0.5.1;
contract basics{
using SafeMath for *;
uint time;
address payable sender;
uint amount;
event moneySent(address s,uint a);
mapping(address=>person) public accounts;
struct person {
uint time;
uint vault;
}
function sendToContract() public payable{// isWithinLimits(msg.value){
accounts[msg.sender].vault=accounts[msg.sender].vault.add(msg.value);
accounts[msg.sender].time=now;
}
function takeFromContract() public payable{
if(now>=accounts[msg.sender].time+10 seconds){
msg.sender.transfer(accounts[msg.sender].vault);
accounts[msg.sender].time=now;
}
}
}
/**
* @title SafeMath v0.1.9
* @dev Math operations with safety checks that throw on error
* change notes: original SafeMath library from OpenZeppelin modified by Inventor
* - added sqrt
* - added sq
* - added pwr
* - changed asserts to requires with error log outputs
* - removed div, its useless
*/
library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
if (a == 0) {
return 0;
}
c = a * b;
require(c / a == b, "SafeMath mul failed");
return c;
}
/**
* @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b)
internal
pure
returns (uint256)
{
require(b <= a, "SafeMath sub failed");
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b)
internal
pure
returns (uint256 c)
{
c = a + b;
require(c >= a, "SafeMath add failed");
return c;
}
/**
* @dev gives square root of given x.
*/
function sqrt(uint256 x)
internal
pure
returns (uint256 y)
{
uint256 z = ((add(x,1)) / 2);
y = x;
while (z < y)
{
y = z;
z = ((add((x / z),z)) / 2);
}
}
/**
* @dev gives square. multiplies x by x
*/
function sq(uint256 x)
internal
pure
returns (uint256)
{
return (mul(x,x));
}
/**
* @dev x to the power of y
*/
function pwr(uint256 x, uint256 y)
internal
pure
returns (uint256)
{
if (x==0)
return (0);
else if (y==0)
return (1);
else
{
uint256 z = x;
for (uint256 i=1; i < y; i++)
z = mul(z,x);
return (z);
}
}
}
given this code, when run and tested, if send 10,000 eth from wallet containing 99 eth the wallet will show that it now has 99,900n eth and when 10,000 is sent again it reverts back to 99 eth in wallet. Could this be an underflow or overflow error?