Skip to content

Commit

Permalink
fix: update the gossip message size checks
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Dec 6, 2024
1 parent cd1211f commit bfece62
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/beacon-node/src/network/gossip/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function msgIdFn(gossipTopicCache: GossipTopicCache, msg: Message): Uint8
export class DataTransformSnappy implements DataTransform {
constructor(
private readonly gossipTopicCache: GossipTopicCache,
/** size of the compressed message */
private readonly maxSizePerMessage: number
) {}

Expand All @@ -79,7 +80,13 @@ export class DataTransformSnappy implements DataTransform {
* - `outboundTransform()`: compress snappy payload
*/
inboundTransform(topicStr: string, data: Uint8Array): Uint8Array {
const uncompressedData = uncompress(data, this.maxSizePerMessage);
if (data.length > this.maxSizePerMessage) {
throw Error(`ssz_snappy data length ${data.length} > maxSizePerMessage`);
}

// snappy compression efficiency is around ~36% so the max uncompressed bound
// should be 3X
const uncompressedData = uncompress(data, 3 * this.maxSizePerMessage);

// check uncompressed data length before we extract beacon block root, slot or
// attestation data at later steps
Expand Down

0 comments on commit bfece62

Please sign in to comment.