Skip to content

feat: lock pool during buy_ticket transfer using reentrancy module#266

Merged
Akshola00 merged 2 commits intoWeb3Novalabs:mainfrom
sonoflawal:feat/buy-ticket-reentrancy-lock
Mar 30, 2026
Merged

feat: lock pool during buy_ticket transfer using reentrancy module#266
Akshola00 merged 2 commits intoWeb3Novalabs:mainfrom
sonoflawal:feat/buy-ticket-reentrancy-lock

Conversation

@sonoflawal
Copy link
Copy Markdown
Contributor

@sonoflawal sonoflawal commented Mar 28, 2026

Summary

Uses the existing reentrancy module to acquire the per-pool lock before the token transfer in buy_ticket, following the same CEI (Checks-Effects-Interactions) pattern already used in refund.

Changes

  • crowdfunding.rs: added reentrancy_lock_logic(&env, pool_id)? before the fee split / token transfer in buy_ticket, and release_pool_lock(&env, pool_id) after all state writes complete
  • test/buy_ticket_reentrancy_test.rs: two security tests:
    • test_buy_ticket_reentrancy_lock_engaged_and_released — manually sets the lock to simulate a concurrent call and asserts Unauthorized is returned; then clears the lock and asserts the next call succeeds
    • test_buy_ticket_lock_released_after_success — calls buy_ticket twice in sequence to prove the lock is released after each successful call
  • test/mod.rs: registered the new test module

Security

The lock prevents a re-entrant call from entering buy_ticket on the same pool while a transfer is in flight. All state writes happen before release_pool_lock, so a re-entrant attacker would find the lock set and be rejected with Unauthorized.

closes #215

Use the existing reentrancy module to acquire the per-pool lock before
the token transfer in buy_ticket and release it unconditionally after
all state writes, following the same CEI pattern used in refund.

- crowdfunding.rs: call reentrancy_lock_logic/release_pool_lock in buy_ticket
- test/buy_ticket_reentrancy_test.rs: security tests verifying the lock is
  engaged during transfer and released cleanly after each call
- test/mod.rs: register the new test module
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@sonoflawal 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

@Akshola00 Akshola00 merged commit 074b62c into Web3Novalabs:main Mar 30, 2026
1 check failed
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.

Add reentrancy guard to withdraw_event_funds

2 participants