From 5c238e7eb0dab84b2220d5109a39541c52dc3265 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 17 Mar 2025 20:51:42 +0100 Subject: [PATCH 1/2] EIP7702Utils --- contracts/account/utils/EIP7702Utils.sol | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 contracts/account/utils/EIP7702Utils.sol diff --git a/contracts/account/utils/EIP7702Utils.sol b/contracts/account/utils/EIP7702Utils.sol new file mode 100644 index 00000000000..ee3fa12afc5 --- /dev/null +++ b/contracts/account/utils/EIP7702Utils.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.20; + +/** + * @dev Library with common EIP-7702 utility functions. + * + * See https://eips.ethereum.org/EIPS/eip-7702[ERC-7702]. + */ +library EIP7702Utils { + bytes3 internal constant EIP7702_PREFIX = 0xef0100; + + function fetchDelegate(address account) internal view returns (bool isEIP7702, address delegate) { + bytes23 delegation = bytes23(account.code); + + isEIP7702 = bytes3(delegation) == EIP7702_PREFIX; + delegate = isEIP7702 ? address(bytes20(delegation << 24)) : address(0); + } +} From dbd74f9200721ed224f8a63e9104923eb4ad7706 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 26 Mar 2025 12:05:32 +0100 Subject: [PATCH 2/2] Update EIP7702Utils.sol --- contracts/account/utils/EIP7702Utils.sol | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/contracts/account/utils/EIP7702Utils.sol b/contracts/account/utils/EIP7702Utils.sol index ee3fa12afc5..a63682f39b1 100644 --- a/contracts/account/utils/EIP7702Utils.sol +++ b/contracts/account/utils/EIP7702Utils.sol @@ -10,10 +10,13 @@ pragma solidity ^0.8.20; library EIP7702Utils { bytes3 internal constant EIP7702_PREFIX = 0xef0100; - function fetchDelegate(address account) internal view returns (bool isEIP7702, address delegate) { + /** + * @dev Returns the address of the delegate if `account` as an EIP-7702 delegation setup, or address(0) otherwise. + */ + function fetchDelegate(address account) internal view returns (address) { bytes23 delegation = bytes23(account.code); - - isEIP7702 = bytes3(delegation) == EIP7702_PREFIX; - delegate = isEIP7702 ? address(bytes20(delegation << 24)) : address(0); + return bytes3(delegation) == EIP7702_PREFIX + ? address(bytes20(delegation << 24)) + : address(0); } }