Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdamSzymanski - Inconsistent Swap Execution Due to Ambiguous directional Logic #210

Open
sherlock-admin2 opened this issue Nov 13, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Nov 13, 2024

AdamSzymanski

Medium

Inconsistent Swap Execution Due to Ambiguous directional Logic

Summary

The reliance on secondary conditions like walletData.length instead of making directional the sole determinant will cause unintended swap flows for users as the swap() function executes both DeFi and stablecoin swaps when only one swap was expected.

Root Cause

The choice to rely on both directional and walletData.length to control the swap flow is a mistake as this creates ambiguity, resulting in inconsistent and unintended execution paths.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. SWAPPER_ROLE calls swap() with directional set to true and walletData.length non-zero.
  2. Both _defiSwap() and _stablecoinSwap() execute even when only one was expected, adjusting ss.oAmount based on incorrect balance differentials.
  3. The user receives an incorrect token amount due to unexpected swap sequencing.

Impact

Users experience incorrect token amounts or unexpected swap flows, causing an approximate loss due to mismatched token balances. The protocol risks users losing confidence in its consistency and reliability.

PoC

  1. Call swap() with directional set to true and walletData.length populated.
  2. Observe the execution of both _defiSwap() and _stablecoinSwap() and the resulting value of ss.oAmount.

Mitigation

  1. Enforce directional as the Sole Controller: Refactor swap() so directional fully dictates swap order, eliminating reliance on walletData.length.
  2. Separate Execution Paths: Distinguish clearly between DeFi-only, stablecoin-only, and combined swaps to avoid unintended dual executions.
@sherlock-admin3 sherlock-admin3 changed the title Handsome Cotton Wolverine - Inconsistent Swap Execution Due to Ambiguous directional Logic AdamSzymanski - Inconsistent Swap Execution Due to Ambiguous directional Logic Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant