Cherrypick 0a77e54c30 onto release-v5.3 (#5605)

Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: ernestognw <ernestognw@gmail.com>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
This commit is contained in:
Hadrien Croubois
2025-03-26 09:36:37 +01:00
committed by GitHub
parent 39f5a0284e
commit bc3b02ff52
10 changed files with 131 additions and 91 deletions

View File

@ -22,7 +22,11 @@ describe('ERC4337Utils', function () {
describe('entrypoint', function () {
it('v0.7.0', async function () {
await expect(this.utils.$ENTRYPOINT_V07()).to.eventually.equal(entrypoint);
await expect(this.utils.$ENTRYPOINT_V07()).to.eventually.equal(entrypoint.v07);
});
it('v0.8.0', async function () {
await expect(this.utils.$ENTRYPOINT_V08()).to.eventually.equal(entrypoint.v08);
});
});
@ -172,22 +176,14 @@ describe('ERC4337Utils', function () {
});
describe('hash', function () {
it('returns the operation hash with specified entrypoint and chainId', async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1 });
const chainId = await ethers.provider.getNetwork().then(({ chainId }) => chainId);
const otherChainId = 0xdeadbeef;
for (const [version, instance] of Object.entries(entrypoint)) {
it(`returns the operation hash for entrypoint ${version}`, async function () {
const userOp = new UserOperation({ sender: this.sender, nonce: 1 });
const expected = await userOp.hash(instance);
// check that helper matches entrypoint logic
await expect(entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(entrypoint, chainId));
// check library against helper
await expect(this.utils.$hash(userOp.packed, entrypoint, chainId)).to.eventually.equal(
userOp.hash(entrypoint, chainId),
);
await expect(this.utils.$hash(userOp.packed, entrypoint, otherChainId)).to.eventually.equal(
userOp.hash(entrypoint, otherChainId),
);
});
await expect(this.utils.$hash(userOp.packed, instance)).to.eventually.equal(expected);
});
}
});
describe('userOp values', function () {

View File

@ -375,7 +375,7 @@ contract ERC7579UtilsTest is Test {
}
function hashUserOperation(PackedUserOperation calldata useroperation) public view returns (bytes32) {
return useroperation.hash(address(ERC4337Utils.ENTRYPOINT_V07), block.chainid);
return useroperation.hash(address(ERC4337Utils.ENTRYPOINT_V07));
}
function _collectAndPrintLogs(bool includeTotalValue) internal {

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"opIndex","type":"uint256"},{"internalType":"string","name":"reason","type":"string"},{"internalType":"bytes","name":"inner","type":"bytes"}],"name":"FailedOpWithRevert","type":"error"},{"inputs":[{"internalType":"bytes","name":"initCode","type":"bytes"}],"name":"createSender","outputs":[{"internalType":"address","name":"sender","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryPoint","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"bytes","name":"initCallData","type":"bytes"}],"name":"initEip7702Sender","outputs":[],"stateMutability":"nonpayable","type":"function"}]

Binary file not shown.

View File

@ -78,26 +78,8 @@ class UserOperation {
};
}
hash(entrypoint, chainId) {
const p = this.packed;
const h = ethers.keccak256(
ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256', 'bytes32', 'bytes32', 'uint256', 'uint256', 'uint256', 'uint256'],
[
p.sender,
p.nonce,
ethers.keccak256(p.initCode),
ethers.keccak256(p.callData),
p.accountGasLimits,
p.preVerificationGas,
p.gasFees,
ethers.keccak256(p.paymasterAndData),
],
),
);
return ethers.keccak256(
ethers.AbiCoder.defaultAbiCoder().encode(['bytes32', 'address', 'uint256'], [h, getAddress(entrypoint), chainId]),
);
hash(entrypoint) {
return entrypoint.getUserOpHash(this.packed);
}
}