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
up
  • Loading branch information
ernestognw committed Dec 6, 2024
commit 87fcd0e7cf3539698bfa9793ed7fafa56c437abe
7 changes: 5 additions & 2 deletions contracts/account/draft-AccountECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {ERC1155HolderLean, IERC1155Receiver} from "../token/ERC1155/utils/ERC115
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {AccountBase} from "./draft-AccountBase.sol";
import {ERC7739Signer} from "../utils/cryptography/draft-ERC7739Signer.sol";

/**
* @dev Account implementation using {ECDSA} signatures and {ERC7739Signer} for replay protection.
*/
abstract contract AccountECDSA is ERC165, ERC7739Signer, ERC721Holder, ERC1155HolderLean, AccountBase {
using MessageHashUtils for bytes32;

address private immutable _signer;

/**
Expand All @@ -40,9 +43,9 @@ abstract contract AccountECDSA is ERC165, ERC7739Signer, ERC721Holder, ERC1155Ho
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view override returns (uint256) {
) internal view virtual override returns (uint256) {
return
_isValidSignature(userOpHash, userOp.signature)
_isValidSignature(userOpHash.toEthSignedMessageHash(), userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/account/draft-AccountP256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {ERC1155HolderLean, IERC1155Receiver} from "../token/ERC1155/utils/ERC115
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {P256} from "@openzeppelin/contracts/utils/cryptography/P256.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {AccountBase} from "./draft-AccountBase.sol";
import {ERC7739Signer} from "../utils/cryptography/draft-ERC7739Signer.sol";

/**
* @dev Account implementation using {P256} signatures and {ERC7739Signer} for replay protection.
*/
abstract contract AccountP256 is ERC165, ERC7739Signer, ERC721Holder, ERC1155HolderLean, AccountBase {
using MessageHashUtils for bytes32;

bytes32 private immutable _qx;
bytes32 private immutable _qy;

Expand All @@ -42,9 +45,9 @@ abstract contract AccountP256 is ERC165, ERC7739Signer, ERC721Holder, ERC1155Hol
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view override returns (uint256) {
) internal view virtual override returns (uint256) {
return
_isValidSignature(userOpHash, userOp.signature)
_isValidSignature(userOpHash.toEthSignedMessageHash(), userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}
Expand Down
7 changes: 5 additions & 2 deletions contracts/account/draft-AccountRSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {ERC1155HolderLean, IERC1155Receiver} from "../token/ERC1155/utils/ERC115
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {RSA} from "@openzeppelin/contracts/utils/cryptography/RSA.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import {AccountBase} from "./draft-AccountBase.sol";
import {ERC7739Signer} from "../utils/cryptography/draft-ERC7739Signer.sol";

Expand All @@ -21,6 +22,8 @@ import {ERC7739Signer} from "../utils/cryptography/draft-ERC7739Signer.sol";
* (see {Clones-cloneDeterministicWithImmutableArgs}).
*/
abstract contract AccountRSA is ERC165, ERC7739Signer, ERC721Holder, ERC1155HolderLean, AccountBase {
using MessageHashUtils for bytes32;

bytes private _e;
bytes private _n;

Expand All @@ -47,9 +50,9 @@ abstract contract AccountRSA is ERC165, ERC7739Signer, ERC721Holder, ERC1155Hold
function _validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal view override returns (uint256) {
) internal view virtual override returns (uint256) {
return
_isValidSignature(userOpHash, userOp.signature)
_isValidSignature(userOpHash.toEthSignedMessageHash(), userOp.signature)
? ERC4337Utils.SIG_VALIDATION_SUCCESS
: ERC4337Utils.SIG_VALIDATION_FAILED;
}
Expand Down
44 changes: 6 additions & 38 deletions test/account/Account.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ function shouldBehaveLikeAnAccountBase() {
]),
})
.then(op => op.sign(this.domain, this.signer));
await expect(
this.mock
.connect(this.other)
.validateUserOp(
operation.packed,
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
0,
),
)
await expect(this.mock.connect(this.other).validateUserOp(operation.packed, operation.hash(), 0))
.to.be.revertedWithCustomError(this.mock, 'AccountUnauthorized')
.withArgs(this.other);
});
Expand All @@ -72,11 +64,7 @@ function shouldBehaveLikeAnAccountBase() {
expect(
await this.mock
.connect(this.entrypointAsSigner)
.validateUserOp.staticCall(
operation.packed,
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
0,
),
.validateUserOp.staticCall(operation.packed, operation.hash(), 0),
).to.eq(SIG_VALIDATION_SUCCESS);
});

Expand All @@ -97,11 +85,7 @@ function shouldBehaveLikeAnAccountBase() {
expect(
await this.mock
.connect(this.entrypointAsSigner)
.validateUserOp.staticCall(
operation.packed,
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
0,
),
.validateUserOp.staticCall(operation.packed, operation.hash(), 0),
).to.eq(SIG_VALIDATION_FAILURE);
});

Expand All @@ -125,11 +109,7 @@ function shouldBehaveLikeAnAccountBase() {

const tx = await this.mock
.connect(this.entrypointAsSigner)
.validateUserOp(
operation.packed,
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
amount,
);
.validateUserOp(operation.packed, operation.hash(), amount);

const receipt = await tx.wait();
const callerFees = receipt.gasUsed * tx.gasPrice;
Expand Down Expand Up @@ -243,14 +223,7 @@ function shouldBehaveLikeAnAccountBaseExecutor({ deployable = true } = {}) {
})
.then(op => op.sign(this.domain, this.signer));

await expect(
this.mock
.connect(this.other)
.executeUserOp(
operation.packed,
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
),
)
await expect(this.mock.connect(this.other).executeUserOp(operation.packed, operation.hash()))
.to.be.revertedWithCustomError(this.mock, 'AccountUnauthorized')
.withArgs(this.other);
});
Expand All @@ -274,12 +247,7 @@ function shouldBehaveLikeAnAccountBaseExecutor({ deployable = true } = {}) {

await expect(this.entrypoint.connect(this.entrypointAsSigner).handleOps([operation.packed], this.beneficiary))
.to.emit(this.entrypoint, 'AccountDeployed')
.withArgs(
operation.hash(operation.context.entrypoint.target, operation.context.chainId),
this.mock,
this.factory,
ethers.ZeroAddress,
)
.withArgs(operation.hash(), this.mock, this.factory, ethers.ZeroAddress)
.to.emit(this.target, 'MockFunctionCalledExtra')
.withArgs(this.mock, 17);
expect(await this.mock.getNonce()).to.equal(1);
Expand Down
7 changes: 5 additions & 2 deletions test/helpers/erc4337.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ class UserOperation extends UserOperationVanilla {
return this;
}

hash() {
return super.hash(this.context.entrypoint.target, this.context.chainId);
}

async sign(domain, signer) {
this.signature = await PersonalSignHelper.sign(
signer.signTypedData.bind(signer),
this.hash(this.context.entrypoint.target, this.context.chainId),
ethers.getBytes(this.hash()),
domain,
);

return this;
}
}
Expand Down
3 changes: 1 addition & 2 deletions test/helpers/signers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class BooleanSigner {

class ERC7739Signer {
signTypedData(domain, types, contents) {
const encoder = ethers.TypedDataEncoder.from(types);
return this._signRaw(hashTypedData(domain, encoder.hash(contents)));
return this._signRaw(hashTypedData(domain, ethers.TypedDataEncoder.from(types).hash(contents)));
}
}

Expand Down
Loading