The Wallet Library That Killed Itself

Hard

· Backend

Incident

SEV-1

BUG-PARITY

Priority: Critical (funds frozen) · reported by security

Time to fix: 35 min

Failing checks on the shipped build

  • re-initialisation is refused

    the library must only initialise once: expected false but got true

  • only the owner may destroy

    expected false but got true

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

Parity multisig · 2017

Modelled on the Parity multisig wallet freeze (November 2017): the shared library contract's initialiser was never claimed, so an anonymous account called it, became the owner, and then invoked kill. Every wallet that delegated to that library was bricked, freezing roughly 513,000 ETH permanently.

wallet.js exposes an initialiser that anyone can call at any time.

Fix the library so ownership can only be set once, and only destructive operations the owner performs are allowed.

Code map

// Shared multisig library.
exports.initialize = function (lib, owner) {
  lib.owner = owner;
  return true;
};

exports.destroy = function (lib, caller) {
  lib.dead = 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 Wallet Library That Killed Itself — JavaScript Bug Hunt

Modelled on the Parity multisig wallet freeze (November 2017): the shared library contract's initialiser was never claimed, so an anonymous account called…

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Hard
  • Concepts: Access Control, Initialization
  • Modelled on: Parity multisig · 2017
  • Visible tests: the first initialisation succeeds; re-initialisation is refused; only the owner may destroy
  • Reward: 50 XP for a complete fix

Incident

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

Failing checks on the shipped build

  • re-initialisation is refused — the library must only initialise once: expected false but got true
  • only the owner may destroy — expected false but got true

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 Parity multisig wallet freeze (November 2017): the shared library contract's initialiser was never claimed, so an anonymous account called it, became the owner, and then invoked kill. Every wallet that delegated to that library was bricked, freezing roughly 513,000 ETH permanently.

wallet.js exposes an initialiser that anyone can call at any time.

Fix the library so ownership can only be set once, and only destructive operations the owner performs are allowed.

Bug report

BUG-PARITY · Priority: Critical (funds frozen) · Reported by: security

The library must behave like this:

  • initialize(lib, owner) sets the owner only if there is not one already; it returns true on success and false if the library is already initialised
  • destroy(lib, caller) sets lib.dead = true only when caller is the owner and returns true; otherwise it changes nothing and returns false

Observed: initialize can be called repeatedly by anyone, so an attacker simply re-initialises to themselves and calls destroy.

Logs

[wallet] initialize called by 0xdevops237 on an already-initialised library
[wallet] destroy succeeded; 587 dependent wallets now unusable

The code as shipped

src/wallet/wallet.js (editable)

// Shared multisig library.
exports.initialize = function (lib, owner) {
  lib.owner = owner;
  return true;
};

exports.destroy = function (lib, caller) {
  lib.dead = true;
  return true;
};

Read-only context: src/wallet/THREAT.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.