Background / Context
contracts/escrow/src/lib.rs::fund() uses issue_id (a u64 chosen off-chain by mergefi-backend/the sponsor's wallet) as the sole key into persistent storage (DataKey::Escrow(issue_id)), and rejects a second fund call on the same id with AlreadyFunded. Critically, fund performs no admin check and no validation that the caller is the "intended" sponsor for that issue — any address can call fund(issue_id, sponsor=attacker, token=<attacker-chosen>, amount=1, deadline=<attacker-chosen>) for any issue_id, as long as they supply a valid require_auth signature for themselves as sponsor.
Problem Statement
Because Stellar issue ids are presumably predictable (sequential GitHub issue numbers, or a deterministic hash the backend computes ahead of time), an attacker who front-runs the real sponsor's fund transaction — or simply calls fund proactively for issue ids they anticipate being funded — permanently claims that issue_id slot with a trivial deposit (amount=1) of a token of their choosing. The legitimate sponsor's later fund call then reverts with AlreadyFunded, and there is no top-up or re-fund-different-id path described in the README. This is a low-cost, high-impact griefing vector against a system whose entire value proposition is "sponsors fund GitHub issues."
Requirements
- Analyze the full griefing surface: is
issue_id predictable/guessable before the real fund call lands? Model the mempool/submission-ordering assumptions on Stellar/Soroban (there is no public mempool in the traditional sense, but front-running via fee/priority is still analyzed differently — investigate Soroban's actual transaction ordering guarantees).
- Propose and implement a mitigation: options include (a) binding
fund to a specific expected sponsor address set at issue-creation time by the admin/oracle, (b) a commit-reveal or admin-pre-registration step before fund is callable, (c) an admin-callable reassign/force_refund_and_reopen recovery path for squatted ids, or another design you can justify as superior.
- Add regression tests in
contracts/escrow/src/test.rs that reproduce the griefing scenario and prove the fix closes it (attacker funds first, legitimate sponsor's transaction should still succeed, or attacker's low-value funding should be recoverable without requiring off-chain intervention).
- Document the chosen trust model change in the README's escrow section.
Acceptance Criteria
Technical Notes / Hints
- Relevant code:
contracts/escrow/src/lib.rs lines ~54-88 (fund), types.rs DataKey::Escrow(u64).
- Consider whether the fix should also apply symmetrically to
create_milestone (contracts/milestones/src/lib.rs) and deposit's implicit pool-creation-on-first-deposit (contracts/maintenance-pool/src/lib.rs) — file separate issues if the fix diverges per contract, but note the shared pattern here.
Difficulty Justification
This requires understanding Soroban/Stellar's actual transaction-ordering and mempool semantics (not assumed from EVM intuition), reasoning about an economic griefing attack with no simple "add a require" fix, and designing a new access-control primitive that doesn't break the permissionless, oracle-driven trust model the rest of the contract relies on. Getting the fix wrong (e.g., adding an admin-only fund) would break the sponsor-initiated funding flow the whole product depends on.
Background / Context
contracts/escrow/src/lib.rs::fund()usesissue_id(au64chosen off-chain bymergefi-backend/the sponsor's wallet) as the sole key into persistent storage (DataKey::Escrow(issue_id)), and rejects a secondfundcall on the same id withAlreadyFunded. Critically,fundperforms no admin check and no validation that the caller is the "intended" sponsor for that issue — any address can callfund(issue_id, sponsor=attacker, token=<attacker-chosen>, amount=1, deadline=<attacker-chosen>)for anyissue_id, as long as they supply a validrequire_authsignature for themselves assponsor.Problem Statement
Because Stellar issue ids are presumably predictable (sequential GitHub issue numbers, or a deterministic hash the backend computes ahead of time), an attacker who front-runs the real sponsor's
fundtransaction — or simply callsfundproactively for issue ids they anticipate being funded — permanently claims thatissue_idslot with a trivial deposit (amount=1) of a token of their choosing. The legitimate sponsor's laterfundcall then reverts withAlreadyFunded, and there is notop-uporre-fund-different-idpath described in the README. This is a low-cost, high-impact griefing vector against a system whose entire value proposition is "sponsors fund GitHub issues."Requirements
issue_idpredictable/guessable before the realfundcall lands? Model the mempool/submission-ordering assumptions on Stellar/Soroban (there is no public mempool in the traditional sense, but front-running via fee/priority is still analyzed differently — investigate Soroban's actual transaction ordering guarantees).fundto a specific expected sponsor address set at issue-creation time by the admin/oracle, (b) a commit-reveal or admin-pre-registration step beforefundis callable, (c) an admin-callablereassign/force_refund_and_reopenrecovery path for squatted ids, or another design you can justify as superior.contracts/escrow/src/test.rsthat reproduce the griefing scenario and prove the fix closes it (attacker funds first, legitimate sponsor's transaction should still succeed, or attacker's low-value funding should be recoverable without requiring off-chain intervention).Acceptance Criteria
issue_idsquatting is exploitable given Soroban's actual ordering model (not just Ethereum-style mempool assumptions)contracts/escrow/src/lib.rscargo test --workspacegreen,make buildstill produces valid wasmfundTechnical Notes / Hints
contracts/escrow/src/lib.rslines ~54-88 (fund),types.rsDataKey::Escrow(u64).create_milestone(contracts/milestones/src/lib.rs) anddeposit's implicit pool-creation-on-first-deposit (contracts/maintenance-pool/src/lib.rs) — file separate issues if the fix diverges per contract, but note the shared pattern here.Difficulty Justification
This requires understanding Soroban/Stellar's actual transaction-ordering and mempool semantics (not assumed from EVM intuition), reasoning about an economic griefing attack with no simple "add a require" fix, and designing a new access-control primitive that doesn't break the permissionless, oracle-driven trust model the rest of the contract relies on. Getting the fix wrong (e.g., adding an admin-only
fund) would break the sponsor-initiated funding flow the whole product depends on.