From 2141d3faf5ac28a40a8619d812a8c72cc609ac81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Garc=C3=ADa?= Date: Tue, 4 Feb 2025 12:39:24 -0600 Subject: [PATCH] Rename ERC4337Utils ENTRYPOINT to ENTRYPOINT_V07 (#5472) Co-authored-by: Hadrien Croubois --- .changeset/chilly-guests-jam.md | 5 -- .../account/utils/draft-ERC4337Utils.sol | 27 +------ test/account/utils/draft-ERC4337Utils.test.js | 75 ++----------------- test/account/utils/draft-ERC7579Utils.t.sol | 15 ++-- 4 files changed, 15 insertions(+), 107 deletions(-) delete mode 100644 .changeset/chilly-guests-jam.md diff --git a/.changeset/chilly-guests-jam.md b/.changeset/chilly-guests-jam.md deleted file mode 100644 index a730ffc6a..000000000 --- a/.changeset/chilly-guests-jam.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'openzeppelin-solidity': minor ---- - -`ERC4337Utils`: Add functions to manage deposit and stake on the paymaster. diff --git a/contracts/account/utils/draft-ERC4337Utils.sol b/contracts/account/utils/draft-ERC4337Utils.sol index 5a56ec752..b17a0db81 100644 --- a/contracts/account/utils/draft-ERC4337Utils.sol +++ b/contracts/account/utils/draft-ERC4337Utils.sol @@ -17,7 +17,7 @@ library ERC4337Utils { using Packing for *; /// @dev Address of the entrypoint v0.7.0 - IEntryPoint internal constant ENTRYPOINT = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032); + IEntryPoint internal constant ENTRYPOINT_V07 = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032); /// @dev For simulation purposes, validateUserOp (and validatePaymasterUserOp) return this value on success. uint256 internal constant SIG_VALIDATION_SUCCESS = 0; @@ -163,29 +163,4 @@ library ERC4337Utils { function paymasterData(PackedUserOperation calldata self) internal pure returns (bytes calldata) { return self.paymasterAndData.length < 52 ? Calldata.emptyBytes() : self.paymasterAndData[52:]; } - - /// @dev Deposit ether into the entrypoint. - function depositTo(address to, uint256 value) internal { - ENTRYPOINT.depositTo{value: value}(to); - } - - /// @dev Withdraw ether from the entrypoint. - function withdrawTo(address payable to, uint256 value) internal { - ENTRYPOINT.withdrawTo(to, value); - } - - /// @dev Add stake to the entrypoint. - function addStake(uint256 value, uint32 unstakeDelaySec) internal { - ENTRYPOINT.addStake{value: value}(unstakeDelaySec); - } - - /// @dev Unlock stake on the entrypoint. - function unlockStake() internal { - ENTRYPOINT.unlockStake(); - } - - /// @dev Withdraw unlocked stake from the entrypoint. - function withdrawStake(address payable to) internal { - ENTRYPOINT.withdrawStake(to); - } } diff --git a/test/account/utils/draft-ERC4337Utils.test.js b/test/account/utils/draft-ERC4337Utils.test.js index 076926851..d3523477a 100644 --- a/test/account/utils/draft-ERC4337Utils.test.js +++ b/test/account/utils/draft-ERC4337Utils.test.js @@ -4,16 +4,15 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { packValidationData, UserOperation } = require('../../helpers/erc4337'); const { MAX_UINT48 } = require('../../helpers/constants'); -const time = require('../../helpers/time'); const ADDRESS_ONE = '0x0000000000000000000000000000000000000001'; const fixture = async () => { - const [authorizer, sender, factory, paymaster, other] = await ethers.getSigners(); + const [authorizer, sender, factory, paymaster] = await ethers.getSigners(); const utils = await ethers.deployContract('$ERC4337Utils'); const SIG_VALIDATION_SUCCESS = await utils.$SIG_VALIDATION_SUCCESS(); const SIG_VALIDATION_FAILED = await utils.$SIG_VALIDATION_FAILED(); - return { utils, authorizer, sender, factory, paymaster, other, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED }; + return { utils, authorizer, sender, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED }; }; describe('ERC4337Utils', function () { @@ -21,6 +20,12 @@ describe('ERC4337Utils', function () { Object.assign(this, await loadFixture(fixture)); }); + describe('entrypoint', function () { + it('v0.7.0', async function () { + await expect(this.utils.$ENTRYPOINT_V07()).to.eventually.equal(entrypoint); + }); + }); + describe('parseValidationData', function () { it('parses the validation data', async function () { const authorizer = this.authorizer; @@ -285,68 +290,4 @@ describe('ERC4337Utils', function () { }); }); }); - - describe('stake management', function () { - const unstakeDelaySec = 3600n; - - beforeEach(async function () { - await this.authorizer.sendTransaction({ to: this.utils, value: ethers.parseEther('1') }); - }); - - it('deposit & withdraw', async function () { - await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(0n); - - // deposit - await expect(this.utils.$depositTo(this.utils, 42n)).to.changeEtherBalances( - [this.utils, entrypoint], - [-42n, 42n], - ); - - await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(42n); - - // withdraw - await expect(this.utils.$withdrawTo(this.other, 17n)).to.changeEtherBalances( - [entrypoint, this.other], - [-17n, 17n], - ); - - await expect(entrypoint.balanceOf(this.utils)).to.eventually.equal(25n); // 42 - 17 - }); - - it('stake, unlock & withdraw stake', async function () { - await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]); - - // stake - await expect(this.utils.$addStake(42n, unstakeDelaySec)).to.changeEtherBalances( - [this.utils, entrypoint], - [-42n, 42n], - ); - - await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, true, 42n, unstakeDelaySec, 0n]); - - // unlock - const unlockTx = this.utils.$unlockStake(); - await expect(unlockTx).to.changeEtherBalances([this.utils, entrypoint], [0n, 0n]); // no ether movement - - const timestamp = await time.clockFromReceipt.timestamp(unlockTx); - await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([ - 0n, - false, - 42n, - unstakeDelaySec, - timestamp + unstakeDelaySec, - ]); - - // wait - await time.increaseBy.timestamp(unstakeDelaySec); - - // withdraw stake - await expect(this.utils.$withdrawStake(this.other)).to.changeEtherBalances( - [this.utils, entrypoint, this.other], - [0n, -42n, 42n], - ); - - await expect(entrypoint.deposits(this.utils)).to.eventually.deep.equal([0n, false, 0n, 0n, 0n]); - }); - }); }); diff --git a/test/account/utils/draft-ERC7579Utils.t.sol b/test/account/utils/draft-ERC7579Utils.t.sol index fdd4edf59..ea5890943 100644 --- a/test/account/utils/draft-ERC7579Utils.t.sol +++ b/test/account/utils/draft-ERC7579Utils.t.sol @@ -20,8 +20,6 @@ contract SampleAccount is IAccount, Ownable { using ERC4337Utils for *; using ERC7579Utils for *; - IEntryPoint internal constant ENTRY_POINT = IEntryPoint(payable(0x0000000071727De22E5E9d8BAf0edAc6f37da032)); - event Log(bool duringValidation, Execution[] calls); error UnsupportedCallType(CallType callType); @@ -33,7 +31,7 @@ contract SampleAccount is IAccount, Ownable { bytes32 userOpHash, uint256 missingAccountFunds ) external override returns (uint256 validationData) { - require(msg.sender == address(ENTRY_POINT), "only from EP"); + require(msg.sender == address(ERC4337Utils.ENTRYPOINT_V07), "only from EP"); // Check signature if (userOpHash.toEthSignedMessageHash().recover(userOp.signature) != owner()) { revert OwnableUnauthorizedAccount(_msgSender()); @@ -81,7 +79,7 @@ contract SampleAccount is IAccount, Ownable { } function execute(Mode mode, bytes calldata executionCalldata) external payable { - require(msg.sender == address(this) || msg.sender == address(ENTRY_POINT), "not auth"); + require(msg.sender == address(this) || msg.sender == address(ERC4337Utils.ENTRYPOINT_V07), "not auth"); (CallType callType, ExecType execType, , ) = mode.decodeMode(); @@ -105,7 +103,6 @@ contract ERC7579UtilsTest is Test { using ERC4337Utils for *; using ERC7579Utils for *; - IEntryPoint private constant ENTRYPOINT = IEntryPoint(payable(0x0000000071727De22E5E9d8BAf0edAc6f37da032)); address private _owner; uint256 private _ownerKey; address private _account; @@ -166,7 +163,7 @@ contract ERC7579UtilsTest is Test { userOps[0].signature = abi.encodePacked(r, s, v); vm.recordLogs(); - ENTRYPOINT.handleOps(userOps, payable(_beneficiary)); + ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary)); assertEq(_recipient1.balance, 1 wei); assertEq(_recipient2.balance, 1 wei); @@ -224,7 +221,7 @@ contract ERC7579UtilsTest is Test { abi.encodeWithSelector(ERC7579Utils.ERC7579DecodingError.selector) ) ); - ENTRYPOINT.handleOps(userOps, payable(_beneficiary)); + ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary)); _collectAndPrintLogs(false); } @@ -282,7 +279,7 @@ contract ERC7579UtilsTest is Test { abi.encodeWithSelector(ERC7579Utils.ERC7579DecodingError.selector) ) ); - ENTRYPOINT.handleOps(userOps, payable(_beneficiary)); + ERC4337Utils.ENTRYPOINT_V07.handleOps(userOps, payable(_beneficiary)); _collectAndPrintLogs(true); } @@ -378,7 +375,7 @@ contract ERC7579UtilsTest is Test { } function hashUserOperation(PackedUserOperation calldata useroperation) public view returns (bytes32) { - return useroperation.hash(address(ENTRYPOINT), block.chainid); + return useroperation.hash(address(ERC4337Utils.ENTRYPOINT_V07), block.chainid); } function _collectAndPrintLogs(bool includeTotalValue) internal {