Skip to content

Commit 1aa1a63

Browse files
committed
errata 2019.04.19
1 parent b4fcf5d commit 1aa1a63

File tree

11 files changed

+31
-31
lines changed

11 files changed

+31
-31
lines changed

ch02.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ From earlier, we know that:
398398
399399
++++
400400
<ul class="simplelist">
401-
<li><em>x</em><sup>3</sup> – <em>s</em><sup>2</sup><em>x</em><sup>2</sup> + (<em>a</em> + 2<em>s</em><sup>2</sup><em>x</em><sub>1</sub> – 2<em>sy</em>~1~)<em>x</em> + <em>b</em> – <em>s</em><sup>2</sup><em>x</em><sub>1</sub><sup>2</sup> + 2<em>sx</em>~1~<em>y</em><sub>1</sub> – <em>y</em><sub>1</sub><sup>2</sup> = 0</li>
401+
<li><em>x</em><sup>3</sup> – <em>s</em><sup>2</sup><em>x</em><sup>2</sup> + (<em>a</em> + 2<em>s</em><sup>2</sup><em>x</em><sub>1</sub> – 2<em>sy</em>~1~)<em>x</em> + <em>b</em> – <em>s</em><sup>2</sup><em>x</em><sub>1</sub><sup>2</sup> + 2<em>sx</em><sub>1</sub><em>y</em><sub>1</sub> – <em>y</em><sub>1</sub><sup>2</sup> = 0</li>
402402
</ul>
403403
++++
404404

ch10.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The timestamp field is 8 bytes (as opposed to 4 bytes in the block header) and i
7474

