Skip to content

fix(reward): scope replay guard by created_tx — allow legit repeat awards#53

Merged
lucca65 merged 1 commit into
masterfrom
fix/reward-guard-tx-scope
Jul 2, 2026
Merged

fix(reward): scope replay guard by created_tx — allow legit repeat awards#53
lucca65 merged 1 commit into
masterfrom
fix/reward-guard-tx-scope

Conversation

@lucca65

@lucca65 lucca65 commented Jul 2, 2026

Copy link
Copy Markdown
Member

DRAFT until backend #344 is merged + deployed — this writes the rewards.created_tx column that migration 20260702120000 creates. Deploying this first would fail every reward insert.

Why

Contract audit finding: reward() has no uniqueness check — the same (action, receiver, awarder) can legitimately be awarded repeatedly (repeatable automatic actions with usages). The replay guard shipped in #50 keys on the trio alone, so it would silently drop a legitimate second award. Never triggered in prod data (zero repeat trios exist), but it's a correctness hole against chain semantics.

What

  • Stamp created_tx on reward inserts (matching every other chain-written table).
  • Guard keys on (action, receiver, awarder) AND (created_tx = this tx OR created_tx IS NULL):
    • exact-tx match → true replay, skip;
    • NULL match → legacy pre-column row; trio-only decides, identical to current behavior for old data;
    • same trio under a different tx → legitimate repeat award, inserted.
  • The _processed_actions ledger (feat: persistent applied-action ledger — replay-safe reindex #52) remains the first line for anything indexed after it went live.

Verified: criteria syntax (or + null → IS NULL) exercised against the dev DB with the migrated column; StandardJS clean.

🤖 Generated with Claude Code

…ards

The contract's reward() has no uniqueness check: the same
(action, receiver, awarder) can legitimately be awarded again for a
repeatable automatic action. The replay guard keyed on the trio alone
would silently drop such a second award (never occurred in prod data,
but allowed by the chain).

Stamp rewards.created_tx (column added by backend migration
20260702120000) and key the guard on (trio + created_tx), falling back
to trio-only for legacy NULL rows — identical to the old behavior for
pre-column data, exact replay detection for everything new.

DEPLOY ORDER: requires the backend migration to be live first (the
insert now writes created_tx).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lucca65
lucca65 marked this pull request as ready for review July 2, 2026 11:40
@lucca65
lucca65 merged commit 98caa2e into master Jul 2, 2026
2 checks passed
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