@@ -19,7 +19,7 @@ import {SparseCalldataSegmentLib} from "../helpers/SparseCalldataSegmentLib.sol"
1919import {ValidationConfigLib} from "../helpers/ValidationConfigLib.sol " ;
2020import {_coalescePreValidation, _coalesceValidation} from "../helpers/ValidationResHelpers.sol " ;
2121
22- import {DIRECT_CALL_VALIDATION_ENTITYID, RESERVED_VALIDATION_DATA_INDEX } from "../helpers/Constants.sol " ;
22+ import {DIRECT_CALL_VALIDATION_ENTITYID} from "../helpers/Constants.sol " ;
2323
2424import {IExecutionHookModule} from "../interfaces/IExecutionHookModule.sol " ;
2525import {ExecutionManifest} from "../interfaces/IExecutionModule.sol " ;
@@ -67,7 +67,6 @@ contract UpgradeableModularAccount is
6767 bytes4 internal constant _1271_MAGIC_VALUE = 0x1626ba7e ;
6868 bytes4 internal constant _1271_INVALID = 0xffffffff ;
6969
70- error NonCanonicalEncoding ();
7170 error NotEntryPoint ();
7271 error PostExecHookReverted (address module , uint32 entityId , bytes revertReason );
7372 error PreExecHookReverted (address module , uint32 entityId , bytes revertReason );
@@ -79,8 +78,6 @@ contract UpgradeableModularAccount is
7978 error UnexpectedAggregator (address module , uint32 entityId , address aggregator );
8079 error UnrecognizedFunction (bytes4 selector );
8180 error ValidationFunctionMissing (bytes4 selector );
82- error ValidationSignatureSegmentMissing ();
83- error SignatureSegmentOutOfOrder ();
8481
8582 // Wraps execution of a native function with runtime validation and hooks
8683 // Used for upgradeTo, upgradeToAndCall, execute, executeBatch, installExecution, uninstallExecution
@@ -347,36 +344,14 @@ contract UpgradeableModularAccount is
347344 bytes calldata signature ,
348345 bytes32 userOpHash
349346 ) internal returns (uint256 ) {
350- // Set up the per-hook data tracking fields
351- bytes calldata signatureSegment;
352- (signatureSegment, signature) = signature.getNextSegment ();
353-
354347 uint256 validationRes;
355348
356349 // Do preUserOpValidation hooks
357350 ModuleEntity[] memory preUserOpValidationHooks =
358351 getAccountStorage ().validationData[userOpValidationFunction].preValidationHooks;
359352
360353 for (uint256 i = 0 ; i < preUserOpValidationHooks.length ; ++ i) {
361- // Load per-hook data, if any is present
362- // The segment index is the first byte of the signature
363- if (signatureSegment.getIndex () == i) {
364- // Use the current segment
365- userOp.signature = signatureSegment.getBody ();
366-
367- if (userOp.signature.length == 0 ) {
368- revert NonCanonicalEncoding ();
369- }
370-
371- // Load the next per-hook data segment
372- (signatureSegment, signature) = signature.getNextSegment ();
373-
374- if (signatureSegment.getIndex () <= i) {
375- revert SignatureSegmentOutOfOrder ();
376- }
377- } else {
378- userOp.signature = "" ;
379- }
354+ (userOp.signature, signature) = signature.advanceSegmentIfAtIndex (uint8 (i));
380355
381356 (address module , uint32 entityId ) = preUserOpValidationHooks[i].unpack ();
382357 uint256 currentValidationRes =
@@ -389,13 +364,9 @@ contract UpgradeableModularAccount is
389364 validationRes = _coalescePreValidation (validationRes, currentValidationRes);
390365 }
391366
392- // Run the user op validationFunction
367+ // Run the user op validation function
393368 {
394- if (signatureSegment.getIndex () != RESERVED_VALIDATION_DATA_INDEX) {
395- revert ValidationSignatureSegmentMissing ();
396- }
397-
398- userOp.signature = signatureSegment.getBody ();
369+ userOp.signature = signature.getFinalSegment ();
399370
400371 uint256 currentValidationRes = _execUserOpValidation (userOpValidationFunction, userOp, userOpHash);
401372
@@ -415,42 +386,21 @@ contract UpgradeableModularAccount is
415386 bytes calldata callData ,
416387 bytes calldata authorizationData
417388 ) internal {
418- // Set up the per-hook data tracking fields
419- bytes calldata authSegment;
420- (authSegment, authorizationData) = authorizationData.getNextSegment ();
421-
422389 // run all preRuntimeValidation hooks
423390 ModuleEntity[] memory preRuntimeValidationHooks =
424391 getAccountStorage ().validationData[runtimeValidationFunction].preValidationHooks;
425392
426393 for (uint256 i = 0 ; i < preRuntimeValidationHooks.length ; ++ i) {
427- bytes memory currentAuthData;
428-
429- if (authSegment.getIndex () == i) {
430- // Use the current segment
431- currentAuthData = authSegment.getBody ();
432-
433- if (currentAuthData.length == 0 ) {
434- revert NonCanonicalEncoding ();
435- }
394+ bytes memory currentAuthSegment;
436395
437- // Load the next per-hook data segment
438- (authSegment, authorizationData) = authorizationData.getNextSegment ();
396+ (currentAuthSegment, authorizationData) = authorizationData.advanceSegmentIfAtIndex (uint8 (i));
439397
440- if (authSegment.getIndex () <= i) {
441- revert SignatureSegmentOutOfOrder ();
442- }
443- } else {
444- currentAuthData = "" ;
445- }
446- _doPreRuntimeValidationHook (preRuntimeValidationHooks[i], callData, currentAuthData);
398+ _doPreRuntimeValidationHook (preRuntimeValidationHooks[i], callData, currentAuthSegment);
447399 }
448400
449- if (authSegment.getIndex () != RESERVED_VALIDATION_DATA_INDEX) {
450- revert ValidationSignatureSegmentMissing ();
451- }
401+ authorizationData = authorizationData.getFinalSegment ();
452402
453- _execRuntimeValidation (runtimeValidationFunction, callData, authSegment. getBody () );
403+ _execRuntimeValidation (runtimeValidationFunction, callData, authorizationData );
454404 }
455405
456406 function _doPreHooks (EnumerableSet.Bytes32Set storage executionHooks , bytes memory data )
0 commit comments