refactor(privacy-channel): consolidate condition/operation validation into one validator#43
Open
AquiGorka wants to merge 1 commit into
Open
refactor(privacy-channel): consolidate condition/operation validation into one validator#43AquiGorka wants to merge 1 commit into
AquiGorka wants to merge 1 commit into
Conversation
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
approved these changes
Jul 9, 2026
fazzatti
left a comment
Contributor
There was a problem hiding this comment.
Great split! This seems to keep the same logic but with a more clear separation of the steps and readability!
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.
What
Consolidates the scattered condition/operation validation in
pre_process_channel_operationinto a single privatevalidate_channel_operationincontracts/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)
spend ∪ deposit ∪ withdraw→BundleHasConflictingConditionsInvalidExternalAmount) + running sum non-overflowing (AmountOverflow); returnstotal_deposittotal_withdrawRepeatedAccountForDeposit/RepeatedAccountForWithdraw/ConflictingConditionsForAccount)UnauthorizedOperation, MOON-01)The validator returns
(total_deposit, total_withdraw)(the totals it necessarily computes while validating amounts), sopre_process_channel_operationshrinks to one call plus the unchanged bundle build.Behavior preservation
AmountOverflow, notRepeatedAccountForDeposit. Conflict (A) still precedes everything; signed-effects (E) still last.conflicts_with,condition_does_not_conflict_with_set,equal_condition_sequence,no_duplicate_addresses) stay inmodules/primitives— called, not relocated.&e/&op→e/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 fmtclean;cargo clippyontransact.rsdown 18→15 warnings (zero new)stellar contract build(CI gate): greenNo version bump. Not merged.