7575
IP addresses can be IPv6, IPv4, or OnionCat (a mapping of TOR's `.onion` addresses to IPv6).
7676
If IPv4, the first 12 bytes are `00000000000000000000ffff` and the last 4 bytes are the IP.
77-
The port is 2 bytes in little-endian. The default on mainnet is 8333, which maps to `8d20` in little-endian hex.
77+
The port is 2 bytes in big-endian. The default on mainnet is 8333, which maps to `208d` in big-endian hex.
7878

7979
A nonce is a number used by a node to detect a connection to itself.
8080
The user agent identifies the software being run.

code-ch02/Chapter2.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"source": [
169169
"### Exercise 6\n",
170170
"\n",
171-
"For the curve \\\\(y^{2}\\\\)=\\\\(x^{3}\\\\)+5x+7, what is (2,5) + (-1,-1)?"
171+
"For the curve \\\\(y^{2}\\\\)=\\\\(x^{3}\\\\)+5x+7, what is (-1,-1) + (-1,-1)?"
172172
]
173173
},
174174
{
@@ -183,8 +183,8 @@
183183
"\n",
184184
"a = 5\n",
185185
"b = 7\n",
186-
"x1, y1 = -1, 1\n",
187-
"# (-1,1) + (-1,1)"
186+
"x1, y1 = -1, -1\n",
187+
"# (-1,-1) + (-1,-1)"
188188
]
189189
},
190190
{

code-ch02/answers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
For the curve __y__^2^ = __x__^3^ + 5__x__ + 7, what is (–1,–1) + (–1,–1)?
4646
# end::exercise6[]
4747
# tag::answer6[]
48-
>>> a, x1, y1 = 5, -1, 1
48+
>>> a, x1, y1 = 5, -1, -1
4949
>>> s = (3 * x1**2 + a) / (2 * y1)
5050
>>> x3 = s**2 - 2*x1
5151
>>> y3 = s*(x1-x3)-y1
5252
>>> print(x3,y3)
53-
18.0 -77.0
53+
18.0 77.0
5454
5555
# end::answer6[]
5656
'''

code-ch02/jupyter.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ from ecc import Point
3232

3333
a = 5
3434
b = 7
35-
x1, y1 = -1, 1
36-
# (-1,1) + (-1,1)
35+
x1, y1 = -1, -1
36+
# (-1,-1) + (-1,-1)
3737
---
3838
exercise7:ecc:PointTest:test_add2

code-ch10/answers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# tag::answer2[]
1212
>>> from network import NetworkEnvelope
1313
>>> from io import BytesIO
14-
>>> message_hex = `f9beb4d976657261636b000000000000000000005df6e0e2`
14+
>>> message_hex = 'f9beb4d976657261636b000000000000000000005df6e0e2'
1515
>>> stream = BytesIO(bytes.fromhex(message_hex))
1616
>>> envelope = NetworkEnvelope.parse(stream)
1717
>>> print(envelope.command)
@@ -118,10 +118,10 @@ def serialize(self):
118118
result += int_to_little_endian(self.timestamp, 8)
119119
result += int_to_little_endian(self.receiver_services, 8)
120120
result += b'\x00' * 10 + b'\xff\xff' + self.receiver_ip
121-
result += int_to_little_endian(self.receiver_port, 2)
121+
result += self.receiver_port.to_bytes(2, 'big')
122122
result += int_to_little_endian(self.sender_services, 8)
123123
result += b'\x00' * 10 + b'\xff\xff' + self.sender_ip
124-
result += int_to_little_endian(self.sender_port, 2)
124+
result += self.sender_port.to_bytes(2, 'big')
125125
result += self.nonce
126126
result += encode_varint(len(self.user_agent))
127127
result += self.user_agent

code-ch10/network.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ def serialize(self):
138138
# timestamp is 8 bytes little endian
139139
# receiver services is 8 bytes little endian
140140
# IPV4 is 10 00 bytes and 2 ff bytes then receiver ip
141-
# receiver port is 2 bytes, little endian should be 0
141+
# receiver port is 2 bytes, big endian
142142
# sender services is 8 bytes little endian
143143
# IPV4 is 10 00 bytes and 2 ff bytes then sender ip
144-
# sender port is 2 bytes, little endian should be 0
144+
# sender port is 2 bytes, big endian
145145
# nonce should be 8 bytes
146146
# useragent is a variable string, so varint first
147147
# latest block is 4 bytes little endian
@@ -153,7 +153,7 @@ class VersionMessageTest(TestCase):
153153

154154
def test_serialize(self):
155155
v = VersionMessage(timestamp=0, nonce=b'\x00' * 8)
156-
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff000000008d20000000000000000000000000000000000000ffff000000008d200000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
156+
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff00000000208d000000000000000000000000000000000000ffff00000000208d0000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
157157

158158

159159
# tag::source3[]

code-ch11/network.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ def serialize(self):
152152
result += int_to_little_endian(self.receiver_services, 8)
153153
# IPV4 is 10 00 bytes and 2 ff bytes then receiver ip
154154
result += b'\x00' * 10 + b'\xff\xff' + self.receiver_ip
155-
# receiver port is 2 bytes, little endian should be 0
156-
result += int_to_little_endian(self.receiver_port, 2)
155+
# receiver port is 2 bytes, big endian
156+
result += self.receiver_port.to_bytes(2, 'big')
157157
# sender services is 8 bytes little endian
158158
result += int_to_little_endian(self.sender_services, 8)
159159
# IPV4 is 10 00 bytes and 2 ff bytes then sender ip
160160
result += b'\x00' * 10 + b'\xff\xff' + self.sender_ip
161-
# sender port is 2 bytes, little endian should be 0
162-
result += int_to_little_endian(self.sender_port, 2)
161+
# sender port is 2 bytes, big endian
162+
result += self.sender_port.to_bytes(2, 'big')
163163
# nonce should be 8 bytes
164164
result += self.nonce
165165
# useragent is a variable string, so varint first
@@ -179,7 +179,7 @@ class VersionMessageTest(TestCase):
179179

180180
def test_serialize(self):
181181
v = VersionMessage(timestamp=0, nonce=b'\x00' * 8)
182-
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff000000008d20000000000000000000000000000000000000ffff000000008d200000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
182+
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff00000000208d000000000000000000000000000000000000ffff00000000208d0000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
183183

184184

185185
class VerAckMessage:

code-ch12/network.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def serialize(self):
156156
result += int_to_little_endian(self.receiver_services, 8)
157157
# IPV4 is 10 00 bytes and 2 ff bytes then receiver ip
158158
result += b'\x00' * 10 + b'\xff\xff' + self.receiver_ip
159-
# receiver port is 2 bytes, little endian should be 0
160-
result += int_to_little_endian(self.receiver_port, 2)
159+
# receiver port is 2 bytes, big endian
160+
result += self.receiver_port.to_bytes(2, 'big')
161161
# sender services is 8 bytes little endian
162162
result += int_to_little_endian(self.sender_services, 8)
163163
# IPV4 is 10 00 bytes and 2 ff bytes then sender ip
164164
result += b'\x00' * 10 + b'\xff\xff' + self.sender_ip
165-
# sender port is 2 bytes, little endian should be 0
166-
result += int_to_little_endian(self.sender_port, 2)
165+
# sender port is 2 bytes, big endian
166+
result += self.sender_port.to_bytes(2, 'big')
167167
# nonce should be 8 bytes
168168
result += self.nonce
169169
# useragent is a variable string, so varint first
@@ -183,7 +183,7 @@ class VersionMessageTest(TestCase):
183183

184184
def test_serialize(self):
185185
v = VersionMessage(timestamp=0, nonce=b'\x00' * 8)
186-
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff000000008d20000000000000000000000000000000000000ffff000000008d200000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
186+
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff00000000208d000000000000000000000000000000000000ffff00000000208d0000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
187187

188188

189189
class VerAckMessage:

code-ch13/network.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ def serialize(self):
156156
result += int_to_little_endian(self.receiver_services, 8)
157157
# IPV4 is 10 00 bytes and 2 ff bytes then receiver ip
158158
result += b'\x00' * 10 + b'\xff\xff' + self.receiver_ip
159-
# receiver port is 2 bytes, little endian should be 0
160-
result += int_to_little_endian(self.receiver_port, 2)
159+
# receiver port is 2 bytes, big endian
160+
result += self.receiver_port.to_bytes(2, 'big')
161161
# sender services is 8 bytes little endian
162162
result += int_to_little_endian(self.sender_services, 8)
163163
# IPV4 is 10 00 bytes and 2 ff bytes then sender ip
164164
result += b'\x00' * 10 + b'\xff\xff' + self.sender_ip
165-
# sender port is 2 bytes, little endian should be 0
166-
result += int_to_little_endian(self.sender_port, 2)
165+
# sender port is 2 bytes, big endian
166+
result += self.sender_port.to_bytes(2, 'big')
167167
# nonce should be 8 bytes
168168
result += self.nonce
169169
# useragent is a variable string, so varint first
@@ -183,7 +183,7 @@ class VersionMessageTest(TestCase):
183183

184184
def test_serialize(self):
185185
v = VersionMessage(timestamp=0, nonce=b'\x00' * 8)
186-
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff000000008d20000000000000000000000000000000000000ffff000000008d200000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
186+
self.assertEqual(v.serialize().hex(), '7f11010000000000000000000000000000000000000000000000000000000000000000000000ffff00000000208d000000000000000000000000000000000000ffff00000000208d0000000000000000182f70726f6772616d6d696e67626974636f696e3a302e312f0000000000')
187187

188188

189189
class VerAckMessage:

preface.asciidoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ $ cd programmingbitcoin
101101
+
102102
[source,bash]
103103
----
104-
$ pip install virtualenv
104+
$ pip install virtualenv --user
105105
----
106106

107107
. Install the requirements:

0 commit comments

Comments
 (0)