Skip to content

fix: prevent double-use in coordinator rollback, fix reputation compile error, wire fee netting - #1270

Merged
Emeka000 merged 1 commit into
Emeka000:mainfrom
vitalis200:rollback
Jul 29, 2026
Merged

fix: prevent double-use in coordinator rollback, fix reputation compile error, wire fee netting #1270
Emeka000 merged 1 commit into
Emeka000:mainfrom
vitalis200:rollback

Conversation

@vitalis200

Copy link
Copy Markdown
Contributor

Summary

closes #1246: rollback() in the coordinator contract could revert an already-Delivered workflow back to Available and refund its payment, letting the same physical blood unit be re-allocated to a different hospital while a copy was already delivered. rollback() now rejects WorkflowStatus::Delivered the same way it already rejects Settled.
closes #1245: the reputation contract called Self::require_admin_auth(...) in four places (submit_rating, record_assignment, flag_fraud, update_from_event) but never defined it, so the crate failed to compile. Implemented require_admin_auth, matching the existing admin-check pattern used by pause/unpause.
closes #1243: FeeStructure::calculate_net_amount was dead code — never called from any production path, despite Payment.amount being documented as "net after fees." Wired it into create_payment so the stored payment amount is actually netted against the fee structure.

Test plan

  • cargo check -p reputation-contract --lib — compiles cleanly (previously failed with 4x E0599)
  • cargo check --lib (top-level contracts crate) — compiles cleanly
  • cargo test --lib test_payments:: / test_protocol_invariants:: (top-level contracts crate) — 39 + 10 tests pass unchanged
  • cargo test -p coordinator-contract — added test_rollback_blocked_after_delivery, asserting rollback() now returns InvalidWorkflowState on a Delivered workflow and leaves workflow/unit/payment state untouched; replaces the previous test which asserted the vulnerable behavior and didn't compile (referenced a nonexistent WorkflowStatus::Locked variant)
  • Fixed one unrelated compile-blocking typo in coordinator tests (CoordinatorError::EmergencyHaltEmergencyHalted) that was preventing the coordinator test suite from building at all
  • Note: several other pre-existing, unrelated compile issues remain in the repo (duplicate enum discriminant in lifebank-soroban/contracts/payments, missing PartialEq derives in top-level contracts tests, stale test signatures in reputation/coordinator tests) — confirmed via git stash comparison to predate this change and left untouched as out of scope.

🤖 Generated with Claude Code

…le error, wire fee netting

- Fix Emeka000#1246: rollback() in the coordinator contract could revert an
  already-Delivered workflow back to Available and refund its payment,
  letting the same physical blood unit be re-allocated to a different
  hospital while a copy was already delivered. rollback() now rejects
  WorkflowStatus::Delivered the same way it already rejects Settled.

- Fix Emeka000#1245: the reputation contract called Self::require_admin_auth(...)
  in four places (submit_rating, record_assignment, flag_fraud,
  update_from_event) but never defined it, so the crate failed to
  compile. Implemented require_admin_auth, matching the existing
  admin-check pattern used by pause/unpause.

- Fix Emeka000#1243: FeeStructure::calculate_net_amount was dead code, never
  called from any production path, despite Payment.amount being
  documented as "net after fees". Wired it into create_payment so the
  stored payment amount is actually netted against the fee structure.

Test plan:
- cargo check -p reputation-contract --lib compiles cleanly (previously
  failed with 4x E0599)
- cargo check --lib (top-level contracts crate) compiles cleanly
- cargo test --lib test_payments:: / test_protocol_invariants:: passes
  (39 + 10 tests, unchanged)
- cargo test -p coordinator-contract passes; added
  test_rollback_blocked_after_delivery asserting rollback() now returns
  InvalidWorkflowState on a Delivered workflow and leaves
  workflow/unit/payment state untouched
- Fixed one unrelated compile-blocking typo in coordinator tests
  (CoordinatorError::EmergencyHalt -> EmergencyHalted) that was
  preventing the coordinator test suite from building at all
@Emeka000
Emeka000 merged commit d60c3f5 into Emeka000:main Jul 29, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment