The Transaction That Changed Its Own Name

Hard

· Backend

Incident

SEV-1

BUG-MALLEABLE

Priority: Critical (double spend) · reported by treasury

Time to fix: 35 min

Failing checks on the shipped build

  • re-encoding the signature does not change the id

    the signature must not be part of the identity: expected "d487ec30" but got "75e31a83"

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

Mt. Gox · 2014

Modelled on transaction malleability as exploited against Mt. Gox (2014): a transaction's id was derived from data that a third party could tamper with without invalidating it. Withdrawals were re-broadcast under a new id, the exchange's bookkeeping never saw the original settle, and it re-sent the funds.

txid.js computes a transaction id over fields that include a mutable signature blob.

Fix computeId so the id depends only on the immutable parts of the transaction.

Code map

function hash(text) {
  var h = 2166136261;
  for (var i = 0; i < text.length; i++) {
    h = h ^ text.charCodeAt(i);
    h = (h * 16777619) >>> 0;
  }
  return h.toString(16);
}

// Identity of a transaction.
exports.computeId = function (tx) {
  return hash(tx.from + "|" + tx.to + "|" + tx.amount + "|" + tx.nonce + "|" + tx.signature);
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Transaction That Changed Its Own Name — Bug Hunt

Modelled on transaction malleability as exploited against Mt.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Hard
  • Concepts: Hashing, Idempotency
  • Modelled on: Mt. Gox · 2014
  • Visible tests: different transfers have different ids; re-encoding the signature does not change the id
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (double spend))
  • Ticket: BUG-MALLEABLE
  • Reported by: treasury
  • Time to fix: 35 minutes, the target for a hard incident

Failing checks on the shipped build

  • re-encoding the signature does not change the id — the signature must not be part of the identity: expected "d487ec30" but got "75e31a83"

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Modelled on transaction malleability as exploited against Mt. Gox (2014): a transaction's id was derived from data that a third party could tamper with without invalidating it. Withdrawals were re-broadcast under a new id, the exchange's bookkeeping never saw the original settle, and it re-sent the funds.

txid.js computes a transaction id over fields that include a mutable signature blob.

Fix computeId so the id depends only on the immutable parts of the transaction.

Bug report

BUG-MALLEABLE · Priority: Critical (double spend) · Reported by: treasury

computeId(tx) must produce the same id for two transactions that move the same funds, even if their signature fields differ — the signature is not part of a transaction's identity.

Observed: re-encoding the signature yields a different id, so the ledger treats a re-broadcast withdrawal as brand new and pays out twice.

Logs

[ledger] withdrawal wd-7781 settled under two distinct ids
[ledger] duplicate payout detected after reconciliation: 1 of 219

The code as shipped

src/tx/txid.js (editable)

function hash(text) {
  var h = 2166136261;
  for (var i = 0; i < text.length; i++) {
    h = h ^ text.charCodeAt(i);
    h = (h * 16777619) >>> 0;
  }
  return h.toString(16);
}

// Identity of a transaction.
exports.computeId = function (tx) {
  return hash(tx.from + "|" + tx.to + "|" + tx.amount + "|" + tx.nonce + "|" + tx.signature);
};

Read-only context: src/tx/PROTOCOL.js.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.