feat(security): audit cross-contract calls and implement reentrancy guard (closes #354) - #387
Open
shobhamerabacha-star wants to merge 2 commits into
Conversation
added 2 commits
September 12, 2026 00:22
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
Closes #354
Delivers a comprehensive cross-contract security audit and robust reentrancy protection architecture across the ChainLearn smart contract ecosystem (
learn-token,credential-nft, andprogress-tracker).Key Changes
docs/reentrancy-audit.md):invoke_contractcalls) inlearn-token(claim_reward,batch_claim_reward,preview_claim_reward) andcredential-nft(mint_credential).contracts/learn-token/src/storage.rs: AddedTokenDataKey::ReentrancyGuardin instance storage withis_reentrancy_lockedandset_reentrancy_locked.contracts/learn-token/src/lib.rs: IntroducedReentrancyGuardRAII struct enforcing zero reentrant entries acrossclaim_reward,batch_claim_reward,mint,transfer,transfer_from,burn,burn_from, andclaim_vested.contracts/credential-nft/src/metadata.rs&contracts/credential-nft/src/lib.rs: AddedCredentialDataKey::ReentrancyGuardand protectedmint_credentialduring external progress-tracker verification.tests/integration/security_reentrancy_tests.rs):test_reentrancy_during_claim_reward_blocked_by_guard: Adversarial progress tracker attempts recursiveclaim_rewardduring quiz score resolution; halted with panic, 0 tokens minted.test_cross_function_reentrancy_blocked_by_guard: Adversarial tracker attemptsmintduring score resolution; halted, total supply and balances remain uncorrupted.test_credential_nft_reentrancy_blocked_by_guard: Adversarial tracker attempts nestedmint_credentialduring eligibility verification; blocked, credential counter remains 0.test_reentrancy_prevented_state_consistent_and_no_funds_lost: Invariance verification under failed reentrancy attacks.test_reentrancy_during_transfer: Transfer level reentrancy prevention.cargo test -p learn-token: 78/78 tests passed.cargo test -p credential-nft: 37/37 tests passed.cargo test --test security_reentrancy_tests: 5/5 tests passed.Verification
cargo test -p learn-token: 78 passed, 0 failed.cargo test -p credential-nft: 37 passed, 0 failed.cargo test --test security_reentrancy_tests: 5 passed, 0 failed.