Possible DOS (out-of-gas) on loops.
The contract's batch functions iterate over an unbounded array of contracts, so if many contracts are pending withdrawal the loop can run out of gas and the transaction fails. An attacker could add many contracts to make the function unusable.
Submitted by 0x29A, also found by minhquanym
https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/BatchRequests.sol#L16
https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/BatchRequests.sol#L36
https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/BatchRequests.sol#L91
Impact
It is possible to get an out-of-gas issue while iterating the for loop.
Please take a look at this link.
Proof of Concept
Let’s say I want to run the function on BatchRequests.sol#L14 and I got a lot of contracts pending for withdrawal.
Recommended Mitigation Steps
Use this pattern;
/**
@notice sendWithdrawalRequests on all addresses in contracts
*/
function sendWithdrawalRequests(uint256 from, uint256 to) external {
uint256 contractsLength = contracts.length;
require(from < contractsLength, "Invalid from");
require(to <= contractsLength, "Invalid to");
for (uint256 i = from; i < to; ) {
if (
contracts[i] != address(0) &&
IStaking(contracts[i]).canBatchTransactions()
) {
IStaking(contracts[i]).sendWithdrawalRequests();
}
unchecked {
++i;
}
}
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
What the attacker needed
Many contracts pending withdrawal
The fix
The function should be changed to process a bounded range of indices (from and to) instead of the whole array, as shown in the recommended pattern.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract function loops over a list of items. If the list gets too long, the transaction runs out of gas (the fee limit) and fails. This means the function can be blocked by making the list very large.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.