Skip to content
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

Add ERC4337 Accounts docs #40

Merged
merged 57 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
a7b170a
WIP: Migrate Account code
ernestognw Nov 26, 2024
1859385
Merge branch 'master' into aa/accounts
ernestognw Nov 29, 2024
7847e80
Merge branch 'master' into aa/accounts
ernestognw Dec 3, 2024
25de3ac
Checkpoint
ernestognw Dec 5, 2024
292dae1
Fix lint
ernestognw Dec 5, 2024
f8657e7
Checkpoint
ernestognw Dec 5, 2024
8699232
up
ernestognw Dec 6, 2024
7bdf69e
up
ernestognw Dec 6, 2024
efd52cd
Adjust
ernestognw Dec 6, 2024
87fcd0e
up
ernestognw Dec 6, 2024
549ab8e
Simplify CallReceiverMock
ernestognw Dec 6, 2024
90c7f5e
Fix slither + Codespell
ernestognw Dec 6, 2024
2e345c3
Fix coverage
ernestognw Dec 6, 2024
af200e4
Merge branch 'master' into aa/accounts
ernestognw Dec 6, 2024
4d03f45
Remove entrypoint
ernestognw Dec 6, 2024
9caded9
Readd entrypoint
ernestognw Dec 6, 2024
f6b4454
Run --ir-minimum in forge coverage
ernestognw Dec 6, 2024
2d2300f
up
ernestognw Dec 7, 2024
d6ba190
Make Accounts initializable
ernestognw Dec 7, 2024
208386f
Finish docs
ernestognw Dec 7, 2024
49fc47d
Merge branch 'master' into aa/accounts
ernestognw Dec 7, 2024
d715e4c
rewrite helpers/signers as alternative to ethers.SigningKey and
Amxx Dec 9, 2024
8ad95a1
Rename _validateNestedEIP712Signature -> _validateSignature
ernestognw Dec 9, 2024
885efdd
Read virtual to ERC7739Signer functions
ernestognw Dec 9, 2024
d5f0dac
lint
ernestognw Dec 9, 2024
130ce04
Implement review recommendations
ernestognw Dec 9, 2024
dcdae8d
Include signer into account factory hash
ernestognw Dec 9, 2024
03d935d
Update Account inheritance order
ernestognw Dec 10, 2024
5456f26
up
ernestognw Dec 10, 2024
9412b65
Merge branch 'master' into aa/accounts
ernestognw Dec 10, 2024
524bf15
Remove ERC1155HolderLean
ernestognw Dec 10, 2024
4718b87
Abstract AccountSignerDomain
ernestognw Dec 10, 2024
c8ad19d
up
ernestognw Dec 10, 2024
ed66cca
Merge branch 'master' into aa/accounts
ernestognw Dec 10, 2024
c41956c
Remove signed hash fn
ernestognw Dec 11, 2024
7e51cd2
Add standalone example of usage
ernestognw Dec 13, 2024
459d594
Merge branch 'master' into aa/accounts
ernestognw Dec 13, 2024
f497fd1
Remove docs
ernestognw Dec 13, 2024
af140c1
Add ERC4337 Accounts docs
ernestognw Dec 13, 2024
6409cb3
ERC4337 userOp validation should not be 7739 wrapped
Amxx Dec 13, 2024
97b33df
documentation
Amxx Dec 13, 2024
ddd17e9
Rename `_validateSignature` to `_rawSignatureValidation` and remove _…
ernestognw Dec 13, 2024
e8ef6d1
errata
ernestognw Dec 13, 2024
d706876
Default _signableUserOpHash to a typed userop signature
ernestognw Dec 13, 2024
62ec7b4
Merge branch 'aa/accounts' into aa/docs
ernestognw Dec 13, 2024
188e71d
Remove docs mocks
ernestognw Dec 13, 2024
5433016
Merge branch 'aa/accounts' into aa/docs
ernestognw Dec 13, 2024
367f6cb
Recover mock docs
ernestognw Dec 13, 2024
afcea37
Merge branch 'master' into aa/docs
ernestognw Dec 17, 2024
afb2ebc
up
ernestognw Dec 17, 2024
94a8481
Merge branch 'master' into aa/docs
ernestognw Dec 17, 2024
21bc637
Merge branch 'master' into aa/docs
ernestognw Dec 24, 2024
af1a6f4
up
ernestognw Dec 24, 2024
336f6bc
Update docs/modules/ROOT/pages/account-abstraction.adoc
ernestognw Dec 25, 2024
51bf8ad
Update docs/modules/ROOT/pages/account-abstraction.adoc
ernestognw Dec 25, 2024
d225734
Apply suggestions from code review
ernestognw Dec 26, 2024
c09b264
Update docs/modules/ROOT/pages/account-abstraction.adoc
ernestognw Dec 26, 2024
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
Prev Previous commit
Next Next commit
Remove signed hash fn
  • Loading branch information
