Last active
May 7, 2021 04:16
-
-
Save adietrichs/865f6445453b2f6af605a48734036a2a to your computer and use it in GitHub Desktop.
EIP-3074
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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