feat: lock pool during buy_ticket transfer using reentrancy module#266
Merged
Akshola00 merged 2 commits intoWeb3Novalabs:mainfrom Mar 30, 2026
Merged
Conversation
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
|
@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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inrefund.Changes
crowdfunding.rs: addedreentrancy_lock_logic(&env, pool_id)?before the fee split / token transfer inbuy_ticket, andrelease_pool_lock(&env, pool_id)after all state writes completetest/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 assertsUnauthorizedis returned; then clears the lock and asserts the next call succeedstest_buy_ticket_lock_released_after_success— callsbuy_tickettwice in sequence to prove the lock is released after each successful calltest/mod.rs: registered the new test moduleSecurity
The lock prevents a re-entrant call from entering
buy_ticketon the same pool while a transfer is in flight. All state writes happen beforerelease_pool_lock, so a re-entrant attacker would find the lock set and be rejected withUnauthorized.closes #215