Skip to content

Commit

Permalink
feat: sizes script
Browse files Browse the repository at this point in the history
test: expand test coverage for MABase

refactor: remove duplicate error definitions

refactor: simplify error types in MABase

feat: custom errors for all module functions

feat: change error param to moduleentity

fix: reorder errors

style: fix import formatting
  • Loading branch information
adamegyed committed Oct 16, 2024
1 parent 06d1caa commit 1987ab5
Show file tree
Hide file tree
Showing 34 changed files with 441 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79531
79501
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113089
113059
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 @@
532162
532174
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 @@
257385
257407
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79969
79939
Original file line number Diff line number Diff line change
@@ -1 +1 @@
113527
113497
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 @@
529742
529747
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 @@
254003
254026
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"
}
}
32 changes: 13 additions & 19 deletions src/account/ModularAccountBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,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();
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 @@ -574,14 +570,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 @@ -727,8 +723,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 @@ -786,8 +781,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 1987ab5

Please sign in to comment.