Skip to content

Commit

Permalink
Update FunctionId naming
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed committed May 29, 2024
1 parent 6aa75b8 commit f347833
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/plugins/owner/ISingleOwnerPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {IValidation} from "../../interfaces/IValidation.sol";

interface ISingleOwnerPlugin is IValidation {
enum FunctionId {
VALIDATION_OWNER_OR_SELF,
VALIDATION_OWNER,
SIG_VALIDATION
}

Expand Down
6 changes: 3 additions & 3 deletions src/plugins/owner/SingleOwnerPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ contract SingleOwnerPlugin is ISingleOwnerPlugin, BasePlugin {
view
override
{
if (functionId == uint8(FunctionId.VALIDATION_OWNER_OR_SELF)) {
if (functionId == uint8(FunctionId.VALIDATION_OWNER)) {
// Validate that the sender is the owner of the account or self.
if (sender != _owners[msg.sender] && sender != msg.sender) {
revert NotAuthorized();
Expand All @@ -101,7 +101,7 @@ contract SingleOwnerPlugin is ISingleOwnerPlugin, BasePlugin {
override
returns (uint256)
{
if (functionId == uint8(FunctionId.VALIDATION_OWNER_OR_SELF)) {
if (functionId == uint8(FunctionId.VALIDATION_OWNER)) {
// Validate the user op signature against the owner.
(address signer,,) = (userOpHash.toEthSignedMessageHash()).tryRecover(userOp.signature);
if (signer == address(0) || signer != _owners[msg.sender]) {
Expand Down Expand Up @@ -158,7 +158,7 @@ contract SingleOwnerPlugin is ISingleOwnerPlugin, BasePlugin {

ManifestFunction memory ownerValidationFunction = ManifestFunction({
functionType: ManifestAssociatedFunctionType.SELF,
functionId: uint8(FunctionId.VALIDATION_OWNER_OR_SELF),
functionId: uint8(FunctionId.VALIDATION_OWNER),
dependencyIndex: 0 // Unused.
});
manifest.validationFunctions = new ManifestAssociatedFunction[](5);
Expand Down
2 changes: 1 addition & 1 deletion test/account/AccountLoupe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract AccountLoupeTest is AccountTestBase {
account1.installPlugin(address(comprehensivePlugin), manifestHash, "", new FunctionReference[](0));

ownerValidation = FunctionReferenceLib.pack(
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);
}

Expand Down
4 changes: 2 additions & 2 deletions test/account/AccountReturnData.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract AccountReturnDataTest is AccountTestBase {
account1.execute,
(address(regularResultContract), 0, abi.encodeCall(RegularResultContract.foo, ()))
),
abi.encodePacked(singleOwnerPlugin, ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
abi.encodePacked(singleOwnerPlugin, ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);

bytes32 result = abi.decode(abi.decode(returnData, (bytes)), (bytes32));
Expand All @@ -83,7 +83,7 @@ contract AccountReturnDataTest is AccountTestBase {

bytes memory retData = account1.executeWithAuthorization(
abi.encodeCall(account1.executeBatch, (calls)),
abi.encodePacked(singleOwnerPlugin, ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
abi.encodePacked(singleOwnerPlugin, ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);

bytes[] memory returnDatas = abi.decode(retData, (bytes[]));
Expand Down
23 changes: 10 additions & 13 deletions test/account/MultiValidation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ contract MultiValidationTest is AccountTestBase {

FunctionReference[] memory validations = new FunctionReference[](2);
validations[0] = FunctionReferenceLib.pack(
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
);
validations[1] = FunctionReferenceLib.pack(
address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);
validations[1] =
FunctionReferenceLib.pack(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER));
FunctionReference[] memory validations2 =
account1.getValidationFunctions(IStandardExecutor.execute.selector);
assertEq(validations2.length, 2);
Expand All @@ -69,17 +68,13 @@ contract MultiValidationTest is AccountTestBase {
);
account1.executeWithAuthorization(
abi.encodeCall(IStandardExecutor.execute, (address(0), 0, "")),
abi.encodePacked(
address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
)
abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER))
);

vm.prank(owner2);
account1.executeWithAuthorization(
abi.encodeCall(IStandardExecutor.execute, (address(0), 0, "")),
abi.encodePacked(
address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
)
abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER))
);
}

Expand All @@ -103,7 +98,8 @@ contract MultiValidationTest is AccountTestBase {
// Generate signature
bytes32 userOpHash = entryPoint.getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner2Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), r, s, v);
userOp.signature =
abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), r, s, v);

PackedUserOperation[] memory userOps = new PackedUserOperation[](1);
userOps[0] = userOp;
Expand All @@ -114,10 +110,11 @@ contract MultiValidationTest is AccountTestBase {

userOp.nonce = 1;
(v, r, s) = vm.sign(owner1Key, userOpHash.toEthSignedMessageHash());
userOp.signature = abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), r, s, v);
userOp.signature =
abi.encodePacked(address(validator2), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), r, s, v);

userOps[0] = userOp;
vm.expectRevert(abi.encodeWithSelector(IEntryPoint.FailedOp.selector, 0, "AA24 signature error"));
entryPoint.handleOps(userOps, beneficiary);
}
}
}
2 changes: 1 addition & 1 deletion test/account/UpgradeableModularAccount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract UpgradeableModularAccountTest is AccountTestBase {
counter.increment(); // amoritze away gas cost of zero->nonzero transition

ownerValidation = FunctionReferenceLib.pack(
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
address(singleOwnerPlugin), uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);
}

Expand Down
13 changes: 5 additions & 8 deletions test/plugin/SingleOwnerPlugin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ contract SingleOwnerPluginTest is OptimizedTest {
assertEq(address(0), plugin.owner());
plugin.transferOwnership(owner1);
assertEq(owner1, plugin.owner());
plugin.validateRuntime(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), owner1, 0, "", "");
plugin.validateRuntime(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), owner1, 0, "", "");

vm.startPrank(b);
vm.expectRevert(ISingleOwnerPlugin.NotAuthorized.selector);
plugin.validateRuntime(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), owner1, 0, "", "");
plugin.validateRuntime(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), owner1, 0, "", "");
}

function testFuzz_validateUserOpSig(string memory salt, PackedUserOperation memory userOp) public {
Expand All @@ -133,19 +133,16 @@ contract SingleOwnerPluginTest is OptimizedTest {
userOp.signature = abi.encodePacked(r, s, v);

// sig check should fail
uint256 success = plugin.validateUserOp(
uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), userOp, userOpHash
);
uint256 success =
plugin.validateUserOp(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), userOp, userOpHash);
assertEq(success, 1);

// transfer ownership to signer
plugin.transferOwnership(signer);
assertEq(signer, plugin.owner());

// sig check should pass
success = plugin.validateUserOp(
uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF), userOp, userOpHash
);
success = plugin.validateUserOp(uint8(ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER), userOp, userOpHash);
assertEq(success, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils/AccountTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ abstract contract AccountTestBase is OptimizedTest {
abi.encodeCall(SingleOwnerPlugin.transferOwnership, (address(this)))
)
),
abi.encodePacked(address(singleOwnerPlugin), ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER_OR_SELF)
abi.encodePacked(address(singleOwnerPlugin), ISingleOwnerPlugin.FunctionId.VALIDATION_OWNER)
);
}

Expand Down

0 comments on commit f347833

Please sign in to comment.