Skip to content

test(identity): make ciphertext tampering deterministic - #61

Merged
damusix merged 1 commit into
masterfrom
fix/crypto-tamper-flake
Jul 29, 2026
Merged

test(identity): make ciphertext tampering deterministic#61
damusix merged 1 commit into
masterfrom
fix/crypto-tamper-flake

Conversation

@damusix

@damusix damusix commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

CI on master went red on the 1.0.0 release merge (run 30407887853) at tests/core/identity/crypto.test.ts — "Received function did not throw".

It's a test bug, not a crypto bug. Both tamper-detection tests built their tampered payload as:

const tampered = { ...payload, ciphertext: 'ff' + payload.ciphertext.slice(2) };

When the ciphertext already starts with ff, that assignment changes nothing. The payload is byte-identical, AES-GCM decrypts it correctly, and .toThrow() fails. 1 in 256.

Measured on the real code path: 18/5000 = 0.36%, against a predicted 1/256 = 0.39%.

Fixed by flipping the byte rather than assigning it, via a shared helper used at both sites. Verified exhaustively over all 256 possible first-byte values: the old form is a no-op for exactly 1, the new form for 0.

Targets master directly because that is the branch that is red and the release is gated behind it.

Both tamper-detection tests built their payload as `'ff' + ct.slice(2)`,
which is a no-op the 1-in-256 times the ciphertext already starts with
`ff` — decryption then succeeds and the assertion fails for reasons
unrelated to the code under test. Measured at 0.36% over 5000 samples,
and it took down CI on the 1.0.0 release merge.

Flipping the byte instead is a no-op for none of the 256 possible values.
@damusix
damusix merged commit d7fd96b into master Jul 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant