<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bitcoinsv.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Benjamin+Watts</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bitcoinsv.io/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Benjamin+Watts"/>
	<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php/Special:Contributions/Benjamin_Watts"/>
	<updated>2026-05-27T21:44:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=VarInt&amp;diff=3118</id>
		<title>VarInt</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=VarInt&amp;diff=3118"/>
		<updated>2023-10-25T13:33:55Z</updated>

		<summary type="html">&lt;p&gt;Benjamin Watts: Changed example hex values from big endian to little endian.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A VarInt or &amp;quot;Variable Integer&amp;quot; is an [[integer]] format used widely in Bitcoin to indicate the lengths of fields within transaction, block and peer-to-peer network data.&lt;br /&gt;
&lt;br /&gt;
A VarInt is a variable length field 1, 3, 5 or 9 bytes in length dependent on the size of the object being defined. The VarInt format is used as it is space efficient over simply using an 8-byte field where variable length objects are used. VarInt values are almost always represented in little endian. &lt;br /&gt;
&lt;br /&gt;
==Using VarInts==&lt;br /&gt;
&lt;br /&gt;
When expressing an integer between zero and &amp;lt;code&amp;gt;0xFC&amp;lt;/code&amp;gt; (252) the value itself can be used and expressed in uint8_t format.&lt;br /&gt;
&lt;br /&gt;
When expressing an integer value greater than &amp;lt;code&amp;gt;0xFC&amp;lt;/code&amp;gt; but less than or equal to &amp;lt;code&amp;gt;0xFFFF&amp;lt;/code&amp;gt; (65,535), the varint is &amp;lt;code&amp;gt;0xFDXXXX&amp;lt;/code&amp;gt; where XXXX represents the two byte integer in uint16_t format.&lt;br /&gt;
&lt;br /&gt;
When expressing an integer value greater than &amp;lt;code&amp;gt;0xFFFF&amp;lt;/code&amp;gt; but less than or equal to &amp;lt;code&amp;gt;0xFFFFFFFF&amp;lt;/code&amp;gt; (4,294,967,295), the varint is &amp;lt;code&amp;gt;0xFEXXXXXXXX&amp;lt;/code&amp;gt; where XXXXXXXX represents the 4 byte integer in uint32_t format.&lt;br /&gt;
&lt;br /&gt;
When expressing an integer value greater than &amp;lt;code&amp;gt;0xFFFFFFFF&amp;lt;/code&amp;gt; but less than or equal to &amp;lt;code&amp;gt;0xFFFFFFFFFFFFFFFF&amp;lt;/code&amp;gt; (18,446,744,073,709,551,615), the varint is &amp;lt;code&amp;gt;0xFFXXXXXXXXXXXXXXXX&amp;lt;/code&amp;gt; where XXXXXXXXXXXXXXXX represents the 8 byte integer in uint64_t format.&lt;br /&gt;
&lt;br /&gt;
===References with Examples===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Value Range &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; Example Value&lt;br /&gt;
! Size Range &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; Example Size&lt;br /&gt;
! VarInt Format &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; Example VarInt&lt;br /&gt;
|-&lt;br /&gt;
| 0 &amp;lt;= Value &amp;lt;= 252 (&amp;lt;code&amp;gt;0xFC&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 187 (&amp;lt;code&amp;gt;0xBB&amp;lt;/code&amp;gt;)&lt;br /&gt;
| 1 byte &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 1 byte&lt;br /&gt;
| uint8_t &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xBB&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 253 &amp;lt;= Value &amp;lt;= 65,535 (&amp;lt;code&amp;gt;0xFFFF&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 255 (&amp;lt;code&amp;gt;0xFF&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 13,337 (&amp;lt;code&amp;gt;0x3419&amp;lt;/code&amp;gt;)&lt;br /&gt;
| 1 - 2 bytes &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 1 byte but greater than &amp;lt;code&amp;gt;0xFC&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 2 bytes&lt;br /&gt;
| 0xFD + number as uint16_t &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFDFF00&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFD1934&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 65,536 &amp;lt;= Value &amp;lt;= ‭4,294,967,295‬ (&amp;lt;code&amp;gt;0xFFFFFFFF&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 14,435,729 (&amp;lt;code&amp;gt;0xDC4591&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 134,250,981 (&amp;lt;code&amp;gt;0x80081E5&amp;lt;/code&amp;gt;)&lt;br /&gt;
| 3 - 4 bytes &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 3 bytes &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 4 bytes&lt;br /&gt;
| 0xFE + number as uint32_t  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFE9145DC00&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFEE5810008&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4,294,967,296 &amp;lt;= value &amp;lt;= ‭18,446,744,073,709,551,615 (&amp;lt;code&amp;gt;0xFFFFFFFFFFFFFFFF&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g.198,849,843,832,919 (&amp;lt;code&amp;gt;0xB4DA564E2857&amp;lt;/code&amp;gt;) &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; e.g. 5,473,425,651,754,713,432 (&amp;lt;code&amp;gt;0x‭4BF583A17D59C158‬&amp;lt;/code&amp;gt;)&lt;br /&gt;
| 5 - 8 bytes &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 6 bytes &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; 8 bytes&lt;br /&gt;
| 0xFF + number as uint64_t  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFF57284E56DAB40000&amp;lt;/code&amp;gt;  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; &amp;lt;code&amp;gt;0xFF58C1597DA183F54B&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Benjamin Watts</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.bitcoinsv.io/index.php?title=ECDSA_Example&amp;diff=3097</id>
		<title>ECDSA Example</title>
		<link rel="alternate" type="text/html" href="https://wiki.bitcoinsv.io/index.php?title=ECDSA_Example&amp;diff=3097"/>
		<updated>2023-04-05T15:40:29Z</updated>

		<summary type="html">&lt;p&gt;Benjamin Watts: Created page with &amp;quot;This page will walk you through a demonstration of the Elliptic Curve Digital Signature Algorithm using secp256k1.  ==ECDSA Signing Algorithm in Python== {| class=&amp;quot;wikitable&amp;quot;...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will walk you through a demonstration of the Elliptic Curve Digital Signature Algorithm using secp256k1.&lt;br /&gt;
&lt;br /&gt;
==ECDSA Signing Algorithm in Python==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Parameter&lt;br /&gt;
! Value&lt;br /&gt;
! Descrption&lt;br /&gt;
|-&lt;br /&gt;
|p&lt;br /&gt;
|115792089237316195423570985008687907853269984665640564039457584007908834671663&lt;br /&gt;
|The elliptic curve is defined over this value. P defines the size of the finite field.  &lt;br /&gt;
|-&lt;br /&gt;
|n&lt;br /&gt;
|115792089237316195423570985008687907852837564279074904382605163141518161494337&lt;br /&gt;
|This value is the order of the group. It defines the number of possible elliptic curve points given the generator point. &lt;br /&gt;
|-&lt;br /&gt;
|Gx&lt;br /&gt;
|55066263022277343669578718895168534326250603453777594175500187360389116729240&lt;br /&gt;
|This value is the x coordinate for the generator point. &lt;br /&gt;
|-&lt;br /&gt;
|Gy&lt;br /&gt;
|32670510020758816978083085130507043184471273380659243275938904335757337482424&lt;br /&gt;
|This value is the y coordinate for the generator point. &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 def ecdsa_sig(m, d):      # ecdsa_sig function takes a message and private key as an integer&lt;br /&gt;
     k = random.randint(1, n - 1)     # Create the ephemeral key, k&lt;br /&gt;
     m1 = hashlib.sha256()     # Create a hash object&lt;br /&gt;
     m1.update(m)&lt;br /&gt;
     hashed_message = m1.hexdigest()     # Hash the message&lt;br /&gt;
     &lt;br /&gt;
     eph_point = Point_Multiplication(Gx, Gy, k, p)     # Calculate ephemeral point using k&lt;br /&gt;
     eph_point_x = eph_point[0]&lt;br /&gt;
 &lt;br /&gt;
     s_temp = (int(hashed_message, 16) + (d * eph_point_x))&lt;br /&gt;
    &lt;br /&gt;
     s = (Mod_Inv(k, n) * (s_temp)) % n     # Create s value&lt;br /&gt;
     r = eph_point_x     # Create r value&lt;br /&gt;
    &lt;br /&gt;
     print(&amp;quot;Signing Complete&amp;quot;)&lt;br /&gt;
     print(&amp;quot;Eph Point x: &amp;quot; + str(eph_point[0]))&lt;br /&gt;
     print(&amp;quot;Eph point y: &amp;quot; + str(eph_point[1]))&lt;br /&gt;
     print(&amp;quot; &amp;quot;)&lt;br /&gt;
     print(&amp;quot;R: &amp;quot; + str(r))&lt;br /&gt;
     print(&amp;quot;S: &amp;quot; + str(s))&lt;br /&gt;
    &lt;br /&gt;
     &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
     1. 0x30 indicates start of DER&lt;br /&gt;
     2. One byte to encode length of data&lt;br /&gt;
     3. 0x02 header byte indicating integer&lt;br /&gt;
     4. One byte to encode length of r&lt;br /&gt;
     5. The r value as big-endian integer&lt;br /&gt;
     6. 0x02 header byte to indicate integer&lt;br /&gt;
     7. One byte to include length of the following s value&lt;br /&gt;
     8. The s value as big-endian integer&lt;br /&gt;
     &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
     # DER Format Code Begin&lt;br /&gt;
     #------------------------------------------------------------&lt;br /&gt;
     r_hex = &amp;quot;00&amp;quot;&lt;br /&gt;
     r_hex = r_hex + str(hex(r)[2:])&lt;br /&gt;
     s_hex = str(hex(s)[2:])&lt;br /&gt;
    &lt;br /&gt;
     serial_1 = &amp;quot;30&amp;quot;&lt;br /&gt;
     serial_2 = hex(int(((get_length(r_hex) / 2) + (get_length(s_hex) / 2) + 4)))[2:]&lt;br /&gt;
     serial_3 = &amp;quot;02&amp;quot;&lt;br /&gt;
     serial_4 = hex(int(get_length(hex(r)[2:]) / 2) + 1)[2:]&lt;br /&gt;
     serial_5 = &amp;quot;00&amp;quot; + hex(r)[2:]&lt;br /&gt;
     serial_6 = &amp;quot;02&amp;quot;&lt;br /&gt;
     serial_7 = hex(int(get_length(hex(r)[2:]) / 2))[2:]&lt;br /&gt;
     serial_8 = hex(s)[2:]&lt;br /&gt;
     &lt;br /&gt;
     sig = serial_1 + str(serial_2) + serial_3 + str(serial_4)&lt;br /&gt;
     sig = sig + str(serial_5) + serial_6 + str(serial_7) + str(serial_8)&lt;br /&gt;
     sig = sig + str(binascii.hexlify(HASH_TYPE))[2:4]&lt;br /&gt;
    &lt;br /&gt;
     sig = bytes.fromhex(sig)&lt;br /&gt;
    &lt;br /&gt;
     return sig&lt;/div&gt;</summary>
		<author><name>Benjamin Watts</name></author>
		
	</entry>
</feed>