Skip to content

Commit 253a924

Browse files
authored
Merge branch 'main' into fix/audit-april-2025-4.10
2 parents 8d8bbbb + 6912e73 commit 253a924

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

src/helpers/DelegationMetaSwapAdapter.sol

Lines changed: 10 additions & 1 deletion
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;
@@ -323,6 +331,7 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
323331
* @param _newSigner The new authorized signer address.
324332
*/
325333
function setSwapApiSigner(address _newSigner) external onlyOwner {
334+
if (_newSigner == address(0)) revert InvalidZeroAddress();
326335
swapApiSigner = _newSigner;
327336
emit SwapApiSignerUpdated(_newSigner);
328337
}
@@ -526,7 +535,7 @@ contract DelegationMetaSwapAdapter is ExecutionHelper, Ownable2Step {
526535
* @param _signatureData Contains the apiData, the expiration and signature.
527536
*/
528537
function _validateSignature(SignatureData memory _signatureData) private view {
529-
if (block.timestamp > _signatureData.expiration) revert SignatureExpired();
538+
if (block.timestamp >= _signatureData.expiration) revert SignatureExpired();
530539

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

test/helpers/DelegationMetaSwapAdapter.t.sol

Lines changed: 57 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
*/
@@ -1130,6 +1156,14 @@ contract DelegationMetaSwapAdapterMockTest is DelegationMetaSwapAdapterBaseTest
11301156
assertEq(delegationMetaSwapAdapter.swapApiSigner(), newSigner_, "Swap API signer was not updated");
11311157
}
11321158

1159+
/// @notice Tests that the owner cannot set the swap API signer to the zero address.
1160+
function test_revert_setSwapApiSigner_ifZeroAddress() public {
1161+
_setUpMockContracts();
1162+
vm.prank(owner);
1163+
vm.expectRevert(DelegationMetaSwapAdapter.InvalidZeroAddress.selector);
1164+
delegationMetaSwapAdapter.setSwapApiSigner(address(0));
1165+
}
1166+
11331167
/// @notice Tests that a non-owner calling setSwapApiSigner reverts.
11341168
function test_revert_setSwapApiSigner_ifNotOwner() public {
11351169
_setUpMockContracts();
@@ -1161,6 +1195,29 @@ contract DelegationMetaSwapAdapterMockTest is DelegationMetaSwapAdapterBaseTest
11611195
delegationMetaSwapAdapter.swapByDelegation(sigData_, delegations_, true);
11621196
}
11631197

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

0 commit comments

Comments
 (0)