@across-protocol/contracts 5.0.22 → 5.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/contracts/external/interfaces/IERC20Auth.sol +31 -0
  2. package/contracts/external/interfaces/IMulticall3.sol +22 -0
  3. package/contracts/interfaces/SpokePoolPeripheryInterface.sol +56 -2
  4. package/contracts/periphery/ERC6492SignatureHandler.sol +84 -0
  5. package/contracts/periphery/SpokePoolPeriphery.sol +120 -14
  6. package/contracts/test/MockERC20.sol +36 -3
  7. package/dist/broadcast/deployed-addresses.json +97 -72
  8. package/dist/evm/artifacts/Constants.sol/Constants.json +1 -1
  9. package/dist/evm/artifacts/CounterfactualConfig.sol/CounterfactualConfig.json +1 -1
  10. package/dist/evm/artifacts/DeploymentUtils.sol/DeploymentUtils.json +1 -1
  11. package/dist/evm/artifacts/ERC6492SignatureHandler.sol/ERC6492SignatureHandler.json +1 -0
  12. package/dist/evm/artifacts/HubPoolTestBase.sol/HubPoolTestBase.json +1 -1
  13. package/dist/evm/artifacts/HubPoolTestBase.sol/MockAddressWhitelist.json +1 -1
  14. package/dist/evm/artifacts/HubPoolTestBase.sol/MockFinder.json +1 -1
  15. package/dist/evm/artifacts/HubPoolTestBase.sol/MockIdentifierWhitelist.json +1 -1
  16. package/dist/evm/artifacts/HubPoolTestBase.sol/MockLpTokenFactory.json +1 -1
  17. package/dist/evm/artifacts/HubPoolTestBase.sol/MockOptimisticOracle.json +1 -1
  18. package/dist/evm/artifacts/HubPoolTestBase.sol/MockStore.json +1 -1
  19. package/dist/evm/artifacts/IERC20Auth.sol/IERC20AuthBytes.json +1 -0
  20. package/dist/evm/artifacts/IMulticall3.sol/IMulticall3.json +1 -1
  21. package/dist/evm/artifacts/MockERC20.sol/MintableERC20.json +1 -1
  22. package/dist/evm/artifacts/MockERC20.sol/MockERC20.json +1 -1
  23. package/dist/evm/artifacts/PeripherySigningLib.sol/PeripherySigningLib.json +1 -1
  24. package/dist/evm/artifacts/SpokePoolPeriphery.sol/SpokePoolPeriphery.json +1 -1
  25. package/dist/evm/artifacts/SpokePoolPeriphery.sol/SwapProxy.json +1 -1
  26. package/dist/evm/artifacts/SpokePoolPeripheryInterface.sol/SpokePoolPeripheryInterface.json +1 -1
  27. package/package.json +1 -1
@@ -33,3 +33,34 @@ interface IERC20Auth {
33
33
  bytes32 s
34
34
  ) external;
35
35
  }
