Skip to content

Commit 9f1c781

Browse files
authored
Add documentation for ERC-7702 delegation (#105)
1 parent 43beb35 commit 9f1c781

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// contracts/MyAccountERC7702.sol
2+
// SPDX-License-Identifier: MIT
3+
pragma solidity ^0.8.20;
4+
5+
import {Account} from "../../../account/Account.sol";
6+
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
7+
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
8+
import {ERC7821} from "../../../account/extensions/ERC7821.sol";
9+
import {SignerERC7702} from "../../../utils/cryptography/SignerERC7702.sol";
10+
11+
contract MyAccountERC7702 is Account, SignerERC7702, ERC7821, ERC721Holder, ERC1155Holder {
12+
/// @dev Allows the entry point as an authorized executor.
13+
function _erc7821AuthorizedExecutor(
14+
address caller,
15+
bytes32 mode,
16+
bytes calldata executionData
17+
) internal view virtual override returns (bool) {
18+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
19+
}
20+
}

contracts/utils/README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Miscellaneous contracts and libraries containing utility functions you can use t
2323

2424
{{SignerP256}}
2525

26+
{{SignerERC7702}}
27+
2628
{{SignerRSA}}
2729

2830
== Libraries

docs/modules/ROOT/pages/account-abstraction.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,20 @@ These rules outline the requirements for operations to be processed by the canon
180180
Accounts can access its own storage during the validation phase, they might easily violate ERC-7562 storage access rules in undirect ways. For example, most accounts access their public keys from storage when validating a signature, limiting the ability of having accounts that validate operations for other accounts (e.g. via ERC-1271)
181181

182182
TIP: Although any Account that breaks such rules may still be processed by a private bundler, developers should keep in mind the centralization tradeoffs of relying on private infrastructure instead of _permissionless_ execution.
183+
184+
=== EIP-7702 Delegation
185+
186+
EIP-7702 enables EOAs to temporarily delegate their execution capabilities to smart contracts. This is particularly useful for:
187+
188+
* Batching multiple operations in a single transaction
189+
* Sponsoring transactions for other users
190+
* Implementing privilege de-escalation (e.g., sub-keys with limited permissions)
191+
192+
xref:api:utils.adoc#SignerERC7702[`SignerERC7702`] helps implement EIP-7702 delegation in smart contract accounts by validating signatures using the EOA's address (i.e., `address(this)`).
193+
194+
[source,solidity]
195+
----
196+
include::api:example$account/MyAccountERC7702.sol[]
197+
----
198+
199+
TIP: Users can delegate to an instance of xref:api:account.adoc#ERC7821[`ERC7821`] for a minimal batch executor that does not use ERC-4337 related code.

0 commit comments

Comments
 (0)