@@ -26,6 +26,14 @@ contract SemiModularAccount is UpgradeableModularAccount {
2626 uint256 internal constant _SEMI_MODULAR_ACCOUNT_STORAGE_SLOT =
2727 0x5b9dc9aa943f8fa2653ceceda5e3798f0686455280432166ba472eca0bc17a32 ;
2828
29+ // keccak256("EIP712Domain(uint256 chainId,address verifyingContract)")
30+ bytes32 private constant _DOMAIN_SEPARATOR_TYPEHASH =
31+ 0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218 ;
32+
33+ // keccak256("ReplaySafeHash(bytes32 hash)")
34+ bytes32 private constant _REPLAY_SAFE_HASH_TYPEHASH =
35+ 0x294a8735843d4afb4f017c76faf3b7731def145ed0025fc9b1d5ce30adf113ff ;
36+
2937 ModuleEntity internal constant _FALLBACK_VALIDATION = ModuleEntity.wrap (bytes24 (type (uint192 ).max));
3038
3139 uint256 internal constant _SIG_VALIDATION_PASSED = 0 ;
@@ -88,6 +96,11 @@ contract SemiModularAccount is UpgradeableModularAccount {
8896 return "erc6900/reference-semi-modular-account/0.8.0 " ;
8997 }
9098
99+ function replaySafeHash (bytes32 hash ) public view virtual returns (bytes32 ) {
100+ return
101+ MessageHashUtils.toTypedDataHash ({domainSeparator: _domainSeparator (), structHash: _hashStruct (hash)});
102+ }
103+
91104 function _execUserOpValidation (
92105 ModuleEntity userOpValidationFunction ,
93106 PackedUserOperation memory userOp ,
@@ -120,9 +133,9 @@ contract SemiModularAccount is UpgradeableModularAccount {
120133 if (msg .sender != fallbackSigner) {
121134 revert FallbackSignerMismatch ();
122135 }
123- return ;
136+ } else {
137+ super ._execRuntimeValidation (runtimeValidationFunction, callData, authorization);
124138 }
125- super ._execRuntimeValidation (runtimeValidationFunction, callData, authorization);
126139 }
127140
128141 function _exec1271Validation (ModuleEntity sigValidation , bytes32 hash , bytes calldata signature )
@@ -134,7 +147,7 @@ contract SemiModularAccount is UpgradeableModularAccount {
134147 if (sigValidation.eq (_FALLBACK_VALIDATION)) {
135148 address fallbackSigner = _getFallbackSigner ();
136149
137- if (SignatureChecker.isValidSignatureNow (fallbackSigner, hash, signature)) {
150+ if (SignatureChecker.isValidSignatureNow (fallbackSigner, replaySafeHash ( hash) , signature)) {
138151 return _1271_MAGIC_VALUE;
139152 }
140153 return _1271_INVALID;
@@ -176,11 +189,25 @@ contract SemiModularAccount is UpgradeableModularAccount {
176189 return address (uint160 (bytes20 (appendedData)));
177190 }
178191
192+ function _domainSeparator () internal view returns (bytes32 ) {
193+ return keccak256 (abi.encode (_DOMAIN_SEPARATOR_TYPEHASH, block .chainid , address (this )));
194+ }
195+
179196 function _getSemiModularAccountStorage () internal pure returns (SemiModularAccountStorage storage ) {
180197 SemiModularAccountStorage storage _storage;
181198 assembly ("memory-safe" ) {
182199 _storage.slot := _SEMI_MODULAR_ACCOUNT_STORAGE_SLOT
183200 }
184201 return _storage;
185202 }
203+
204+ function _hashStruct (bytes32 hash ) internal pure virtual returns (bytes32 ) {
205+ bytes32 res;
206+ assembly ("memory-safe" ) {
207+ mstore (0x00 , _REPLAY_SAFE_HASH_TYPEHASH)
208+ mstore (0x20 , hash)
209+ res := keccak256 (0 , 0x40 )
210+ }
211+ return res;
212+ }
186213}
0 commit comments