36
+
37
+ /*
38
+ * @notice Minimal interface for tokens that implement the extended EIP-3009 form which accepts
39
+ * an unstructured `bytes` signature, allowing both EOA (ECDSA) and contract (EIP-1271) signers.
40
+ * @dev This has a different selector than the canonical EIP-3009 `receiveWithAuthorization`, so a
41
+ * single token can implement both. Used by tokens such as USDC v2.2.
42
+ */
43
+ interface IERC20AuthBytes {
44
+ /**
45
+ * @notice Receive a transfer with a signed authorization from the payer
46
+ * @dev This has an additional check to ensure that the payee's address matches
47
+ * the caller of this function to prevent front-running attacks. (See security
48
+ * considerations)
49
+ * @param from Payer's address (Authorizer)
50
+ * @param to Payee's address
51
+ * @param value Amount to be transferred
52
+ * @param validAfter The time after which this is valid (unix time)
53
+ * @param validBefore The time before which this is valid (unix time)
54
+ * @param nonce Unique nonce
55
+ * @param signature Unstructured bytes signature signed by an EOA wallet or a contract wallet
56
+ */
57
+ function receiveWithAuthorization(
58
+ address from,
59
+ address to,
60
+ uint256 value,
61
+ uint256 validAfter,
62
+ uint256 validBefore,
63
+ bytes32 nonce,
64
+ bytes memory signature
65
+ ) external;
66
+ }
@@ -0,0 +1,22 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @notice Minimal interface for the canonical Multicall3 singleton.
6
+ * @dev Only the subset used to make a neutral, failure-tolerant external call is declared here. The
7
+ * canonical Multicall3 is deployed at 0xcA11bde05977b3631167028862bE2a173976CA11 on virtually all
8
+ * EVM chains. See https://github.com/mds1/multicall.
9
+ */
10
+ interface IMulticall3 {
11
+ struct Call {
12
+ address target;
13
+ bytes callData;
14
+ }
15
+
16
+ struct Result {
17
+ bool success;
18
+ bytes returnData;
19
+ }
20
+
21
+ function tryAggregate(bool requireSuccess, Call[] calldata calls) external payable returns (Result[] memory);
22
+ }
@@ -184,10 +184,13 @@ interface SpokePoolPeripheryInterface {
184
184
  * Caller can specify their slippage tolerance for the swap and Across deposit params.
185
185
  * @dev This function assumes the caller has properly set an allowance for the permit2 contract on this network.
186
186
  * @dev This function assumes that the amount of token to be swapped is equal to the amount of the token to be received from permit2.
187
+ * @dev `signature` may be ERC-6492 wrapped. When it is, the embedded factory call is executed first
188
+ * (deploying a counterfactual contract-wallet signer) before permit2 verifies the unwrapped inner
189
+ * signature. See ERC6492SignatureHandler.
187
190
  * @param signatureOwner The owner of the permit2 signature and depositor for the Across spoke pool.
188
191
  * @param swapAndDepositData Specifies the params we need to perform a swap on a generic exchange.
189
192
  * @param permit The permit data signed over by the owner.
190
- * @param signature The permit2 signature to verify against the deposit data.
193
+ * @param signature The permit2 signature to verify against the deposit data (EOA, EIP-1271, or ERC-6492 wrapped).
191
194
  */
192
195
  function swapAndBridgeWithPermit2(
193
196
  address signatureOwner,
@@ -216,6 +219,30 @@ interface SpokePoolPeripheryInterface {
216
219
  bytes calldata receiveWithAuthSignature
217
220
  ) external;
218
221
 
222
+ /**
223
+ * @notice Same as `swapAndBridgeWithAuthorization`, but for tokens that implement the extended
224
+ * EIP-3009 `receiveWithAuthorization` overload that accepts an unstructured `bytes signature`
225
+ * (e.g. USDC v2.2). The bytes form supports both EOA (ECDSA) signers and contract (EIP-1271)
226
+ * signers.
227
+ * @dev If swapToken does not implement the bytes-signature `receiveWithAuthorization` overload,
228
+ * this call will revert.
229
+ * @dev `receiveWithAuthSignature` may be ERC-6492 wrapped. When it is, the embedded factory call is
230
+ * executed first (deploying a counterfactual contract-wallet signer) before the token verifies the
231
+ * unwrapped inner signature. See ERC6492SignatureHandler.
232
+ * @param signatureOwner The owner of the EIP3009 signature and swapAndDepositData signature. Assumed to be the depositor for the Across spoke pool.
233
+ * @param swapAndDepositData Specifies the params we need to perform a swap on a generic exchange.
234
+ * @param validAfter The unix time after which the `receiveWithAuthorization` signature is valid.
235
+ * @param validBefore The unix time before which the `receiveWithAuthorization` signature is valid.
236
+ * @param receiveWithAuthSignature EIP3009 signature, unstructured bytes (EOA, EIP-1271, or ERC-6492 wrapped).
237
+ */
238
+ function swapAndBridgeWithAuthorizationBytes(
239
+ address signatureOwner,
240
+ SwapAndDepositData calldata swapAndDepositData,
241
+ uint256 validAfter,
242
+ uint256 validBefore,
243
+ bytes calldata receiveWithAuthSignature
244
+ ) external;
245
+
219
246
  /**
220
247
  * @notice Deposits an EIP-2612 token Across input token into the Spoke Pool contract.
221
248
  * @dev If the token does not implement `permit` to the specifications of EIP-2612, the permit call result will be ignored and the function will continue.
@@ -245,10 +272,13 @@ interface SpokePoolPeripheryInterface {
245
272
  * @notice Uses permit2 to transfer and submit an Across deposit to the Spoke Pool contract.
246
273
  * @dev This function assumes the caller has properly set an allowance for the permit2 contract on this network.
247
274
  * @dev This function assumes that the amount of token to be swapped is equal to the amount of the token to be received from permit2.
275
+ * @dev `signature` may be ERC-6492 wrapped. When it is, the embedded factory call is executed first
276
+ * (deploying a counterfactual contract-wallet signer) before permit2 verifies the unwrapped inner
277
+ * signature. See ERC6492SignatureHandler.
248
278
  * @param signatureOwner The owner of the permit2 signature and depositor for the Across spoke pool.
249
279
  * @param depositData Specifies the Across deposit params we'll send after the swap.
250
280
  * @param permit The permit data signed over by the owner.
251
- * @param signature The permit2 signature to verify against the deposit data.
281
+ * @param signature The permit2 signature to verify against the deposit data (EOA, EIP-1271, or ERC-6492 wrapped).
252
282
  */
253
283
  function depositWithPermit2(
254
284
  address signatureOwner,
@@ -276,6 +306,30 @@ interface SpokePoolPeripheryInterface {
276
306
  bytes calldata receiveWithAuthSignature
277
307
  ) external;
278
308
 
309
+ /**
310
+ * @notice Same as `depositWithAuthorization`, but for tokens that implement the extended
311
+ * EIP-3009 `receiveWithAuthorization` overload that accepts an unstructured `bytes signature`
312
+ * (e.g. USDC v2.2). The bytes form supports both EOA (ECDSA) signers and contract (EIP-1271)
313
+ * signers.
314
+ * @dev If `acrossInputToken` does not implement the bytes-signature `receiveWithAuthorization`
315
+ * overload, this call will revert.
316
+ * @dev `receiveWithAuthSignature` may be ERC-6492 wrapped. When it is, the embedded factory call is
317
+ * executed first (deploying a counterfactual contract-wallet signer) before the token verifies the
318
+ * unwrapped inner signature. See ERC6492SignatureHandler.
319
+ * @param signatureOwner The owner of the EIP3009 signature and depositData signature. Assumed to be the depositor for the Across spoke pool.
320
+ * @param depositData Specifies the Across deposit params to send.
321
+ * @param validAfter The unix time after which the `receiveWithAuthorization` signature is valid.
322
+ * @param validBefore The unix time before which the `receiveWithAuthorization` signature is valid.
323
+ * @param receiveWithAuthSignature EIP3009 signature, unstructured bytes (EOA, EIP-1271, or ERC-6492 wrapped).
324
+ */
325
+ function depositWithAuthorizationBytes(
326
+ address signatureOwner,
327
+ DepositData calldata depositData,
328
+ uint256 validAfter,
329
+ uint256 validBefore,
330
+ bytes calldata receiveWithAuthSignature
331
+ ) external;
332
+
279
333
  /**
280
334
  * @notice Returns the current permit nonce for a user.
281
335
  * @param user The user whose nonce to return.
@@ -0,0 +1,84 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ import { IMulticall3 } from "../external/interfaces/IMulticall3.sol";
5
+
6
+ /**
7
+ * @title ERC6492SignatureHandler
8
+ * @notice Base contract that performs the "prepare" (deploy) step of an ERC-6492 signature without
9
+ * being the signature verifier itself.
10
+ * @dev Some downstream verifiers — the ERC-3009 `receiveWithAuthorization(...,bytes)` overload on
11
+ * tokens such as USDC v2.2, and Uniswap's Permit2 — validate contract-wallet signatures via EIP-1271
12
+ * but have no concept of ERC-6492. A signature from a *counterfactual* (not-yet-deployed)
13
+ * smart-contract wallet therefore fails, because there is no code at the signer's address to call
14
+ * `isValidSignature` on.
15
+ *
16
+ * ERC-6492 (https://eips.ethereum.org/EIPS/eip-6492) solves this by wrapping the real signature with
17
+ * the factory call needed to deploy the wallet. Since we cannot change the token's verification, we
18
+ * replicate only the *deploy* half of the flow here: if a signature carries the ERC-6492 magic
19
+ * suffix, we run its embedded factory call to materialize the wallet, then hand the unwrapped inner
20
+ * signature back to the caller to pass on to the real verifier (the token). Once the wallet exists,
21
+ * the token's own EIP-1271 check against the signer succeeds.
22
+ *
23
+ * @dev This contract does NOT validate the signature; it only ensures the signer is deployed. The
24
+ * embedded factory `target`/`callData` is fully attacker-controlled, so the call is routed through a
25
+ * neutral public Multicall3 singleton rather than made directly. This guarantees the prepare call can
26
+ * never execute with this contract as `msg.sender` and thus cannot abuse any of this contract's
27
+ * allowances or privileges. The call is made with `requireSuccess: false`, so an already-deployed
28
+ * wallet (whose factory call reverts on redeploy) is tolerated; correctness ultimately rests on the
29
+ * downstream verifier.
30
+ *
31
+ * Inspired by Coinbase's ERC6492SignatureHandler
32
+ * (https://github.com/base/commerce-payments/blob/main/src/collectors/ERC6492SignatureHandler.sol).
33
+ * @custom:security-contact bugs@across.to
34
+ */
35
+ abstract contract ERC6492SignatureHandler {
36
+ // Magic suffix that marks a signature as ERC-6492 wrapped.
37
+ bytes32 internal constant _ERC6492_MAGIC_VALUE = 0x6492649264926492649264926492649264926492649264926492649264926492;
38
+
39
+ // Canonical Multicall3 singleton used to make the neutral ERC-6492 prepare/deploy call.
40
+ IMulticall3 public immutable multicall3;
41
+
42
+ /**
43
+ * @notice Constructs the handler.
44
+ * @param _multicall3 Address of the canonical Multicall3 singleton used to route prepare calls.
45
+ */
46
+ constructor(address _multicall3) {
47
+ require(_multicall3 != address(0), "Multicall3 cannot be zero address");
48
+ require(_multicall3.code.length > 0, "Multicall3 must be a contract");
49
+ multicall3 = IMulticall3(_multicall3);
50
+ }
51
+
52
+ /**
53
+ * @notice Detects an ERC-6492 wrapped signature and, if present, runs its embedded factory call
54
+ * to deploy the (counterfactual) signer before returning the unwrapped inner signature.
55
+ * @param signature The user-provided signature, possibly ERC-6492 wrapped.
56
+ * @return The inner signature to forward to the real verifier. If `signature` is not ERC-6492
57
+ * wrapped it is returned unchanged.
58
+ */
59
+ function _handleERC6492Signature(bytes calldata signature) internal returns (bytes memory) {
60
+ // An ERC-6492 signature is at least the 32-byte magic suffix; anything shorter passes through.
61
+ uint256 signatureLength = signature.length;
62
+ if (signatureLength < _ERC6492_MAGIC_VALUE.length) return signature;
63
+
64
+ // Pass through unless the trailing 32 bytes are the ERC-6492 magic value.
65
+ if (bytes32(signature[signatureLength - _ERC6492_MAGIC_VALUE.length:]) != _ERC6492_MAGIC_VALUE)
66
+ return signature;
67
+
68
+ // Decode the wrapped (factory, factoryCalldata, innerSignature) directly from the calldata
69
+ // slice that strips the magic suffix.
70
+ (address prepareTarget, bytes memory prepareData, bytes memory innerSignature) = abi.decode(
71
+ signature[:signatureLength - _ERC6492_MAGIC_VALUE.length],
72
+ (address, bytes, bytes)
73
+ );
74
+
75
+ // Route the deploy call through the neutral Multicall3 so this contract is never the sender of
76
+ // attacker-controlled calldata. Failure is tolerated (e.g. the wallet is already deployed);
77
+ // the downstream verifier is the source of truth on signature validity.
78
+ IMulticall3.Call[] memory calls = new IMulticall3.Call[](1);
79
+ calls[0] = IMulticall3.Call(prepareTarget, prepareData);
80
+ multicall3.tryAggregate({ requireSuccess: false, calls: calls });
81
+
82
+ return innerSignature;
83
+ }
84
+ }
@@ -10,12 +10,13 @@ import { ReentrancyGuard } from "@openzeppelin/contracts-v4/security/ReentrancyG
10
10
  import { SignatureChecker } from "@openzeppelin/contracts-v4/utils/cryptography/SignatureChecker.sol";
11
11
  import { EIP712 } from "@openzeppelin/contracts-v4/utils/cryptography/EIP712.sol";
12
12
  import { V3SpokePoolInterface } from "../interfaces/V3SpokePoolInterface.sol";
13
- import { IERC20Auth } from "../external/interfaces/IERC20Auth.sol";
13
+ import { IERC20Auth, IERC20AuthBytes } from "../external/interfaces/IERC20Auth.sol";
14
14
  import { WETH9Interface } from "../external/interfaces/WETH9Interface.sol";
15
15
  import { IPermit2 } from "../external/interfaces/IPermit2.sol";
16
16
  import { PeripherySigningLib } from "../libraries/PeripherySigningLib.sol";
17
17
  import { SpokePoolPeripheryInterface } from "../interfaces/SpokePoolPeripheryInterface.sol";
18
18
  import { AddressToBytes32 } from "../libraries/AddressConverters.sol";
19
+ import { ERC6492SignatureHandler } from "./ERC6492SignatureHandler.sol";
19
20
 
20
21
  /**
21
22
  * @title SwapProxy
@@ -143,7 +144,13 @@ contract SwapProxy is ReentrancyGuard {
143
144
  * @notice Contract for performing more complex interactions with an Across spoke pool deployment.
144
145
  * @custom:security-contact bugs@across.to
145
146
  */
146
- contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, MultiCaller, EIP712 {
147
+ contract SpokePoolPeriphery is
148
+ SpokePoolPeripheryInterface,
149
+ ReentrancyGuard,
150
+ MultiCaller,
151
+ EIP712,
152
+ ERC6492SignatureHandler
153
+ {
147
154
  using SafeERC20 for IERC20;
148
155
  using Address for address;
149
156
  using AddressToBytes32 for address;
@@ -188,8 +195,13 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
188
195
  /**
189
196
  * @notice Construct a new Periphery contract.
190
197
  * @param _permit2 Address of the canonical permit2 contract.
198
+ * @param _multicall3 Address of the canonical Multicall3 singleton used to route ERC-6492
199
+ * prepare/deploy calls (see ERC6492SignatureHandler).
191
200
  */
192
- constructor(IPermit2 _permit2) EIP712("ACROSS-PERIPHERY", "1.0.0") {
201
+ constructor(
202
+ IPermit2 _permit2,
203
+ address _multicall3
204
+ ) EIP712("ACROSS-PERIPHERY", "1.0.0") ERC6492SignatureHandler(_multicall3) {
193
205
  require(address(_permit2) != address(0), "Permit2 cannot be zero address");
194
206
  require(_isContract(address(_permit2)), "Permit2 must be a contract");
195
207
  permit2 = _permit2;
@@ -315,6 +327,9 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
315
327
  * This case should be extremely rare as both values would need to be > 1e18 * 1e18.
316
328
  * Users will only see a generic failure without explanatory error message.
317
329
  * @dev Does not support native tokens as swap output. Only ERC20 tokens can be deposited via this function.
330
+ * @dev Permit2 verifies both EOA (ECDSA) and contract (EIP-1271) signatures. The signature may be
331
+ * ERC-6492 wrapped to additionally support counterfactual (not-yet-deployed) contract wallets; see
332
+ * `_handleERC6492Signature`.
318
333
  */
319
334
  function swapAndBridgeWithPermit2(
320
335
  address signatureOwner,
@@ -331,13 +346,16 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
331
346
  requestedAmount: swapAndDepositData.swapTokenAmount + _submissionFeeAmount
332
347
  });
333
348
 
349
+ // If the signature is ERC-6492 wrapped, deploy the (counterfactual) signer first and unwrap to
350
+ // the inner signature. Permit2 remains the verifier; we only ensure the signer has code.
351
+ bytes memory innerSignature = _handleERC6492Signature(signature);
334
352
  permit2.permitWitnessTransferFrom(
335
353
  permit,
336
354
  transferDetails,
337
355
  signatureOwner,
338
356
  witness,
339
357
  PeripherySigningLib.EIP712_SWAP_AND_DEPOSIT_TYPE_STRING,
340
- signature
358
+ innerSignature
341
359
  );
342
360
  _paySubmissionFees(
343
361
  swapAndDepositData.swapToken,
@@ -365,14 +383,13 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
365
383
  ) external override nonReentrant {
366
384
  bytes32 witness = getERC3009SwapAndBridgeWitness(swapAndDepositData);
367
385
  (bytes32 r, bytes32 s, uint8 v) = PeripherySigningLib.deserializeSignature(receiveWithAuthSignature);
368
- uint256 _submissionFeeAmount = swapAndDepositData.submissionFees.amount;
369
386
  // While any contract can vacuously implement `receiveWithAuthorization` (or just have a fallback),
370
387
  // if tokens were not sent to this contract, by this call to swapData.swapToken, this function will revert
371
388
  // when attempting to swap tokens it does not own.
372
389
  IERC20Auth(address(swapAndDepositData.swapToken)).receiveWithAuthorization(
373
390
  signatureOwner,
374
391
  address(this),
375
- swapAndDepositData.swapTokenAmount + _submissionFeeAmount,
392
+ swapAndDepositData.swapTokenAmount + swapAndDepositData.submissionFees.amount,
376
393
  validAfter,
377
394
  validBefore,
378
395
  witness,
@@ -380,10 +397,53 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
380
397
  r,
381
398
  s
382
399
  );
400
+ _finishSwapAndBridgeWithAuthorization(swapAndDepositData, witness, signatureOwner);
401
+ }
402
+
403
+ /**
404
+ * @inheritdoc SpokePoolPeripheryInterface
405
+ * @dev Mirrors `swapAndBridgeWithAuthorization` but pulls tokens via the extended EIP-3009
406
+ * `receiveWithAuthorization(...,bytes signature)` overload, allowing both EOA (ECDSA) and
407
+ * contract (EIP-1271) signers. The signature may be ERC-6492 wrapped to additionally support
408
+ * counterfactual (not-yet-deployed) contract wallets; see `_handleERC6492Signature`.
409
+ */
410
+ function swapAndBridgeWithAuthorizationBytes(
411
+ address signatureOwner,
412
+ SwapAndDepositData calldata swapAndDepositData,
413
+ uint256 validAfter,
414
+ uint256 validBefore,
415
+ bytes calldata receiveWithAuthSignature
416
+ ) external override nonReentrant {
417
+ bytes32 witness = getERC3009SwapAndBridgeWitness(swapAndDepositData);
418
+ // If the signature is ERC-6492 wrapped, deploy the (counterfactual) signer first and unwrap to
419
+ // the inner signature. The token remains the verifier; we only ensure the signer has code.
420
+ bytes memory innerSignature = _handleERC6492Signature(receiveWithAuthSignature);
421
+ IERC20AuthBytes(address(swapAndDepositData.swapToken)).receiveWithAuthorization(
422
+ signatureOwner,
423
+ address(this),
424
+ swapAndDepositData.swapTokenAmount + swapAndDepositData.submissionFees.amount,
425
+ validAfter,
426
+ validBefore,
427
+ witness,
428
+ innerSignature
429
+ );
430
+ _finishSwapAndBridgeWithAuthorization(swapAndDepositData, witness, signatureOwner);
431
+ }
432
+
433
+ /**
434
+ * @notice Shared tail logic for swapAndBridgeWithAuthorization* entry points after the token
435
+ * pull has succeeded. Pays submission fees and dispatches the swap+bridge using the witness as
436
+ * the ERC-3009 nonce.
437
+ */
438
+ function _finishSwapAndBridgeWithAuthorization(
439
+ SwapAndDepositData calldata swapAndDepositData,
440
+ bytes32 witness,
441
+ address signatureOwner
442
+ ) private {
383
443
  _paySubmissionFees(
384
444
  swapAndDepositData.swapToken,
385
445
  swapAndDepositData.submissionFees.recipient,
386
- _submissionFeeAmount
446
+ swapAndDepositData.submissionFees.amount
387
447
  );
388
448
 
389
449
  // Note: No need to validate our internal nonce for receiveWithAuthorization
@@ -445,6 +505,9 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
445
505
 
446
506
  /**
447
507
  * @inheritdoc SpokePoolPeripheryInterface
508
+ * @dev Permit2 verifies both EOA (ECDSA) and contract (EIP-1271) signatures. The signature may be
509
+ * ERC-6492 wrapped to additionally support counterfactual (not-yet-deployed) contract wallets; see
510
+ * `_handleERC6492Signature`.
448
511
  */
449
512
  function depositWithPermit2(
450
513
  address signatureOwner,
@@ -461,13 +524,16 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
461
524
  requestedAmount: depositData.inputAmount + _submissionFeeAmount
462
525
  });
463
526
 
527
+ // If the signature is ERC-6492 wrapped, deploy the (counterfactual) signer first and unwrap to
528
+ // the inner signature. Permit2 remains the verifier; we only ensure the signer has code.
529
+ bytes memory innerSignature = _handleERC6492Signature(signature);
464
530
  permit2.permitWitnessTransferFrom(
465
531
  permit,
466
532
  transferDetails,
467
533
  signatureOwner,
468
534
  witness,
469
535
  PeripherySigningLib.EIP712_DEPOSIT_TYPE_STRING,
470
- signature
536
+ innerSignature
471
537
  );
472
538
  _paySubmissionFees(
473
539
  depositData.baseDepositData.inputToken,
@@ -507,16 +573,13 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
507
573
  bytes calldata receiveWithAuthSignature
508
574
  ) external override nonReentrant {
509
575
  bytes32 witness = getERC3009DepositWitness(depositData);
510
- // Load variables used multiple times onto the stack.
511
- uint256 _inputAmount = depositData.inputAmount;
512
- uint256 _submissionFeeAmount = depositData.submissionFees.amount;
513
576
 
514
577
  // Redeem the receiveWithAuthSignature.
515
578
  (bytes32 r, bytes32 s, uint8 v) = PeripherySigningLib.deserializeSignature(receiveWithAuthSignature);
516
579
  IERC20Auth(depositData.baseDepositData.inputToken).receiveWithAuthorization(
517
580
  signatureOwner,
518
581
  address(this),
519
- _inputAmount + _submissionFeeAmount,
582
+ depositData.inputAmount + depositData.submissionFees.amount,
520
583
  validAfter,
521
584
  validBefore,
522
585
  witness,
@@ -524,10 +587,53 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
524
587
  r,
525
588
  s
526
589
  );
590
+ _finishDepositWithAuthorization(depositData, witness, signatureOwner);
591
+ }
592
+
593
+ /**
594
+ * @inheritdoc SpokePoolPeripheryInterface
595
+ * @dev Mirrors `depositWithAuthorization` but pulls tokens via the extended EIP-3009
596
+ * `receiveWithAuthorization(...,bytes signature)` overload, allowing both EOA (ECDSA) and
597
+ * contract (EIP-1271) signers. The signature may be ERC-6492 wrapped to additionally support
598
+ * counterfactual (not-yet-deployed) contract wallets; see `_handleERC6492Signature`.
599
+ */
600
+ function depositWithAuthorizationBytes(
601
+ address signatureOwner,
602
+ DepositData calldata depositData,
603
+ uint256 validAfter,
604
+ uint256 validBefore,
605
+ bytes calldata receiveWithAuthSignature
606
+ ) external override nonReentrant {
607
+ bytes32 witness = getERC3009DepositWitness(depositData);
608
+ // If the signature is ERC-6492 wrapped, deploy the (counterfactual) signer first and unwrap to
609
+ // the inner signature. The token remains the verifier; we only ensure the signer has code.
610
+ bytes memory innerSignature = _handleERC6492Signature(receiveWithAuthSignature);
611
+ IERC20AuthBytes(depositData.baseDepositData.inputToken).receiveWithAuthorization(
612
+ signatureOwner,
613
+ address(this),
614
+ depositData.inputAmount + depositData.submissionFees.amount,
615
+ validAfter,
616
+ validBefore,
617
+ witness,
618
+ innerSignature
619
+ );
620
+ _finishDepositWithAuthorization(depositData, witness, signatureOwner);
621
+ }
622
+
623
+ /**
624
+ * @notice Shared tail logic for depositWithAuthorization* entry points after the token pull has
625
+ * succeeded. Pays submission fees and dispatches the bridge using the witness as the ERC-3009
626
+ * nonce.
627
+ */
628
+ function _finishDepositWithAuthorization(
629
+ DepositData calldata depositData,
630
+ bytes32 witness,
631
+ address signatureOwner
632
+ ) private {
527
633
  _paySubmissionFees(
528
634
  depositData.baseDepositData.inputToken,
529
635
  depositData.submissionFees.recipient,
530
- _submissionFeeAmount
636
+ depositData.submissionFees.amount
531
637
  );
532
638
 
533
639
  // Note: No need to validate our internal nonce for receiveWithAuthorization
@@ -539,7 +645,7 @@ contract SpokePoolPeriphery is SpokePoolPeripheryInterface, ReentrancyGuard, Mul
539
645
  depositData.baseDepositData.recipient,
540
646
  depositData.baseDepositData.inputToken,
541
647
  depositData.baseDepositData.outputToken,
542
- _inputAmount,
648
+ depositData.inputAmount,
543
649
  depositData.baseDepositData.outputAmount,
544
650
  depositData.baseDepositData.destinationChainId,
545
651
  depositData.baseDepositData.exclusiveRelayer,
@@ -1,7 +1,7 @@
1
1
  //SPDX-License-Identifier: Unlicense
2
2
  pragma solidity ^0.8.0;
3
3
 
4
- import { IERC20Auth } from "../external/interfaces/IERC20Auth.sol";
4
+ import { IERC20Auth, IERC20AuthBytes } from "../external/interfaces/IERC20Auth.sol";
5
5
  import { ERC20Permit } from "@openzeppelin/contracts-v4/token/ERC20/extensions/ERC20Permit.sol";
6
6
  import { ERC20 } from "@openzeppelin/contracts-v4/token/ERC20/ERC20.sol";
7
7
  import { SignatureChecker } from "@openzeppelin/contracts-v4/utils/cryptography/SignatureChecker.sol";
@@ -46,7 +46,7 @@ contract MintableERC20 is ERC20 {
46
46
  * @title MockERC20
47
47
  * @notice Implements mocked ERC20 contract with various features.
48
48
  */
49
- contract MockERC20 is IERC20Auth, ERC20Permit {
49
+ contract MockERC20 is IERC20Auth, IERC20AuthBytes, ERC20Permit {
50
50
  bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH =
51
51
  keccak256(
52
52
  "ReceiveWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce)"
@@ -69,9 +69,42 @@ contract MockERC20 is IERC20Auth, ERC20Permit {
69
69
  bytes32 r,
70
70
  bytes32 s
71
71
  ) external {
72
+ _verifyAndTransferWithAuthorization(
73
+ from,
74
+ to,
75
+ value,
76
+ validAfter,
77
+ validBefore,
78
+ nonce,
79
+ bytes.concat(r, s, bytes1(v))
80
+ );
81
+ }
82
+
83
+ // Extended EIP-3009 overload that accepts an unstructured signature (EOA or EIP-1271).
84
+ // Selector differs from the v/r/s form, so both can coexist on the same contract.
85
+ function receiveWithAuthorization(
86
+ address from,
87
+ address to,
88
+ uint256 value,
89
+ uint256 validAfter,
90
+ uint256 validBefore,
91
+ bytes32 nonce,
92
+ bytes memory signature
93
+ ) external {
94
+ _verifyAndTransferWithAuthorization(from, to, value, validAfter, validBefore, nonce, signature);
95
+ }
96
+
97
+ function _verifyAndTransferWithAuthorization(
98
+ address from,
99
+ address to,
100
+ uint256 value,
101
+ uint256 validAfter,
102
+ uint256 validBefore,
103
+ bytes32 nonce,
104
+ bytes memory signature
105
+ ) internal {
72
106
  require(validAfter <= block.timestamp && validBefore >= block.timestamp, "Invalid time bounds");
73
107
  require(msg.sender == to, "Receiver not caller");
74
- bytes memory signature = bytes.concat(r, s, bytes1(v));
75
108
 
76
109
  bytes32 structHash = keccak256(
77
110
  abi.encode(RECEIVE_WITH_AUTHORIZATION_TYPEHASH, from, to, value, validAfter, validBefore, nonce)