Skip to content

Commit 120127b

Browse files
ernestognwAmxx
andauthored
Split ERC-7821 executor into its own contract (#61)
Co-authored-by: Hadrien Croubois <[email protected]>
1 parent e30bd56 commit 120127b

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 13-01-2025
22

33
- Rename `ERC7739Signer` into `ERC7739` to avoid confusion with the `AbstractSigner` family of contracts.
4+
- Remove `AccountERC7821` in favor of `ERC7821`, an ERC-7821 implementation that doesn't rely on (but is compatible with) `AccountCore`.
45

56
## 23-12-2024
67

contracts/account/Account.sol

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,26 @@ pragma solidity ^0.8.20;
55
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
66
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
77
import {ERC7739} from "../utils/cryptography/ERC7739.sol";
8+
import {ERC7821} from "./extensions/ERC7821.sol";
89
import {AccountCore} from "./AccountCore.sol";
9-
import {AccountERC7821} from "./extensions/AccountERC7821.sol";
1010

1111
/**
1212
* @dev Extension of {AccountCore} with recommended feature that most account abstraction implementation will want:
1313
*
14-
* * {AccountERC7821} for performing external calls in batches.
1514
* * {ERC721Holder} and {ERC1155Holder} to accept ERC-712 and ERC-1155 token transfers transfers.
1615
* * {ERC7739} for ERC-1271 signature support with ERC-7739 replay protection
16+
* * {ERC7821} for performing external calls in batches.
1717
*
1818
* NOTE: To use this contract, the {ERC7739-_rawSignatureValidation} function must be
1919
* implemented using a specific signature verification algorithm. See {SignerECDSA}, {SignerP256} or {SignerRSA}.
2020
*/
21-
abstract contract Account is AccountCore, AccountERC7821, ERC721Holder, ERC1155Holder, ERC7739 {}
21+
abstract contract Account is AccountCore, ERC721Holder, ERC1155Holder, ERC7739, ERC7821 {
22+
/// @inheritdoc ERC7821
23+
function _erc7821AuthorizedExecutor(
24+
address caller,
25+
bytes32 mode,
26+
bytes calldata executionData
27+
) internal view virtual override returns (bool) {
28+
return super._erc7821AuthorizedExecutor(caller, mode, executionData) || caller == address(entryPoint());
29+
}
30+
}

contracts/account/README.adoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
[.readme-notice]
33
NOTE: This document is better viewed at https://docs.openzeppelin.com/community-contracts/api/account
44

5-
This directory includes contracts to build accounts for ERC-4337.
5+
This directory includes contracts to build accounts for ERC-4337. These include:
6+
7+
* {AccountCore}: An ERC-4337 smart account implementation that includes the core logic to process user operations.
8+
* {Account}: An extension of `AccountCore` that implements the recommended features for ERC-4337 smart accounts.
9+
* {AccountSignerERC7702}: An account implementation with low-level signature validation performed by an EOA.
10+
* {ERC7821}: Minimal batch executor implementation contracts. Useful to enable easy batch execution for smart contracts.
611

712
== Core
813

@@ -14,4 +19,4 @@ This directory includes contracts to build accounts for ERC-4337.
1419

1520
{{AccountSignerERC7702}}
1621

17-
{{AccountERC7821}}
22+
{{ERC7821}}

contracts/account/extensions/AccountERC7821.sol renamed to contracts/account/extensions/ERC7821.sol

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ import {IERC7821} from "../../interfaces/IERC7821.sol";
77
import {AccountCore} from "../AccountCore.sol";
88

99
/**
10-
* @dev Minimal batch executor following ERC7821. Only supports basic mode (no optional "opData").
10+
* @dev Minimal batch executor following ERC-7821. Only supports basic mode (no optional "opData").
1111
*/
12-
abstract contract AccountERC7821 is AccountCore, IERC7821 {
12+
abstract contract ERC7821 is IERC7821 {
1313
using ERC7579Utils for *;
1414

1515
error UnsupportedExecutionMode();
1616

17-
/// @inheritdoc IERC7821
18-
function execute(bytes32 mode, bytes calldata executionData) public payable virtual onlyEntryPointOrSelf {
17+
/**
18+
* @dev Executes the calls in `executionData` with no optional `opData` support.
19+
*
20+
* NOTE: Access to this function is controlled by {_erc7821AuthorizedExecutor}. Changing access permissions, for
21+
* example to approve calls by the ERC-4337 entrypoint, should be implement by overriding it.
22+
*
23+
* Reverts and bubbles up error if any call fails.
24+
*/
25+
function execute(bytes32 mode, bytes calldata executionData) public payable virtual {
26+
if (!_erc7821AuthorizedExecutor(msg.sender, mode, executionData))
27+
revert AccountCore.AccountUnauthorized(msg.sender);
1928
if (!supportsExecutionMode(mode)) revert UnsupportedExecutionMode();
2029
executionData.execBatch(ERC7579Utils.EXECTYPE_DEFAULT);
2130
}
@@ -28,4 +37,15 @@ abstract contract AccountERC7821 is AccountCore, IERC7821 {
2837
execType == ERC7579Utils.EXECTYPE_DEFAULT &&
2938
modeSelector == ModeSelector.wrap(0x00000000);
3039
}
40+
41+
/**
42+
* @dev Access control mechanism for the {execute} function.
43+
*/
44+
function _erc7821AuthorizedExecutor(
45+
address caller,
46+
bytes32 /* mode */,
47+
bytes calldata /* executionData */
48+
) internal view virtual returns (bool) {
49+
return caller == address(this);
50+
}
3151
}

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[profile.default]
22
solc_version = '0.8.27'
33
evm_version = 'cancun'
4+
optimizer = true
5+
optimizer-runs = 200
46
src = 'contracts'
57
out = 'out'
68
libs = ['node_modules', 'lib']

0 commit comments

Comments
 (0)