Skip to content

Add ERC7913 signers and utilities #5659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f5544fd
Add Account framework
ernestognw May 2, 2025
40dfd20
Add missing mocks
ernestognw May 2, 2025
0bcc521
Adding missing hardhat config
ernestognw May 2, 2025
7e75026
up
ernestognw May 2, 2025
5fb074c
Remove unnecessary files for mocks
ernestognw May 2, 2025
e5df541
Remove more unnecessary mock files
ernestognw May 2, 2025
5ad9788
replace hardcoded links
ernestognw May 2, 2025
7090f67
lockfile
ernestognw May 2, 2025
c4af1d7
update ethers
ernestognw May 2, 2025
aa8f29b
add missing interface
ernestognw May 2, 2025
415c00d
Add changesets
ernestognw May 2, 2025
f60aa3a
up
ernestognw May 2, 2025
087a844
up
ernestognw May 2, 2025
79629b7
up
ernestognw May 2, 2025
f47cab7
up
ernestognw May 2, 2025
8f58197
up
ernestognw May 2, 2025
ecede7f
up
ernestognw May 2, 2025
68bd96a
up
ernestognw May 2, 2025
d5cb119
chore: empty commit
ernestognw May 2, 2025
6a0ae8a
change read permissions
ernestognw May 2, 2025
a49a157
Update lucky-donuts-scream.md
ernestognw May 2, 2025
a634278
Update clean-ways-push.md
ernestognw May 2, 2025
8b6501a
Update tame-bears-mix.md
ernestognw May 2, 2025
39a1026
reset package-lock.json
ernestognw May 2, 2025
71a6b25
up
ernestognw May 2, 2025
35d4a12
up
ernestognw May 2, 2025
a95705b
reset dependencies
ernestognw May 2, 2025
90509bd
reset dependencies
ernestognw May 2, 2025
10f40d7
reset dependencies
ernestognw May 2, 2025
36fb044
lint
ernestognw May 2, 2025
7e10f80
Attempt to fix tests
ernestognw May 2, 2025
c6ed868
up
ernestognw May 2, 2025
b87c8e2
Merge branch 'master' into feature/account-abstraction
ernestognw May 2, 2025
f6d07c2
adjust action.yml
ernestognw May 2, 2025
cfa2392
up
ernestognw May 2, 2025
9a8e63f
Merge branch 'master' into feature/account-abstraction
ernestognw May 2, 2025
3a90091
lint
ernestognw May 2, 2025
bdec803
lint
ernestognw May 2, 2025
73c12c7
Merge branch 'master' into feature/account-abstraction
ernestognw May 2, 2025
7764515
up
ernestognw May 2, 2025
11c42c3
checks
ernestognw May 2, 2025
be68753
up
ernestognw May 2, 2025
f0a1155
build in slither
ernestognw May 2, 2025
c42a7fd
Update build command
ernestognw May 2, 2025
6e576ca
compile hardhat too
ernestognw May 2, 2025
593e879
revert slither changes
ernestognw May 2, 2025
c3f39a1
Remove package-lock.json to skip installing dependencies
ernestognw May 2, 2025
db76c3b
up
ernestognw May 2, 2025
8eebff0
Add @custom:stateless tag
ernestognw May 3, 2025
65fa7de
update upgradeable.patch
ernestognw May 3, 2025
abac3bd
fix conflicts
ernestognw May 3, 2025
7d120b9
rollback <package-version>
ernestognw May 3, 2025
02eccc1
update upgradeable.patch
ernestognw May 3, 2025
6a60523
Remove console.log
ernestognw May 3, 2025
80edba8
Add EnumerableSetExtended and EnumerableMapExtended
ernestognw May 2, 2025
29c48d9
Fix lint and enable formatting after generation
ernestognw May 3, 2025
fae0a67
Add ERC7913 signers and utilities
ernestognw May 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/clean-ways-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`AccountERC7579`: Extension of `Account` that implements support for ERC-7579 modules of type executor, validator, and fallback handler.
5 changes: 5 additions & 0 deletions .changeset/funny-years-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`Account`: Added a simple ERC-4337 account implementation with minimal logic to process user operations.
5 changes: 5 additions & 0 deletions .changeset/lazy-poets-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`SignerERC7702`: Implementation of `AbstractSigner` for Externally Owned Accounts (EOAs). Useful with ERC-7702.
5 changes: 5 additions & 0 deletions .changeset/lucky-donuts-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC7739`: An abstract contract to validate signatures following the rehashing scheme from `ERC7739Utils`.
5 changes: 5 additions & 0 deletions .changeset/proud-tables-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC7739Utils`: Add a library that implements a defensive rehashing mechanism to prevent replayability of smart contract signatures based on the ERC-7739.
5 changes: 5 additions & 0 deletions .changeset/rotten-apes-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`IERC7821`, `ERC7821`: Interface and logic for minimal batch execution. No support for additional `opData` is included.
5 changes: 5 additions & 0 deletions .changeset/strong-points-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`AccountERC7579Hooked`: Extension of `AccountERC7579` that implements support for ERC-7579 hook modules.
5 changes: 5 additions & 0 deletions .changeset/tame-bears-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`AbstractSigner`, `SignerECDSA`, `SignerP256`, and `SignerRSA`: Add an abstract contract and various implementations for contracts that deal with signature verification.
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runs:
path: '**/node_modules'
key: npm-v3-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm ci
run: npm ci --legacy-peer-deps
shell: bash
if: steps.cache.outputs.cache-hit != 'true'
- name: Install Foundry
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ jobs:
- uses: actions/checkout@v4
- name: Set up environment
uses: ./.github/actions/setup
- run: rm package-lock.json package.json # Dependencies already installed
- uses: crytic/[email protected]

