Skip to content

Commit aa642cc

Browse files
ernestognwAmxx
andauthored
Remove ERC-7821 from Account.sol (#67)
Co-authored-by: Hadrien Croubois <[email protected]>
1 parent fed22bf commit aa642cc

File tree

13 files changed

+119
-22
lines changed

13 files changed

+119
-22
lines changed

contracts/account/Account.sol

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
77
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
88
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
99
import {ERC7739} from "../utils/cryptography/ERC7739.sol";
10-
import {ERC7821} from "./extensions/ERC7821.sol";
1110
import {AccountCore} from "./AccountCore.sol";
1211

1312
/**
@@ -17,10 +16,12 @@ import {AccountCore} from "./AccountCore.sol";
1716
* * {ERC7739} for ERC-1271 signature support with ERC-7739 replay protection
1817
* * {ERC7821} for performing external calls in batches.
1918
*
19+
* TIP: Use {ERC7821} to enable external calls in batches.
20+
*
2021
* NOTE: To use this contract, the {ERC7739-_rawSignatureValidation} function must be
2122
* implemented using a specific signature verification algorithm. See {SignerECDSA}, {SignerP256} or {SignerRSA}.
2223
*/
23-
abstract contract Account is AccountCore, EIP712, ERC721Holder, ERC1155Holder, ERC7739, ERC7821 {
24+
abstract contract Account is AccountCore, EIP712, ERC721Holder, ERC1155Holder, ERC7739 {
2425
bytes32 internal constant _PACKED_USER_OPERATION =
2526
keccak256(
2627
"PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData)"
@@ -52,13 +53,4 @@ abstract contract Account is AccountCore, EIP712, ERC721Holder, ERC1155Holder, E
5253
)
5354
);
5455
}
55-
56-
/// @inheritdoc ERC7821
57-
function _erc7821AuthorizedExecutor(
58-
address caller,
59-
bytes32 mode,
60-
bytes calldata executionData
61-
) internal view virtual override returns (bool) {
62-
return super._erc7821AuthorizedExecutor(caller, mode, executionData) || caller == address(entryPoint());
63-
}
6456
}

