Repository navigation
fix(tempo): align push payment verification with the charge spec (mppx#1372, mppx#1374) - #774
Conversation
…x#1372, mppx#1374)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
✅ Changelog found on PR. |
There was a problem hiding this comment.
Beyond the inline findings, I checked whether the slice == in ChallengeBinding::is_bound (memo.rs) breaks the AGENTS.md rule that HMACs and Challenge IDs must be compared in constant time. It doesn't. The bytes it compares are public fingerprints read from the on-chain memo, not an HMAC. verify_server and verify_challenge_binding in src/tempo/attribution.rs already compare these bytes the same way.
Extended reasoning...
Beyond the inline findings, I examined the slice equality in ChallengeBinding::is_bound. It matches the existing comparisons in src/tempo/attribution.rs, and the values it compares are public memo fingerprints rather than HMACs.
Findings marked 🟡 are optional suggestions and need no follow-up push.
| let is_fallback = !primary && expected.memo.is_none() && !bound; | ||
| if is_fallback && fallback.is_some() { | ||
| continue; | ||
| } | ||
| // Last, so that `validate_sender` only sees transfers that | ||
| // could be used. | ||
| if !transfer.from.is_some_and(|from| policy.allows(from)) { | ||
| continue; | ||
| } | ||
| if is_fallback { | ||
| fallback = Some(index); | ||
| continue; | ||
| } | ||
| found = Some(index); | ||
| break; |
There was a problem hiding this comment.
Low: Push receipt matcher asks validate_sender about a split transfer it discards
For a split without a memo, match_bound_transfers checks the sender of a plain transfer before it reaches a later transfer carrying this Challenge's attribution memo. The bound transfer is used, yet the with_validate_sender callback has been asked about a transfer the payment never counts. The base matcher searched memo transfers first and made no such call.
Valid? React with 👍 / 👎.
| let pays_other_challenge = effects.iter().any(|effect| { | ||
| effect.token == currency | ||
| && effect | ||
| .memo | ||
| .is_some_and(|memo| attribution::is_mpp_memo(&memo) && !binding.is_bound(&memo)) | ||
| }); | ||
| if unbound_match && pays_other_challenge { | ||
| return Err(replayed(challenge_bound_memo_error())); |
There was a problem hiding this comment.
Low (trigger unconfirmed): Zero-value foreign-tagged transfer makes hash verification reject a paid split charge
match_push_receipt_transfers treats any same-currency transfer effect carrying another Challenge's attribution memo as a competing payment, without checking its amount. A zero-value tagged transfer in the payer's transaction therefore makes a fully paid charge with a plain split fail as a replayed Credential. The base accepted the same receipt.
Valid? React with 👍 / 👎.
| if !memo_matches { | ||
| unbound |= primary || expected.memo.is_none(); | ||
| continue; | ||
| } | ||
| // A Zone portal's payout settles a Zone withdrawal, which pays | ||
| // only through its `zone` Credential. | ||
| if transfer.from.is_some_and(zone::is_portal_address) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Low: Tempo push matcher reports sender-ineligible transfers as replayed Credentials
match_bound_transfers flags a memo mismatch before checking that the transfer could count for the Credential payer. A hash Credential whose only fitting transfer came from an unauthorized sender, with no bound memo, now fails as CredentialReplayed instead of the missing-transfer verification failure the base returned.
Valid? React with 👍 / 👎.
| let plain_request = push_request(serde_json::json!({})); | ||
| let challenge = push_challenge("challenge-memo", &memo_request); | ||
| let bound = push_receipt(&[(push_merchant(), 1000, Some(memo_for(&challenge.id)))]); | ||
|
|
||
| // Read from the request being verified and from the signed Challenge. | ||
| for (name, request) in [("request", &memo_request), ("signed", &plain_request)] { | ||
| let error = verify_push(&challenge, request, &bound) |
There was a problem hiding this comment.
Informational: Hash memo regression test never isolates the explicit-request memo check
test_verify_hash_rejects_challenge_with_server_memo builds the echoed Challenge from the memo-bearing request in both of its cases, so the signed-Challenge predicate of ensure_no_server_memo is true each time. The predicate on the request being verified is never the deciding input, and removing it leaves the test green.
Valid? React with 👍 / 👎.
A challenge whose request sets methodDetails.memo now advertises supportedModes without push, as the charge spec requires, and the client pays it by pull. A memo challenge that only takes push fails before anything is broadcast, and providers skip it for another offer. Push matching assigns splits with a memo before the primary, so the primary can't take the only transfer carrying a split's memo.
| let binding = ChallengeBinding::new(&challenge.id, &challenge.realm); | ||
| let matched = match_push_receipt_transfers( | ||
| receipt.logs(), |
There was a problem hiding this comment.
Medium: Tempo push verification redeems only one Challenge per batched transaction
verify_hash now matches each Challenge in a batched push transaction to its own memo-bound transfers. It then reserves one replay key for the whole transaction hash. After the first Challenge redeems, every other Challenge fully paid in the same transaction is refused as CredentialReplayed.
Valid? React with 👍 / 👎.
A memo rules out hash Credentials, not Zone withdrawals. Issuance keeps push on a memo charge that accepts Zones, and a provider with a Zone that accepts a push-only memo offer still selects it and pays from the Zone.
| let Ok(request) = challenge.request.decode::<ChargeRequest>() else { | ||
| return false; | ||
| }; | ||
| request.amount_u256().is_ok_and(|amount| !amount.is_zero()) | ||
| && request.tempo_method_details().is_ok_and(|details| { | ||
| details.splits.is_none() && zone::is_accepted(details.zones.as_ref(), zone_id) | ||
| }) |
There was a problem hiding this comment.
Medium: Zone prefilter selects memo push-only offer that execution then rejects
select_challenge accepts a memo-bearing push-only Tempo offer whenever the configured Zone's may_pay passes. may_pay skips the expiry-versus-settlement-time and parent-chain checks that pays applies. When pays declines, the direct path rejects the memo push-only offer and the exchange fails, even though a payable pull offer was ranked after it.
Valid? React with 👍 / 👎.
A memo charge that accepts Zones keeps push for Zone withdrawals but must also offer pull, so payers without the Zone and split charges stay payable. Challenge selection keeps a push-only memo offer only when the configured Zone would pay it, using the same check as payment.
There was a problem hiding this comment.
Besides the inline finding, I checked whether the == slice comparisons in ChallengeBinding::is_bound (memo.rs:29) break the constant-time comparison rule. They don't. They compare public on-chain memo fingerprints, not HMACs or Challenge IDs, and they work the same way as the existing attribution::verify_server and verify_challenge_binding.
Extended reasoning...
The change touches Tempo hash-Credential verification on the server, push-mode exclusion at Challenge issuance, and client offer selection with Zone fallback. The memo comparison checked here is against SHA-derived fingerprints of the realm and Challenge ID, which are already visible on-chain. The existing attribution helpers compare them the same way.
The last 4 reviews of this pull request each found new blocking issues. Where they share a root cause, one fix may close them together.
Challenge selection keeps a push-only memo offer when deciding whether the Zone pays it fails, such as for an outstanding withdrawal, so paying it reports the failure instead of paying another offer.
There was a problem hiding this comment.
I reviewed the latest push and didn't find any new bugs. The change rewrites how hash Credential payments are verified on the server, so a human look would still be worthwhile.
What was reviewed:
TempoZone::may_pay(zone.rs) now keeps an offer whenpayserrors (unwrap_or(true)). A pending Zone settlement now reachespay_fromand is reported there, so selection no longer falls through to a second offer.exclude_push_for_server_memoin tempo/mod.rs: memo charges that accept Zones must also offerpull, and a missing list becomes["pull"].can_pay_offerfiltering in both providers, and the bound-memo matching in matching.rs, receipt_logs.rs and memo.rs.
Extended reasoning...
The change spans 13 files. It covers server verification of Tempo push receipts (memo binding, batched-transfer skipping, plain-split counting) and Challenge issuance of supportedModes, as well as client offer selection for providers and Zones. This is payment-acceptance logic: if it is wrong, a server could take a replayed or misattributed payment or turn down a valid one after the funds have moved. The latest commit addresses the Zone selection concern from the previous review. The bug hunt ran until it stopped finding anything and reported nothing new. I deferred because the change is large and touches security-sensitive verification, which calls for a human reviewer.
Motivation
mppx 0.22.2 and 0.22.3 aligned Tempo charge push payments (hash Credentials) with the charge spec. The Rust server accepted push payments that mppx now refuses, and refused batched push payments that mppx now accepts:
methodDetails.memotook a hash Credential whenever a split carried this Challenge's attribution memo.Summary
Server-side hash Credential verification only:
methodDetails.memo, whateversupportedModessays.ChallengeBinding);assert_challenge_bound_memosalso hashes it once, on the first attribution memo.Tests in
tests/hash_credential.rsmirror the mppx tests: server memo rejection (from the request and from the signed Challenge), memo only on a split, other Challenges' transfers first, last and from another realm, a plain split shared with another Challenge, splits matched to their own Challenge, the sender check of only the split used, and the binding matching exactly whatis_challenge_bound_memoaccepts.Key design considerations
match_bound_transfers), so transaction Credentials and the call matcher keep their current behavior.verify_hashdid before.tempo-receipt-verification.jsonpasses 42/42, includingexplicit_memo_hash_credential_with_attribution_memo_rejected,attribution_memo_only_on_split_rejected,batched_transfer_for_other_challenge_first_ignoredandbatched_transfer_for_other_challenge_last_ignored.tempo-accepted-transfers.jsonpasses 4/5:split_transfer_counted_onceexpects the first of two Challenges sharing one plain split to be accepted, which mppx 0.22.2 rejects as well under the rule this ports (a plain split counts only when the transaction pays no other Challenge). fix(conformance): restore the harness fixes for the mppx 0.22 pins mpp-tools#422 lists it as a known failure of the reference awaiting a decision on the vector.Verified:
cargo fmt --all -- --check,cargo clippy --workspace --all-targets --all-features -- -D warnings,cargo test --features tempo,stripe,ws,server,client,axum,middleware,tower,utils,integration-stripe,integration-ws(2,120 passed).Propagated from wevm/mppx#1372 (17086611a7f66fedf8c403f0977164c3559b5e24) and wevm/mppx#1374 (955c4c136dcde86a7c283f434bdad1c50c725a37) by Agricola.