Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- MinimalForwarder
- Optimization enabled
- true
- Compiler version
- v0.8.0+commit.c7dfd78e
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2021-06-06T18:18:05.520870Z
Contract source code
// Sources flattened with hardhat v2.3.0 https://hardhat.org
// File @openzeppelin/contracts/utils/cryptography/[email protected]
pragma solidity ^0.8.0;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
// Check the signature length
// - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) {
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
} else if (signature.length == 64) {
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
assembly {
let vs := mload(add(signature, 0x40))
r := mload(add(signature, 0x20))
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
}
} else {
revert("ECDSA: invalid signature length");
}
return recover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value");
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
require(signer != address(0), "ECDSA: invalid signature");
return signer;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
}
}
// File @openzeppelin/contracts/utils/cryptography/[email protected]
pragma solidity ^0.8.0;
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* _Available since v3.4._
*/
abstract contract EIP712 {
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {
return keccak256(
abi.encode(
typeHash,
name,
version,
block.chainid,
address(this)
)
);
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
}
// File @openzeppelin/contracts/metatx/[email protected]
pragma solidity ^0.8.0;
/*
* @dev Simple minimal forwarder to be used together with an ERC2771 compatible contract. See {ERC2771Context}.
*/
contract MinimalForwarder is EIP712 {
using ECDSA for bytes32;
struct ForwardRequest {
address from;
address to;
uint256 value;
uint256 gas;
uint256 nonce;
bytes data;
}
bytes32 private constant TYPEHASH = keccak256("ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,bytes data)");
mapping(address => uint256) private _nonces;
constructor() EIP712("MinimalForwarder", "0.0.1") {}
function getNonce(address from) public view returns (uint256) {
return _nonces[from];
}
function verify(ForwardRequest calldata req, bytes calldata signature) public view returns (bool) {
address signer = _hashTypedDataV4(keccak256(abi.encode(
TYPEHASH,
req.from,
req.to,
req.value,
req.gas,
req.nonce,
keccak256(req.data)
))).recover(signature);
return _nonces[req.from] == req.nonce && signer == req.from;
}
function execute(ForwardRequest calldata req, bytes calldata signature) public payable returns (bool, bytes memory) {
require(verify(req, signature), "MinimalForwarder: signature does not match request");
_nonces[req.from] = req.nonce + 1;
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = req.to.call{gas: req.gas, value: req.value}(abi.encodePacked(req.data, req.from));
// Validate that the relayer has sent enough gas for the call.
// See https://ronan.eth.link/blog/ethereum-gas-dangers/
assert(gasleft() > req.gas / 63);
return (success, returndata);
}
}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"function","stateMutability":"payable","outputs":[{"type":"bool","name":"","internalType":"bool"},{"type":"bytes","name":"","internalType":"bytes"}],"name":"execute","inputs":[{"type":"tuple","name":"req","internalType":"struct MinimalForwarder.ForwardRequest","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"uint256","name":"gas","internalType":"uint256"},{"type":"uint256","name":"nonce","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"bytes","name":"signature","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"getNonce","inputs":[{"type":"address","name":"from","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"verify","inputs":[{"type":"tuple","name":"req","internalType":"struct MinimalForwarder.ForwardRequest","components":[{"type":"address","name":"from","internalType":"address"},{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"value","internalType":"uint256"},{"type":"uint256","name":"gas","internalType":"uint256"},{"type":"uint256","name":"nonce","internalType":"uint256"},{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"bytes","name":"signature","internalType":"bytes"}]}]
Contract Creation Code
0x61012060405234801561001157600080fd5b50604080518082018252601081526f26b4b734b6b0b62337b93bb0b93232b960811b602080830191825283518085019094526005845264302e302e3160d81b908401528151902060c08190527fae209a0b48f21c054280f2455d32cf309387644879d9acbd8ffc19916381188560e08190524660a0529192917f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6100b68184846100c7565b608052610100525061012d92505050565b600083838346306040516020016100e2959493929190610101565b6040516020818303038152906040528051906020012090509392505050565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b60805160a05160c05160e05161010051610a906101716000396000610484015260006104c6015260006104a5015260006104320152600061045b0152610a906000f3fe6080604052600436106100345760003560e01c80632d0335ab1461003957806347153f821461006f578063bf5d3bdb14610090575b600080fd5b34801561004557600080fd5b5061005961005436600461064a565b6100bd565b6040516100669190610991565b60405180910390f35b61008261007d366004610678565b6100d8565b60405161006692919061078b565b34801561009c57600080fd5b506100b06100ab366004610678565b61023e565b6040516100669190610780565b6001600160a01b031660009081526020819052604090205490565b600060606100e785858561023e565b61010c5760405162461bcd60e51b815260040161010390610884565b60405180910390fd5b61011b608086013560016109e6565b60008061012b602089018961064a565b6001600160a01b03166001600160a01b0316815260200190815260200160002081905550600080866020016020810190610165919061064a565b6001600160a01b03166060880135604089013561018560a08b018b61099a565b61019260208d018d61064a565b6040516020016101a493929190610720565b60408051601f19818403018152908290526101be91610749565b600060405180830381858888f193505050503d80600081146101fc576040519150601f19603f3d011682016040523d82523d6000602084013e610201565b606091505b509092509050610216603f6060890135610a0a565b5a1161023257634e487b7160e01b600052600160045260246000fd5b90969095509350505050565b60008061032484848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061031e92507fdd8f4b70b0f4393e889bd39128a30628a78b61816a9eb8199759e7a349657e4891506102ae905060208a018a61064a565b6102be60408b0160208c0161064a565b60408b013560608c013560808d01356102da60a08f018f61099a565b6040516102e8929190610710565b604051908190038120610303979695949392916020016107c7565b6040516020818303038152906040528051906020012061038f565b906103a8565b9050608085013560008061033b602089018961064a565b6001600160a01b03166001600160a01b03168152602001908152602001600020541480156103865750610371602086018661064a565b6001600160a01b0316816001600160a01b0316145b95945050505050565b60006103a261039c61042e565b836104f0565b92915050565b6000806000808451604114156103d25750505060208201516040830151606084015160001a610418565b8451604014156104005750505060408201516020830151906001600160ff1b0381169060ff1c601b01610418565b60405162461bcd60e51b8152600401610103906108d6565b61042486828585610523565b9695505050505050565b60007f000000000000000000000000000000000000000000000000000000000000000046141561047f57507f00000000000000000000000000000000000000000000000000000000000000006104ed565b6104ea7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000610610565b90505b90565b60008282604051602001610505929190610765565b60405160208183030381529060405280519060200120905092915050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08211156105655760405162461bcd60e51b81526004016101039061090d565b8360ff16601b148061057a57508360ff16601c145b6105965760405162461bcd60e51b81526004016101039061094f565b6000600186868686604051600081526020016040526040516105bb949392919061082f565b6020604051602081039080840390855afa1580156105dd573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166103865760405162461bcd60e51b81526004016101039061084d565b6000838383463060405160200161062b959493929190610803565b6040516020818303038152906040528051906020012090509392505050565b60006020828403121561065b578081fd5b81356001600160a01b0381168114610671578182fd5b9392505050565b60008060006040848603121561068c578182fd5b833567ffffffffffffffff808211156106a3578384fd5b9085019060c082880312156106b6578384fd5b909350602085013590808211156106cb578384fd5b818601915086601f8301126106de578384fd5b8135818111156106ec578485fd5b8760208285010111156106fd578485fd5b6020830194508093505050509250925092565b6000828483379101908152919050565b6000838583375060609190911b6bffffffffffffffffffffffff19169101908152601401919050565b6000825161075b818460208701610a2a565b9190910192915050565b61190160f01b81526002810192909252602282015260420190565b901515815260200190565b600083151582526040602083015282518060408401526107b2816060850160208701610a2a565b601f01601f1916919091016060019392505050565b9687526001600160a01b0395861660208801529390941660408601526060850191909152608084015260a083019190915260c082015260e00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b60208082526018908201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604082015260600190565b60208082526032908201527f4d696e696d616c466f727761726465723a207369676e617475726520646f6573604082015271081b9bdd081b585d18da081c995c5d595cdd60721b606082015260800190565b6020808252601f908201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604082015260600190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604082015261756560f01b606082015260800190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604082015261756560f01b606082015260800190565b90815260200190565b6000808335601e198436030181126109b0578283fd5b83018035915067ffffffffffffffff8211156109ca578283fd5b6020019150368190038213156109df57600080fd5b9250929050565b60008219821115610a0557634e487b7160e01b81526011600452602481fd5b500190565b600082610a2557634e487b7160e01b81526012600452602481fd5b500490565b60005b83811015610a45578181015183820152602001610a2d565b83811115610a54576000848401525b5050505056fea264697066735822122029a53885c5a96a603146f772152e446a3b820fabfb47258f6befd3a1bc40378364736f6c63430008000033
Deployed ByteCode
0x6080604052600436106100345760003560e01c80632d0335ab1461003957806347153f821461006f578063bf5d3bdb14610090575b600080fd5b34801561004557600080fd5b5061005961005436600461064a565b6100bd565b6040516100669190610991565b60405180910390f35b61008261007d366004610678565b6100d8565b60405161006692919061078b565b34801561009c57600080fd5b506100b06100ab366004610678565b61023e565b6040516100669190610780565b6001600160a01b031660009081526020819052604090205490565b600060606100e785858561023e565b61010c5760405162461bcd60e51b815260040161010390610884565b60405180910390fd5b61011b608086013560016109e6565b60008061012b602089018961064a565b6001600160a01b03166001600160a01b0316815260200190815260200160002081905550600080866020016020810190610165919061064a565b6001600160a01b03166060880135604089013561018560a08b018b61099a565b61019260208d018d61064a565b6040516020016101a493929190610720565b60408051601f19818403018152908290526101be91610749565b600060405180830381858888f193505050503d80600081146101fc576040519150601f19603f3d011682016040523d82523d6000602084013e610201565b606091505b509092509050610216603f6060890135610a0a565b5a1161023257634e487b7160e01b600052600160045260246000fd5b90969095509350505050565b60008061032484848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061031e92507fdd8f4b70b0f4393e889bd39128a30628a78b61816a9eb8199759e7a349657e4891506102ae905060208a018a61064a565b6102be60408b0160208c0161064a565b60408b013560608c013560808d01356102da60a08f018f61099a565b6040516102e8929190610710565b604051908190038120610303979695949392916020016107c7565b6040516020818303038152906040528051906020012061038f565b906103a8565b9050608085013560008061033b602089018961064a565b6001600160a01b03166001600160a01b03168152602001908152602001600020541480156103865750610371602086018661064a565b6001600160a01b0316816001600160a01b0316145b95945050505050565b60006103a261039c61042e565b836104f0565b92915050565b6000806000808451604114156103d25750505060208201516040830151606084015160001a610418565b8451604014156104005750505060408201516020830151906001600160ff1b0381169060ff1c601b01610418565b60405162461bcd60e51b8152600401610103906108d6565b61042486828585610523565b9695505050505050565b60007f000000000000000000000000000000000000000000000000000000000000004d46141561047f57507ff74179abcc4afe2c9debd383fe314a09bc876e44a59c54004a2ad20e49826dce6104ed565b6104ea7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f9e0923a39f515e9a8cebc9fb694b9abf7e4b8c3f7ab6f81b56eabdac504b08dc7fae209a0b48f21c054280f2455d32cf309387644879d9acbd8ffc199163811885610610565b90505b90565b60008282604051602001610505929190610765565b60405160208183030381529060405280519060200120905092915050565b60007f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08211156105655760405162461bcd60e51b81526004016101039061090d565b8360ff16601b148061057a57508360ff16601c145b6105965760405162461bcd60e51b81526004016101039061094f565b6000600186868686604051600081526020016040526040516105bb949392919061082f565b6020604051602081039080840390855afa1580156105dd573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166103865760405162461bcd60e51b81526004016101039061084d565b6000838383463060405160200161062b959493929190610803565b6040516020818303038152906040528051906020012090509392505050565b60006020828403121561065b578081fd5b81356001600160a01b0381168114610671578182fd5b9392505050565b60008060006040848603121561068c578182fd5b833567ffffffffffffffff808211156106a3578384fd5b9085019060c082880312156106b6578384fd5b909350602085013590808211156106cb578384fd5b818601915086601f8301126106de578384fd5b8135818111156106ec578485fd5b8760208285010111156106fd578485fd5b6020830194508093505050509250925092565b6000828483379101908152919050565b6000838583375060609190911b6bffffffffffffffffffffffff19169101908152601401919050565b6000825161075b818460208701610a2a565b9190910192915050565b61190160f01b81526002810192909252602282015260420190565b901515815260200190565b600083151582526040602083015282518060408401526107b2816060850160208701610a2a565b601f01601f1916919091016060019392505050565b9687526001600160a01b0395861660208801529390941660408601526060850191909152608084015260a083019190915260c082015260e00190565b9485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b93845260ff9290921660208401526040830152606082015260800190565b60208082526018908201527f45434453413a20696e76616c6964207369676e61747572650000000000000000604082015260600190565b60208082526032908201527f4d696e696d616c466f727761726465723a207369676e617475726520646f6573604082015271081b9bdd081b585d18da081c995c5d595cdd60721b606082015260800190565b6020808252601f908201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604082015260600190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c604082015261756560f01b606082015260800190565b60208082526022908201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c604082015261756560f01b606082015260800190565b90815260200190565b6000808335601e198436030181126109b0578283fd5b83018035915067ffffffffffffffff8211156109ca578283fd5b6020019150368190038213156109df57600080fd5b9250929050565b60008219821115610a0557634e487b7160e01b81526011600452602481fd5b500190565b600082610a2557634e487b7160e01b81526012600452602481fd5b500490565b60005b83811015610a45578181015183820152602001610a2d565b83811115610a54576000848401525b5050505056fea264697066735822122029a53885c5a96a603146f772152e446a3b820fabfb47258f6befd3a1bc40378364736f6c63430008000033