fix(globe-wallet): implement reentrancy-safe wiring to token-wrapper with token allowlist and CEI ordering (#92) - #104
Closed
s6pa1rta3n-lab wants to merge 1 commit into
Closed
Conversation
…with token allowlist and CEI ordering - Add admin-curated token allowlist via `set_token_allowed` and `is_token_allowed` (with `TokenNotAllowed = 1034`) to reject untrusted token contract addresses. - Add `GlobeWallet::send` entrypoint wiring `globe-wallet` to `token-wrapper::transfer_from` with strict Checks-Effects-Interactions (CEI) ordering. - Commit spend bookkeeping to persistent storage before calling external contract code. - Add unit tests verifying token allowlist admin enforcement, wired transfer settlement, daily limit enforcement, and rollback on malicious re-entrant token callbacks. - Update architecture design and reentrancy documentation with threat model analysis and platform invariants. Closes Orbit-Wal#92
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
Resolves #92.
This PR implements a reentrancy-safe on-chain wiring between
globe-walletandtoken-wrappervia a new entrypointGlobeWallet::send, fulfilling the architectural design outlined indocs/design/architecture.mdand addressing the threat model of arbitrary/malicious token contracts.Definition of Done Checklist
token_idcould do if allowed to reach the wiring, and why the chosen mitigation closes it.set_token_allowed/is_token_allowed/TokenNotAllowed) and a CEI-ordering guarantee across the wired call implemented as part of the wiring work.transfer, proving the wiring is not exploitable (test_send_malicious_reentrant_token_rejected_and_rolled_back).record_spend's existing single-function reentrancy invariant/tests.cargo test --workspaceoutput pasted below.Threat Model & Mitigations
Threat Model
When invoking a caller-supplied
token_id, the contract code executed on-chain is untrusted. A custom or malicious token contract could:transferexecution, the token contract could attempt to call back intoGlobeWallet::send,GlobeWallet::record_spend,GlobeWallet::set_spend_limit, or guardian management functions before the initial invocation unwinds.DailySpentstate and could drain funds beyond the configured daily limit.Chosen Mitigations
set_token_allowed,is_token_allowed,TokenNotAllowed = 1034):GlobeWallet::sendrejects anytoken_idnot explicitly approved by the admin withWalletError::TokenNotAllowedduring the pre-checks phase, before invokingtoken-wrapperor external code.GlobeWallet::sendexecutes in strict CEI order:require_auth), verifies amount > 0, validatestoken_idallowlist membership, checks spend limit against current ledger day bucket.DailySpentin persistent storage, extends TTL, and publishesspend_recordedbefore making any external contract invocation.TokenWrapperClient::transfer_fromwithglobe-wallet's contract address as the authorized spender.DailySpentrecord and cannot bypass the daily cap.ContractReentryMode::Prohibitedfor normal contract calls, causing any attempted re-entry into active call frames to immediately trap withError(Context, InvalidAction).Test Output (
cargo test --workspace)Payout Routing
0xF46C9F6d70C50BF81ef3588AB523a90a594a2F89GCL6OXAMLD75BMTINA6EMRUDWK5THQUSHMYNLSNBCJAPZJHNYJTUNIBC