Skip to content

Fix Test/reentrancy guard v2 - #61

Closed
Idrhas wants to merge 6 commits into
ShadeProtocol:mainfrom
Idrhas:test/reentrancy-guard-v2
Closed

Idrhas wants to merge 6 commits into
ShadeProtocol:mainfrom
Idrhas:test/reentrancy-guard-v2

Conversation

@Idrhas

@Idrhas Idrhas commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR addresses and fixes a critical issue with the reentrancy guard implementation and extends its protection to all applicable state-changing functions across the contract.

closes #11

Changes Made

  • Fixed Lock Persistence Bug: Switched the storage type in reentrancy.rs from persistent() to instance(). This ensures that if a guarded function panics, the lock is automatically cleared at the end of the transaction rather than permanently bricking the contract functions.
  • Expanded Guard Coverage: Added reentrancy::enter(env) and reentrancy::exit(env) to the following unprotected state-changing functions:
    • register_merchant (merchant.rs)
    • create_invoice (invoice.rs)
    • pause and unpause (pausable.rs)
    • grant_role and revoke_role (access_control.rs)
  • Comprehensive Testing: Added a dedicated test suite (test_reentrancy.rs) to verify that the low-level locking works properly and that attempting re-entrant calls into guarded functions correctly results in an Error(Contract, #4) panic.

Testing

  • All 33 unit tests pass successfully in the wasm32-unknown-unknown environment, including the newly added mock reentrancy scenarios.

@Idrhas Idrhas closed this Feb 25, 2026
@Idrhas
Idrhas deleted the test/reentrancy-guard-v2 branch February 25, 2026 14:41
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.

Create Comprehensive Tests for Reentrancy Guard

2 participants