Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 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
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
188e71d
Remove docs mocks
ernestognw Dec 13, 2024
6ace1a7
Remove ERC7739 from AccountBase
ernestognw Dec 14, 2024
9793e49
Make ERC7739Signer validations private
ernestognw Dec 14, 2024
9e34432
Move EIP712 userop signing to Accountbase
ernestognw Dec 14, 2024
ae6a665
Split AccountCore / Account
Amxx Dec 16, 2024
07ca067
remove intermediary variable
Amxx Dec 16, 2024
6aa5597
doc
Amxx Dec 16, 2024
0513f3a
spelling
Amxx Dec 16, 2024
e3ce6b5
abstract signer
Amxx Dec 16, 2024
69cc3da
docs
Amxx Dec 16, 2024
d0bd34f
ERC7702 signer
Amxx Dec 16, 2024
3b1c1f4
fix
Amxx Dec 16, 2024
190b5a5
doc example for ERC7739 use signers
Amxx Dec 16, 2024
a6ab43b
Complete minimal documentation
ernestognw Dec 17, 2024
5c210cf
Update CHANGELOG.md
ernestognw Dec 17, 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
Default _signableUserOpHash to a typed userop signature
  • Loading branch information
ernestognw committed Dec 13, 2024
commit d706876d361ea78df427f530db948216da666d0c
2 changes: 1 addition & 1 deletion contracts/account/draft-AccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ abstract contract AccountBase is IAccount, IAccountExecute, ERC7739Signer {
PackedUserOperation calldata /* userOp */,
bytes32 userOpHash
) internal view virtual returns (bytes32) {
return userOpHash.toEthSignedMessageHash();
return userOpHash;
}

/**
Expand Down
34 changes: 32 additions & 2 deletions contracts/account/extensions/draft-AccountECDSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
import {PackedUserOperation} from "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
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 {AccountBase} from "../draft-AccountBase.sol";
Expand Down Expand Up @@ -33,7 +32,10 @@ import {AccountBase} from "../draft-AccountBase.sol";
* or during initialization (if used as a clone) may leave the account either front-runnable or unusable.
*/
abstract contract AccountECDSA is AccountBase, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;
bytes32 internal constant _PACKED_USER_OPERATION =
keccak256(
"PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData,address entrypoint)"
);

/**
* @dev The {signer} is already initialized.
Expand All @@ -57,6 +59,34 @@ abstract contract AccountECDSA is AccountBase, ERC721Holder, ERC1155Holder {
return _signer;
}

/**
* @dev Customize the user operation hash to sign. See {AccountBase-_signableUserOpHash}.
*
* This implementation uses the EIP-712 typed data hashing mechanism for readability.
*/
function _signableUserOpHash(
PackedUserOperation calldata userOp,
bytes32 /* userOpHash */
) internal view virtual override returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
_PACKED_USER_OPERATION,
userOp.sender,
userOp.nonce,
keccak256(userOp.initCode),
keccak256(userOp.callData),
userOp.accountGasLimits,
userOp.preVerificationGas,
userOp.gasFees,
keccak256(userOp.paymasterAndData),
msg.sender
)
)
);
}

/**
* @dev Validates the signature using the account's signer.
*/
Expand Down
34 changes: 32 additions & 2 deletions contracts/account/extensions/draft-AccountP256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
import {PackedUserOperation} from "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
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 {AccountBase} from "../draft-AccountBase.sol";
Expand Down Expand Up @@ -33,7 +32,10 @@ import {AccountBase} from "../draft-AccountBase.sol";
* or during initialization (if used as a clone) may leave the account either front-runnable or unusable.
*/
abstract contract AccountP256 is AccountBase, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;
bytes32 internal constant _PACKED_USER_OPERATION =
keccak256(
"PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData,address entrypoint)"
);

/**
* @dev The {signer} is already initialized.
Expand All @@ -59,6 +61,34 @@ abstract contract AccountP256 is AccountBase, ERC721Holder, ERC1155Holder {
return (_qx, _qy);
}

/**
* @dev Customize the user operation hash to sign. See {AccountBase-_signableUserOpHash}.
*
* This implementation uses the EIP-712 typed data hashing mechanism for readability.
*/
function _signableUserOpHash(
PackedUserOperation calldata userOp,
bytes32 /* userOpHash */
) internal view virtual override returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
_PACKED_USER_OPERATION,
userOp.sender,
userOp.nonce,
keccak256(userOp.initCode),
keccak256(userOp.callData),
userOp.accountGasLimits,
userOp.preVerificationGas,
userOp.gasFees,
keccak256(userOp.paymasterAndData),
msg.sender
)
)
);
}