codespell:
Expand Down
144 changes: 144 additions & 0 deletions contracts/account/Account.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import {PackedUserOperation, IAccount, IEntryPoint} from "../interfaces/draft-IERC4337.sol";
import {ERC4337Utils} from "./utils/draft-ERC4337Utils.sol";
import {AbstractSigner} from "../utils/cryptography/AbstractSigner.sol";

/**
* @dev A simple ERC4337 account implementation. This base implementation only includes the minimal logic to process
* user operations.
*
* Developers must implement the {AbstractSigner-_rawSignatureValidation} function to define the account's validation logic.
*
* NOTE: This core account doesn't include any mechanism for performing arbitrary external calls. This is an essential
* feature that all Account should have. We leave it up to the developers to implement the mechanism of their choice.
* Common choices include ERC-6900, ERC-7579 and ERC-7821 (among others).
*
* IMPORTANT: Implementing a mechanism to validate signatures is a security-sensitive operation as it may allow an
* attacker to bypass the account's security measures. Check out {SignerECDSA}, {SignerP256}, or {SignerRSA} for
* digital signature validation implementations.
*
* @custom:stateless
*/
abstract contract Account is AbstractSigner, IAccount {
/**
* @dev Unauthorized call to the account.
*/
error AccountUnauthorized(address sender);

/**
* @dev Revert if the caller is not the entry point or the account itself.
*/
modifier onlyEntryPointOrSelf() {
_checkEntryPointOrSelf();
_;
}

/**
* @dev Revert if the caller is not the entry point.
*/
modifier onlyEntryPoint() {
_checkEntryPoint();
_;
}

/**
* @dev Canonical entry point for the account that forwards and validates user operations.
*/
function entryPoint() public view virtual returns (IEntryPoint) {
return ERC4337Utils.ENTRYPOINT_V08;
}

/**
* @dev Return the account nonce for the canonical sequence.
*/
function getNonce() public view virtual returns (uint256) {
return getNonce(0);
}

/**
* @dev Return the account nonce for a given sequence (key).
*/
function getNonce(uint192 key) public view virtual returns (uint256) {
return entryPoint().getNonce(address(this), key);
}

/**
* @inheritdoc IAccount
*/
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash,
uint256 missingAccountFunds
) public virtual onlyEntryPoint returns (uint256) {
uint256 validationData = _validateUserOp(userOp, userOpHash);
_payPrefund(missingAccountFunds);
return validationData;
}

/**
* @dev Returns the validationData for a given user operation. By default, this checks the signature of the
* signable hash (produced by {_signableUserOpHash}) using the abstract signer ({AbstractSigner-_rawSignatureValidation}).
*
* NOTE: The userOpHash is assumed to be correct. Calling this function with a userOpHash that does not match the
* userOp will result in undefined behavior.
*/
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal virtual returns (uint256) {
return
_rawSignatureValidation(_signableUserOpHash(userOp, userOpHash), userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}

/**
* @dev Virtual function that returns the signable hash for a user operations. Since v0.8.0 of the entrypoint,
* `userOpHash` is an EIP-712 hash that can be signed directly.
*/
function _signableUserOpHash(
PackedUserOperation calldata /*userOp*/,
bytes32 userOpHash
) internal view virtual returns (bytes32) {
return userOpHash;
}

/**
* @dev Sends the missing funds for executing the user operation to the {entrypoint}.
* The `missingAccountFunds` must be defined by the entrypoint when calling {validateUserOp}.
*/
function _payPrefund(uint256 missingAccountFunds) internal virtual {
if (missingAccountFunds > 0) {
(bool success, ) = payable(msg.sender).call{value: missingAccountFunds}("");
success; // Silence warning. The entrypoint should validate the result.
}
}

/**
* @dev Ensures the caller is the {entrypoint}.
*/
function _checkEntryPoint() internal view virtual {
address sender = msg.sender;
if (sender != address(entryPoint())) {
revert AccountUnauthorized(sender);
}
}

/**
* @dev Ensures the caller is the {entrypoint} or the account itself.
*/
function _checkEntryPointOrSelf() internal view virtual {
address sender = msg.sender;
if (sender != address(this) && sender != address(entryPoint())) {
revert AccountUnauthorized(sender);
}
}

/**
* @dev Receive Ether.
*/
receive() external payable virtual {}
}
24 changes: 21 additions & 3 deletions contracts/account/README.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
= Account

[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/account
NOTE: This document is better viewed at https://docs.openzeppelin.com/community-contracts/api/account

This directory includes contracts to build accounts for ERC-4337. These include:

* {Account}: An ERC-4337 smart account implementation that includes the core logic to process user operations.
* {AccountERC7579}: An extension of `Account` that implements support for ERC-7579 modules.
* {AccountERC7579Hooked}: An extension of `AccountERC7579` with support for a single hook module (type 4).
* {ERC7821}: Minimal batch executor implementation contracts. Useful to enable easy batch execution for smart contracts.
* {ERC4337Utils}: Utility functions for working with ERC-4337 user operations.
* {ERC7579Utils}: Utility functions for working with ERC-7579 modules and account modularity.

== Core

{{Account}}

== Extensions

{{AccountERC7579}}

{{AccountERC7579Hooked}}

This directory includes contracts to build accounts for ERC-4337.
{{ERC7821}}

== Utilities

Expand Down
Loading
Loading