Skip to content

feat(security): add reentrancy guard and enforce CEI around token transfers (#37) - #65

Closed
huangji6693-max wants to merge 1 commit into
trustflow-protocol:mainfrom
huangji6693-max:feat/reentrancy-safe-token-transfer-guard-37
Closed

huangji6693-max wants to merge 1 commit into
trustflow-protocol:mainfrom
huangji6693-max:feat/reentrancy-safe-token-transfer-guard-37

Conversation

@huangji6693-max

Copy link
Copy Markdown

Summary

Implements a re-entrancy guard (DataKey::ReentrancyGuard, TrustFlowError::ReentrancyDetected, with_reentrancy_guard) and enforces strict Checks-Effects-Interactions (CEI) ordering around all cross-contract token transfers in trustflow.

Changes

  • contracts/trustflow/src/lib.rs:
    • Added DataKey::ReentrancyGuard, TrustFlowError::ReentrancyDetected = 24, and enter_reentrancy_guard / exit_reentrancy_guard / with_reentrancy_guard.
    • Enforced Checks-Effects-Interactions ordering and wrapped token client calls in with_reentrancy_guard across stake, unstake, create_escrow, init_escrow, release_milestone_tranche, and resolve_dispute so all storage accounting (JurorStake, EscrowRecord, EscrowStatus::Settled, EscrowReleased) is committed before external token::Client transfers execute.
    • Added unit test test_reentrancy_guard_blocks_malicious_token_callback verifying both direct guard re-entry rejection (Err(TrustFlowError::ReentrancyDetected)) and protection against a malicious token contract attempting to re-enter release_milestone_tranche during transfer.
  • contracts/src/{settlement,errors,storage}.rs:
    • Updated release_to_beneficiary to persist EscrowStatus::Released before token_client.transfer under DataKey::ReentrancyGuard.

Verification

  • cargo test --package trustflow (65 passed; 0 failed)

Closes #37
/claim #37


Payout Wallets

  • EVM / Base (USDC): 0x380C97bcbcAEf29DAc2d0ba7E180F1b4A7F38fdd
  • Stellar (XLM / USDC): GBYWLISGOUWQ43VQEGXX6KRGDZ3CKAFFK3JXVLXKDO5TIFJUJ3OHJYOZ
  • Solana (USDC / SOL): AyXYaA9Nf4z5fpLKY6DmubWe6D2qveMd79w8pEDNHcDw

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.

Reentrancy-Safe Cross-Contract Token Transfer Guard

2 participants