Skip to content

Commit

Permalink
Remove EIP-712 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikesymmetry authored Oct 8, 2024
1 parent d77c53b commit d648a6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 109 deletions.
80 changes: 0 additions & 80 deletions src/EIP712.sol

This file was deleted.

35 changes: 6 additions & 29 deletions src/SpendPermissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import {IERC1271} from "openzeppelin-contracts/contracts/interfaces/IERC1271.sol
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {CoinbaseSmartWallet} from "smart-wallet/CoinbaseSmartWallet.sol";

import {EIP712} from "./EIP712.sol";

/// @title SpendPermissions
///
/// @notice Allow spending native and ERC20 tokens with a recurring allowance.
///
/// @dev Allowance and spend values capped at uint160 ~ 1e48.
///
/// @author Coinbase (https://github.com/coinbase/smart-wallet-permissions)
contract SpendPermissions is EIP712 {
contract SpendPermissions {
/// @notice A recurring allowance for an external spender to withdraw an account's tokens.
struct RecurringAllowance {
/// @dev Smart account this recurring allowance is valid for.
Expand Down Expand Up @@ -43,11 +41,6 @@ contract SpendPermissions is EIP712 {
uint160 spend;
}

/// @notice Hash of EIP-712 message type
bytes32 internal constant _RECURRING_ALLOWANCE_TYPEHASH = keccak256(
"RecurringAllowance(address account,address spender,address token,uint48 start,uint48 end,uint48 period,uint160 allowance)"
);

/// @notice ERC-7528 address convention for ether (https://eips.ethereum.org/EIPS/eip-7528).
address public constant ETHER = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

Expand Down Expand Up @@ -169,7 +162,10 @@ contract SpendPermissions is EIP712 {
/// @param signature Signed hash of the recurring allowance data.
function permit(RecurringAllowance memory recurringAllowance, bytes memory signature) public {
// validate signature over recurring allowance data
if (_isValidSignature(recurringAllowance.account, getHash(recurringAllowance), signature)) {
if (
IERC1271(recurringAllowance.account).isValidSignature(getHash(recurringAllowance), signature)
!= IERC1271.isValidSignature.selector
) {
revert UnauthorizedRecurringAllowance();
}

Expand Down Expand Up @@ -198,7 +194,7 @@ contract SpendPermissions is EIP712 {
///
/// @return hash Hash of the recurring allowance and replay protection parameters.
function getHash(RecurringAllowance memory recurringAllowance) public view returns (bytes32) {
return _eip712Hash(keccak256(abi.encode(_RECURRING_ALLOWANCE_TYPEHASH, recurringAllowance)));
return keccak256(abi.encode(recurringAllowance, block.chainid, address(this)));
}

/// @notice Return if recurring allowance is authorized i.e. approved and not revoked.
Expand Down Expand Up @@ -332,23 +328,4 @@ contract SpendPermissions is EIP712 {
function _execute(address account, address target, uint256 value, bytes memory data) internal virtual {
CoinbaseSmartWallet(payable(account)).execute({target: target, value: value, data: data});
}

/// @notice Validate an EIP-1271 contract signature.
///
/// @param account Address of the user account.
/// @param hash Hash of the message.
/// @param signature Bytes for the user signature.
///
/// @return isValid True if signature is valid.
function _isValidSignature(address account, bytes32 hash, bytes memory signature) internal view returns (bool) {
return IERC1271(account).isValidSignature(hash, signature) != IERC1271.isValidSignature.selector;
}

/// @notice Returns the domain name and version to use when creating EIP-712 signatures.
///
/// @return name The user readable name of signing domain.
/// @return version The current major version of the signing domain.
function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) {
return ("SpendPermissions", "1");
}
}

0 comments on commit d648a6e

Please sign in to comment.