Pick a provably wrong nonce in the proof-of-work refusal test

"nope" against a random challenge at 8 bits is a right answer 1 time in
256, and then the test force-unwrapped a nil error and crashed the whole
runner (seen in wave 0a's first full run). The nonce is now chosen by
checking it has fewer than 8 leading zero bits for this challenge, and the
error is unwrapped with #require.

Falsified: choosing a nonce with 8 or more bits turns the test red.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Paul Hitt
2026-10-07 14:37:23 -04:00
co-authored by Claude Opus 5.5
parent aca12ca7f3
commit 378de4f6d7
@@ -293,12 +293,21 @@ struct SignupProofOfWorkFallbackTests {
try await withRelay { h in
let r = routes(h, bits: 8, withoutPoW: 50)
let issued = SignupChallenge.issue(secret: secret, now: now, bits: 8)
// A nonce shown to be wrong for THIS challenge. A fixed one like
// "nope" against a random challenge at 8 bits is a right answer
// 1 time in 256, and then this test crashed the runner on the
// force-unwrap below it.
let wrong = try #require(
(0..<10_000).lazy.map { "wrong-\($0)" }.first { nonce in
SignupChallenge.leadingZeroBits(
of: SHA256.hash(data: Data("\(issued.challenge).\(nonce)".utf8))) < 8
})
let err = await #expect(throws: WireError.self) {
_ = try await r.signup(
self.post(h, self.body(1, challenge: issued.challenge, nonce: "nope")),
self.post(h, self.body(1, challenge: issued.challenge, nonce: wrong)),
clientIP: self.ip, now: self.now)
}
#expect(code(err!) == "challenge_failed")
#expect(code(try #require(err)) == "challenge_failed")
let created = try await User.query(on: h.db).count()
#expect(created == 0, "a wrong answer created an account")
}