fix: prevent double-use in coordinator rollback, fix reputation compile error, wire fee netting - #1270
Merged
Merged
Conversation
…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
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
closes #1246:
rollback()in the coordinator contract could revert an already-Deliveredworkflow back toAvailableand refund its payment, letting the same physical blood unit be re-allocated to a different hospital while a copy was already delivered.rollback()now rejectsWorkflowStatus::Deliveredthe same way it already rejectsSettled.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. Implementedrequire_admin_auth, matching the existing admin-check pattern used bypause/unpause.closes #1243:
FeeStructure::calculate_net_amountwas dead code — never called from any production path, despitePayment.amountbeing documented as "net after fees." Wired it intocreate_paymentso the stored payment amount is actually netted against the fee structure.Test plan
cargo check -p reputation-contract --lib— compiles cleanly (previously failed with 4xE0599)cargo check --lib(top-levelcontractscrate) — compiles cleanlycargo test --lib test_payments::/test_protocol_invariants::(top-levelcontractscrate) — 39 + 10 tests pass unchangedcargo test -p coordinator-contract— addedtest_rollback_blocked_after_delivery, assertingrollback()now returnsInvalidWorkflowStateon aDeliveredworkflow and leaves workflow/unit/payment state untouched; replaces the previous test which asserted the vulnerable behavior and didn't compile (referenced a nonexistentWorkflowStatus::Lockedvariant)CoordinatorError::EmergencyHalt→EmergencyHalted) that was preventing the coordinator test suite from building at alllifebank-soroban/contracts/payments, missingPartialEqderives in top-levelcontractstests, stale test signatures in reputation/coordinator tests) — confirmed viagit stashcomparison to predate this change and left untouched as out of scope.🤖 Generated with Claude Code