did-btcr2-js

ADR 136: A Negative Vector Names the Rule That It Breaks, and the Pipeline Checks the Cause

Context

Each network of the test-vector corpus has 27 negative vector sets. A negative set records only the DID Resolution error code in didResolutionMetadata.error. The README of a network told a consumer to compare the code only, because errorMessage is the text of this implementation.

An error code does not identify a rule. INVALID_DID_UPDATE covers 14 rules of the negative sets. A resolver that fails a set for another rule gets the correct code and passes the comparison.

The pipeline had the same gap. The verifiers compared the code only. The pinned set n27 must break the rule “update.proof.expires is before update.proof.created”. Its recorded errorMessage is “proof.expires is before the mediantime”, so the set breaks another rule of the same section. No step of the pipeline found the defect.

An implementer who runs the vectors in another test harness asked for two properties:

  1. A cause check for every negative set. The pipeline must not record a set that fails for another rule.
  2. Stable ids. The implementer maps the causes of the harness to the ids, so an id must not change between two generations of the corpus.

The specification defines the error codes. It does not define a cause code or a rule id.

Decision

other.json names the rule of a negative set

The other.json of a negative set gets the key expectedFailure, after scenarioId. The value is a rule id. A positive set has no expectedFailure. The layout of ADR 113 does not change otherwise.

One id names one rule

An id names a rule of the specification, not a set. Two sets that break the same rule share the id. The 27 negative sets of a network use 24 ids. The pairs n10 and n11, n16 and n17, and n30 and n31 share an id.

The ids are stable

One table holds the rules

FAILURE_RULES in packages/api/lib/_scenario-helpers.ts maps each id to:

A negative recipe has expect: { error, rule }. loadRecipes refuses a recipe if expect.rule is not an id of the table, or if the error of the rule is not expect.error.

Rule id Error Sets Section blockTimes
did-checksum-invalid INVALID_DID n01 did-btcr2-identifier-decoding  
did-padding-nonzero INVALID_DID n02 did-btcr2-identifier-decoding  
did-network-reserved INVALID_DID n03 did-btcr2-identifier-decoding  
genesis-hash-mismatch INVALID_DID n04 process-sidecar-data  
update-missing MISSING_UPDATE_DATA n05 find-beacon-signals  
update-context-mismatch INVALID_DID_UPDATE n10, n11 check-update-proof  
proof-context-mismatch INVALID_DID_UPDATE n12 check-update-proof  
proof-capability-action-mismatch INVALID_DID_UPDATE n13 check-update-proof  
proof-capability-mismatch INVALID_DID_UPDATE n14 check-update-proof  
proof-purpose-mismatch INVALID_DID_UPDATE n15 check-update-proof  
proof-method-unauthorized INVALID_DID_UPDATE n16, n17 check-update-proof  
proof-not-verified INVALID_DID_UPDATE n18 check-update-proof  
source-hash-mismatch INVALID_DID_UPDATE n19 apply-update  
target-hash-mismatch INVALID_DID_UPDATE n20 apply-update  
version-skip LATE_PUBLISHING n21 check-update-version  
patch-apply-failure INVALID_DID_UPDATE n22 apply-update  
document-id-mismatch INVALID_DID_UPDATE n23 apply-update  
document-not-conformant INVALID_DID_UPDATE n24 apply-update  
proof-created-after-block INVALID_DID_UPDATE n25 check-update-proof yes
proof-expires-before-mediantime INVALID_DID_UPDATE n26 check-update-proof yes
proof-expires-before-created INVALID_DID_UPDATE n27 check-update-proof yes
duplicate-hash-mismatch LATE_PUBLISHING n28 confirm-duplicate-update  
smt-proof-not-verified INVALID_SIGNAL_DATA n29 process-smt-beacon  
smt-proof-missing MISSING_UPDATE_DATA n30, n31 process-smt-beacon  

The verifiers check the cause

The main resolve of a negative set must fail for the rule of the set. The verifiers first compare the error code with the expected output. If the code matches, they compare the message with the pattern of the rule (causeDiff). A mismatch fails the case.

A proof time tamper breaks only its rule

The 3 rules with blockTimes compare the proof times with the block of the signal. A proof time that breaks one rule can break a second rule of the window, and the resolver can stop at the second rule first. Thus scenario:verify:live checks each update with a proof time tamper against the block of its signal. The update must break the rule of its tamper and no other rule. Else the set fails, and it needs a new key and a new anchor.

The README lists the rules

The README of a network shows the rule id of each negative set next to its error code. A section “Expected failures” lists each rule id with its error code, the rule, the link to the specification section, and the sets that break it. The comparison rules tell a consumer to compare the code, then to check the cause against expectedFailure, and not to compare errorMessage.

Alternatives

Consequences

Positive.

Negative.

Neutral.

Implementation

References