@@ -6,13 +6,14 @@ import {KSSmartIntentRouterAccounting} from './KSSmartIntentRouterAccounting.sol
66import {KSSmartIntentRouterNonces} from './KSSmartIntentRouterNonces.sol ' ;
77
88import {IKSSmartIntentRouter} from './interfaces/IKSSmartIntentRouter.sol ' ;
9+ import {IKSAllowanceHub} from './interfaces/actions/IKSAllowanceHub.sol ' ;
910import {IKSSwapRouterV2} from './interfaces/actions/IKSSwapRouterV2.sol ' ;
1011import {IKSSwapRouterV3} from './interfaces/actions/IKSSwapRouterV3.sol ' ;
1112import {IKSZapRouter} from './interfaces/actions/IKSZapRouter.sol ' ;
12-
1313import {HookLibrary} from './libraries/HookLibrary.sol ' ;
1414
1515import {ActionData} from './types/ActionData.sol ' ;
16+ import {ActionWitness} from './types/ActionWitness.sol ' ;
1617import {IntentCoreData} from './types/IntentCoreData.sol ' ;
1718import {IntentData} from './types/IntentData.sol ' ;
1819
@@ -78,7 +79,7 @@ contract KSSmartIntentRouter is
7879 revert NotMainAddress ();
7980 }
8081
81- _delegate (intentData, _hashTypedDataV4 (hasher.hash (intentData)));
82+ _delegate (intentData, _hashTypedDataV4 (hasher.hashIntentData (intentData)));
8283 }
8384
8485 /// @inheritdoc IKSSmartIntentRouter
@@ -87,7 +88,7 @@ contract KSSmartIntentRouter is
8788 revert NotMainAddress ();
8889 }
8990
90- bytes32 intentHash = _hashTypedDataV4 (hasher.hash (intentData));
91+ bytes32 intentHash = _hashTypedDataV4 (hasher.hashIntentData (intentData));
9192 intentStatuses[intentHash] = IntentStatus.REVOKED;
9293
9394 emit RevokeIntent (intentHash);
@@ -101,7 +102,7 @@ contract KSSmartIntentRouter is
101102 bytes calldata gdSignature ,
102103 ActionData calldata actionData
103104 ) public {
104- bytes32 intentHash = _hashTypedDataV4 (hasher.hash (intentData));
105+ bytes32 intentHash = _hashTypedDataV4 (hasher.hashIntentData (intentData));
105106 _execute (intentHash, intentData, dkSignature, guardian, gdSignature, actionData);
106107 }
107108
@@ -114,7 +115,7 @@ contract KSSmartIntentRouter is
114115 bytes calldata gdSignature ,
115116 ActionData calldata actionData
116117 ) public {
117- bytes32 intentHash = _hashTypedDataV4 (hasher.hash (intentData));
118+ bytes32 intentHash = _hashTypedDataV4 (hasher.hashIntentData (intentData));
118119 if (! intentData.coreData.mainAddress.isValidSignatureNowCalldata (intentHash, maSignature)) {
119120 revert InvalidMainAddressSignature ();
120121 }
@@ -164,11 +165,7 @@ contract KSSmartIntentRouter is
164165 _useUnorderedNonce (intentHash, actionData.nonce);
165166
166167 _validateActionData (
167- intentData.coreData,
168- dkSignature,
169- guardian,
170- gdSignature,
171- _hashTypedDataV4 (hasher.hash (actionData))
168+ intentHash, intentData.coreData, actionData, dkSignature, guardian, gdSignature
172169 );
173170
174171 (uint256 [] memory fees , bytes memory beforeExecutionData ) =
@@ -212,40 +209,44 @@ contract KSSmartIntentRouter is
212209 selector == IKSSwapRouterV2.swap.selector
213210 || selector == IKSSwapRouterV2.swapSimpleMode.selector
214211 || selector == IKSSwapRouterV3.swap.selector || selector == IKSZapRouter.zap.selector
212+ || selector == IKSAllowanceHub.permitTransferAndExecute.selector
215213 ) {
216214 return IKSGenericForwarder (address (0 ));
217215 }
218216 return forwarder;
219217 }
220218
221219 function _validateActionData (
220+ bytes32 intentHash ,
222221 IntentCoreData calldata coreData ,
222+ ActionData calldata actionData ,
223223 bytes calldata dkSignature ,
224224 address guardian ,
225- bytes calldata gdSignature ,
226- bytes32 actionHash
225+ bytes calldata gdSignature
227226 ) internal view {
227+ bytes32 witnessHash = _hashTypedDataV4 (hasher.hashActionWitness (intentHash, actionData));
228+
228229 if (coreData.signatureVerifier == address (0 )) {
229230 /// @dev use ECDSA scheme
230231 address delegatedAddress = coreData.delegatedKey.decodeAddress ();
231232 if (
232233 msg .sender != delegatedAddress
233- && ! delegatedAddress.isValidSignatureNowCalldata (actionHash , dkSignature)
234+ && ! delegatedAddress.isValidSignatureNowCalldata (witnessHash , dkSignature)
234235 ) {
235236 revert InvalidDelegatedKeySignature ();
236237 }
237238 } else {
238239 if (
239240 IERC7913SignatureVerifier (coreData.signatureVerifier)
240- .verify (coreData.delegatedKey, actionHash , dkSignature)
241+ .verify (coreData.delegatedKey, witnessHash , dkSignature)
241242 != IERC7913SignatureVerifier .verify.selector
242243 ) {
243244 revert InvalidDelegatedKeySignature ();
244245 }
245246 }
246247
247248 if (msg .sender != guardian) {
248- if (! guardian.isValidSignatureNowCalldata (actionHash , gdSignature)) {
249+ if (! guardian.isValidSignatureNowCalldata (witnessHash , gdSignature)) {
249250 revert InvalidGuardianSignature ();
250251 }
251252 }
0 commit comments