From e8aaa197c94e44666abd427a77dcaaf6f71a62dd Mon Sep 17 00:00:00 2001 From: Sowmayjain Date: Mon, 11 Mar 2019 01:08:53 +0530 Subject: [PATCH] Using SafeMath & updating lastActivity on execute. --- UserProxy.sol | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/UserProxy.sol b/UserProxy.sol index 456b522..0bb3fc3 100644 --- a/UserProxy.sol +++ b/UserProxy.sol @@ -1,7 +1,21 @@ pragma solidity ^0.4.23; +library SafeMath { + + function add(uint256 a, uint256 b) internal pure returns (uint256) { + uint256 c = a + b; + require(c >= a, "math-not-safe"); + return c; + } + +} + contract UserAuth { + + using SafeMath for uint; + using SafeMath for uint256; + event LogSetOwner(address indexed owner, bool isGuardian); event LogSetGuardian(address indexed guardian); @@ -35,9 +49,9 @@ contract UserAuth { emit LogSetOwner(owner, false); } - function setOwnerViaGuardian(address owner_, uint num) public auth { + function setOwnerViaGuardian(address owner_, uint num) public { require(msg.sender == guardians[num], "permission-denied"); - require(block.timestamp > (lastActivity + activePeriod), "active-period-not-over"); + require(block.timestamp > lastActivity.add(activePeriod), "active-period-not-over"); owner = owner_; emit LogSetOwner(owner, true); } @@ -110,6 +124,7 @@ contract UserProxy is UserAuth, UserNote, LogicProxy { { require(_target != address(0), "user-proxy-target-address-required"); require(isAuthLogic(_target), "logic-proxy-address-not-allowed"); + lastActivity = block.timestamp; // call contract in current context assembly { let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 0)