Skip to content

Instantly share code, notes, and snippets.

@Perseverance
Created October 2, 2018 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Perseverance/b98f2c637168f2aaac259ab8b67afa4f to your computer and use it in GitHub Desktop.
Save Perseverance/b98f2c637168f2aaac259ab8b67afa4f to your computer and use it in GitHub Desktop.
contract IdentityContract {
uint256 public nonce;
function getSigner(bytes32 raw, bytes sig) public view returns(address signer) {
return ECTools.prefixedRecover(raw, sig);
}
modifier onlyValidSignature(uint256 relayerReward, address target, uint256 value, bytes data, bytes dataHashSignature) {
bytes32 dataHash = keccak256(abi.encodePacked(data, relayerReward, value, target, nonce));
address signer = getSigner(dataHash, dataHashSignature);
require(isSigner[signer]);
emit LogActionAuthorised(nonce, signer);
_;
}
/**
     * @dev executes a transaction only if it is formatted and signed by the owner of this. Anyone can call execute. Nonce introduced as anti replay attack mechanism.
     *
     * @param relayerReward - the value to be sent back to the relayer
     * @param target - the contract to be called
     * @param value - the value to be sent to the target
     * @param data - the data to be sent to be target
     * @param dataHashSignature - signed bytes of the keccak256 of target, nonce, value and data keccak256(target, nonce, value, data)
     */
function execute(address target, uint256 relayerReward, uint256 value, bytes data, bytes dataHashSignature) public payable onlyValidSignature(relayerReward, target, value, data, dataHashSignature) returns (bool) {
// solium-disable-next-line security/no-call-value
nonce++;
require(target.call.value(value)(data));
emit LogActionExecuted(nonce-1, target, relayerReward, value, data, dataHashSignature);
require(rewardMsgSender(relayerReward));
return true;
}
function rewardMsgSender(uint256 reward) internal returns(bool) {
// Override this to make your reward logic work
msg.sender.transfer(reward);
emit LogRewardsPaid(nonce-1, msg.sender, reward, deployer, 0x0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment