fix(p2p): frame gossipsub msgId and restrict allowedTopics (A-1256) - #24214
Merged
PhilWindle merged 3 commits intoJun 22, 2026
Conversation
The gossipsub msgId was SHA256(topic || data) with no framing between the topic string and the message bytes, and no allowedTopics was set. A peer could publish on an unsubscribed topic T+data[0] with data[1:], whose (topic, data) concatenation is byte-identical to a real message on topic T, hashing to the same msgId. gossipsub transformed it and inserted the id into seenCache before the subscription check, so the genuine proposal/attestation was later dropped as a duplicate, suppressing a time-sensitive consensus message. - Frame the topic length into the msgId input (uint32be(topicLen) || topic || data) so the (topic, data) boundary is unambiguous and a boundary-shifted pair no longer collides. - Set exact allowedTopics on the gossipsub config so an unsubscribed-topic message is rejected before transform / msgId / seenCache insertion. Defense in depth: either fix alone breaks the attack. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PhilWindle
marked this pull request as ready for review
June 22, 2026 11:58
fcarreiro
approved these changes
Jun 22, 2026
| */ | ||
| export async function getMsgIdFn({ topic, data }: Message): Promise<Uint8Array> { | ||
| const buffer = Buffer.concat([Buffer.from(topic), data]); | ||
| export async function getMsgIdFn({ topic, data }: Pick<Message, 'topic' | 'data'>): Promise<Uint8Array> { |
Contributor
There was a problem hiding this comment.
Are any changes needed to fastMsgIdFn or msgIdToStrFn above?
I'm a bit unclear on when those are used (and why it's called fast, since I think using webcrypto.subtle is faster)
Contributor
Author
There was a problem hiding this comment.
Yes, you are right. Though I actually think the best course of action is to just remove the fastMsgId. It's an optional optimisation that actually makes the message caching non-collision resistant.
…(A-1256) The gossipsub fast-path dedup cache keyed on fastMsgIdFn — a non-cryptographic 64-bit xxhash of the raw data only (no topic), seeded from Math.random (~2^30, non-CSPRNG). A fast-id collision (accidental, or engineered given the weak seed, or simply same-data-on-a-different-topic) makes gossipsub drop a different message as a duplicate with no fallback to the full id, so it's a gossip-suppression vector that the framed full msgId does not close (the fast path short-circuits before it). fastMsgIdFn is optional; removing it leaves dedup resting solely on the cryptographic, topic-framed msgIdFn (SHA-256). Also removes the now-unused xxhash machinery from encoding.ts. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
No longer used after removing fastMsgIdFn. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PhilWindle
deleted the
phil/a-1256-p2pgossipsub-unframed-topicdata-msgid-lets-arbitrary-topics
branch
June 22, 2026 15:53
rangozd
pushed a commit
to rangozd/aztec-packages
that referenced
this pull request
Aug 5, 2026
BEGIN_COMMIT_OVERRIDE fix(p2p): re-seed discovery from persisted peer ENRs after restart (AztecProtocol#24169) docs(e2e): annotate e2e tests with setup/category notes (AztecProtocol#24191) chore: merge v5-next into merge-train/spartan-v5 (raw, conflict markers) (AztecProtocol#24221) fix(archiver): index zero-field logs under empty tag instead of throwing (A-1253) (AztecProtocol#24212) fix(prover-node): report awaiting-root and publishing-proof phases in EpochSession (A-1212) (AztecProtocol#24216) fix(p2p): bound declared contract-class bytecode length before allocating (A-1258) (AztecProtocol#24213) fix(p2p): frame gossipsub msgId and restrict allowedTopics (A-1256) (AztecProtocol#24214) chore: merge v5-next into merge-train/spartan-v5 (AztecProtocol#24226) fix(p2p): guard ENR address parsing against malformed TCP fields (A-1255) (AztecProtocol#24215) END_COMMIT_OVERRIDE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes A-1256.
Problem
The gossipsub full message id was
SHA256(topic || data)[0..20]with no framing between the topic string and the message bytes, andLibP2PServiceset noallowedTopics. Raw concatenation isn't injective: for a real message(T, D), a peer can craftT' = T + D[0],D' = D[1:]soT' || D'is byte-identical toT || D→ same msgId. ChainSafe gossipsub transforms the arbitrary-topic message and inserts that id intoseenCachebefore the subscription check (it isn't delivered to us, since we're not subscribed toT'). When the genuine proposal/attestation arrives onT, gossipsub drops it as a duplicate before application validation, peer scoring, or handling — suppressing a time-sensitive consensus message within the slot.Fix (defense in depth — either alone breaks the attack)
uint32be(topicLen) || topic || data(encoding.ts). The topic length pins the(topic, data)boundary, so a boundary-shifted pair no longer collides. (getMsgIdFn's parameter is narrowed toPick<Message, 'topic' | 'data'>— the only fields it reads — which stays assignable to gossipsub'smsgIdFnslot.)allowedTopics(libp2p_service.ts) to the subscribed Aztec topic strings. Verified against the installed gossipsub: the allowlist is enforced inhandleReceivedRpcbeforehandleReceivedMessage/seenCache.put, so an unsubscribed-topic message is dropped before transform / msgId / seenCache.Test
encoding.test.ts: builds a realP2PMessage.toMessageData()buffer (confirmingdata[0] === 0x00), constructs the shifted(T', D'), and asserts the two msg ids now differ (they collided before the framing change); plus a determinism check.Compatibility
msgIdis computed locally for dedup; changing the function doesn't change any on-wire format. During a rolling upgrade, mixed nodes briefly compute different ids for the same message (minor IHAVE/IWANT inefficiency), with no correctness impact.