ernestognw committed Dec 11, 2024
commit c41956c70ada76fceb18897c34433dedae869994
24 changes: 6 additions & 18 deletions contracts/account/draft-AccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ abstract contract AccountBase is IAccount, IAccountExecute {
return entryPoint().getNonce(address(this), key);
}

/**
* @dev Returns the digest the offchain signer signed instead of the opaque `userOpHash`.
*
* Given the `userOpHash` calculation is defined by ERC-4337, offchain signers
* may need to sign again this hash by rehashing it with other schemes.
*
* Returns the `userOpHash` by default.
*/
function _userOpSignedHash(
PackedUserOperation calldata /* userOp */,
bytes32 userOpHash
) internal view virtual returns (bytes32) {
return userOpHash;
}

/**
* @inheritdoc IAccount
*/
Expand All @@ -77,7 +62,7 @@ abstract contract AccountBase is IAccount, IAccountExecute {
bytes32 userOpHash,
uint256 missingAccountFunds
) public virtual onlyEntryPoint returns (uint256) {
uint256 validationData = _validateUserOp(userOp, _userOpSignedHash(userOp, userOpHash));
uint256 validationData = _validateUserOp(userOp, userOpHash);
_payPrefund(missingAccountFunds);
return validationData;
}
Expand All @@ -94,15 +79,18 @@ abstract contract AccountBase is IAccount, IAccountExecute {
}

/**
* @dev Validation logic for {validateUserOp}. The `userOpSignedHash` is the digest from {_userOpSignedHash}.
* @dev Validation logic for {validateUserOp}.
*
* Given the `userOpHash` calculation is defined by ERC-4337, offchain signers
* may need to sign this hash by wrapping it in other schemes (e.g. ERC-191)
*
* IMPORTANT: Implementing a mechanism to validate user operations is a security-sensitive operation
* as it may allow an attacker to bypass the account's security measures. Check out {AccountECDSA},
* {AccountP256}, or {AccountRSA} for digital signature validation implementations.
*/
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpSignedHash
bytes32 userOpHash
) internal virtual returns (uint256 validationData);

