Description
The AaveDIVAWrapper contract's batch operation functions lack maximum size restrictions, allowing arbitrarily large batches that could exhaust block gas limits or cause excessive resource consumption.
https://github.com/Cyfrin/2025-01-diva/blob/main/contracts/src/AaveDIVAWrapper.sol#L126
function batchAddLiquidity(AddLiquidityArgs[] calldata _addLiquidityArgs) external nonReentrant {
for (uint256 i = 0; i < _addLiquidityArgs.length; i++) {
_addLiquidity(
_addLiquidityArgs[i].poolId,
_addLiquidityArgs[i].collateralAmount,
_addLiquidityArgs[i].longRecipient,
_addLiquidityArgs[i].shortRecipient
);
}
}
function batchRedeemWToken(RedeemWTokenArgs[] calldata _redeemWTokenArgs) external nonReentrant {
for (uint256 i = 0; i < _redeemWTokenArgs.length; i++) {
_redeemWToken(...);
}
}
Impact
Gas limit exhaustion from oversized batches
Failed transactions due to out-of-gas
Recommended Fix
Add maximum batch size constants and checks:
contract AaveDIVAWrapperCore {
uint256 private constant MAX_BATCH_SIZE = 100;
error BatchTooLarge(uint256 size, uint256 maxSize);
function batchAddLiquidity(
AddLiquidityArgs[] calldata _addLiquidityArgs
) external nonReentrant {
if (_addLiquidityArgs.length > MAX_BATCH_SIZE) {
revert BatchTooLarge(
_addLiquidityArgs.length,
MAX_BATCH_SIZE
);
}
for (uint256 i = 0; i < _addLiquidityArgs.length; i++) {
_addLiquidity(...);
}
}
function batchRedeemWToken(...) external nonReentrant {
if (_redeemWTokenArgs.length > MAX_BATCH_SIZE) {
revert BatchTooLarge(
_redeemWTokenArgs.length,
MAX_BATCH_SIZE
);
}
}
}
The fix provides reasonable limits while maintaining batch functionality.