contracts/account/extensions/ERC7821.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ abstract contract ERC7821 is IERC7821 {
4040

4141
/**
4242
* @dev Access control mechanism for the {execute} function.
43+
* By default, only the contract itself is allowed to execute.
44+
*
45+
* Override this function to implement custom access control, for example to allow the
46+
* ERC-4337 entrypoint to execute.
47+
*
48+
* ```solidity
49+
* function _erc7821AuthorizedExecutor(
50+
* address caller,
51+
* bytes32 mode,
52+
* bytes calldata executionData
53+
* ) internal view virtual override returns (bool) {
54+
* return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
55+
* }
56+
* ```
4357
*/
4458
function _erc7821AuthorizedExecutor(
4559
address caller,

contracts/mocks/account/AccountECDSAMock.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
pragma solidity ^0.8.20;
44

55
import {Account} from "../../account/Account.sol";
6+
import {ERC7821} from "../../account/extensions/ERC7821.sol";
67
import {SignerECDSA} from "../../utils/cryptography/SignerECDSA.sol";
78

8-
abstract contract AccountECDSAMock is Account, SignerECDSA {
9+
abstract contract AccountECDSAMock is Account, SignerECDSA, ERC7821 {
910
constructor(address signerAddr) {
1011
_initializeSigner(signerAddr);
1112
}
13+
14+
/// @inheritdoc ERC7821
15+
function _erc7821AuthorizedExecutor(
16+
address caller,
17+
bytes32 mode,
18+
bytes calldata executionData
19+
) internal view virtual override returns (bool) {
20+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
21+
}
1222
}

contracts/mocks/account/AccountERC7702Mock.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
pragma solidity ^0.8.20;
44

55
import {Account} from "../../account/Account.sol";
6+
import {ERC7821} from "../../account/extensions/ERC7821.sol";
67
import {SignerERC7702} from "../../utils/cryptography/SignerERC7702.sol";
78

8-
abstract contract AccountERC7702Mock is Account, SignerERC7702 {}
9+
abstract contract AccountERC7702Mock is Account, SignerERC7702, ERC7821 {
10+
/// @inheritdoc ERC7821
11+
function _erc7821AuthorizedExecutor(
12+
address caller,
13+
bytes32 mode,
14+
bytes calldata executionData
15+
) internal view virtual override returns (bool) {
16+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
17+
}
18+
}

contracts/mocks/account/AccountMock.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
pragma solidity ^0.8.20;
44

55
import {PackedUserOperation} from "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
6+
import {ERC7821} from "../../account/extensions/ERC7821.sol";
67
import {ERC4337Utils} from "@openzeppelin/contracts/account/utils/draft-ERC4337Utils.sol";
78
import {Account} from "../../account/Account.sol";
89

9-
abstract contract AccountMock is Account {
10+
abstract contract AccountMock is Account, ERC7821 {
1011
/// Validates a user operation with a boolean signature.
1112
function _rawSignatureValidation(
1213
bytes32 /* userOpHash */,
1314
bytes calldata signature
1415
) internal pure override returns (bool) {
1516
return bytes1(signature[0:1]) == bytes1(0x01);
1617
}
18+
19+
/// @inheritdoc ERC7821
20+
function _erc7821AuthorizedExecutor(
21+
address caller,
22+
bytes32 mode,
23+
bytes calldata executionData
24+
) internal view virtual override returns (bool) {
25+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
26+
}
1727
}

contracts/mocks/account/AccountP256Mock.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
pragma solidity ^0.8.20;
44

55
import {Account} from "../../account/Account.sol";
6+
import {ERC7821} from "../../account/extensions/ERC7821.sol";
67
import {SignerP256} from "../../utils/cryptography/SignerP256.sol";
78

8-
abstract contract AccountP256Mock is Account, SignerP256 {
9+
abstract contract AccountP256Mock is Account, SignerP256, ERC7821 {
910
constructor(bytes32 qx, bytes32 qy) {
1011
_initializeSigner(qx, qy);
1112
}
13+
14+
/// @inheritdoc ERC7821
15+
function _erc7821AuthorizedExecutor(
16+
address caller,
17+
bytes32 mode,
18+
bytes calldata executionData
19+
) internal view virtual override returns (bool) {
20+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
21+
}
1222
}

contracts/mocks/account/AccountRSAMock.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
pragma solidity ^0.8.20;
44

55
import {Account} from "../../account/Account.sol";
6+
import {ERC7821} from "../../account/extensions/ERC7821.sol";
67
import {SignerRSA} from "../../utils/cryptography/SignerRSA.sol";
78

8-
abstract contract AccountRSAMock is Account, SignerRSA {
9+
abstract contract AccountRSAMock is Account, SignerRSA, ERC7821 {
910
constructor(bytes memory e, bytes memory n) {
1011
_initializeSigner(e, n);
1112
}
13+
14+
/// @inheritdoc ERC7821
15+
function _erc7821AuthorizedExecutor(
16+
address caller,
17+
bytes32 mode,
18+
bytes calldata executionData
19+
) internal view virtual override returns (bool) {
20+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
21+
}
1222
}

contracts/mocks/docs/account/MyAccount.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pragma solidity ^0.8.20;
66
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
77
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
88
import {Account} from "../../../account/Account.sol"; // or AccountCore
9+
import {ERC7821} from "../../../account/extensions/ERC7821.sol";
910

10-
contract MyAccount is Account, Initializable {
11+
contract MyAccount is Account, ERC7821, Initializable {
1112
/**
1213
* NOTE: EIP-712 domain is set at construction because each account clone
1314
* will recalculate its domain separator based on their own address.
@@ -25,4 +26,13 @@ contract MyAccount is Account, Initializable {
2526
function initializeSigner() public initializer {
2627
// Most accounts will require some form of signer initialization logic
2728
}
29+
30+
/// @dev Allows the entry point as an authorized executor.
31+
function _erc7821AuthorizedExecutor(
32+
address caller,
33+
bytes32 mode,
34+
bytes calldata executionData
35+
) internal view virtual override returns (bool) {
36+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
37+
}
2838
}

contracts/mocks/docs/account/MyAccountECDSA.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ pragma solidity ^0.8.20;
55

66
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
77
import {Account} from "../../../account/Account.sol";
8+
import {ERC7821} from "../../../account/extensions/ERC7821.sol";
89
import {SignerECDSA} from "../../../utils/cryptography/SignerECDSA.sol";
910

10-
contract MyAccountECDSA is Account, SignerECDSA {
11+
contract MyAccountECDSA is Account, SignerECDSA, ERC7821 {
1112
constructor() EIP712("MyAccountECDSA", "1") {}
1213

1314
function initializeSigner(address signerAddr) public virtual {
1415
// Will revert if the signer is already initialized
1516
_initializeSigner(signerAddr);
1617
}
18+
19+
/// @dev Allows the entry point as an authorized executor.
20+
function _erc7821AuthorizedExecutor(
21+
address caller,
22+
bytes32 mode,
23+
bytes calldata executionData
24+
) internal view virtual override returns (bool) {
25+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
26+
}
1727
}

contracts/mocks/docs/account/MyAccountP256.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ pragma solidity ^0.8.20;
55

66
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";
77
import {Account} from "../../../account/Account.sol";
8+
import {ERC7821} from "../../../account/extensions/ERC7821.sol";
89
import {SignerP256} from "../../../utils/cryptography/SignerP256.sol";
910

10-
contract MyAccountP256 is Account, SignerP256 {
11+
contract MyAccountP256 is Account, SignerP256, ERC7821 {
1112
constructor() EIP712("MyAccountP256", "1") {}
1213

1314
function initializeSigner(bytes32 qx, bytes32 qy) public virtual {
1415
// Will revert if the signer is already initialized
1516
_initializeSigner(qx, qy);
1617
}
18+
19+
/// @dev Allows the entry point as an authorized executor.
20+
function _erc7821AuthorizedExecutor(
21+
address caller,
22+
bytes32 mode,
23+
bytes calldata executionData
24+
) internal view virtual override returns (bool) {
25+
return caller == address(entryPoint()) || super._erc7821AuthorizedExecutor(caller, mode, executionData);
26+
}
1727
}

0 commit comments

Comments
 (0)