/**
Expand Down
14 changes: 7 additions & 7 deletions contracts/account/draft-AccountECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {AccountSignerDomain} from "./extensions/draft-AccountSignerDomain.sol";
import {AccountERC7739} from "./extensions/draft-AccountERC7739.sol";

/**
* @dev Account implementation using {ECDSA} signatures and {AccountSignerDomain} for replay protection.
* @dev Account implementation using {ECDSA} signatures and {AccountERC7739} for replay protection.
*
* An {_initializeSigner} function is provided to set the account's signer address. Doing so it's
* easier for a factory, whose likely to use initializable clones of this contract.
*
* IMPORTANT: Avoiding to call {_initializeSigner} either during construction (if used standalone)
* or during initialization (if used as a clone) may leave the account unusable.
*/
abstract contract AccountECDSA is AccountSignerDomain, ERC721Holder, ERC1155Holder {
abstract contract AccountECDSA is AccountERC7739, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;

/**
Expand Down Expand Up @@ -47,11 +47,11 @@ abstract contract AccountECDSA is AccountSignerDomain, ERC721Holder, ERC1155Hold
/**
* @dev Returns the ERC-191 signed `userOpHash` hashed with keccak256 using `personal_sign`.
*/
function _userOpSignedHash(
PackedUserOperation calldata /* userOp */,
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view virtual override returns (bytes32) {
return userOpHash.toEthSignedMessageHash();
) internal view virtual override returns (uint256) {
return super._validateUserOp(userOp, userOpHash.toEthSignedMessageHash());
}

/**
Expand Down
14 changes: 7 additions & 7 deletions contracts/account/draft-AccountP256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import {P256} from "@openzeppelin/contracts/utils/cryptography/P256.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {AccountSignerDomain} from "./extensions/draft-AccountSignerDomain.sol";
import {AccountERC7739} from "./extensions/draft-AccountERC7739.sol";

/**
* @dev Account implementation using {P256} signatures and {AccountSignerDomain} for replay protection.
* @dev Account implementation using {P256} signatures and {AccountERC7739} for replay protection.
*
* An {_initializeSigner} function is provided to set the account's signer address. Doing so it's
* easier for a factory, whose likely to use initializable clones of this contract.
*
* IMPORTANT: Avoiding to call {_initializeSigner} either during construction (if used standalone)
* or during initialization (if used as a clone) may leave the account unusable.
*/
abstract contract AccountP256 is AccountSignerDomain, ERC721Holder, ERC1155Holder {
abstract contract AccountP256 is AccountERC7739, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;

/**
Expand Down Expand Up @@ -49,11 +49,11 @@ abstract contract AccountP256 is AccountSignerDomain, ERC721Holder, ERC1155Holde
/**
* @dev Returns the ERC-191 signed `userOpHash` hashed with keccak256 using `personal_sign`.
*/
function _userOpSignedHash(
PackedUserOperation calldata /* userOp */,
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view virtual override returns (bytes32) {
return userOpHash.toEthSignedMessageHash();
) internal view virtual override returns (uint256) {
return super._validateUserOp(userOp, userOpHash.toEthSignedMessageHash());
}

/**
Expand Down
14 changes: 7 additions & 7 deletions contracts/account/draft-AccountRSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import {RSA} from "@openzeppelin/contracts/utils/cryptography/RSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import {AccountSignerDomain} from "./extensions/draft-AccountSignerDomain.sol";
import {AccountERC7739} from "./extensions/draft-AccountERC7739.sol";

/**
* @dev Account implementation using {RSA} signatures and {AccountSignerDomain} for replay protection.
* @dev Account implementation using {RSA} signatures and {AccountERC7739} for replay protection.
*
* An {_initializeSigner} function is provided to set the account's signer address. Doing so it's
* easier for a factory, whose likely to use initializable clones of this contract.
*
* IMPORTANT: Avoiding to call {_initializeSigner} either during construction (if used standalone)
* or during initialization (if used as a clone) may leave the account unusable.
*/
abstract contract AccountRSA is AccountSignerDomain, ERC721Holder, ERC1155Holder {
abstract contract AccountRSA is AccountERC7739, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;

/**
Expand Down Expand Up @@ -49,11 +49,11 @@ abstract contract AccountRSA is AccountSignerDomain, ERC721Holder, ERC1155Holder
/**
* @dev Returns the ERC-191 signed `userOpHash` hashed with keccak256 using `personal_sign`.
*/
function _userOpSignedHash(
PackedUserOperation calldata /* userOp */,
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view virtual override returns (bytes32) {
return userOpHash.toEthSignedMessageHash();
) internal view virtual override returns (uint256) {
return super._validateUserOp(userOp, userOpHash.toEthSignedMessageHash());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ import {AccountBase} from "../draft-AccountBase.sol";
/**
* @dev An ERC-4337 account implementation that validates domain-specific signatures following ERC-7739.
*/
abstract contract AccountSignerDomain is ERC165, IERC5267, ERC7739Signer, AccountBase {
abstract contract AccountERC7739 is ERC165, IERC5267, ERC7739Signer, AccountBase {
/**
* @dev Internal version of {validateUserOp} that relies on {_validateSignature}.
*
* The `userOpSignedHash` is the digest from {_userOpSignedHash}.
*
* NOTE: To override the signature functionality, try overriding {_validateSignature} instead.
*/
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpSignedHash
bytes32 userOpHash
) internal view virtual override returns (uint256) {
return
_isValidSignature(userOpSignedHash, userOp.signature)
_isValidSignature(userOpHash, userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/mocks/docs/account/MyAccountCustom.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ contract MyAccountCustom is ERC7739Signer, AccountBase, Initializable {
// Custom initialization logic
}

/// @dev Receives an `userOpSignedHash` to validate. See {_userOpSignedHash}.
/// @inheritdoc AccountBase
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpSignedHash
bytes32 userOpHash
) internal view virtual override returns (uint256) {
return
_isValidSignature(userOpSignedHash, userOp.signature)
_isValidSignature(userOpHash, userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}
Expand Down
Loading