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

chore: update to 4337 v0.7 (1/n) #48

Merged
merged 6 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion lib/account-abstraction
6 changes: 3 additions & 3 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.25;

import {BaseAccount} from "@eth-infinitism/account-abstraction/core/BaseAccount.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {EnumerableMap} from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
Expand Down Expand Up @@ -317,7 +317,7 @@ contract UpgradeableModularAccount is
// INTERNAL FUNCTIONS

// Parent function validateUserOp enforces that this call can only be made by the EntryPoint
function _validateSignature(UserOperation calldata userOp, bytes32 userOpHash)
function _validateSignature(PackedUserOperation calldata userOp, bytes32 userOpHash)
internal
virtual
override
Expand All @@ -337,7 +337,7 @@ contract UpgradeableModularAccount is
function _doUserOpValidation(
bytes4 selector,
FunctionReference userOpValidationFunction,
UserOperation calldata userOp,
PackedUserOperation calldata userOp,
bytes32 userOpHash
) internal returns (uint256 validationData) {
if (userOpValidationFunction.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/IPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.25;

import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

// Forge formatter will displace the first comment for the enum field out of the enum itself,
// so annotating here to prevent that.
Expand Down Expand Up @@ -116,7 +116,7 @@ interface IPlugin {
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function preUserOpValidationHook(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function preUserOpValidationHook(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
returns (uint256);

Expand All @@ -126,7 +126,7 @@ interface IPlugin {
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function userOpValidationFunction(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function userOpValidationFunction(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
returns (uint256);

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/BasePlugin.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.25;

import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import {IPlugin, PluginManifest, PluginMetadata} from "../interfaces/IPlugin.sol";
Expand Down Expand Up @@ -38,7 +38,7 @@ abstract contract BasePlugin is ERC165, IPlugin {
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function preUserOpValidationHook(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function preUserOpValidationHook(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
virtual
returns (uint256)
Expand All @@ -53,7 +53,7 @@ abstract contract BasePlugin is ERC165, IPlugin {
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function userOpValidationFunction(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function userOpValidationFunction(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
virtual
returns (uint256)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/owner/SingleOwnerPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.25;
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {IERC1271} from "@openzeppelin/contracts/interfaces/IERC1271.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

import {UUPSUpgradeable} from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
import {IPluginManager} from "../../interfaces/IPluginManager.sol";
Expand Down Expand Up @@ -91,7 +91,7 @@ contract SingleOwnerPlugin is BasePlugin, ISingleOwnerPlugin, IERC1271 {
}

/// @inheritdoc BasePlugin
function userOpValidationFunction(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function userOpValidationFunction(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
view
override
Expand Down
4 changes: 2 additions & 2 deletions src/samples/plugins/ModularSessionKeyPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.25;

// import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
// import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
// import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
// import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
// import {UpgradeableModularAccount} from "../../account/UpgradeableModularAccount.sol";
// import {
// ManifestFunction,
Expand Down Expand Up @@ -188,7 +188,7 @@ pragma solidity ^0.8.25;
// }

// /// @inheritdoc BasePlugin
// function userOpValidationFunction(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
// function userOpValidationFunction(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
// external
// view
// override
Expand Down
2 changes: 1 addition & 1 deletion src/samples/plugins/interfaces/ISessionKeyPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.25;

// import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
// import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

// interface IModularSessionKeyPlugin {
// enum FunctionId {
Expand Down
2 changes: 1 addition & 1 deletion src/samples/plugins/interfaces/ITokenSessionKeyPlugin.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.25;

// import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
// import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

// interface ITokenSessionKeyPlugin {
// error NotAuthorized();
Expand Down
4 changes: 2 additions & 2 deletions standard/ERCs/erc-6900.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ interface IPlugin {
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function preUserOpValidationHook(uint8 functionId, UserOperation memory userOp, bytes32 userOpHash) external returns (uint256);
function preUserOpValidationHook(uint8 functionId, PackedUserOperation memory userOp, bytes32 userOpHash) external returns (uint256);

/// @notice Run the user operation validationFunction specified by the `functionId`.
/// @param functionId An identifier that routes the call to different internal implementations, should there be
/// more than one.
/// @param userOp The user operation.
/// @param userOpHash The user operation hash.
/// @return Packed validation data for validAfter (6 bytes), validUntil (6 bytes), and authorizer (20 bytes).
function userOpValidationFunction(uint8 functionId, UserOperation calldata userOp, bytes32 userOpHash)
function userOpValidationFunction(uint8 functionId, PackedUserOperation calldata userOp, bytes32 userOpHash)
external
returns (uint256);

Expand Down
69 changes: 31 additions & 38 deletions test/account/UpgradeableModularAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.19;
import {console} from "forge-std/Test.sol";

import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import {UserOperation} from "@eth-infinitism/account-abstraction/interfaces/UserOperation.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";

import {PluginManagerInternals} from "../../src/account/PluginManagerInternals.sol";
import {UpgradeableModularAccount} from "../../src/account/UpgradeableModularAccount.sol";
Expand Down Expand Up @@ -42,6 +42,11 @@ contract UpgradeableModularAccountTest is AccountTestBase {
event PluginUninstalled(address indexed plugin, bool indexed callbacksSucceeded);
event ReceivedCall(bytes msgData, uint256 msgValue);

// helper function to compress 2 gas values into a single bytes32
function _encodeGas(uint256 g1, uint256 g2) internal pure returns (bytes32) {
return bytes32(uint256(g1 << 128 + uint128(g2)));
}

howydev marked this conversation as resolved.
Show resolved Hide resolved
function setUp() public {
tokenReceiverPlugin = _deployTokenReceiverPlugin();

Expand All @@ -62,16 +67,14 @@ contract UpgradeableModularAccountTest is AccountTestBase {
}

function test_postDeploy_ethSend() public {
UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});
Expand All @@ -81,7 +84,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

entryPoint.handleOps(userOps, beneficiary);
Expand All @@ -90,16 +93,14 @@ contract UpgradeableModularAccountTest is AccountTestBase {
}

function test_basicUserOp_withInitCode() public {
UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account2),
nonce: 0,
initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))),
callData: abi.encodeCall(SingleOwnerPlugin.transferOwnership, (owner2)),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 2,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 2),
paymasterAndData: "",
signature: ""
});
Expand All @@ -109,7 +110,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner2Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

entryPoint.handleOps(userOps, beneficiary);
Expand All @@ -118,16 +119,14 @@ contract UpgradeableModularAccountTest is AccountTestBase {
function test_standardExecuteEthSend_withInitcode() public {
address payable recipient = payable(makeAddr("recipient"));

UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account2),
nonce: 0,
initCode: abi.encodePacked(address(factory), abi.encodeCall(factory.createAccount, (owner2, 0))),
callData: abi.encodeCall(UpgradeableModularAccount.execute, (recipient, 1 wei, "")),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 2,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});
Expand All @@ -137,7 +136,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner2Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

entryPoint.handleOps(userOps, beneficiary);
Expand All @@ -146,16 +145,14 @@ contract UpgradeableModularAccountTest is AccountTestBase {
}

function test_debug_upgradeableModularAccount_storageAccesses() public {
UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(UpgradeableModularAccount.execute, (ethRecipient, 1 wei, "")),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});
Expand All @@ -165,7 +162,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

vm.record();
Expand All @@ -174,18 +171,16 @@ contract UpgradeableModularAccountTest is AccountTestBase {
}

function test_contractInteraction() public {
UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(
UpgradeableModularAccount.execute, (address(counter), 0, abi.encodeCall(counter.increment, ()))
),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
),
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});
Expand All @@ -195,7 +190,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

entryPoint.handleOps(userOps, beneficiary);
Expand All @@ -209,16 +204,14 @@ contract UpgradeableModularAccountTest is AccountTestBase {
calls[0] = Call({target: ethRecipient, value: 1 wei, data: ""});
calls[1] = Call({target: address(counter), value: 0, data: abi.encodeCall(counter.increment, ())});

UserOperation memory userOp = UserOperation({
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(UpgradeableModularAccount.executeBatch, (calls)),
callGasLimit: CALL_GAS_LIMIT,
verificationGasLimit: VERIFICATION_GAS_LIMIT,
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
maxFeePerGas: 1,
maxPriorityFeePerGas: 1,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});
Expand All @@ -228,7 +221,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(r, s, v);

UserOperation[] memory userOps = new UserOperation[](1);
PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;

entryPoint.handleOps(userOps, beneficiary);
Expand Down
Loading
Loading