/**
* @dev Validates the signature using the account's signer.
*/
Expand Down
34 changes: 32 additions & 2 deletions contracts/account/extensions/draft-AccountRSA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.20;
import {PackedUserOperation} from "@openzeppelin/contracts/interfaces/draft-IERC4337.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
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 {AccountBase} from "../draft-AccountBase.sol";
Expand Down Expand Up @@ -33,7 +32,10 @@ import {AccountBase} from "../draft-AccountBase.sol";
* or during initialization (if used as a clone) may leave the account either front-runnable or unusable.
*/
abstract contract AccountRSA is AccountBase, ERC721Holder, ERC1155Holder {
using MessageHashUtils for bytes32;
bytes32 internal constant _PACKED_USER_OPERATION =
keccak256(
"PackedUserOperation(address sender,uint256 nonce,bytes initCode,bytes callData,bytes32 accountGasLimits,uint256 preVerificationGas,bytes32 gasFees,bytes paymasterAndData,address entrypoint)"
);

/**
* @dev The {signer} is already initialized.
Expand All @@ -59,6 +61,34 @@ abstract contract AccountRSA is AccountBase, ERC721Holder, ERC1155Holder {
return (_e, _n);
}

/**
* @dev Customize the user operation hash to sign. See {AccountBase-_signableUserOpHash}.
*
* This implementation uses the EIP-712 typed data hashing mechanism for readability.
*/
function _signableUserOpHash(
PackedUserOperation calldata userOp,
bytes32 /* userOpHash */
) internal view virtual override returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
_PACKED_USER_OPERATION,
userOp.sender,
userOp.nonce,
keccak256(userOp.initCode),
keccak256(userOp.callData),
userOp.accountGasLimits,
userOp.preVerificationGas,
userOp.gasFees,
keccak256(userOp.paymasterAndData),
msg.sender
)
)
);
}

/**
* @dev Validates the signature using the account's signer.
*/
Expand Down
13 changes: 7 additions & 6 deletions test/account/Account.behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function shouldBehaveLikeAnAccountBase() {
),
]),
})
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

await expect(this.mock.connect(this.other).validateUserOp(operation.packed, operation.hash(), 0))
.to.be.revertedWithCustomError(this.mock, 'AccountUnauthorized')
.withArgs(this.other);
Expand All @@ -59,7 +60,7 @@ function shouldBehaveLikeAnAccountBase() {
),
]),
})
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

expect(
await this.mock
Expand Down Expand Up @@ -101,7 +102,7 @@ function shouldBehaveLikeAnAccountBase() {
),
]),
})
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

const prevAccountBalance = await ethers.provider.getBalance(this.mock.target);
const prevEntrypointBalance = await ethers.provider.getBalance(this.entrypoint.target);
Expand Down Expand Up @@ -221,7 +222,7 @@ function shouldBehaveLikeAnAccountBaseExecutor({ deployable = true } = {}) {
),
]),
})
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

await expect(this.mock.connect(this.other).executeUserOp(operation.packed, operation.hash()))
.to.be.revertedWithCustomError(this.mock, 'AccountUnauthorized')
Expand All @@ -243,7 +244,7 @@ function shouldBehaveLikeAnAccountBaseExecutor({ deployable = true } = {}) {
]),
})
.then(op => op.addInitCode())
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

await expect(this.entrypoint.connect(this.entrypointAsSigner).handleOps([operation.packed], this.beneficiary))
.to.emit(this.entrypoint, 'AccountDeployed')
Expand Down Expand Up @@ -292,7 +293,7 @@ function shouldBehaveLikeAnAccountBaseExecutor({ deployable = true } = {}) {
),
]),
})
.then(op => op.sign(this.signer));
.then(op => this.signUserOp(op));

expect(await this.mock.getNonce()).to.equal(0);
await expect(this.entrypoint.connect(this.entrypointAsSigner).handleOps([operation.packed], this.beneficiary))
Expand Down
6 changes: 5 additions & 1 deletion test/account/draft-AccountBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ async function fixture() {
const signer = new NonNativeSigner({ sign: () => ({ serialized: '0x01' }) });
const helper = new ERC4337Helper('$AccountBaseMock');
const smartAccount = await helper.newAccount(['AccountBase', '1']);
const signUserOp = async userOp => {
userOp.signature = await signer.signMessage(userOp.hash());
return userOp;
};

return { ...helper, mock: smartAccount, signer, target, beneficiary, other };
return { ...helper, mock: smartAccount, signer, target, beneficiary, other, signUserOp };
}

