Skip to content

Commit 0805bca

Browse files
committed
make verifyParams a modifier
1 parent 701cb5c commit 0805bca

File tree

3 files changed

+57
-38
lines changed

3 files changed

+57
-38
lines changed

contracts/periphery/counterfactual/CounterfactualDepositCCTP.sol

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ contract CounterfactualDepositCCTP is CounterfactualDepositBase {
6767
/// @notice CCTP source domain ID for this chain
6868
uint32 public immutable sourceDomain;
6969

70+
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
71+
modifier verifyParams(CCTPImmutables memory params) {
72+
_verifyParamsHash(keccak256(abi.encode(params)));
73+
_;
74+
}
75+
7076
constructor(address _srcPeriphery, uint32 _sourceDomain) {
7177
srcPeriphery = _srcPeriphery;
7278
sourceDomain = _sourceDomain;
@@ -88,9 +94,7 @@ contract CounterfactualDepositCCTP is CounterfactualDepositBase {
8894
bytes32 nonce,
8995
uint256 cctpDeadline,
9096
bytes calldata signature
91-
) external {
92-
_verifyParams(params);
93-
97+
) external verifyParams(params) {
9498
address inputToken = address(uint160(uint256(params.depositParams.burnToken)));
9599

96100
// transfer execution fee to execution fee recipient
@@ -136,8 +140,12 @@ contract CounterfactualDepositCCTP is CounterfactualDepositBase {
136140
* @param to Recipient of the withdrawn tokens.
137141
* @param amount Amount to withdraw.
138142
*/
139-
function adminWithdraw(CCTPImmutables memory params, address token, address to, uint256 amount) external {
140-
_verifyParams(params);
143+
function adminWithdraw(
144+
CCTPImmutables memory params,
145+
address token,
146+
address to,
147+
uint256 amount
148+
) external verifyParams(params) {
141149
_adminWithdraw(params.executionParams.adminWithdrawAddress, token, to, amount);
142150
}
143151

@@ -148,14 +156,12 @@ contract CounterfactualDepositCCTP is CounterfactualDepositBase {
148156
* @param to Recipient of the withdrawn tokens.
149157
* @param amount Amount to withdraw.
150158
*/
151-
function userWithdraw(CCTPImmutables memory params, address token, address to, uint256 amount) external {
152-
_verifyParams(params);
159+
function userWithdraw(
160+
CCTPImmutables memory params,
161+
address token,
162+
address to,
163+
uint256 amount
164+
) external verifyParams(params) {
153165
_userWithdraw(params.executionParams.userWithdrawAddress, token, to, amount);
154166
}
155-
156-
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
157-
/// @param params Route parameters to verify.
158-
function _verifyParams(CCTPImmutables memory params) internal view {
159-
_verifyParamsHash(keccak256(abi.encode(params)));
160-
}
161167
}

contracts/periphery/counterfactual/CounterfactualDepositOFT.sol

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ contract CounterfactualDepositOFT is CounterfactualDepositBase {
6767
/// @notice OFT source endpoint ID for this chain
6868
uint32 public immutable srcEid;
6969

70+
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
71+
modifier verifyParams(OFTImmutables memory params) {
72+
_verifyParamsHash(keccak256(abi.encode(params)));
73+
_;
74+
}
75+
7076
constructor(address _oftSrcPeriphery, uint32 _srcEid) {
7177
oftSrcPeriphery = _oftSrcPeriphery;
7278
srcEid = _srcEid;
@@ -88,9 +94,7 @@ contract CounterfactualDepositOFT is CounterfactualDepositBase {
8894
bytes32 nonce,
8995
uint256 oftDeadline,
9096
bytes calldata signature
91-
) external payable {
92-
_verifyParams(params);
93-
97+
) external payable verifyParams(params) {
9498
// transfer execution fee to execution fee recipient
9599
if (params.executionParams.executionFee > 0) {
96100
IERC20(params.depositParams.token).safeTransfer(executionFeeRecipient, params.executionParams.executionFee);
@@ -135,8 +139,12 @@ contract CounterfactualDepositOFT is CounterfactualDepositBase {
135139
* @param to Recipient of the withdrawn tokens.
136140
* @param amount Amount to withdraw.
137141
*/
138-
function adminWithdraw(OFTImmutables memory params, address token, address to, uint256 amount) external {
139-
_verifyParams(params);
142+
function adminWithdraw(
143+
OFTImmutables memory params,
144+
address token,
145+
address to,
146+
uint256 amount
147+
) external verifyParams(params) {
140148
_adminWithdraw(params.executionParams.adminWithdrawAddress, token, to, amount);
141149
}
142150

@@ -147,14 +155,12 @@ contract CounterfactualDepositOFT is CounterfactualDepositBase {
147155
* @param to Recipient of the withdrawn tokens.
148156
* @param amount Amount to withdraw.
149157
*/
150-
function userWithdraw(OFTImmutables memory params, address token, address to, uint256 amount) external {
151-
_verifyParams(params);
158+
function userWithdraw(
159+
OFTImmutables memory params,
160+
address token,
161+
address to,
162+
uint256 amount
163+
) external verifyParams(params) {
152164
_userWithdraw(params.executionParams.userWithdrawAddress, token, to, amount);
153165
}
154-
155-
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
156-
/// @param params Route parameters to verify.
157-
function _verifyParams(OFTImmutables memory params) internal view {
158-
_verifyParamsHash(keccak256(abi.encode(params)));
159-
}
160166
}

contracts/periphery/counterfactual/CounterfactualDepositSpokePool.sol

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ contract CounterfactualDepositSpokePool is CounterfactualDepositBase, EIP712 {
6060
/// @notice Signer that authorizes execution parameters
6161
address public immutable signer;
6262

63+
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
64+
modifier verifyParams(SpokePoolImmutables memory params) {
65+
_verifyParamsHash(keccak256(abi.encode(params)));
66+
_;
67+
}
68+
6369
constructor(address _spokePool, address _signer) EIP712("CounterfactualDepositSpokePool", "v1.0.0") {
6470
spokePool = _spokePool;
6571
signer = _signer;
@@ -87,8 +93,7 @@ contract CounterfactualDepositSpokePool is CounterfactualDepositBase, EIP712 {
8793
uint32 quoteTimestamp,
8894
uint32 fillDeadline,
8995
bytes calldata signature
90-
) external {
91-
_verifyParams(params);
96+
) external verifyParams(params) {
9297
_verifySignature(inputAmount, outputAmount, exclusiveRelayer, exclusivityDeadline, fillDeadline, signature);
9398

9499
address inputToken = address(uint160(uint256(params.depositParams.inputToken)));
@@ -135,8 +140,12 @@ contract CounterfactualDepositSpokePool is CounterfactualDepositBase, EIP712 {
135140
* @param to Recipient of the withdrawn tokens.
136141
* @param amount Amount to withdraw.
137142
*/
138-
function adminWithdraw(SpokePoolImmutables memory params, address token, address to, uint256 amount) external {
139-
_verifyParams(params);
143+
function adminWithdraw(
144+
SpokePoolImmutables memory params,
145+
address token,
146+
address to,
147+
uint256 amount
148+
) external verifyParams(params) {
140149
_adminWithdraw(params.executionParams.adminWithdrawAddress, token, to, amount);
141150
}
142151

@@ -147,8 +156,12 @@ contract CounterfactualDepositSpokePool is CounterfactualDepositBase, EIP712 {
147156
* @param to Recipient of the withdrawn tokens.
148157
* @param amount Amount to withdraw.
149158
*/
150-
function userWithdraw(SpokePoolImmutables memory params, address token, address to, uint256 amount) external {
151-
_verifyParams(params);
159+
function userWithdraw(
160+
SpokePoolImmutables memory params,
161+
address token,
162+
address to,
163+
uint256 amount
164+
) external verifyParams(params) {
152165
_userWithdraw(params.executionParams.userWithdrawAddress, token, to, amount);
153166
}
154167

@@ -182,10 +195,4 @@ contract CounterfactualDepositSpokePool is CounterfactualDepositBase, EIP712 {
182195
);
183196
if (ECDSA.recover(_hashTypedDataV4(structHash), signature) != signer) revert InvalidSignature();
184197
}
185-
186-
/// @dev Hashes caller-supplied params and checks against the clone's stored hash.
187-
/// @param params Route parameters to verify.
188-
function _verifyParams(SpokePoolImmutables memory params) internal view {
189-
_verifyParamsHash(keccak256(abi.encode(params)));
190-
}
191198
}

0 commit comments

Comments
 (0)