Skip to content

feat(contracts): arbiter activation path for the dispute subsystem - #1934

Open
achiever2110 wants to merge 5 commits into
LabsCrypt:mainfrom
achiever2110:fix/arbiter-activation-path
Open

achiever2110 wants to merge 5 commits into
LabsCrypt:mainfrom
achiever2110:fix/arbiter-activation-path

Conversation

@achiever2110

Copy link
Copy Markdown
Contributor

The dispute/escrow subsystem existed, was tested, and could not be reached.

Closes #1897

The problem

Every stream constructor writes arbiter: None, and no entrypoint ever wrote
stream.arbiter. So request_dispute always failed with
DisputeNotSupported, resolve_dispute could never run, and the only way to
exercise the subsystem at all was for the tests to reach into storage and inject
the field — which the existing test does, with a comment saying it is standing in
for "the escrow deployment flow". There was no such flow.

The change

set_stream_arbiter(sender, stream_id, arbiter: Option<Address>):

  • Sender-authorized (require_auth plus an ownership check), because the
    arbiter is the party who decides a cancellation dispute.
  • Refused with the new ArbiterLocked once dispute_status != None. A sender
    who could swap the decider mid-dispute could simply pick someone who rules in
    their favour, so this fails loudly instead of being ignored.
  • Refuses the contract itself and the sender as arbiter — self-dealing, and a
    no-op respectively.
  • None detaches the arbiter, which makes the stream non-disputable again.
  • Emits stream_arbiter_set with the full record, so a later "the arbiter was
    always that address" is checkable against history.

ArbiterLocked is a new error code (49). The diagnostics round-trip test that
used 49 as its "unknown code" sentinel now uses 50.

On the yield half of the issue

The issue also mentions yield_enabled and the YieldStrategy trait. I did not
add a toggle for it: nothing in the contract reads yield_enabled and nothing
implements YieldStrategy, so such an entrypoint would set a flag that changes
no behaviour — exactly the kind of half-live surface the other issues in this
series are about. Dropping it from the public API is the honest option, and it is
already absent from it. When a strategy is implemented, the toggle should ship
with the code path that consumes it. Say the word and I will open a follow-up
that removes the dead trait and the storage field properly, with a migration.

Tests

cargo test -p stream_contract — 278 passed, 1 ignored (was 275 + 1).

New:

  • request_dispute fails before an arbiter is set and succeeds after — through
    the public API only, no storage injection
  • only the sender may set the arbiter; the sender and the contract are rejected
    as arbiter
  • setting is refused with ArbiterLocked once a dispute is open

bash scripts/lint-rust.sh passes (pre-commit hook).

Every stream constructor wrote arbiter: None and nothing ever changed it, so
request_dispute always failed with DisputeNotSupported: the escrow/dispute
subsystem was unreachable from the public API, and its tests injected the field
into storage to exercise it at all (LabsCrypt#1897).

set_stream_arbiter lets the sender name (or replace, or detach) the arbiter on an
active stream. Swapping the decider once a dispute is open would let the sender
choose the verdict, so that is refused with a new ArbiterLocked error rather
than ignored. The contract itself and the sender cannot be the arbiter, for the
same reason. The change emits stream_arbiter_set, so 'the arbiter was always
that address' is auditable.

Three tests: the dispute path becomes reachable through the public API alone
(request_dispute succeeds only after an arbiter is set), only the sender may set
it, and it locks once a dispute is open.
…rbiter-activation-path

# Conflicts:
#	contracts/stream_contract/src/test.rs
The merge appended the arbiter tests after a trailing newline; rustfmt flags
the extra blank line at EOF and the Soroban Contracts CI job fails on it.
ArbiterLocked now occupies discriminant 50, so asserting try_from(50) is
unknown contradicted the variant added by this PR and failed the contracts
test suite.

This branch has not been deployed

No deployments
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.

[Contracts] Provide an arbiter activation path for the dispute/escrow subsystem

1 participant