Skip to content

Commit dffb0d9

Browse files
committed
Audit April 2025 - 7.2.1 and 7.2.2 - Constructor Inputs and Expiration
1 parent 0f8e128 commit dffb0d9

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/helpers/DelegationMetaSwapAdapter.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
146146
/// @dev Error thrown when the signature expiration has passed.
147147
error SignatureExpired();
148148

149+
/// @dev Error thrown when the address is zero.
150+
error InvalidZeroAddress();
151+
149152
////////////////////////////// Modifiers //////////////////////////////
150153

151154
/**
@@ -184,6 +187,11 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
184187
)
185188
Ownable(_owner)
186189
{
190+
if (
191+
_swapApiSigner == address(0) || address(_delegationManager) == address(0) || address(_metaSwap) == address(0)
192+
|| _argsEqualityCheckEnforcer == address(0)
193+
) revert InvalidZeroAddress();
194+
187195
swapApiSigner = _swapApiSigner;
188196
delegationManager = _delegationManager;
189197
metaSwap = _metaSwap;
@@ -274,7 +282,7 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
274282
* @param _tokenTo The output token of the swap.
275283
* @param _recipient The address that will receive the swapped tokens.
276284
* @param _amountFrom The amount of tokens to be swapped.
277-
* @param _balanceFromBefore The contracts balance of _tokenFrom before the incoming token transfer is credited.
285+
* @param _balanceFromBefore The contract's balance of _tokenFrom before the incoming token transfer is credited.
278286
* @param _swapData Arbitrary data required by the aggregator (e.g. encoded swap params).
279287
*/
280288
function swapTokens(
@@ -524,7 +532,7 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
524532
* @param _signatureData Contains the apiData, the expiration and signature.
525533
*/
526534
function _validateSignature(SignatureData memory _signatureData) private view {
527-
if (block.timestamp > _signatureData.expiration) revert SignatureExpired();
535+
if (block.timestamp >= _signatureData.expiration) revert SignatureExpired();
528536

529537
bytes32 messageHash_ = keccak256(abi.encodePacked(_signatureData.apiData, _signatureData.expiration));
530538
bytes32 ethSignedMessageHash_ = MessageHashUtils.toEthSignedMessageHash(messageHash_);

test/helpers/DelegationMetaSwapAdapter.t.sol

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,32 @@ contract DelegationMetaSwapAdapterMockTest is DelegationMetaSwapAdapterBaseTest
300300
super.setUp();
301301
}
302302

303+
/**
304+
* @notice Verifies that the contract reverts when the zero address is used as an input.
305+
*/
306+
function test_revert_invalidZeroAddressInConstructor() public {
307+
address owner_ = address(1);
308+
address swapApiSigner_ = address(1);
309+
IDelegationManager delegationManager_ = IDelegationManager(address(1));
310+
IMetaSwap metaSwap_ = IMetaSwap(address(1));
311+
address argsEqualityCheckEnforcer_ = address(1);
312+
313+
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableInvalidOwner.selector, address(0)));
314+
new DelegationMetaSwapAdapter(address(0), swapApiSigner_, delegationManager_, metaSwap_, argsEqualityCheckEnforcer_);
315+
316+
vm.expectRevert(DelegationMetaSwapAdapter.InvalidZeroAddress.selector);
317+
new DelegationMetaSwapAdapter(owner_, address(0), delegationManager_, metaSwap_, argsEqualityCheckEnforcer_);
318+
319+
vm.expectRevert(DelegationMetaSwapAdapter.InvalidZeroAddress.selector);
320+
new DelegationMetaSwapAdapter(owner_, swapApiSigner_, IDelegationManager(address(0)), metaSwap_, argsEqualityCheckEnforcer_);
321+
322+
vm.expectRevert(DelegationMetaSwapAdapter.InvalidZeroAddress.selector);
323+
new DelegationMetaSwapAdapter(owner_, swapApiSigner_, delegationManager_, IMetaSwap(address(0)), argsEqualityCheckEnforcer_);
324+
325+
vm.expectRevert(DelegationMetaSwapAdapter.InvalidZeroAddress.selector);
326+
new DelegationMetaSwapAdapter(owner_, swapApiSigner_, delegationManager_, metaSwap_, address(0));
327+
}
328+
303329
/**
304330
* @notice Verifies that tokens can be swapped by delegations in a purely local environment (using a MetaSwapMock).
305331
*/
@@ -1161,6 +1187,29 @@ contract DelegationMetaSwapAdapterMockTest is DelegationMetaSwapAdapterBaseTest
11611187
delegationMetaSwapAdapter.swapByDelegation(sigData_, delegations_, true);
11621188
}
11631189

1190+
/// @notice Tests that swapByDelegation reverts with SignatureExpired when the signature expiration is equal to current
1191+
/// timestamp.
1192+
function test_revert_swapByDelegation_signatureExpired_equal() public {
1193+
_setUpMockContracts();
1194+
bytes memory swapData_ = _encodeSwapData(IERC20(tokenA), IERC20(tokenB), amountFrom, amountTo, hex"", 0, address(0), true);
1195+
bytes memory apiData_ = _encodeApiData(aggregatorId, IERC20(tokenA), amountFrom, swapData_);
1196+
// Set expiration in the current time.
1197+
uint256 expiredTime = block.timestamp;
1198+
bytes memory signature = _getValidSignature(apiData_, expiredTime);
1199+
DelegationMetaSwapAdapter.SignatureData memory sigData_ =
1200+
DelegationMetaSwapAdapter.SignatureData({ apiData: apiData_, expiration: expiredTime, signature: signature });
1201+
1202+
Delegation[] memory delegations_ = new Delegation[](2);
1203+
Delegation memory vaultDelegation_ = _getVaultDelegation();
1204+
Delegation memory subVaultDelegation_ = _getSubVaultDelegation(EncoderLib._getDelegationHash(vaultDelegation_));
1205+
delegations_[1] = vaultDelegation_;
1206+
delegations_[0] = subVaultDelegation_;
1207+
1208+
vm.prank(address(subVault.deleGator));
1209+
vm.expectRevert(DelegationMetaSwapAdapter.SignatureExpired.selector);
1210+
delegationMetaSwapAdapter.swapByDelegation(sigData_, delegations_, true);
1211+
}
1212+
11641213
/// @notice Tests that swapByDelegation reverts with InvalidApiSignature when the signature is invalid.
11651214
function test_revert_swapByDelegation_invalidApiSignature() public {
11661215
_setUpMockContracts();

0 commit comments

Comments
 (0)