Skip to content

Commit

Permalink
Check arrays length matches in claimWithdrawals
Browse files Browse the repository at this point in the history
  • Loading branch information
Psirex committed Apr 13, 2023
1 parent 7a40ae9 commit 6db4af6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contracts/0.8.9/WithdrawalQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit
error InvalidReportTimestamp();
error RequestIdsNotSorted();
error ZeroRecipient();
error ArraysLengthMismatch(uint256 _firstArrayLength, uint256 _secondArrayLength);

/// @param _wstETH address of WstETH contract
constructor(IWstETH _wstETH) {
Expand Down Expand Up @@ -238,13 +239,17 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit
/// @param _recipient address where claimed ether will be sent to
/// @dev
/// Reverts if recipient is equal to zero
/// Reverts if requestIds and hints arrays length differs
/// Reverts if any requestId or hint in arguments are not valid
/// Reverts if any request is not finalized or already claimed
/// Reverts if msg sender is not an owner of the requests
function claimWithdrawalsTo(uint256[] calldata _requestIds, uint256[] calldata _hints, address _recipient)
external
{
if (_recipient == address(0)) revert ZeroRecipient();
if (_requestIds.length != _hints.length) {
revert ArraysLengthMismatch(_requestIds.length, _hints.length);
}

for (uint256 i = 0; i < _requestIds.length; ++i) {
_claim(_requestIds[i], _hints[i], _recipient);
Expand All @@ -257,10 +262,15 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit
/// @param _hints checkpoint hint for each id.
/// Can be retrieved with `findCheckpointHints()`
/// @dev
/// Reverts if requestIds and hints arrays length differs
/// Reverts if any requestId or hint in arguments are not valid
/// Reverts if any request is not finalized or already claimed
/// Reverts if msg sender is not an owner of the requests
function claimWithdrawals(uint256[] calldata _requestIds, uint256[] calldata _hints) external {
if (_requestIds.length != _hints.length) {
revert ArraysLengthMismatch(_requestIds.length, _hints.length);
}

for (uint256 i = 0; i < _requestIds.length; ++i) {
_claim(_requestIds[i], _hints[i], msg.sender);
_emitTransfer(msg.sender, address(0), _requestIds[i]);
Expand Down
11 changes: 11 additions & 0 deletions test/0.8.9/withdrawal-queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@ contract('WithdrawalQueue', ([owner, stranger, daoAgent, user, pauser, resumer,
)
})

it('reverts when requestIds and hints arrays length mismatch', async () => {
await assert.reverts(
withdrawalQueue.claimWithdrawalsTo([0], [1, 2], user, { from: owner }),
'ArraysLengthMismatch(1, 2)'
)
})

it('reverts with zero _requestId', async () => {
await assert.reverts(withdrawalQueue.claimWithdrawalsTo([0], [1], user, { from: owner }), 'InvalidRequestId(0)')
})
Expand Down Expand Up @@ -722,6 +729,10 @@ contract('WithdrawalQueue', ([owner, stranger, daoAgent, user, pauser, resumer,
await withdrawalQueue.requestWithdrawals([amount], owner, { from: user })
})

it('reverts when requestIds and hints arrays length mismatch', async () => {
await assert.reverts(withdrawalQueue.claimWithdrawals([1, 2], [1], { from: owner }), 'ArraysLengthMismatch(2, 1)')
})

it('claims correct requests', async () => {
await steth.mintShares(owner, shares(300)) // 1 share to user and 299 shares to owner total = 300 ETH
await steth.approve(withdrawalQueue.address, StETH(300), { from: owner })
Expand Down

0 comments on commit 6db4af6

Please sign in to comment.