Skip to content

fix(core): gate NIP-44 encrypt at effective 65,408-byte limit - #7640

Draft
gruming wants to merge 1 commit into
block:mainfrom
gruming:fix/engram-nip44-effective-limit
Draft

gruming wants to merge 1 commit into
block:mainfrom
gruming:fix/engram-nip44-effective-limit

Conversation

@gruming

@gruming gruming commented Sep 14, 2026

Copy link
Copy Markdown

Why

nostr's nip44::encrypt refuses plaintext larger than 65,408 bytes (MAX_SUPPORTED_PLAINTEXT_SIZE = 65_536 - 128, nostr 0.44.7 nip44/v2.rs:35; unchanged in 0.45.1), 127 bytes below the NIP-44 spec cap of 65,535. Our size gates (engram build_event, observer, private managed agent) checked the spec cap, so bodies serialized to 65,409..=65,535 bytes passed the gate and then failed inside encrypt with a bare message too long instead of a size error that reports the byte count.

What

  • New NIP44_ENCRYPT_MAX = 65_408 (implementation cap) next to the unchanged spec constants; the 5 encrypt/decrypt gates now use it and the errors report the limit and actual size.
  • Tests: (a) build_event_rejects_inside_nip44_blind_spot — 65,500-byte serialized body → BodyTooLarge (was Encrypt("message too long")); (b) nip44_plaintext_boundary_is_65408 — literal 65,408 ok / 65,409 err, guards against silent upstream changes; (c) existing oversize test pinned to literal 65,535 with a serialized-size assertion.
  • buzz-cli mem set comment corrected (no logic change).

cargo test -p buzz-core 257 passed · -p buzz-cli 463 passed · -p buzz-acp 914 passed · cargo fmt --check clean.

Draft: opened for review; not requesting merge yet.

nostr's nip44::encrypt refuses plaintext larger than 65,408 bytes
(MAX_SUPPORTED_PLAINTEXT_SIZE = 65,536 - 128), 127 below the NIP-44 spec
cap of 65,535. Our size gates checked the spec cap, so bodies in the
65,409..=65,535 blind spot passed the gate and then failed cryptically
inside encrypt with "message too long" instead of a clean size error.

Separate the spec value from the implementation limit: keep the spec
constants (NIP44_PLAINTEXT_MAX, OBSERVER_MAX_PLAINTEXT_LEN,
MAX_PLAINTEXT_BYTES = 65,535) as documented values and add
NIP44_ENCRYPT_MAX = 65,408 for the real gate. Move the encrypt/decrypt
gates in engram, observer, and private_managed_agent to the effective
limit, and make the size-limit errors carry both the limit and the
actual byte count (pairing/session decrypt is left unchanged).

Add regression tests in engram: one that rejects a body sized inside the
blind spot via our gate, and one that watches nostr's external limit with
literal 65,408/65,409 bounds so a future nostr change is caught. Fix two
stale comments whose intent broke once the gate moved (the mem set stdin
guard and the existing body_too_large test).

Signed-off-by: gruming <tnalsl1984@naver.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 4cd82f513214aad11c2b742ce7cc7c681e8e32a0...7ac318ee887130822e50bba71ad5d77cbffd6c83.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review 7ac318ee887130822e50bba71ad5d77cbffd6c83 to authorize a new review.
Any previous review applies only to its recorded range.

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