Skip to content

Instantly share code, notes, and snippets.

@adietrichs
Last active May 7, 2021 04:16
Show Gist options
  • Save adietrichs/865f6445453b2f6af605a48734036a2a to your computer and use it in GitHub Desktop.
Save adietrichs/865f6445453b2f6af605a48734036a2a to your computer and use it in GitHub Desktop.
EIP-3074
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract AuthorizeProxy {
address public latestSigner;
function call(uint256 commit, uint256 v, uint256 r, uint256 s, uint256 _gas, address payable addr, bytes memory data) external payable {
address signer;
bool success;
assembly {
signer := auth(commit, v, r, s)
success := authcall(_gas, addr, callvalue(), 0, add(data, 0x20), mload(data), 0, 0)
}
require(success, "authcall failed");
latestSigner = signer;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TrustedProxy {
struct Signature {
bool v;
uint256 r;
uint256 s;
}
struct Call {
uint64 gas;
address addr;
uint256 value;
bytes data;
}
function auth(Signature calldata sig) public view returns (address signer) {
bytes32 commit = bytes32(uint256(uint160(msg.sender)));
bool v = sig.v; uint256 r = sig.r; uint256 s = sig.s;
assembly {
signer := auth(commit, v, r, s)
}
}
function authcall(Call calldata call) internal returns (bool success) {
uint64 _gas = call.gas; address addr = call.addr; uint256 value = call.value; bytes memory data = call.data;
assembly {
success := authcall(_gas, addr, value, 0, add(data, 0x20), mload(data), 0, 0)
}
}
function requireAll(Signature calldata sig, Call[] calldata calls) external payable {
address signer = auth(sig);
require(signer != address(0), "invalid signature!");
for (uint256 i = 0; i < calls.length; i++) {
bool success = authcall(calls[i]);
require(success, "unsuccessful call!");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment