Skip to content

fix(amm): eliminate duplicate unlock calls and pre-panic unlocks [SC-… - #1991

Open
thelmaoffiong wants to merge 1 commit into
StellarDevHub:mainfrom
thelmaoffiong:fix/SC-059-amm-reentrancy-guard-hardening
Open

thelmaoffiong wants to merge 1 commit into
StellarDevHub:mainfrom
thelmaoffiong:fix/SC-059-amm-reentrancy-guard-hardening

Conversation

@thelmaoffiong

@thelmaoffiong thelmaoffiong commented Nov 25, 2026 •

Copy link
Copy Markdown

Redundant Self::unlock(&env) calls appeared at the end of add_liquidity, remove_liquidity, swap_a_for_b, and swap_b_for_a — the result of copy-paste from an earlier pattern where unlock preceded the return statement, then a second was added before the event emission without removing the first.

Additionally, manual Self::unlock calls before panic_with_error! in every early-exit path were removed. In Soroban, panic_with_error! triggers a host trap that rolls back all storage changes for the current invocation, so temporary storage written by Self::lock is automatically discarded; a manual unlock before the panic is not only redundant but creates a window where the guard is absent while execution is still live.

Changes:

  • Remove duplicate trailing Self::unlock in add_liquidity, remove_liquidity, swap_a_for_b, and swap_b_for_a (each now has exactly one unlock at the single successful-exit point).
  • Remove Self::unlock calls that preceded every panic_with_error! in those four functions; the transaction rollback is the correct cleanup mechanism.
  • Add seven fuzz-style tests in test.rs verifying that the reentrancy mutex key (RG_KEY) is absent from temporary storage after every operation, whether the call succeeds or fails.

Closes #1856

…059]

Redundant Self::unlock(&env) calls appeared at the end of add_liquidity,
remove_liquidity, swap_a_for_b, and swap_b_for_a — the result of copy-paste
from an earlier pattern where unlock preceded the return statement, then a
second was added before the event emission without removing the first.

Additionally, manual Self::unlock calls before panic_with_error! in every
early-exit path were removed. In Soroban, panic_with_error! triggers a host
trap that rolls back all storage changes for the current invocation, so
temporary storage written by Self::lock is automatically discarded; a manual
unlock before the panic is not only redundant but creates a window where the
guard is absent while execution is still live.

Changes:
- Remove duplicate trailing Self::unlock in add_liquidity, remove_liquidity,
  swap_a_for_b, and swap_b_for_a (each now has exactly one unlock at the
  single successful-exit point).
- Remove Self::unlock calls that preceded every panic_with_error! in those
  four functions; the transaction rollback is the correct cleanup mechanism.
- Add seven fuzz-style tests in test.rs verifying that the reentrancy mutex
  key (RG_KEY) is absent from temporary storage after every operation,
  whether the call succeeds or fails.

Closes StellarDevHub#1856
@vercel

vercel Bot commented Nov 25, 2026

Copy link
Copy Markdown

@thelmaoffiong is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Nov 25, 2026

Copy link
Copy Markdown

@thelmaoffiong Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

[SC-059] AMM Reentrancy Guard Hardening: Elimination of Duplicate Unlocks

1 participant