fix(p2p): frame gossipsub msgId and restrict allowedTopics (A-1256)#24214
Draft
PhilWindle wants to merge 1 commit into
Draft
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>
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.