2019-04-06 12:49:08 +00:00
|
|
|
pragma solidity ^0.5.2;
|
2019-03-10 19:38:53 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
2019-04-03 18:59:32 +00:00
|
|
|
* @title RegistryInterface Interface
|
2019-03-18 21:14:58 +00:00
|
|
|
*/
|
2019-04-03 18:59:32 +00:00
|
|
|
interface RegistryInterface {
|
|
|
|
function logic(address logicAddr) external view returns (bool);
|
|
|
|
function record(address currentOwner, address nextOwner) external;
|
2019-03-18 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 13:05:47 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
2019-03-19 20:20:40 +00:00
|
|
|
* @title Address Registry Record
|
2019-03-18 21:14:58 +00:00
|
|
|
*/
|
2019-03-18 22:39:43 +00:00
|
|
|
contract AddressRecord {
|
|
|
|
|
|
|
|
/**
|
2019-03-19 20:20:40 +00:00
|
|
|
* @dev address registry of system, logic and wallet addresses
|
2019-03-18 22:39:43 +00:00
|
|
|
*/
|
|
|
|
address public registry;
|
2019-03-24 21:49:14 +00:00
|
|
|
|
|
|
|
/**
|
2019-04-02 23:24:36 +00:00
|
|
|
* @dev Throws if the logic is not authorised
|
2019-03-24 21:49:14 +00:00
|
|
|
*/
|
2019-04-02 23:24:36 +00:00
|
|
|
modifier logicAuth(address logicAddr) {
|
|
|
|
require(logicAddr != address(0), "logic-proxy-address-required");
|
2019-04-03 18:59:32 +00:00
|
|
|
bool islogic = RegistryInterface(registry).logic(logicAddr);
|
|
|
|
require(islogic, "logic-not-authorised");
|
2019-04-02 23:24:36 +00:00
|
|
|
_;
|
2019-03-24 21:49:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 22:39:43 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
|
|
|
* @title User Auth
|
|
|
|
*/
|
2019-03-18 22:39:43 +00:00
|
|
|
contract UserAuth is AddressRecord {
|
2019-03-11 12:30:45 +00:00
|
|
|
|
2019-04-02 23:15:32 +00:00
|
|
|
event LogSetOwner(address indexed owner);
|
2019-03-10 11:23:11 +00:00
|
|
|
address public owner;
|
2019-03-09 20:42:05 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
|
|
|
* @dev Throws if not called by owner or contract itself
|
|
|
|
*/
|
2019-03-09 20:42:05 +00:00
|
|
|
modifier auth {
|
2019-03-10 11:23:11 +00:00
|
|
|
require(isAuth(msg.sender), "permission-denied");
|
2019-03-09 20:42:05 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
2019-04-02 23:15:32 +00:00
|
|
|
* @dev sets new owner
|
2019-03-19 20:20:40 +00:00
|
|
|
*/
|
2019-04-02 23:15:32 +00:00
|
|
|
function setOwner(address nextOwner) public auth {
|
2019-04-03 18:59:32 +00:00
|
|
|
RegistryInterface(registry).record(owner, nextOwner);
|
2019-04-02 23:15:32 +00:00
|
|
|
owner = nextOwner;
|
|
|
|
emit LogSetOwner(nextOwner);
|
2019-03-19 20:20:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
|
|
|
* @dev checks if called by owner or contract itself
|
|
|
|
* @param src is the address initiating the call
|
|
|
|
*/
|
2019-03-24 21:49:14 +00:00
|
|
|
function isAuth(address src) public view returns (bool) {
|
2019-04-02 23:15:32 +00:00
|
|
|
if (src == owner) {
|
2019-03-11 12:30:45 +00:00
|
|
|
return true;
|
2019-04-02 23:15:32 +00:00
|
|
|
} else if (src == address(this)) {
|
2019-03-19 14:03:31 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 21:14:58 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 22:39:43 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
/**
|
|
|
|
* @dev logging the execute events
|
|
|
|
*/
|
2019-03-10 07:40:51 +00:00
|
|
|
contract UserNote {
|
2019-03-11 22:28:00 +00:00
|
|
|
event LogNote(
|
|
|
|
bytes4 indexed sig,
|
|
|
|
address indexed guy,
|
|
|
|
bytes32 indexed foo,
|
|
|
|
bytes32 bar,
|
|
|
|
uint wad,
|
|
|
|
bytes fax
|
|
|
|
);
|
2019-03-09 20:42:05 +00:00
|
|
|
|
|
|
|
modifier note {
|
|
|
|
bytes32 foo;
|
|
|
|
bytes32 bar;
|
|
|
|
assembly {
|
|
|
|
foo := calldataload(4)
|
|
|
|
bar := calldataload(36)
|
|
|
|
}
|
2019-03-11 12:30:45 +00:00
|
|
|
emit LogNote(
|
|
|
|
msg.sig,
|
|
|
|
msg.sender,
|
|
|
|
foo,
|
|
|
|
bar,
|
2019-04-02 23:15:32 +00:00
|
|
|
msg.value,
|
2019-03-11 12:30:45 +00:00
|
|
|
msg.data
|
|
|
|
);
|
2019-03-09 20:42:05 +00:00
|
|
|
_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-11 12:30:45 +00:00
|
|
|
|
2019-03-18 21:49:39 +00:00
|
|
|
/**
|
2019-03-18 22:39:43 +00:00
|
|
|
* @title User Owned Contract Wallet
|
2019-03-18 21:49:39 +00:00
|
|
|
*/
|
2019-04-02 23:24:36 +00:00
|
|
|
contract UserWallet is UserAuth, UserNote {
|
2019-03-11 12:30:45 +00:00
|
|
|
|
2019-03-22 22:25:46 +00:00
|
|
|
event LogExecute(address sender, address target, uint srcNum, uint sessionNum);
|
2019-03-18 21:49:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev sets the "address registry", owner's last activity, owner's active period and initial owner
|
|
|
|
*/
|
2019-03-19 20:20:40 +00:00
|
|
|
constructor() public {
|
2019-03-18 22:39:43 +00:00
|
|
|
registry = msg.sender;
|
2019-04-02 23:15:32 +00:00
|
|
|
owner = msg.sender;
|
2019-03-09 20:42:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-10 08:38:03 +00:00
|
|
|
function() external payable {}
|
2019-03-09 20:42:05 +00:00
|
|
|
|
2019-03-18 21:49:39 +00:00
|
|
|
/**
|
2019-04-06 12:49:08 +00:00
|
|
|
* @dev Execute authorised calls via delegate call
|
2019-03-18 21:49:39 +00:00
|
|
|
* @param _target logic proxy address
|
|
|
|
* @param _data delegate call data
|
2019-04-06 12:49:08 +00:00
|
|
|
* @param _srcNum to find the source
|
|
|
|
* @param _sessionNum to find the session
|
2019-03-18 21:49:39 +00:00
|
|
|
*/
|
|
|
|
function execute(
|
|
|
|
address _target,
|
|
|
|
bytes memory _data,
|
2019-04-06 12:49:08 +00:00
|
|
|
uint _srcNum,
|
|
|
|
uint _sessionNum
|
2019-03-18 21:49:39 +00:00
|
|
|
)
|
|
|
|
public
|
|
|
|
payable
|
|
|
|
note
|
2019-04-02 23:15:32 +00:00
|
|
|
auth
|
2019-04-02 23:24:36 +00:00
|
|
|
logicAuth(_target)
|
2019-03-18 21:49:39 +00:00
|
|
|
returns (bytes memory response)
|
|
|
|
{
|
2019-03-22 22:25:46 +00:00
|
|
|
emit LogExecute(
|
|
|
|
msg.sender,
|
|
|
|
_target,
|
2019-04-06 12:49:08 +00:00
|
|
|
_srcNum,
|
|
|
|
_sessionNum
|
2019-03-22 22:25:46 +00:00
|
|
|
);
|
2019-03-18 21:49:39 +00:00
|
|
|
|
2019-03-09 20:42:05 +00:00
|
|
|
// call contract in current context
|
|
|
|
assembly {
|
|
|
|
let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 0)
|
|
|
|
let size := returndatasize
|
|
|
|
|
|
|
|
response := mload(0x40)
|
|
|
|
mstore(0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))))
|
|
|
|
mstore(response, size)
|
|
|
|
returndatacopy(add(response, 0x20), 0, size)
|
|
|
|
|
|
|
|
switch iszero(succeeded)
|
2019-03-11 12:30:45 +00:00
|
|
|
case 1 {
|
|
|
|
// throw if delegatecall failed
|
|
|
|
revert(add(response, 0x20), size)
|
|
|
|
}
|
2019-03-09 20:42:05 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-18 21:14:58 +00:00
|
|
|
|
2019-03-19 14:03:31 +00:00
|
|
|
}
|