-
Notifications
You must be signed in to change notification settings - Fork 22
fix(bridge): add mint and burn replay protection (#6) #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,8 @@ import type { WpiContractClient } from './wpiContractClient.js'; | |
|
|
||
| /** | ||
| * Watches the wPi contract for `redemption_burned` events and releases the | ||
| * corresponding native Pi via `PiPayoutClient`, deduping by the event's | ||
| * globally-unique RPC id so a burn is never paid out twice. | ||
| * corresponding native Pi via `PiPayoutClient`, deduping by the contract's | ||
| * on-chain redemption ID so a burn is never paid out twice. | ||
| */ | ||
| export class RedemptionWatcher { | ||
| constructor( | ||
|
|
@@ -26,17 +26,17 @@ export class RedemptionWatcher { | |
| const { events, nextLedger } = await this.contractClient.getRedemptionBurnEvents(since); | ||
|
|
||
| for (const event of events) { | ||
| if (this.store.hasRedemption(event.eventId)) continue; | ||
| if (this.store.hasRedemption(event.redemptionId)) continue; | ||
| this.store.upsertRedemption({ | ||
| redemptionId: event.eventId, | ||
| redemptionId: event.redemptionId, | ||
|
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift Migrate legacy event-ID records before switching the dedupe key. Records persisted by the previous watcher are keyed by RPC #!/bin/bash
# Map the idempotency-store surface before inspecting persistence-key usage.
ast-grep outline relayer/src --items all --type class,interface,function --match 'Idempotency|Store'
# Locate the concrete storage implementation and any migration/compatibility logic.
rg -n -C 4 --glob '*.ts' \
'hasRedemption\s*\(|upsertRedemption\s*\(|listRedemptionsByStatus\s*\(|eventId|redemptionId' \
relayer/src🤖 Prompt for AI Agents |
||
| nonce: event.nonce, | ||
| amountStroops: event.amountStroops, | ||
| piDestination: event.piDestination, | ||
| status: 'observed', | ||
| updatedAt: new Date().toISOString(), | ||
| }); | ||
| this.log.info('observed wPi redemption burn, queued for Pi release', { | ||
| redemptionId: event.eventId, | ||
| redemptionId: event.redemptionId, | ||
| piDestination: event.piDestination, | ||
| }); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Match the documented mint API to the contract.
mint_from_depositis minter-authorized, takes(to, amount, pi_deposit_id), and returnsResult<bool, Error>so callers handleOk(false)volume-limit rejections. The documentedadminparameter andResult<(), Error>will mislead the follow-up implementation.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents