Skip to content

fix(referral): mitigate cross-contract reentrancy in distribute_rewards - #70

Merged
merlik787-droi merged 1 commit into
Riddlrealm:mainfrom
Spaully:fix/issue-16-reentrancy-protection
Jul 22, 2026
Merged

fix(referral): mitigate cross-contract reentrancy in distribute_rewards#70
merlik787-droi merged 1 commit into
Riddlrealm:mainfrom
Spaully:fix/issue-16-reentrancy-protection

Conversation

@Spaully

@Spaully Spaully commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Add reentrancy guard to prevent reentrant calls during token transfers in distribute_rewards.

Changes

  • Add ReentrancyGuard storage key
  • Add acquire_guard/release_guard helper functions
  • Guard is acquired before external token_client.transfer calls
  • Guard is released after all transfers complete
  • Panic with Reentrancy detected if guard is already held

distribute_rewards updates

  • Uses reentrancy guard around external calls
  • Uses event::emit module for consistent event emissions

Tests

  • test_reentrancy_guard_released_after_distribution: verifies guard is properly released

Closes #16

@Spaully
Spaully force-pushed the fix/issue-16-reentrancy-protection branch 3 times, most recently from 2c6b01b to aa1547f Compare July 22, 2026 10:35
Add reentrancy guard to prevent reentrant calls during token transfers:
- Add ReentrancyGuard storage key
- Add acquire_guard/release_guard helper functions
- Guard is acquired before external token_client.transfer calls
- Guard is released after all transfers complete
- Panic with 'Reentrancy detected' if guard is already held

Update distribute_rewards to:
- Use reentrancy guard around external calls
- Keep inline event emissions (event module is separate PR)

Add test to verify guard is properly released after distribution.

Implements Issue Riddlrealm#16
@Spaully
Spaully force-pushed the fix/issue-16-reentrancy-protection branch from aa1547f to e9b5a57 Compare July 22, 2026 10:41

@merlik787-droi merlik787-droi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@merlik787-droi
merlik787-droi merged commit eba962b into Riddlrealm:main Jul 22, 2026
3 checks passed
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.

Mitigate cross-contract reentrancy in referral::distribute_rewards

2 participants