feat(security): Cross-Contract Call Reentrancy Lock using Host Invocation Key (#073) - #106
Open
Ranjeet2063 wants to merge 1 commit into
Open
Ranjeet2063 wants to merge 1 commit into
Ranjeet2063 wants to merge 1 commit into
Conversation
…tion Key (LatterFixxx#73) - Implemented Host Invocation Key validation guard in src/reentrancy_guard.rs - Enforced strict call stack depth limits with configurable ceiling - Reordered state transitions and external transfers to enforce Checks-Effects-Interactions (CEI) - Secured complete_task, cancel_task, and resolve_dispute entry points - Added events emit_reentrancy_lock_acquired, emit_reentrancy_lock_released, emit_max_call_depth_updated - Added comprehensive 10-test security suite simulating malicious callback contracts in src/reentrancy_test.rs - Verified clean compilation under wasm32-unknown-unknown and 165+ tests passing Closes LatterFixxx#73
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
feat(security): Cross-Contract Call Reentrancy Lock using Host Invocation Key (#73)
Closes #73
Summary
Adds an advanced, multi-tiered Cross-Contract Call Reentrancy Guard to secure external token transfer entry points across task settlements, refunds, and dispute distributions. The protection combines:
TaskStatus::Verified,TaskStatus::Cancelled,TaskStatus::Resolved, escrow release) commit before external token transfers dispatch.Threat Model & Attack Surface
During external token transfers (
token_client.transfer), control temporarily exitsTaskManagerContractto the external token contract or recipient address. If the target contract or recipient implements a malicious callback handler, an attacker can attempt recursive entry into task settlement functions (complete_task,cancel_task,resolve_dispute) before state changes take effect, draining escrow funds or claiming duplicate payouts.Defense-in-Depth Architecture
Acceptance Criteria
src/reentrancy_guard.rs(HostInvocationKey,non_reentrant_enter,non_reentrant_exit)src/lib.rs(complete_task,cancel_task,resolve_dispute)reentrancy_guard::get_call_depth,set_max_call_depth,get_max_call_depthsrc/reentrancy_test.rs(MaliciousCallbackTokensimulating reentrant complete & cancel attacks)cargo test --lib&cargo build --target wasm32-unknown-unknown --release(201 KB WASM)Key Changes
src/reentrancy_guard.rs: New core module containingReentrancyStatus,HostInvocationKey,ReentrancyKey, guard functions, call depth trackers, and admin configurator.src/events.rs: Added event emittersemit_reentrancy_lock_acquired,emit_reentrancy_lock_released, andemit_max_call_depth_updated.src/lib.rs:reentrancy_guardandreentrancy_test.complete_task,cancel_task, andresolve_disputewithnon_reentrant_enter/non_reentrant_exit.get_reentrancy_status,get_call_depth,get_max_call_depth,get_invocation_key, andset_max_call_depth.src/reentrancy_test.rs: Comprehensive 10-test security suite testing cross-contract callback intercepts, stack depth limit violations, authorization checks, and state invariant proofs.