Skip to content

fix: tx hash replay protection for charge intent#89

Merged
Slokh merged 2 commits intomainfrom
fix/charge-tx-hash-replay-protection
Mar 18, 2026
Merged

fix: tx hash replay protection for charge intent#89
Slokh merged 2 commits intomainfrom
fix/charge-tx-hash-replay-protection

Conversation

@Slokh
Copy link
Contributor

@Slokh Slokh commented Mar 18, 2026

Summary

Fixes transaction hash replay vulnerability in ChargeIntent. A malicious client could pay once and reuse the same tx hash across multiple challenges to get free service.

Changes

  • Created mpp.store module with Store protocol and MemoryStore
  • Added optional store parameter to ChargeIntent.__init__
  • In _verify_hash: checks store for previously-seen hash before RPC verification; records hash after success
  • Exported Store and MemoryStore from mpp
  • Added 3 tests: replay rejection, backward compat without store, store recording

Usage

from mpp import MemoryStore
from mpp.methods.tempo import ChargeIntent

intent = ChargeIntent(chain_id=42431, store=MemoryStore())

Store is opt-in — existing usage without a store is unaffected.

Add optional store parameter to ChargeIntent for transaction hash
deduplication. Before verifying a hash on-chain, checks if it has
already been used. After successful verification, records the hash.

This prevents replay attacks where a client pays once and reuses
the same tx hash across multiple challenges to get free service.

Adds Store protocol and MemoryStore implementation in mpp.store.
The store is opt-in to maintain backward compatibility.

Amp-Thread-ID: https://ampcode.com/threads/T-019d02b5-0e49-75a9-a69f-92b70d81ba0f
Co-authored-by: Amp <amp@ampcode.com>
@Slokh Slokh force-pushed the fix/charge-tx-hash-replay-protection branch from c223f96 to 5747ed5 Compare March 18, 2026 21:16
Add optional store parameter to ChargeIntent for transaction hash
deduplication. Before verifying a hash on-chain, checks if it has
already been used. After successful verification, records the hash.

This prevents replay attacks where a client pays once and reuses
the same tx hash across multiple challenges to get free service.

Adds Store protocol and MemoryStore implementation in mpp.store.
The store is opt-in to maintain backward compatibility.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019d02b5-0e49-75a9-a69f-92b70d81ba0f
@Slokh Slokh force-pushed the fix/charge-tx-hash-replay-protection branch from 5747ed5 to c8e41aa Compare March 18, 2026 21:17
@Slokh Slokh merged commit e3bfdd1 into main Mar 18, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 18, 2026
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.

1 participant