diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 28e42f28..1a33af0d 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -132,8 +132,11 @@ CompactBlock.prototype.fromRaw = function fromRaw(data) { this.totalTX += idCount; - for (let i = 0; i < idCount; i++) - this.ids.push(br.readU32() + br.readU16() * 0x100000000); + for (let i = 0; i < idCount; i++) { + const lo = br.readU32(); + const hi = br.readU16(); + this.ids.push(hi * 0x100000000 + lo); + } const txCount = br.readVarint(); @@ -259,8 +262,8 @@ CompactBlock.prototype.writeRaw = function writeRaw(bw, witness) { for (const id of this.ids) { const lo = id % 0x100000000; - let hi = (id - lo) / 0x100000000; - hi &= 0xffff; + const hi = (id - lo) / 0x100000000; + assert(hi <= 0xffff); bw.writeU32(lo); bw.writeU16(hi); }