@@ -7,67 +7,78 @@ import {ModuleEntity, ValidationConfig} from "../interfaces/IModularAccount.sol"
77// Layout:
88// 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA________________________ // Address
99// 0x________________________________________BBBBBBBB________________ // Entity ID
10- // 0x________________________________________________CC______________ // isGlobal
11- // 0x__________________________________________________DD____________ // isSignatureValidation
12- // 0x____________________________________________________000000000000 // unused
10+ // 0x________________________________________________CC______________ // validation flags
11+ // 0x__________________________________________________00000000000000 // unused
12+
13+ // Validation flags layout:
14+ // 0b00000___ // unused
15+ // 0b_____A__ // isGlobal
16+ // 0b______B_ // isSignatureValidation
17+ // 0b_______C // isUserOpValidation
1318
1419library ValidationConfigLib {
15- function pack (ModuleEntity _validationFunction , bool _isGlobal , bool _isSignatureValidation )
16- internal
17- pure
18- returns (ValidationConfig)
19- {
20+ // is user op validation flag stored in last bit of the 25th byte
21+ bytes32 internal constant _VALIDATION_FLAG_IS_USER_OP = bytes32 (uint256 (1 ) << 56 );
22+ // is signature validation flag stored in second to last bit of the 25th byte
23+ bytes32 internal constant _VALIDATION_FLAG_IS_SIGNATURE = bytes32 (uint256 (1 ) << 57 );
24+ // is global flag stored in the third to last bit of the 25th byte
25+ bytes32 internal constant _VALIDATION_FLAG_IS_GLOBAL = bytes32 (uint256 (1 ) << 58 );
26+
27+ function pack (
28+ ModuleEntity _validationFunction ,
29+ bool _isGlobal ,
30+ bool _isSignatureValidation ,
31+ bool _isUserOpValidation
32+ ) internal pure returns (ValidationConfig) {
2033 return ValidationConfig.wrap (
21- bytes26 (
22- bytes26 (ModuleEntity.unwrap (_validationFunction))
23- // isGlobal flag stored in the 25th byte
24- | bytes26 (bytes32 (_isGlobal ? uint256 (1 ) << 56 : 0 ))
25- // isSignatureValidation flag stored in the 26th byte
26- | bytes26 (bytes32 (_isSignatureValidation ? uint256 (1 ) << 48 : 0 ))
34+ bytes25 (
35+ bytes25 (ModuleEntity.unwrap (_validationFunction))
36+ | bytes25 (bytes32 (_isGlobal ? _VALIDATION_FLAG_IS_GLOBAL : bytes32 (0 )))
37+ | bytes25 (bytes32 (_isSignatureValidation ? _VALIDATION_FLAG_IS_SIGNATURE : bytes32 (0 )))
38+ | bytes25 (bytes32 (_isUserOpValidation ? _VALIDATION_FLAG_IS_USER_OP : bytes32 (0 )))
2739 )
2840 );
2941 }
3042
31- function pack (address _module , uint32 _entityId , bool _isGlobal , bool _isSignatureValidation )
32- internal
33- pure
34- returns (ValidationConfig)
35- {
43+ function pack (
44+ address _module ,
45+ uint32 _entityId ,
46+ bool _isGlobal ,
47+ bool _isSignatureValidation ,
48+ bool _isUserOpValidation
49+ ) internal pure returns (ValidationConfig) {
3650 return ValidationConfig.wrap (
37- bytes26 (
51+ bytes25 (
3852 // module address stored in the first 20 bytes
39- bytes26 (bytes20 (_module))
53+ bytes25 (bytes20 (_module))
4054 // entityId stored in the 21st - 24th byte
41- | bytes26 (bytes24 (uint192 (_entityId)))
42- // isGlobal flag stored in the 25th byte
43- | bytes26 (bytes32 (_isGlobal ? uint256 (1 ) << 56 : 0 ))
44- // isSignatureValidation flag stored in the 26th byte
45- | bytes26 (bytes32 (_isSignatureValidation ? uint256 (1 ) << 48 : 0 ))
55+ | bytes25 (bytes24 (uint192 (_entityId)))
56+ | bytes25 (bytes32 (_isGlobal ? _VALIDATION_FLAG_IS_GLOBAL : bytes32 (0 )))
57+ | bytes25 (bytes32 (_isSignatureValidation ? _VALIDATION_FLAG_IS_SIGNATURE : bytes32 (0 )))
58+ | bytes25 (bytes32 (_isUserOpValidation ? _VALIDATION_FLAG_IS_USER_OP : bytes32 (0 )))
4659 )
4760 );
4861 }
4962
5063 function unpackUnderlying (ValidationConfig config )
5164 internal
5265 pure
53- returns (address _module , uint32 _entityId , bool _isGlobal , bool _isSignatureValidation )
66+ returns (address _module , uint32 _entityId , uint8 flags )
5467 {
55- bytes26 configBytes = ValidationConfig.unwrap (config);
68+ bytes25 configBytes = ValidationConfig.unwrap (config);
5669 _module = address (bytes20 (configBytes));
5770 _entityId = uint32 (bytes4 (configBytes << 160 ));
58- _isGlobal = uint8 (configBytes[24 ]) == 1 ;
59- _isSignatureValidation = uint8 (configBytes[25 ]) == 1 ;
71+ flags = uint8 (configBytes[24 ]);
6072 }
6173
6274 function unpack (ValidationConfig config )
6375 internal
6476 pure
65- returns (ModuleEntity _validationFunction , bool _isGlobal , bool _isSignatureValidation )
77+ returns (ModuleEntity _validationFunction , uint8 flags )
6678 {
67- bytes26 configBytes = ValidationConfig.unwrap (config);
79+ bytes25 configBytes = ValidationConfig.unwrap (config);
6880 _validationFunction = ModuleEntity.wrap (bytes24 (configBytes));
69- _isGlobal = uint8 (configBytes[24 ]) == 1 ;
70- _isSignatureValidation = uint8 (configBytes[25 ]) == 1 ;
81+ flags = uint8 (configBytes[24 ]);
7182 }
7283
7384 function module (ValidationConfig config ) internal pure returns (address ) {
@@ -83,10 +94,26 @@ library ValidationConfigLib {
8394 }
8495
8596 function isGlobal (ValidationConfig config ) internal pure returns (bool ) {
86- return uint8 (ValidationConfig.unwrap (config)[24 ]) == 1 ;
97+ return ValidationConfig.unwrap (config) & _VALIDATION_FLAG_IS_GLOBAL != 0 ;
98+ }
99+
100+ function isGlobal (uint8 flags ) internal pure returns (bool ) {
101+ return flags & 0x04 != 0 ;
87102 }
88103
89104 function isSignatureValidation (ValidationConfig config ) internal pure returns (bool ) {
90- return uint8 (ValidationConfig.unwrap (config)[25 ]) == 1 ;
105+ return ValidationConfig.unwrap (config) & _VALIDATION_FLAG_IS_SIGNATURE != 0 ;
106+ }
107+
108+ function isSignatureValidation (uint8 flags ) internal pure returns (bool ) {
109+ return flags & 0x02 != 0 ;
110+ }
111+
112+ function isUserOpValidation (ValidationConfig config ) internal pure returns (bool ) {
113+ return ValidationConfig.unwrap (config) & _VALIDATION_FLAG_IS_USER_OP != 0 ;
114+ }
115+
116+ function isUserOpValidation (uint8 flags ) internal pure returns (bool ) {
117+ return flags & 0x01 != 0 ;
91118 }
92119}
0 commit comments