<p>It refers to the CompactSize encoding frequently used in the Bitcoin P2P protocol for integers (in particular, lengths of vectors). It's also called VarInt in some other protocol descriptions. Since it predates the BIP process (was part of the original 2009 Bitcoin protocol), it is not described in any BIP.</p>
<p>It encodes integers between 0 and 252 as a single byte, though bigger integers as 3, 5, or 9 bytes.</p>
<p>It is not in BIP340 because it has nothing to do with the digital signature scheme.</p>

CC BY-SA 4.0
2022-07-23T14:14:34.913Z
2022-07-23T14:25:19.323Z
2022-07-23T14:25:19.323Z
Pieter Wuille
<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki" rel="nofollow noreferrer">BIP341</a> uses a function named <em>compact_size</em> in two instances: when constructing the tapleaf hash, it takes as input the size of the spending script, and when constructing the signature message, if the annex is present, it takes as input the size of the annex.</p>
<p>However, unlike other functions in the document which are mostly defined in <a href="https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki" rel="nofollow noreferrer">BIP340</a>, I can't find the definition for this one in either of them, so what is it?</p>

<taproot><bip>
What is the compact_size function used in BIP341?
Vojtěch Strnad
# What is the compact_size function used in BIP341?

(Asked by: username_0 on 2022-07-23)

[BIP341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki) uses a function named *compact\_size* in two instances: when constructing the tapleaf hash, it takes as input the size of the spending script, and when constructing the signature message, if the annex is present, it takes as input the size of the annex.

However, unlike other functions in the document which are mostly defined in [BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki), I can't find the definition for this one in either of them, so what is it?

**Tags:** taproot, bip


---

## 1 answers

### Answer by username_1 on 2022-07-23. Score: 4 | Accepted answer

It refers to the CompactSize encoding frequently used in the Bitcoin P2P protocol for integers (in particular, lengths of vectors). It's also called VarInt in some other protocol descriptions. Since it predates the BIP process (was part of the original 2009 Bitcoin protocol), it is not described in any BIP.

It encodes integers between 0 and 252 as a single byte, though bigger integers as 3, 5, or 9 bytes.

It is not in BIP340 because it has nothing to do with the digital signature scheme.


---