describe('AccountBase', function () {
Expand Down
19 changes: 19 additions & 0 deletions test/account/draft-AccountECDSA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { ERC4337Helper } = require('../helpers/erc4337');
const { shouldBehaveLikeERC7739Signer } = require('../utils/cryptography/ERC7739Signer.behavior');
const { PackedUserOperation } = require('../helpers/eip712');

async function fixture() {
const [beneficiary, other] = await ethers.getSigners();
Expand All @@ -20,6 +21,23 @@ async function fixture() {
chainId: helper.chainId,
verifyingContract: smartAccount.address,
};
const signUserOp = async userOp => {
const types = { PackedUserOperation };
const packed = userOp.packed;
const typedOp = {
sender: packed.sender,
nonce: packed.nonce,
initCode: packed.initCode,
callData: packed.callData,
accountGasLimits: packed.accountGasLimits,
preVerificationGas: packed.preVerificationGas,
gasFees: packed.gasFees,
paymasterAndData: packed.paymasterAndData,
entrypoint: userOp.context.entrypoint.target,
};
userOp.signature = await signer.signTypedData(domain, types, typedOp);
return userOp;
};

return {
...helper,
Expand All @@ -29,6 +47,7 @@ async function fixture() {
target,
beneficiary,
other,
signUserOp,
};
}

Expand Down
20 changes: 19 additions & 1 deletion test/account/draft-AccountP256.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { ERC4337Helper } = require('../helpers/erc4337');
const { NonNativeSigner, P256SigningKey } = require('../helpers/signers');
const { shouldBehaveLikeERC7739Signer } = require('../utils/cryptography/ERC7739Signer.behavior');
const { PackedUserOperation } = require('../helpers/eip712');

async function fixture() {
const [beneficiary, other] = await ethers.getSigners();
Expand All @@ -26,8 +27,25 @@ async function fixture() {
chainId: helper.chainId,
verifyingContract: smartAccount.address,
};
const signUserOp = async userOp => {
const types = { PackedUserOperation };
const packed = userOp.packed;
const typedOp = {
sender: packed.sender,
nonce: packed.nonce,
initCode: packed.initCode,
callData: packed.callData,
accountGasLimits: packed.accountGasLimits,
preVerificationGas: packed.preVerificationGas,
gasFees: packed.gasFees,
paymasterAndData: packed.paymasterAndData,
entrypoint: userOp.context.entrypoint.target,
};
userOp.signature = await signer.signTypedData(domain, types, typedOp);
return userOp;
};

return { ...helper, domain, mock: smartAccount, signer, target, beneficiary, other };
return { ...helper, domain, mock: smartAccount, signer, target, beneficiary, other, signUserOp };
}

describe('AccountP256', function () {
Expand Down
20 changes: 19 additions & 1 deletion test/account/draft-AccountRSA.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { ERC4337Helper } = require('../helpers/erc4337');
const { NonNativeSigner, RSASHA256SigningKey } = require('../helpers/signers');
const { shouldBehaveLikeERC7739Signer } = require('../utils/cryptography/ERC7739Signer.behavior');
const { PackedUserOperation } = require('../helpers/eip712');

async function fixture() {
const [beneficiary, other] = await ethers.getSigners();
Expand All @@ -26,8 +27,25 @@ async function fixture() {
chainId: helper.chainId,
verifyingContract: smartAccount.address,
};
const signUserOp = async userOp => {
const types = { PackedUserOperation };
const packed = userOp.packed;
const typedOp = {
sender: packed.sender,
nonce: packed.nonce,
initCode: packed.initCode,
callData: packed.callData,
accountGasLimits: packed.accountGasLimits,
preVerificationGas: packed.preVerificationGas,
gasFees: packed.gasFees,
paymasterAndData: packed.paymasterAndData,
entrypoint: userOp.context.entrypoint.target,
};
userOp.signature = await signer.signTypedData(domain, types, typedOp);
return userOp;
};

return { ...helper, domain, mock: smartAccount, signer, target, beneficiary, other };
return { ...helper, domain, mock: smartAccount, signer, target, beneficiary, other, signUserOp };
}

describe('AccountRSA', function () {
Expand Down
22 changes: 22 additions & 0 deletions test/helpers/eip712.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { types, formatType } = require('../../lib/@openzeppelin-contracts/test/helpers/eip712');
const { mapValues } = require('../../lib/@openzeppelin-contracts/test/helpers/iterate');

module.exports = {
...types,
...mapValues(
{
PackedUserOperation: {
sender: 'address',
nonce: 'uint256',
initCode: 'bytes',
callData: 'bytes',
accountGasLimits: 'bytes32',
preVerificationGas: 'uint256',
gasFees: 'bytes32',
paymasterAndData: 'bytes',
entrypoint: 'address',
},
},
formatType,
),
};
6 changes: 0 additions & 6 deletions test/helpers/erc4337.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { setCode } = require('@nomicfoundation/hardhat-network-helpers');
const { ethers } = require('hardhat');
const { UserOperation: UserOperationVanilla } = require('../../lib/@openzeppelin-contracts/test/helpers/erc4337');
const { PersonalSignHelper } = require('./erc7739');

const CANONICAL_ENTRYPOINT = '0x0000000071727De22E5E9d8BAf0edAc6f37da032';

Expand Down Expand Up @@ -98,11 +97,6 @@ class UserOperation extends UserOperationVanilla {
hash() {
return super.hash(this.context.entrypoint.target, this.context.chainId);
}

async sign(signer) {
this.signature = await signer.signMessage(ethers.getBytes(this.hash()));
return this;
}
}

module.exports = {
Expand Down
Loading