diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/Simple7702Account.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/Simple7702Account.sol index b3fc0eb1..74d96086 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/Simple7702Account.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/Simple7702Account.sol @@ -37,7 +37,7 @@ contract Simple7702Account is BaseAccount, IERC165, IERC1271, ERC1155Holder, ERC return _checkSignature(userOpHash, userOp.signature) ? SIG_VALIDATION_SUCCESS : SIG_VALIDATION_FAILED; } - function isValidSignature(bytes32 hash, bytes memory signature) public view returns (bytes4 magicValue) { + function isValidSignature(bytes32 hash, bytes memory signature) public virtual view returns (bytes4 magicValue) { return _checkSignature(hash, signature) ? this.isValidSignature.selector : bytes4(0xffffffff); } @@ -57,7 +57,7 @@ contract Simple7702Account is BaseAccount, IERC165, IERC1271, ERC1155Holder, ERC ); } - function supportsInterface(bytes4 id) public override(ERC1155Holder, IERC165) pure returns (bool) { + function supportsInterface(bytes4 id) public virtual override(ERC1155Holder, IERC165) pure returns (bool) { return id == type(IERC165).interfaceId || id == type(IAccount).interfaceId || diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccount.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccount.sol index 82a19626..82ccebf4 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccount.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccount.sol @@ -71,7 +71,7 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In function _initialize(address anOwner) internal virtual { owner = anOwner; - emit SimpleAccountInitialized(_entryPoint, owner); + emit SimpleAccountInitialized(entryPoint(), owner); } // Require the function call went through EntryPoint or owner @@ -99,7 +99,7 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In /** * check current account deposit in the entryPoint */ - function getDeposit() public view returns (uint256) { + function getDeposit() public virtual view returns (uint256) { return entryPoint().balanceOf(address(this)); } @@ -115,7 +115,7 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In * @param withdrawAddress target to send to * @param amount to withdraw */ - function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public onlyOwner { + function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public virtual onlyOwner { entryPoint().withdrawTo(withdrawAddress, amount); } diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccountFactory.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccountFactory.sol index f542db34..524fab59 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccountFactory.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/accounts/SimpleAccountFactory.sol @@ -52,7 +52,7 @@ contract SimpleAccountFactory { /** * calculate the counterfactual address of this account as it would be returned by createAccount() */ - function getAddress(address owner,uint256 salt) public view returns (address) { + function getAddress(address owner,uint256 salt) public virtual view returns (address) { return Create2.computeAddress(bytes32(salt), keccak256(abi.encodePacked( type(ERC1967Proxy).creationCode, abi.encode( diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/BasePaymaster.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/BasePaymaster.sol index 5137e34a..5544a413 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/BasePaymaster.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/BasePaymaster.sol @@ -107,7 +107,7 @@ abstract contract BasePaymaster is IPaymaster, Stakeable { * Add a deposit for this paymaster, used for paying for transaction fees. */ function deposit() public payable { - _entryPoint.depositTo{value: msg.value}(address(this)); + entryPoint().depositTo{value: msg.value}(address(this)); } /** @@ -119,13 +119,13 @@ abstract contract BasePaymaster is IPaymaster, Stakeable { address payable withdrawAddress, uint256 amount ) public onlyOwner { - _entryPoint.withdrawTo(withdrawAddress, amount); + entryPoint().withdrawTo(withdrawAddress, amount); } /** * Return current paymaster's deposit on the entryPoint. */ - function getDeposit() public view returns (uint256) { + function getDeposit() public virtual view returns (uint256) { return _entryPoint.balanceOf(address(this)); } @@ -133,7 +133,7 @@ abstract contract BasePaymaster is IPaymaster, Stakeable { * Validate the call is made from a valid entrypoint */ function _requireFromEntryPoint() internal virtual { - require(msg.sender == address(_entryPoint), + require(msg.sender == address(entryPoint()), NotFromEntryPoint( msg.sender, address(this), diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Eip7702Support.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Eip7702Support.sol index 9823aefa..51cababd 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Eip7702Support.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Eip7702Support.sol @@ -1,5 +1,6 @@ -pragma solidity ^0.8.28; // SPDX-License-Identifier: MIT +pragma solidity ^0.8.28; + // solhint-disable no-inline-assembly import "../interfaces/PackedUserOperation.sol"; @@ -75,7 +76,6 @@ library Eip7702Support { // To be a valid EIP-7702 delegate, the first 3 bytes are EIP7702_PREFIX // followed by the delegate address if (bytes3(senderCode) != EIP7702_PREFIX) { - // instead of just "not an EIP-7702 delegate", if some info. require(sender.code.length > 0, Eip7702SenderWithoutCode(sender)); revert Eip7702SenderNotDelegate(sender); } diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/EntryPoint.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/EntryPoint.sol index 1244b710..3b4feb6e 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/EntryPoint.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/EntryPoint.sol @@ -22,6 +22,8 @@ import "@openzeppelin/contracts/utils/introspection/ERC165.sol"; import "@openzeppelin/contracts/utils/cryptography/EIP712.sol"; /** + * Always verify the EntryPoint addresses across multiple trusted sources. + * Visit https://docs.erc4337.io/ for instructions and official documentation. * Account-Abstraction (EIP-4337) singleton EntryPoint v0.9 implementation. * Only one instance required on each chain. * @custom:security-contact https://bounty.ethereum.org @@ -210,6 +212,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ERC165, EIP712 { */ function _compensate(address payable beneficiary, uint256 amount) internal virtual { require(beneficiary != address(0), InvalidBeneficiary(beneficiary)); + currentUserOpHash = bytes32(0); (bool success, bytes memory ret) = beneficiary.call{value: amount}(""); require(success, FailedSendToBeneficiary(beneficiary, amount, ret)); } @@ -681,7 +684,6 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ERC165, EIP712 { bool success; uint256 contextLength; uint256 contextOffset; - uint256 maxContextLength; uint256 len; assembly ("memory-safe") { success := call(paymasterVerificationGasLimit, paymaster, 0, add(validatePaymasterCall, 0x20), mload(validatePaymasterCall), 0, 0) @@ -699,15 +701,19 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ERC165, EIP712 { returndatacopy(freePtr, 0, len) validationData := mload(add(freePtr, 32)) contextOffset := mload(freePtr) - maxContextLength := sub(len, 96) context := add(freePtr, 64) contextLength := mload(context) } unchecked { - if (!success || contextOffset != 64 || contextLength + 31 < maxContextLength) { + if (!success) { revert FailedOpWithRevert(opIndex, "AA33 reverted", Exec.getReturnData(REVERT_REASON_MAX_LEN)); } + // for a given 'contextLength', calculate the only valid 'returndatasize' value + uint256 expectedReturnDataSize = 96 + ((contextLength + 31) / 32) * 32; + if (contextOffset != 64 || len != expectedReturnDataSize) { + revert FailedOpWithRevert(opIndex, "AA35 malformed paymaster data", Exec.getReturnData(REVERT_REASON_MAX_LEN)); + } } finalizeAllocation(freePtr, len); } @@ -769,7 +775,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ERC165, EIP712 { } ValidationData memory data = _parseValidationData(validationData); // using top bit of 'validAfter' and 'validUntil' to indicate block-range instead of time-range - if (data.validAfter > VALIDITY_BLOCK_RANGE_FLAG && data.validUntil > VALIDITY_BLOCK_RANGE_FLAG) { + if (data.validAfter >= VALIDITY_BLOCK_RANGE_FLAG && data.validUntil >= VALIDITY_BLOCK_RANGE_FLAG) { uint48 validAfterBlock = data.validAfter & VALIDITY_BLOCK_RANGE_MASK; uint48 validUntilBlock = data.validUntil & VALIDITY_BLOCK_RANGE_MASK; outOfValidityRange = block.number > validUntilBlock || block.number <= validAfterBlock; @@ -805,7 +811,7 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ERC165, EIP712 { MemoryUserOp memory mUserOp = outOpInfo.mUserOp; _copyUserOpToMemory(userOp, mUserOp); - // getUserOpHash uses temporary allocations, no required after it returns + // 'getUserOpHash' uses temporary memory allocation and all data allocated inside can be reused after it returns uint256 freePtr = _getFreePtr(); outOpInfo.userOpHash = getUserOpHash(userOp); _restoreFreePtr(freePtr); diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Helpers.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Helpers.sol index aba53e3f..b00524b2 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Helpers.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/Helpers.sol @@ -108,7 +108,7 @@ function calldataKeccak(bytes calldata data) pure returns (bytes32 ret) { * This function copies the first `len` bytes from the given calldata array `data` into memory. * The assembly code is equivalent to: * keccak256(abi.encodePacked(data[0:len], suffix)) - * But more efficient, and doesn't leave the copied data in memory. + * But more efficient, and doesn't move the free memory pointer, allowing the memory to be reused later. * * @param data Calldata byte array to read from. * @param len Number of bytes to copy from `data` starting at its offset. diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/NonceManager.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/NonceManager.sol index 5be79d5e..4c0becd2 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/NonceManager.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/core/NonceManager.sol @@ -15,7 +15,7 @@ abstract contract NonceManager is INonceManager { /// @inheritdoc INonceManager function getNonce(address sender, uint192 key) - public view override returns (uint256 nonce) { + public virtual view override returns (uint256 nonce) { return nonceSequenceNumber[sender][key] | (uint256(key) << 64); } diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPoint.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPoint.sol index 26697fd2..7d5f568b 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPoint.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPoint.sol @@ -127,13 +127,17 @@ interface IEntryPoint is IStakeManager, INonceManager { event SignatureAggregatorChanged(address indexed aggregator); /** - * A custom revert error of handleOps andhandleAggregatedOps, to identify the offending op. - * Should be caught in off-chain handleOps/handleAggregatedOps simulation and not happen on-chain. + * A custom revert error of 'handleOps' and 'handleAggregatedOps', to identify the offending UserOperation. + * Should be caught in off-chain 'handleOps'/'handleAggregatedOps' simulation and should not happen on-chain. + * * Useful for mitigating DoS attempts against batchers or for troubleshooting of factory/account/paymaster reverts. - * NOTE: If simulateValidation passes successfully, there should be no reason for handleOps to fail on it. - * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). + * NOTE: If 'simulateValidation' passes successfully, there should be no reason for 'handleOps' to revert as well. + * + * @param opIndex - Index into the array of ops to the failed one. + * When using 'simulateValidation', this value is always zero. + * * @param reason - Revert reason. The string starts with a unique code "AAmn", - * where "m" is "1" for factory, "2" for account and "3" for paymaster issues, + * where "m" is "1" for factory, "2" for account, "3" for paymaster, and "9" for other issues, * so a failure can be attributed to the correct entity. */ error FailedOp(uint256 opIndex, string reason); @@ -146,9 +150,9 @@ interface IEntryPoint is IStakeManager, INonceManager { /** * A custom revert error of handleOps and handleAggregatedOps, to report a revert by account or paymaster. - * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). - * @param reason - Revert reason. see FailedOp(uint256,string), above - * @param inner - data from inner cought revert reason + * @param opIndex - Index of the failed UserOperation in the array of ops. In simulateValidation, this value is always zero. + * @param reason - Revert reason. See the 'FailedOp(uint256,string)' error above. + * @param inner - Revert data caught from the inner revert reason of an entity contract. * @dev note that inner is truncated to 2048 bytes */ error FailedOpWithRevert(uint256 opIndex, string reason, bytes inner); diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPointSimulations.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPointSimulations.sol index 60cab7d3..9e54c2a9 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPointSimulations.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/IEntryPointSimulations.sol @@ -58,13 +58,11 @@ interface IEntryPointSimulations is IEntryPoint { ); /** - * Simulate full execution of a UserOperation (including both validation and target execution) - * It performs full validation of the UserOperation, but ignores signature error. - * An optional target address is called after the userop succeeds, - * and its value is returned (before the entire call is reverted). - * Note that in order to collect the the success/failure of the target call, it must be executed - * with trace enabled to track the emitted events. - * @param op The UserOperation to simulate. + * Simulate the full execution of a UserOperation, including both validation and target execution. + * It performs a full validation of the UserOperation, but ignores signature error. + * An optional target address is called after the UserOperation succeeds, + * and this call's status and returned data value are returned as part of the `ExecutionResult` struct. + * @param op - The UserOperation to simulate. * @param target - If nonzero, a target address to call after userop simulation. If called, * the targetSuccess and targetResult are set to the return from that call. * @param targetCallData - CallData to pass to target address. diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/INonceManager.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/INonceManager.sol index 8f2cb1b9..dd136091 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/INonceManager.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/INonceManager.sol @@ -17,7 +17,7 @@ interface INonceManager { /** * Manually increment the nonce of the sender. - * This method is exposed just for completeness.. + * This method is exposed just for completeness. * Account does NOT need to call it, neither during validation, nor elsewhere, * as the EntryPoint will update the nonce regardless. * Possible use-case is call it with various keys to "initialize" their nonces to one, so that future diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/PackedUserOperation.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/PackedUserOperation.sol index c16dec78..bc14fb30 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/PackedUserOperation.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/interfaces/PackedUserOperation.sol @@ -22,7 +22,8 @@ pragma solidity ^0.8.28; * - nonce = uint192(key) || uint64(sequence); EntryPoint tracks sequential values of `sequence` separately for each `key` value. * - initCode: * * non-7702: `initCode = factory(20) || factoryCalldata`; the factory must return `sender` and deploy code. - * * 7702: `0x7702` (magic prefix), optionally padded to 20 bytes and followed by `initizlizationCode`. This optional payload is executed on `sender` to finalise delegate setup. + * * The `initCode` will be ignored if the `sender` is already deployed. + * * 7702: `0x7702` (magic prefix), optionally padded to 20 bytes and followed by the actual `initializationCode` data. This optional payload is executed on `sender` to finalise delegate setup. * - callData: executed verbatim; if it starts with `IAccountExecute.executeUserOp.selector` (0x8dd7712f), EntryPoint wraps and forwards `(userOp, userOpHash)`. * - accountGasLimits =`uint128(verificationGasLimit) || uint128(callGasLimit)` * - gasFees = `uint128(maxPriorityFeePerGas) || uint128(maxFeePerGas)` diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestAggregatedAccountFactory.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestAggregatedAccountFactory.sol index d1cda5e7..37a98655 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestAggregatedAccountFactory.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestAggregatedAccountFactory.sol @@ -39,7 +39,7 @@ contract TestAggregatedAccountFactory { /** * calculate the counterfactual address of this account as it would be returned by createAccount() */ - function getAddress(address owner,uint256 salt) public view returns (address) { + function getAddress(address owner,uint256 salt) public virtual view returns (address) { return Create2.computeAddress(bytes32(salt), keccak256(abi.encodePacked( type(ERC1967Proxy).creationCode, abi.encode( diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestExecAccountFactory.sol b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestExecAccountFactory.sol index 00162edc..b377eb1f 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestExecAccountFactory.sol +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/contracts/test/TestExecAccountFactory.sol @@ -15,7 +15,7 @@ contract TestExecAccountFactory { accountImplementation = new TestExecAccount(_entryPoint); } - function createAccount(address owner, uint256 salt) public returns (address ret) { + function createAccount(address owner, uint256 salt) public virtual returns (address ret) { address addr = getAddress(owner, salt); uint256 codeSize = addr.code.length; if (codeSize > 0) { diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/hardhat.config.ts b/dependencies/eth-infinitism-account-abstraction-0.9.0/hardhat.config.ts index df70c416..fd05e9be 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/hardhat.config.ts +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/hardhat.config.ts @@ -5,7 +5,7 @@ import 'hardhat-deploy' import * as fs from 'fs' -const SALT = '0xf62e359b3876ea3aed0db458ca0d376745a17f194044ffb6da0fd0d9ffe0dc58' +const SALT = '0x7702864008ddeab30aa67b7adc3d2653bc8d162714b1fe8fe4582df814f3bf61' process.env.SALT = process.env.SALT ?? SALT task('deploy', 'Deploy contracts') diff --git a/dependencies/eth-infinitism-account-abstraction-0.9.0/reports/gas-checker.txt b/dependencies/eth-infinitism-account-abstraction-0.9.0/reports/gas-checker.txt index f2729e8b..daeceb8f 100644 --- a/dependencies/eth-infinitism-account-abstraction-0.9.0/reports/gas-checker.txt +++ b/dependencies/eth-infinitism-account-abstraction-0.9.0/reports/gas-checker.txt @@ -12,36 +12,36 @@ ║ │ │ │ (delta for │ (compared to ║ ║ │ │ │ one UserOp) │ account.exec()) ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 1 │ 77637 │ │ ║ +║ simple │ 1 │ 77742 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple - diff from previous │ 2 │ │ 41882 │ 10761 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple │ 10 │ 454671 │ │ ║ +║ simple │ 10 │ 454776 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple - diff from previous │ 11 │ │ 41879 │ 10758 ║ +║ simple - diff from previous │ 11 │ │ 41927 │ 10806 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 1 │ 83312 │ │ ║ +║ simple paymaster │ 1 │ 83434 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 2 │ │ 40305 │ 9184 ║ +║ simple paymaster with diff │ 2 │ │ 40274 │ 9153 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 10 │ 446120 │ │ ║ +║ simple paymaster │ 10 │ 446011 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 11 │ │ 40270 │ 9149 ║ +║ simple paymaster with diff │ 11 │ │ 40323 │ 9202 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 1 │ 167403 │ │ ║ +║ big tx 5k │ 1 │ 167520 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 2 │ │ 131133 │ 14567 ║ +║ big tx - diff from previous │ 2 │ │ 131109 │ 14543 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx 5k │ 10 │ 1347527 │ │ ║ +║ big tx 5k │ 10 │ 1347572 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ big tx - diff from previous │ 11 │ │ 131082 │ 14516 ║ +║ big tx - diff from previous │ 11 │ │ 131142 │ 14576 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 1 │ 84708 │ │ ║ +║ paymaster+postOp │ 1 │ 84782 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 2 │ │ 41666 │ 10545 ║ +║ paymaster+postOp with diff │ 2 │ │ 41659 │ 10538 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 10 │ 459717 │ │ ║ +║ paymaster+postOp │ 10 │ 459644 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 11 │ │ 41716 │ 10595 ║ +║ paymaster+postOp with diff │ 11 │ │ 41637 │ 10516 ║ ╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝ diff --git a/foundry.toml b/foundry.toml index 389c4e85..fdb43bf9 100644 --- a/foundry.toml +++ b/foundry.toml @@ -30,7 +30,7 @@ depth = 1000 [dependencies] solady = "0.1.26" -eth-infinitism-account-abstraction = { version = "0.9.0", git = "https://github.com/eth-infinitism/account-abstraction.git", branch = "release-v09" } +eth-infinitism-account-abstraction = { version = "0.9.0", git = "https://github.com/eth-infinitism/account-abstraction.git", rev = "b36a1ed52ae00da6f8a4c8d50181e2877e4fa410" } "@openzeppelin-contracts" = "5.4.0" a16z-halmos-cheatcodes = "6da4e692c357ba6d641a2e677a28298cac9f76ab" forge-std = "1.11.0" diff --git a/soldeer.lock b/soldeer.lock index 7a003576..246d031c 100644 --- a/soldeer.lock +++ b/soldeer.lock @@ -16,7 +16,7 @@ integrity = "d61b6628a05317095546185bf5bd4037050fc2a9c7db23c54cc398a618266ea4" name = "eth-infinitism-account-abstraction" version = "0.9.0" git = "https://github.com/eth-infinitism/account-abstraction.git" -rev = "86fcd84cf7263fe384d61d078ee747b16e69a496" +rev = "b36a1ed52ae00da6f8a4c8d50181e2877e4fa410" [[dependencies]] name = "forge-std" diff --git a/src/lib/Lib4337.sol b/src/lib/Lib4337.sol index 470684fb..09d3d97b 100644 --- a/src/lib/Lib4337.sol +++ b/src/lib/Lib4337.sol @@ -77,9 +77,9 @@ library Lib4337 { return _intersectValidationData(a, b); } - /// @dev Returns true if validation data uses block number format per EntryPoint v0.9. + /// @dev The EntryPoint v0.9.0 release uses block mode when both bounds have MODE_BIT set. function _usesBlockNumberFormat(uint48 validAfter, uint48 validUntil) internal pure returns (bool) { - return validAfter > MODE_BIT && validUntil > MODE_BIT; + return validAfter >= MODE_BIT && validUntil >= MODE_BIT; } function _intersectValidationData(uint256 preValidationData, uint256 validationRes) diff --git a/test/CheckValidation.t.sol b/test/CheckValidation.t.sol index 51e2d16f..59bb91b8 100644 --- a/test/CheckValidation.t.sol +++ b/test/CheckValidation.t.sol @@ -98,13 +98,19 @@ contract CheckValidationTest is Test { assertTrue(Lib4337.checkValidation(_pack(MODE_BIT | 100, 0, address(0)))); } - // --- exact MODE_BIT classification (strictly greater than the flag) ------- + function test_Block_ExactModeBitValidAfter_RejectsBlockZero() public { + vm.roll(0); + assertFalse(Lib4337.checkValidation(_pack(MODE_BIT, MODE_BIT | 10, address(0)))); + } + + function test_Block_ExactModeBitValidAfter_AcceptsBlockOne() public { + vm.roll(1); + assertTrue(Lib4337.checkValidation(_pack(MODE_BIT, MODE_BIT | 10, address(0)))); + } - function test_ExactModeBitBound_ClassifiesAsTimestampMode() public pure { - // EntryPoint v0.9 uses block-number mode only when both bounds exceed the flag. - assertFalse(Lib4337._usesBlockNumberFormat(MODE_BIT, MODE_BIT)); - assertFalse(Lib4337._usesBlockNumberFormat(MODE_BIT, MODE_BIT | 10)); - // One bound below MODE_BIT → timestamp format. + function test_ExactModeBitBound_ClassifiesAsBlockMode() public pure { + assertTrue(Lib4337._usesBlockNumberFormat(MODE_BIT, MODE_BIT)); + assertTrue(Lib4337._usesBlockNumberFormat(MODE_BIT, MODE_BIT | 10)); assertFalse(Lib4337._usesBlockNumberFormat(MODE_BIT - 1, MODE_BIT)); assertFalse(Lib4337._usesBlockNumberFormat(MODE_BIT, MODE_BIT - 1)); } diff --git a/test/IntersectValidationData.t.sol b/test/IntersectValidationData.t.sol index c9198bca..61839f54 100644 --- a/test/IntersectValidationData.t.sol +++ b/test/IntersectValidationData.t.sol @@ -381,11 +381,11 @@ contract IntersectValidationDataTest is Test { uint48 validAfter2, uint48 validUntil2 ) public { - // EntryPoint v0.9 uses block number format only when both bounds exceed MODE_BIT. - validAfter1 = (validAfter1 & (TIMESTAMP_MASK - 1)) + MODE_BIT + 1; - validUntil1 = (validUntil1 & (TIMESTAMP_MASK - 1)) + MODE_BIT + 1; - validAfter2 = (validAfter2 & (TIMESTAMP_MASK - 1)) + MODE_BIT + 1; - validUntil2 = (validUntil2 & (TIMESTAMP_MASK - 1)) + MODE_BIT + 1; + // Set the mode bit while retaining all possible block-number bounds. + validAfter1 |= MODE_BIT; + validUntil1 |= MODE_BIT; + validAfter2 |= MODE_BIT; + validUntil2 |= MODE_BIT; uint256 val1 = createValidationData(validAfter1, validUntil1, address(0)); uint256 val2 = createValidationData(validAfter2, validUntil2, address(0)); diff --git a/test/halmos/ValidityDataCompositionHalmos.t.sol b/test/halmos/ValidityDataCompositionHalmos.t.sol new file mode 100644 index 00000000..3342bd51 --- /dev/null +++ b/test/halmos/ValidityDataCompositionHalmos.t.sol @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.30; + +import {Vm} from "forge-std/Vm.sol"; +import {EntryPoint} from "account-abstraction/core/EntryPoint.sol"; +import {Lib4337} from "src/lib/Lib4337.sol"; + +contract EntryPointPredicate is EntryPoint { + function acceptsWindow(uint256 authorization) external view returns (bool) { + (address authorizer, bool invalidWindow,) = _getValidationData(authorization); + return authorizer != address(1) && !invalidWindow; + } +} + +contract ValidityDataCompositionHalmos { + Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code"))))); + EntryPointPredicate private entry; + + function setUp() external { + entry = new EntryPointPredicate(); + } + + function merge(uint256 first, uint256 second) external pure returns (uint256) { + return Lib4337.intersectValidationData(first, second); + } + + function check_MergePreservesEveryAuthorizationWindow( + uint256 first, + uint256 second, + uint48 timestamp, + uint48 blockNumber + ) external { + vm.assume(timestamp > 0); + vm.warp(timestamp); + vm.roll(blockNumber); + (bool success, bytes memory output) = address(this).staticcall(abi.encodeCall(this.merge, (first, second))); + if (!success) return; + uint256 result = abi.decode(output, (uint256)); + if (entry.acceptsWindow(result)) { + assert(entry.acceptsWindow(first) && entry.acceptsWindow(second)); + uint160 authorizer = uint160(result); + assert(uint160(first) == 0 || uint160(first) == authorizer); + assert(uint160(second) == 0 || uint160(second) == authorizer); + } + } +}