The Zero Root Everyone Trusted

Hard

· Backend

Incident

SEV-1

BUG-NOMAD

Priority: Critical · reported by incident response

Time to fix: 35 min

Failing checks on the shipped build

  • after a zero-root upgrade, unproven messages are rejected

    a message nobody proved must never pass: expected an error to be thrown

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

Nomad · 2022

Modelled on the Nomad bridge exploit of 1 August 2022: a routine upgrade initialised the bridge's trusted root to 0x00. A message that has never been proven also maps to the default root 0x00, so the check "is this message's root confirmed?" passed for any message. Once the first exploit transaction appeared, hundreds of copycats replayed it with their own addresses, and roughly $190 million was drained.

This project is a reconstruction. replica.js keeps confirmed roots, proven messages and processed messages; process looks up a message's root — defaulting to the zero root — and asks whether that root is acceptable.

Fix the replica so the zero root is never acceptable, however the contract was initialised.

Code map

var c = require("./constants");

exports.create = function () {
  return { confirmAt: {}, messages: {}, processed: {} };
};

exports.initialize = function (state, committedRoot) {
  state.confirmAt[committedRoot] = 1;
};

exports.prove = function (state, message, root) {
  state.messages[c.hashMessage(message)] = root;
};

exports.acceptableRoot = function (state, root, now) {
  var t = state.confirmAt[root];
  if (!t) return false;
  return t <= now;
};

exports.process = function (state, message, now) {
  var h = c.hashMessage(message);
  if (state.processed[h]) throw new Error("already processed");
  var root = state.messages[h] || c.ZERO_ROOT;
  if (!exports.acceptableRoot(state, root, now)) throw new Error("not proven");
  state.processed[h] = true;
  return true;
};

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 Zero Root Everyone Trusted — JavaScript Bug Hunt

Modelled on the Nomad bridge exploit of 1 August 2022: a routine upgrade initialised the bridge's trusted root to 0x00.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Hard
  • Concepts: Security, State
  • Modelled on: Nomad · 2022
  • Visible tests: a proven message under a confirmed root is processed; after a zero-root upgrade, unproven messages are rejected
  • Reward: 50 XP for a complete fix

Incident

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

Failing checks on the shipped build

  • after a zero-root upgrade, unproven messages are rejected — a message nobody proved must never pass: expected an error to be thrown

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 the Nomad bridge exploit of 1 August 2022: a routine upgrade initialised the bridge's trusted root to 0x00. A message that has never been proven also maps to the default root 0x00, so the check "is this message's root confirmed?" passed for any message. Once the first exploit transaction appeared, hundreds of copycats replayed it with their own addresses, and roughly $190 million was drained.

This project is a reconstruction. replica.js keeps confirmed roots, proven messages and processed messages; process looks up a message's root — defaulting to the zero root — and asks whether that root is acceptable.

Fix the replica so the zero root is never acceptable, however the contract was initialised.

Bug report

BUG-NOMAD · Priority: Critical · Reported by: incident response

  • acceptableRoot(state, root, now) is true only when root is NOT the zero root, root has a confirmation time, and that time is <= now
  • initialize(state, root) may be called with the zero root (the upgrade did exactly that) — it must not make any unproven message acceptable
  • process(state, message, now) throws when the message was already processed, or when its proven root is missing or not acceptable; otherwise marks it processed and returns true

Observed: after the upgrade, process() accepted messages that were never proven.

Logs

[replica] initialize committedRoot=0x00
[replica] process msg=h:withdraw-100-to-0xbeef root=0x00 -> accepted
[replica] 300+ processed messages with no proof in the next hours

The code as shipped

src/bridge/replica.js (editable)

var c = require("./constants");

exports.create = function () {
  return { confirmAt: {}, messages: {}, processed: {} };
};

exports.initialize = function (state, committedRoot) {
  state.confirmAt[committedRoot] = 1;
};

exports.prove = function (state, message, root) {
  state.messages[c.hashMessage(message)] = root;
};

exports.acceptableRoot = function (state, root, now) {
  var t = state.confirmAt[root];
  if (!t) return false;
  return t <= now;
};

exports.process = function (state, message, now) {
  var h = c.hashMessage(message);
  if (state.processed[h]) throw new Error("already processed");
  var root = state.messages[h] || c.ZERO_ROOT;
  if (!exports.acceptableRoot(state, root, now)) throw new Error("not proven");
  state.processed[h] = true;
  return true;
};

Read-only context: src/bridge/constants.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.