Cheerful Taffy Dolphin - Array Length Mismatch in Vault's _manage() Function Could Lead to Fund Loss via Invalid Position Management #49
Labels
Sponsor Disputed
The sponsor disputed this issue's validity
Cheerful Taffy Dolphin
Medium
Array Length Mismatch in Vault's _manage() Function Could Lead to Fund Loss via Invalid Position Management
Summary
A critical vulnerability has been identified in the _manage function's memory handling. This function serves as the core mechanism for managing market positions and collateral allocation across registered markets. The vulnerability stems from unsafe array access patterns between the context's registrations and strategy-generated targets, potentially compromising the vault's financial operations and position management.
The vulnerability centers on array length management between
context.registrations
and thetargets
array returned by the virtual_strategy
function. In the current implementation:https://github.com/sherlock-audit/2025-01-perennial-v2-4-update/blob/main/perennial-v2/packages/vault/contracts/Vault.sol#L434
The core issue lies in the array access pattern where the loop iterates using
context.registrations.length
but accessestargets[marketId]
without any length verification. Since_strategy
is a virtual function, its implementation could return an array of any length, creating a critical mismatch.Impact
When
targets.length < context.registrations.length
, this leads to out-of-bounds access and potential contract reversion. Conversely, iftargets.length > context.registrations.length
, some target positions remain unprocessed, leading to incomplete strategy execution.The financial implications are severe – mismatched array lengths can result in incorrect position management, unbalanced collateral distribution, and potential fund loss through improper allocations. The system's risk management capabilities are compromised as market exposure becomes misaligned with intended strategy.
Fix
Implement strict length validation:
Alternatively, a more flexible approach using dynamic length handling:
The text was updated successfully, but these errors were encountered: