Skip to content

refactor(privacy-channel): consolidate condition/operation validation into one validator#43

Open
AquiGorka wants to merge 1 commit into
mainfrom
refactor/consolidate-condition-validation
Open

refactor(privacy-channel): consolidate condition/operation validation into one validator#43
AquiGorka wants to merge 1 commit into
mainfrom
refactor/consolidate-condition-validation

Conversation

@AquiGorka

Copy link
Copy Markdown
Contributor

What

Consolidates the scattered condition/operation validation in pre_process_channel_operation into a single private validate_channel_operation in contracts/privacy-channel/src/transact.rs. Pure, behavior-preserving relocation per the RV audit informative (2026-07-07) — no predicate, error, or outcome-affecting order changed.

Checks folded (1:1, same order)

  1. A — no conflicting conditions across spend ∪ deposit ∪ withdrawBundleHasConflictingConditions
  2. B — each deposit amount strictly positive (InvalidExternalAmount) + running sum non-overflowing (AmountOverflow); returns total_deposit
  3. C — same for withdraw amounts; returns total_withdraw
  4. D — no duplicate deposit/withdraw addresses + cross-side condition-sequence equality (RepeatedAccountForDeposit / RepeatedAccountForWithdraw / ConflictingConditionsForAccount)
  5. E — owner-signed create/withdraw effects are executed (UnauthorizedOperation, MOON-01)

The validator returns (total_deposit, total_withdraw) (the totals it necessarily computes while validating amounts), so pre_process_channel_operation shrinks to one call plus the unchanged bundle build.

Behavior preservation

  • Order is intact. Amount/overflow (B/C) run before duplicate/cross-side (D), so an input that both overflows and repeats an address still reports AmountOverflow, not RepeatedAccountForDeposit. Conflict (A) still precedes everything; signed-effects (E) still last.
  • Primitive predicates (conflicts_with, condition_does_not_conflict_with_set, equal_condition_sequence, no_duplicate_addresses) stay in modules/primitives — called, not relocated.
  • Only cosmetic ref change in the moved code: &e/&ope/op (semantically identical).

Tests (equivalence backstop, inline in transact.rs)

Added accept/reject + ordering tests, prioritising the checks with no prior negative coverage (A conflict, B2/C2 overflow, D1/D2 dup-address, D3 cross-side sequence), plus two ordering guards that lock the error-precedence in place.

  • cargo test --workspace: green (privacy-channel 25 passed — 14 pre-existing unchanged + 11 new; all other crates green)
  • cargo fmt clean; cargo clippy on transact.rs down 18→15 warnings (zero new)
  • stellar contract build (CI gate): green

No version bump. Not merged.

Move the scattered condition/operation checks in pre_process_channel_operation
into a single private validate_channel_operation. Behavior-preserving: same
predicates, same error codes, same short-circuit order (conflict -> deposit
amount/overflow -> withdraw amount/overflow -> duplicate/cross-side addresses ->
signed-effects binding), and it returns the deposit/withdraw totals it computes.

The order is kept intact so the surfaced error on multi-violation inputs is
unchanged (e.g. overflow-and-duplicate-deposit still reports AmountOverflow, not
RepeatedAccountForDeposit). Primitive predicates stay in modules/primitives
(called, not relocated).

Add equivalence-backstop tests covering each check's accept/reject path and the
ordering guards; all pre-existing tests pass unchanged.

@fazzatti fazzatti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great split! This seems to keep the same logic but with a more clear separation of the steps and readability!

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.

2 participants