Summary
The claimAndSwap
function in the StrategyMainnet
contract does not validate the _routeNumber
parameter, allowing potential out-of-bounds access to route mappings. This could result in transaction reverts, operational disruption, or unintended fund handling. Mitigations include strict validation of route indices and fallback mechanisms to prevent contract reversion.
Technical Details
The function directly uses the _routeNumber
parameter to access routes
, swapParams
, and pools
mappings without ensuring the parameter is within the valid range of existing routes. This lack of validation opens the function to edge cases where invalid indices could disrupt operations or lead to unexpected behaviors.
Direct Access Risk: The routes[_routeNumber]
, swapParams[_routeNumber]
, and pools[_routeNumber]
mappings rely on _routeNumber
for indexing. If _routeNumber
exceeds nRoutes
, the contract may revert or access unintended storage.
Lack of Graceful Handling: Out-of-bounds access does not have fallback mechanisms, making the system brittle to invalid inputs.
Attack Scenarios
Setup: An attacker calls claimAndSwap
with _routeNumber
greater than the number of defined routes (nRoutes
).
Execution: The function attempts to access non-existent indices in routes
, causing a revert.
Impact: Repeated invalid calls lead to transaction failures, disrupting the protocol's functionality and creating user frustration.
Setup: Due to edge cases or unforeseen storage layouts, an invalid _routeNumber
may unintentionally access unrelated storage slots.
Execution: The contract operates on invalid data or unintentionally overwrites storage.
Impact: This could result in unpredictable behavior, leading to incorrect fund swaps or state corruption.
Financial Impact: Potential for mismanaged funds due to invalid route handling.
Operational Impact: Disruption of normal operations caused by transaction reverts or invalid swaps.
Reputational Impact: Poor handling of basic parameter validation undermines trust in the protocol’s robustness.
Mitigation Recommendations
Add checks to ensure _routeNumber
is within the bounds of defined routes (nRoutes
):
Implement a fallback mechanism to handle invalid _routeNumber
gracefully:
Proof of Concept (PoC)
Deploy the StrategyMainnet
contract with predefined routes (nRoutes = 3
).
Call claimAndSwap
with _routeNumber = 5
.
Observe a transaction revert due to out-of-bounds mapping access.
Add the recommended require
validation to the function.
Repeat the invalid call with _routeNumber = 5
.
Observe that the function now gracefully handles the error by reverting with a meaningful message.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.