Skip to content

Harden TaskBounty escrow: safe transfers, refund event amount, fix build - #136

Merged
Abd-Standard merged 2 commits into
Core-Foundry:mainfrom
N-thnI:escrow-mechanism-for-bounty-rewards
Jul 30, 2026
Merged

Harden TaskBounty escrow: safe transfers, refund event amount, fix build#136
Abd-Standard merged 2 commits into
Core-Foundry:mainfrom
N-thnI:escrow-mechanism-for-bounty-rewards

Conversation

@N-thnI

@N-thnI N-thnI commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Closes #130

Summary

  • The escrow mechanism (lock reward on create_task, release on approve_submission, refund on cancel_task) already existed in Documents/Task Bounty/src/{task,submission}.rs, but the crate did not compile, so it had never actually been built or tested.
  • Fixed the build: Error needed #[contracterror] (not #[contracttype]) for panic_with_error! to work, storage keys used raw byte-string literals that current soroban-sdk no longer accepts as tuple keys (switched to symbol_short!, matching the existing pattern in events.rs), panic_with_error! needed an explicit import, and soroban-sdk was bumped from 21 → 23 (matching the sibling contract/ crate already in this repo) since 21's pinned soroban-env-host pulls an unbounded ed25519-dalek release that no longer builds against current crates.io.
  • Token transfers (lock/release/refund) now use try_transfer and surface the existing-but-previously-unused Error::PaymentFailed instead of panicking with an opaque host error on a failed payment.
  • The refund event now carries the refunded amount, so deposits, releases, and refunds are all auditable on-chain with amounts.
  • Added tests: refund-after-deadline-expiry, refund event includes the correct amount, and a completed (paid-out) task can no longer be cancelled for a refund.

Test plan

  • cargo test — 15/15 passing
  • cargo build — clean (warnings only, pre-existing/unrelated to this change)

N-thnI added 2 commits July 30, 2026 00:46
The escrow flow (lock on create_task, release on approve_submission,
refund on cancel_task) already existed but the crate could not compile
or run its test suite, so none of it had ever actually been verified:

- Error used #[contracttype] instead of #[contracterror], so
  panic_with_error! couldn't compile.
- Storage keys used raw byte-string literals (b"TASK", ...) as tuple
  keys, which current soroban-sdk no longer accepts; switched to
  symbol_short!, matching the pattern already used in events.rs.
- panic_with_error! needs an explicit import in current soroban-sdk.
- Bumped soroban-sdk 21 -> 23 (matching the sibling contract crate in
  this repo) since 21's pinned soroban-env-host pulls an unbounded
  ed25519-dalek release that no longer builds; updated the one test
  helper (mint) whose API moved to StellarAssetClient in the process.

On top of getting it building and green, hardened the escrow itself:

- Token transfers (escrow lock, release, refund) now use try_transfer
  and surface the existing-but-unused Error::PaymentFailed instead of
  panicking with an opaque host error on a failed payment.
- The refund event now carries the refunded amount, so deposits,
  releases, and refunds are all auditable on-chain with amounts.
- Added tests for refund-after-deadline, the refund event's amount,
  and that a completed task can no longer be cancelled/refunded out
  from under an already-paid contributor.

All 15 unit tests pass (cargo test).
Kept the escrow-safety additions from this branch (try_transfer +
PaymentFailed, refund event amount, new cancel/refund tests) on top
of upstream's newer task categories/tags/duplicate-detection work.

Also fixed three build/test bugs already present in upstream main
that this merge exposed (none introduced by this branch):
- storage.rs's has_duplicate_task/set_duplicate_task used String
  without importing it.
- test.rs called .address() on TokenClient's `address` field instead
  of accessing it directly, in 5 tests.
- create_task moved `description` into the Task struct before also
  borrowing it for the duplicate-task key.
- test_same_task_allowed_for_different_poster never funded the
  second poster before it tried to create a task, so it always
  failed on insufficient balance.
@Abd-Standard
Abd-Standard merged commit 713f504 into Core-Foundry:main Jul 30, 2026
2 checks passed
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.

Implement Escrow-Based Reward Distribution

2 participants