Skip to content

Commit

Permalink
fix: ModularAccountBase cleanup, coverage, custom error types (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamegyed authored Oct 16, 2024
1 parent e8a42af commit eea68dc
Show file tree
Hide file tree
Showing 34 changed files with 441 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79509
79479
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113067
113037
2 changes: 1 addition & 1 deletion .forge-snapshots/ModularAccount_UserOp_BatchTransfers.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
198425
198437
2 changes: 1 addition & 1 deletion .forge-snapshots/ModularAccount_UserOp_Erc20Transfer.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
185394
185406
Original file line number Diff line number Diff line change
@@ -1 +1 @@
532140
532152
2 changes: 1 addition & 1 deletion .forge-snapshots/ModularAccount_UserOp_NativeTransfer.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
161675
161687
Original file line number Diff line number Diff line change
@@ -1 +1 @@
195886
195938
Original file line number Diff line number Diff line change
@@ -1 +1 @@
227010
227062
Original file line number Diff line number Diff line change
@@ -1 +1 @@
261242
261264
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79925
79895
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113483
113453
Original file line number Diff line number Diff line change
@@ -1 +1 @@
193634
193639
Original file line number Diff line number Diff line change
@@ -1 +1 @@
180730
180735
Original file line number Diff line number Diff line change
@@ -1 +1 @@
529720
529725
Original file line number Diff line number Diff line change
@@ -1 +1 @@
157005
157010
Original file line number Diff line number Diff line change
@@ -1 +1 @@
196127
196232
Original file line number Diff line number Diff line change
@@ -1 +1 @@
227263
227368
Original file line number Diff line number Diff line change
@@ -1 +1 @@
257938
257961
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lint:gas": "solhint --max-warnings 0 -c ./config/solhint-gas.json './gas/**/*.sol'",
"lint:script": "solhint --max-warnings 0 -c ./config/solhint-script.json './script/**/*.sol'",
"prep": "pnpm fmt && forge b --deny-warnings && pnpm lint && pnpm test && pnpm gas",
"sizes": "FOUNDRY_PROFILE=optimized-build forge b --sizes | grep '^|' | grep -v -e '| 17 |' -e 'Lib'",
"test": "forge test"
}
}
33 changes: 13 additions & 20 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,16 @@ abstract contract ModularAccountBase is

event DeferredActionNonceInvalidated(uint256 nonce);

error PostExecHookReverted(address module, uint32 entityId, bytes revertReason);
error PreExecHookReverted(address module, uint32 entityId, bytes revertReason);
error PreRuntimeValidationHookFailed(address module, uint32 entityId, bytes revertReason);
error CreateFailed();
error DeferredActionNonceInvalid();
error DeferredActionSignatureInvalid();
error RequireUserOperationContext();
error RuntimeValidationFunctionReverted(address module, uint32 entityId, bytes revertReason);
error SelfCallRecursionDepthExceeded();
error SignatureValidationInvalid(address module, uint32 entityId);
error UserOpValidationInvalid(address module, uint32 entityId);
error UnexpectedAggregator(address module, uint32 entityId, address aggregator);
error SignatureValidationInvalid(ModuleEntity validationFunction);
error UserOpValidationInvalid(ModuleEntity validationFunction);
error UnexpectedAggregator(ModuleEntity validationFunction, address aggregator);
error UnrecognizedFunction(bytes4 selector);
error ValidationFunctionMissing(bytes4 selector);
error DeferredActionNonceInvalid();
error DeferredActionSignatureInvalid();
// This error is trigged in performCreate and performCreate2
error CreateFailed();

// Wraps execution of a native function with runtime validation and hooks
// Used for upgradeTo, upgradeToAndCall, execute, executeBatch, installExecution, uninstallExecution,
Expand Down Expand Up @@ -577,14 +572,14 @@ abstract contract ModularAccountBase is
(currentSignatureSlice, signature) =
signature.advanceSegmentIfAtIndex(uint8(preUserOpValidationHooks.length - i - 1));

uint256 currentValidationRes = ExecutionLib.invokeUserOpCallBuffer(
userOpCallBuffer, preUserOpValidationHooks[i].moduleEntity(), currentSignatureSlice
);
ModuleEntity uoValidationHook = preUserOpValidationHooks[i].moduleEntity();

uint256 currentValidationRes =
ExecutionLib.invokeUserOpCallBuffer(userOpCallBuffer, uoValidationHook, currentSignatureSlice);

if (uint160(currentValidationRes) > 1) {
// If the aggregator is not 0 or 1, it is an unexpected value
(address module, uint32 entityId) = preUserOpValidationHooks[i].moduleEntity().unpack();
revert UnexpectedAggregator(module, entityId, address(uint160(currentValidationRes)));
revert UnexpectedAggregator(uoValidationHook, address(uint160(currentValidationRes)));
}
validationRes = _coalescePreValidation(validationRes, currentValidationRes);
}
Expand Down Expand Up @@ -730,8 +725,7 @@ abstract contract ModularAccountBase is
AccountStorage storage _storage = getAccountStorage();

if (!_storage.validationStorage[userOpValidationFunction].isUserOpValidation) {
(address module, uint32 entityId) = userOpValidationFunction.unpack();
revert UserOpValidationInvalid(module, entityId);
revert UserOpValidationInvalid(userOpValidationFunction);
}

ExecutionLib.convertToValidationBuffer(callBuffer);
Expand Down Expand Up @@ -789,8 +783,7 @@ abstract contract ModularAccountBase is
AccountStorage storage _storage = getAccountStorage();

if (!_storage.validationStorage[sigValidation].isSignatureValidation) {
(address module, uint32 entityId) = sigValidation.unpack();
revert SignatureValidationInvalid(module, entityId);
revert SignatureValidationInvalid(sigValidation);
}

if (ExecutionLib.invokeSignatureValidation(buffer, sigValidation, signatureSegment) == _1271_MAGIC_VALUE) {
Expand Down
Loading

0 comments on commit eea68dc

Please sign in to comment.