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

fix: [CL ALCHEMY-001] validation applicability check in deferred action #278

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 gas-snapshots/ModularAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"UserOp_NativeTransfer": "161531",
"UserOp_UseSessionKey_Case1_Counter": "195236",
"UserOp_UseSessionKey_Case1_Token": "226220",
"UserOp_deferredValidation": "257078"
"UserOp_deferredValidation": "257289"
}
2 changes: 1 addition & 1 deletion gas-snapshots/SemiModularAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"UserOp_NativeTransfer": "156773",
"UserOp_UseSessionKey_Case1_Counter": "195464",
"UserOp_UseSessionKey_Case1_Token": "226460",
"UserOp_deferredValidation": "253524"
"UserOp_deferredValidation": "253735"
}
4 changes: 2 additions & 2 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ abstract contract ModularAccountBase is
ValidationConfig uoValidation = ValidationConfig.wrap(bytes25(encodedData[38:63]));

// Check if the outer validation applies to the function call
_checkIfValidationAppliesSelector(
bytes4(encodedData[63:67]),
_checkIfValidationAppliesCallData(
encodedData[63:],
sigValidation,
isGlobalValidation ? ValidationCheckingType.GLOBAL : ValidationCheckingType.SELECTOR
);
Expand Down
117 changes: 115 additions & 2 deletions test/account/DeferredAction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ExecutionManifest,
ManifestExecutionFunction
} from "@erc6900/reference-implementation/interfaces/IExecutionModule.sol";
import {IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {Call, IModularAccount} from "@erc6900/reference-implementation/interfaces/IModularAccount.sol";
import {ValidationConfigLib} from "@erc6900/reference-implementation/libraries/ValidationConfigLib.sol";
import {IEntryPoint} from "@eth-infinitism/account-abstraction/interfaces/IEntryPoint.sol";
import {PackedUserOperation} from "@eth-infinitism/account-abstraction/interfaces/PackedUserOperation.sol";
Expand Down Expand Up @@ -125,7 +125,7 @@ contract DeferredActionTest is AccountTestBase {

// Install a new execution function that the validation does not have the privilege to call.
// Assert that user op validation reverts if the deferred action tries to call it.
function test_deferredAction_noPrivilegeEscalation() public {
function test_deferredAction_validationApplicabilityCheck() public {
bytes4 newFunctionSelector = bytes4(0xabcdabcd);

ExecutionManifest memory m;
Expand Down Expand Up @@ -186,4 +186,117 @@ contract DeferredActionTest is AccountTestBase {
);
entryPoint.handleOps(userOps, beneficiary);
}

function test_deferredAction_privilegeEscalationPrevented_executeSingle() public {
// Should not be allowed to call `execute` on the account itself
// Attempt to call it via a deferred action in a user op
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(IModularAccount.execute, (address(0), 0 wei, "")),
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});

bytes32 userOpHash = entryPoint.getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, MessageHashUtils.toEthSignedMessageHash(userOpHash));
bytes memory uoSig = _packFinalSignature(abi.encodePacked(EOA_TYPE_SIGNATURE, r, s, v));

uint256 deferredInstallNonce = 0;
uint48 deferredInstallDeadline = 0;

bytes memory deferredAction = abi.encodeCall(
IModularAccount.execute, (address(account1), 0 wei, abi.encodeCall(account1.accountId, ()))
);

userOp.signature = _buildFullDeferredInstallSig(
deferredInstallNonce,
deferredInstallDeadline,
deferredAction,
// Use the same validation for the deferred action and the user op
ValidationConfigLib.pack(_signerValidation, true, false, false),
account1,
owner1Key,
uoSig
);

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

vm.prank(beneficiary);
vm.expectRevert(
abi.encodeWithSelector(
IEntryPoint.FailedOpWithRevert.selector,
0,
"AA23 reverted",
abi.encodeWithSelector(ModularAccountBase.SelfCallRecursionDepthExceeded.selector)
)
);
entryPoint.handleOps(userOps, beneficiary);
}

function test_deferredAction_privilegeEscalationPrevented_executeBatch() public {
// Should not be allowed to call `executeBatch` with an internal call to `execute`/`executeBatch`.
// Attempt to call it via a deferred action in a user op
PackedUserOperation memory userOp = PackedUserOperation({
sender: address(account1),
nonce: 0,
initCode: "",
callData: abi.encodeCall(IModularAccount.execute, (address(0), 0 wei, "")),
accountGasLimits: _encodeGas(VERIFICATION_GAS_LIMIT, CALL_GAS_LIMIT),
preVerificationGas: 0,
gasFees: _encodeGas(1, 1),
paymasterAndData: "",
signature: ""
});

bytes32 userOpHash = entryPoint.getUserOpHash(userOp);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(owner1Key, MessageHashUtils.toEthSignedMessageHash(userOpHash));
bytes memory uoSig = _packFinalSignature(abi.encodePacked(EOA_TYPE_SIGNATURE, r, s, v));

uint256 deferredInstallNonce = 0;
uint48 deferredInstallDeadline = 0;

Call[] memory innerCalls = new Call[](1);
innerCalls[0] =
Call({target: address(account1), value: 0, data: abi.encodeCall(IModularAccount.accountId, ())});

Call[] memory outerCalls = new Call[](1);
outerCalls[0] = Call({
target: address(account1),
value: 0,
data: abi.encodeCall(IModularAccount.executeBatch, (innerCalls))
});

bytes memory deferredAction = abi.encodeCall(IModularAccount.executeBatch, (outerCalls));

userOp.signature = _buildFullDeferredInstallSig(
deferredInstallNonce,
deferredInstallDeadline,
deferredAction,
// Use the same validation for the deferred action and the user op
ValidationConfigLib.pack(_signerValidation, true, false, false),
account1,
owner1Key,
uoSig
);

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

vm.prank(beneficiary);
vm.expectRevert(
abi.encodeWithSelector(
IEntryPoint.FailedOpWithRevert.selector,
0,
"AA23 reverted",
abi.encodeWithSelector(ModularAccountBase.SelfCallRecursionDepthExceeded.selector)
)
);
entryPoint.handleOps(userOps, beneficiary);
}
}
Loading