Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: high
Invalid

Missing totalSwapRequests++ after successful swap processing.

Summary

The initiateSwap function in the StabilityBranch contract does not increment the totalSwapRequests counter after successfully processing a swap request. This omission leads will to incorrect tracking of swap requests, which can cause accounting discrepancies and misalignment between the system's state and the actual number of swap requests.

Vulnerability Details

/StabilityBranch.sol/initiateSwap

function initiateSwap(uint128[] calldata vaultIds, uint128[] calldata amountsIn, uint128[] calldata minAmountsOut) external {
// Perform length checks
if (vaultIds.length != amountsIn.length) {
revert Errors.ArrayLengthMismatch(vaultIds.length, amountsIn.length);
}
if (amountsIn.length != minAmountsOut.length) {
revert Errors.ArrayLengthMismatch(amountsIn.length, minAmountsOut.length);
}
// Missing increment of totalSwapRequests after successful swap initiation
// This causes the swap request counter to remain unchanged, violating the rule.
}

The bug manifests in the StabilityBranch contract, specifically in the initiateSwap function. The function processes swap requests but fails to update the totalSwapRequests counter, which is critical for maintaining an accurate record of swap activity.

Look at this scenario when:

  1. A user calls initiateSwap with valid parameters:

    • vaultIds = [1]

    • amountsIn = [100]

    • minAmountsOut = [50]

  2. The function performs length checks and validates the inputs.

  3. The swap request is processed successfully, but totalSwapRequests is not incremented.

Impact

  • Swap requests are not properly tracked, leading to potential undercounting.

  • This could affect fee distribution, settlement, and other processes that rely on accurate swap request tracking.

  • System keepers and users may lose trust in the protocol's ability to manage swap requests correctly.

Tools Used

vs

Recommendations

function initiateSwap(uint128[] calldata vaultIds, uint128[] calldata amountsIn, uint128[] calldata minAmountsOut) external {
// Perform length checks
if (vaultIds.length != amountsIn.length) {
revert Errors.ArrayLengthMismatch(vaultIds.length, amountsIn.length);
}
if (amountsIn.length != minAmountsOut.length) {
revert Errors.ArrayLengthMismatch(amountsIn.length, minAmountsOut.length);
}
// Increment totalSwapRequests to track swap requests correctly
totalSwapRequests++;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
4 months ago
inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.