fix(relay): a name read aloud is unambiguous, and the secret label holds 128 bits

The word list had 'dong' and three words of death and estates (probate,
testament, executor); it held both a word and its inflection (accrue and
accrued, audit and audited, ...) and homophones (peer and pier, sell and
cell, current and currant, ...). Four spoken words must identify one
name, so each pair keeps the base form or one spelling, 'fulfil' is
'fulfill', and the list is 1 427 words: 41.9 bits for four, over the
40-bit floor, which a test now states. A second test scans the list for
stem + ed/s/ing pairs and a list of alike-sounding groups.

The secret label was accepted at 16 characters ('aaaaaaaaaaaaaaaa'). The
app makes it from at least 128 random bits, 25 or more base 36 characters,
and the relay now refuses a label shorter than 25.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 09:52:54 -07:00
1 parent 5902580819
commit 8988769015
2 files changed
+99 -30

No files matched your search

+98 -2
View File
@@ -133,8 +133,10 @@ impl fmt::Debug for Name {
} }
/// The shortest and longest secret label the relay will route. The app /// The shortest and longest secret label the relay will route. The app
/// makes the label; the relay checks only its shape. /// makes the label, from at least 128 random bits (25 or more random
pub const SECRET_LEN: std::ops::RangeInclusive<usize> = 16..=63; /// base 36 characters: 25 of them are 129.2 bits); the relay checks only
/// its shape, and refuses a label too short to hold that much.
pub const SECRET_LEN: std::ops::RangeInclusive<usize> = 25..=63;
/// What a host name (a TLS server name or a DNS name) is. /// What a host name (a TLS server name or a DNS name) is.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@@ -243,9 +245,79 @@ mod tests {
] { ] {
assert!(list.binary_search(&bad).is_err(), "{bad} is on the list"); assert!(list.binary_search(&bad).is_err(), "{bad} is on the list");
} }
// Words with a reading a customer would not want in an address, and
// words of death and estates (an assistant's name should not be
// "executor" or "testament" of anything).
for bad in ["dong", "probate", "testament", "executor"] {
assert!(list.binary_search(&bad).is_err(), "{bad} is on the list");
}
assert!(name_bits() > 40.0, "{} bits", name_bits()); assert!(name_bits() > 40.0, "{} bits", name_bits());
} }
/// Four words must be at least 40 bits of choice (1 024 words is the
/// floor), so a name is hard to guess and rare to collide. Removing
/// words for being confusable must be made up with finance and
/// accounting words before this goes red.
#[test]
fn four_words_are_at_least_40_bits() {
assert!(words().len() >= 1024, "{} words", words().len());
assert!(name_bits() >= 40.0, "{} bits", name_bits());
}
/// A name read aloud must be unambiguous: no word is the inflection of
/// another on the list (the base form stays), and no two words sound
/// alike.
#[test]
fn no_word_is_an_inflection_or_a_homophone_of_another() {
let list = words();
let has = |w: &str| list.binary_search(&w).is_ok();
for w in list {
for suffix in ["s", "es", "d", "ed", "ing", "ies", "ied"] {
assert!(!has(&format!("{w}{suffix}")), "{w} and {w}{suffix}");
}
if let Some(stem) = w.strip_suffix('e') {
assert!(!has(&format!("{stem}ing")), "{w} and {stem}ing");
}
if let Some(stem) = w.strip_suffix('y') {
for suffix in ["ied", "ies"] {
assert!(!has(&format!("{stem}{suffix}")), "{w} and {stem}{suffix}");
}
}
if let Some(last) = w.chars().last() {
for suffix in ["ed", "ing"] {
assert!(
!has(&format!("{w}{last}{suffix}")),
"{w} and {w}{last}{suffix}"
);
}
}
}
// Words that sound alike: at most one of each group is listed.
for group in [
["peer", "pier", "", ""],
["sell", "cell", "", ""],
["current", "currant", "", ""],
["real", "riel", "reel", ""],
["sum", "som", "some", ""],
["sole", "sol", "soul", ""],
["site", "sight", "cite", ""],
["cache", "cash", "", ""],
["fair", "fare", "", ""],
["steel", "steal", "", ""],
["suite", "sweet", "", ""],
["route", "root", "", ""],
["counsel", "council", "", ""],
["principal", "principle", "", ""],
["profit", "prophet", "", ""],
["stake", "steak", "", ""],
] {
let listed: Vec<_> = group.iter().filter(|w| !w.is_empty() && has(w)).collect();
assert!(listed.len() <= 1, "alike-sounding words listed: {listed:?}");
}
assert!(!has("fulfil"), "it is fulfill");
assert!(has("fulfill"));
}
#[test] #[test]
fn a_name_is_four_listed_words_and_prints_as_itself() { fn a_name_is_four_listed_words_and_prints_as_itself() {
let n = Name::parse("ledger-accrual-tally-mint").expect("listed words"); let n = Name::parse("ledger-accrual-tally-mint").expect("listed words");
@@ -296,6 +368,30 @@ mod tests {
} }
} }
/// The secret label is at least 128 bits when the app makes it (25 or
/// more random base 36 characters); a label too short to hold that is
/// not routed, whatever it spells.
#[test]
fn a_secret_label_under_25_characters_is_not_routed() {
let zone = Zone::new("wanderbooks.link", "relay.wanderbooks.link");
let name = Name::parse("ledger-accrual-tally-mint").unwrap();
let on = |secret: &str| {
zone.classify(&format!(
"{secret}.ledger-accrual-tally-mint.wanderbooks.link"
))
};
assert_eq!(on("aaaaaaaaaaaaaaaa"), HostKind::Other, "16 characters");
assert_eq!(on(&"a".repeat(24)), HostKind::Other, "24 characters");
assert_eq!(on(&"a".repeat(25)), HostKind::App(name), "25 characters");
assert_eq!(on(&"a".repeat(63)), HostKind::App(name), "63 characters");
assert_eq!(on(&"a".repeat(64)), HostKind::Other, "64 characters");
assert!(
25.0 * 36f64.log2() >= 128.0,
"25 base 36 characters are 128 bits"
);
assert!(24.0 * 36f64.log2() < 128.0);
}
#[test] #[test]
fn below_names_the_labels_under_the_zone() { fn below_names_the_labels_under_the_zone() {
let zone = Zone::new("wanderbooks.link", "relay.wanderbooks.link"); let zone = Zone::new("wanderbooks.link", "relay.wanderbooks.link");
+1 -28
View File
@@ -6,7 +6,6 @@ accountant
accredit accredit
accrual accrual
accrue accrue
accrued
accumulate accumulate
accurate accurate
acquire acquire
@@ -67,7 +66,6 @@ attain
attest attest
auction auction
audit audit
audited
auditor auditor
authorize authorize
avail avail
@@ -75,7 +73,6 @@ average
award award
baht baht
balance balance
balanced
balboa balboa
ballast ballast
banker banker
@@ -107,10 +104,8 @@ blueprint
boardroom boardroom
bolivar bolivar
bond bond
bonded
bonus bonus
book book
booked
bookkeeper bookkeeper
bookkeeping bookkeeping
booth booth
@@ -124,7 +119,6 @@ brokerage
bronze bronze
brook brook
budget budget
budgeted
buffer buffer
bulk bulk
bullion bullion
@@ -155,7 +149,6 @@ cashier
catalog catalog
cedar cedar
cedi cedi
cell
cent cent
centime centime
certificate certificate
@@ -164,7 +157,6 @@ chamber
charity charity
chart chart
charter charter
chartered
check check
checkbook checkbook
checklist checklist
@@ -176,7 +168,6 @@ circuit
citrus citrus
claim claim
clear clear
clearing
clerk clerk
client client
clientele clientele
@@ -254,7 +245,6 @@ crop
crossfoot crossfoot
crown crown
cumulative cumulative
currant
currency currency
current current
curve curve
@@ -324,7 +314,6 @@ docket
document document
dollar dollar
domain domain
dong
donor donor
dossier dossier
draft draft
@@ -393,7 +382,6 @@ excel
excess excess
exchange exchange
execute execute
executor
exemption exemption
exercise exercise
exhibit exhibit
@@ -440,7 +428,6 @@ flux
folder folder
folio folio
foot foot
footing
footnote footnote
footprint footprint
forecast forecast
@@ -462,7 +449,7 @@ freight
frequency frequency
front front
frugal frugal
fulfil fulfill
full full
fund fund
fundamental fundamental
@@ -518,7 +505,6 @@ hinge
hire hire
historic historic
hold hold
holding
home home
honest honest
honor honor
@@ -644,7 +630,6 @@ liable
liberty liberty
library library
license license
licensed
lighthouse lighthouse
lime lime
limit limit
@@ -655,7 +640,6 @@ linkage
liquid liquid
lira lira
list list
listing
literal literal
live live
loading loading
@@ -698,7 +682,6 @@ marketable
mart mart
master master
match match
matched
material material
mature mature
maximum maximum
@@ -783,7 +766,6 @@ omit
onboard onboard
ongoing ongoing
open open
opening
operate operate
operator operator
opinion opinion
@@ -862,7 +844,6 @@ personal
peso peso
petty petty
phase phase
pier
pilot pilot
pine pine
pinnacle pinnacle
@@ -925,7 +906,6 @@ priority
private private
privilege privilege
prize prize
probate
procedure procedure
proceed proceed
process process
@@ -1079,7 +1059,6 @@ rial
ribbon ribbon
rice rice
ridge ridge
riel
rigor rigor
ring ring
ringgit ringgit
@@ -1123,7 +1102,6 @@ scribe
scroll scroll
scrutiny scrutiny
seal seal
sealed
search search
season season
secure secure
@@ -1153,7 +1131,6 @@ shift
shilling shilling
ship ship
shipment shipment
shipping
shoal shoal
shop shop
sign sign
@@ -1176,12 +1153,10 @@ smooth
snapshot snapshot
social social
society society
sol
sole sole
solid solid
solution solution
solvent solvent
som
sound sound
source source
sovereign sovereign
@@ -1288,7 +1263,6 @@ tenure
term term
terrace terrace
territory territory
testament
thaler thaler
thorough thorough
thread thread
@@ -1351,7 +1325,6 @@ unanimous
undertake undertake
underwrite underwrite
unearned unearned
unified
uniform uniform
unify unify
union union