Skip to content

Commit 8c731c5

Browse files
committed
Harding feedback on script
1 parent fb1ac7a commit 8c731c5

13 files changed

Lines changed: 161 additions & 153 deletions

File tree

ch06.asciidoc

Lines changed: 116 additions & 108 deletions
Large diffs are not rendered by default.

ch08.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It is possible to "split" a key into multiple private keys and use an interactiv
1818

1919
=== Bare Multisig
2020

21-
Bare Multisig was the first attempt at creating a transaction that could be signed by multiple parties. To understand Bare Multisig, one must first understand the OP_CHECKMULTISIG operator. As discussed in Chapter 6, SCRIPT has a lot of different OP codes. OP_CHECKMULTISIG is one of them at `ae`. The operator consumes a lot of elements from the stack and returns whether or not a certain number of signatures are valid for this transaction.
21+
Bare Multisig was the first attempt at creating a transaction that could be signed by multiple parties. To understand Bare Multisig, one must first understand the OP_CHECKMULTISIG operator. As discussed in Chapter 6, SCRIPT has a lot of different opcodes. OP_CHECKMULTISIG is one of them at `ae`. The operator consumes a lot of elements from the stack and returns whether or not a certain number of signatures are valid for this transaction.
2222

2323
The transaction is called "bare" multisig because it's a really long ScriptPubKey. Here's what a ScriptPubKey for a 1-of-2 multisig looks like.
2424

@@ -67,7 +67,7 @@ The elements consumed by OP_CHECKMULTISIG are supposed to be:
6767
6868
m, m different signatures, n, n different pubkeys.
6969
70-
The number of elements consumed should be 2 (m and n themselves) + m (signatures) + n (pubkeys). Unfortunately, the OP code actually consumes 1 more element than the m+n+2 that it's supposed to. OP_CHECKMULTISIG consumes m+n+3, so the extra element is added in order to not cause a failure. The OP code does nothing with that extra element and that extra element can be anything.
70+
The number of elements consumed should be 2 (m and n themselves) + m (signatures) + n (pubkeys). Unfortunately, the opcode actually consumes 1 more element than the m+n+2 that it's supposed to. OP_CHECKMULTISIG consumes m+n+3, so the extra element is added in order to not cause a failure. The opcode does nothing with that extra element and that extra element can be anything.
7171
7272
As a way to combat malleabilty, however, most nodes on the Bitcoin network will not relay the transaction unless that extra element is OP_0. Note that if we had m+n+2 elements, that OP_CHECKMULTISIG will just fail as there are not enough elements to be consumed and the transaction will be invalid.
7373
====

code-ch05/script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def parse(cls, s):
6969
instructions.append(s.read(data_length))
7070
count += data_length + 2
7171
else:
72-
# we have an op code. set the current byte to op_code
72+
# we have an opcode. set the current byte to op_code
7373
op_code = current_byte
7474
# add the op_code to the list of instructions
7575
instructions.append(op_code)
@@ -82,15 +82,15 @@ def raw_serialize(self):
8282
result = b''
8383
# go through each instruction
8484
for instruction in self.instructions:
85-
# if the instruction is an integer, it's an op code
85+
# if the instruction is an integer, it's an opcode
8686
if type(instruction) == int:
8787
# turn the instruction into a single byte integer using int_to_little_endian
8888
result += int_to_little_endian(instruction, 1)
8989
else:
9090
# otherwise, this is an element
9191
# get the length in bytes
9292
length = len(instruction)
93-
# for large lengths, we have to use a pushdata op code
93+
# for large lengths, we have to use a pushdata opcode
9494
if length < 75:
9595
# turn the length into a single byte integer
9696
result += int_to_little_endian(length, 1)
@@ -124,7 +124,7 @@ def evaluate(self, z):
124124
while len(instructions) > 0:
125125
instruction = instructions.pop(0)
126126
if type(instruction) == int:
127-
# do what the op code says
127+
# do what the opcode says
128128
operation = OP_CODE_FUNCTIONS[instruction]
129129
if instruction in (99, 100):
130130
# op_if/op_notif require the instructions array

code-ch06/Programming Blockchain Chapter 6.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"* a7 = OP_SHA1\n",
144144
"\n",
145145
"\n",
146-
"#### Hint: Use the Script.parse method and look up what various OP codes do here: \n",
146+
"#### Hint: Use the Script.parse method and look up what various opcodes do here: \n",
147147
"#### https://en.bitcoin.it/wiki/Script"
148148
]
149149
},

code-ch06/script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def parse(cls, s):
7272
instructions.append(s.read(data_length))
7373
count += data_length + 2
7474
else:
75-
# we have an op code. set the current byte to op_code
75+
# we have an opcode. set the current byte to op_code
7676
op_code = current_byte
7777
# add the op_code to the list of instructions
7878
instructions.append(op_code)
@@ -85,15 +85,15 @@ def raw_serialize(self):
8585
result = b''
8686
# go through each instruction
8787
for instruction in self.instructions:
88-
# if the instruction is an integer, it's an op code
88+
# if the instruction is an integer, it's an opcode
8989
if type(instruction) == int:
9090
# turn the instruction into a single byte integer using int_to_little_endian
9191
result += int_to_little_endian(instruction, 1)
9292
else:
9393
# otherwise, this is an element
9494
# get the length in bytes
9595
length = len(instruction)
96-
# for large lengths, we have to use a pushdata op code
96+
# for large lengths, we have to use a pushdata opcode
9797
if length < 75:
9898
# turn the length into a single byte integer
9999
result += int_to_little_endian(length, 1)
@@ -127,7 +127,7 @@ def evaluate(self, z):
127127
while len(instructions) > 0:
128128
instruction = instructions.pop(0)
129129
if type(instruction) == int:
130-
# do what the op code says
130+
# do what the opcode says
131131
operation = OP_CODE_FUNCTIONS[instruction]
132132
if instruction in (99, 100):
133133
# op_if/op_notif require the instructions array

code-ch07/script.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def parse(cls, s):
7777
instructions.append(s.read(data_length))
7878
count += data_length + 2
7979
else:
80-
# we have an op code. set the current byte to op_code
80+
# we have an opcode. set the current byte to op_code
8181
op_code = current_byte
8282
# add the op_code to the list of instructions
8383
instructions.append(op_code)
@@ -90,15 +90,15 @@ def raw_serialize(self):
9090
result = b''
9191
# go through each instruction
9292
for instruction in self.instructions:
93-
# if the instruction is an integer, it's an op code
93+
# if the instruction is an integer, it's an opcode
9494
if type(instruction) == int:
9595
# turn the instruction into a single byte integer using int_to_little_endian
9696
result += int_to_little_endian(instruction, 1)
9797
else:
9898
# otherwise, this is an element
9999
# get the length in bytes
100100
length = len(instruction)
101-
# for large lengths, we have to use a pushdata op code
101+
# for large lengths, we have to use a pushdata opcode
102102
if length < 75:
103103
# turn the length into a single byte integer
104104
result += int_to_little_endian(length, 1)
@@ -132,7 +132,7 @@ def evaluate(self, z):
132132
while len(instructions) > 0:
133133
instruction = instructions.pop(0)
134134
if type(instruction) == int:
135-
# do what the op code says
135+
# do what the opcode says
136136
operation = OP_CODE_FUNCTIONS[instruction]
137137
if instruction in (99, 100):
138138
# op_if/op_notif require the instructions array

code-ch08/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse(cls, s):
8585
instructions.append(s.read(data_length))
8686
count += data_length + 2
8787
else:
88-
# we have an op code. set the current byte to op_code
88+
# we have an opcode. set the current byte to op_code
8989
op_code = current_byte
9090
# add the op_code to the list of instructions
9191
instructions.append(op_code)
@@ -98,15 +98,15 @@ def raw_serialize(self):
9898
result = b''
9999
# go through each instruction
100100
for instruction in self.instructions:
101-
# if the instruction is an integer, it's an op code
101+
# if the instruction is an integer, it's an opcode
102102
if type(instruction) == int:
103103
# turn the instruction into a single byte integer using int_to_little_endian
104104
result += int_to_little_endian(instruction, 1)
105105
else:
106106
# otherwise, this is an element
107107
# get the length in bytes
108108
length = len(instruction)
109-
# for large lengths, we have to use a pushdata op code
109+
# for large lengths, we have to use a pushdata opcode
110110
if length < 75:
111111
# turn the length into a single byte integer
112112
result += int_to_little_endian(length, 1)
@@ -140,7 +140,7 @@ def evaluate(self, z):
140140
while len(instructions) > 0:
141141
instruction = instructions.pop(0)
142142
if type(instruction) == int:
143-
# do what the op code says
143+
# do what the opcode says
144144
operation = OP_CODE_FUNCTIONS[instruction]
145145
if instruction in (99, 100):
146146
# op_if/op_notif require the instructions array
@@ -168,7 +168,7 @@ def evaluate(self, z):
168168
if len(instructions) == 3 and instructions[0] == 0xa9 \
169169
and type(instructions[1]) == bytes and len(instructions[1]) == 20 \
170170
and instructions[2] == 0x87:
171-
# we execute the next three op codes
171+
# we execute the next three opcodes
172172
instructions.pop()
173173
h160 = instructions.pop()
174174
instructions.pop()

code-ch09/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse(cls, s):
8585
instructions.append(s.read(data_length))
8686
count += data_length + 2
8787
else:
88-
# we have an op code. set the current byte to op_code
88+
# we have an opcode. set the current byte to op_code
8989
op_code = current_byte
9090
# add the op_code to the list of instructions
9191
instructions.append(op_code)
@@ -98,15 +98,15 @@ def raw_serialize(self):
9898
result = b''
9999
# go through each instruction
100100
for instruction in self.instructions:
101-
# if the instruction is an integer, it's an op code
101+
# if the instruction is an integer, it's an opcode
102102
if type(instruction) == int:
103103
# turn the instruction into a single byte integer using int_to_little_endian
104104
result += int_to_little_endian(instruction, 1)
105105
else:
106106
# otherwise, this is an element
107107
# get the length in bytes
108108
length = len(instruction)
109-
# for large lengths, we have to use a pushdata op code
109+
# for large lengths, we have to use a pushdata opcode
110110
if length < 75:
111111
# turn the length into a single byte integer
112112
result += int_to_little_endian(length, 1)
@@ -140,7 +140,7 @@ def evaluate(self, z):
140140
while len(instructions) > 0:
141141
instruction = instructions.pop(0)
142142
if type(instruction) == int:
143-
# do what the op code says
143+
# do what the opcode says
144144
operation = OP_CODE_FUNCTIONS[instruction]
145145
if instruction in (99, 100):
146146
# op_if/op_notif require the instructions array
@@ -168,7 +168,7 @@ def evaluate(self, z):
168168
if len(instructions) == 3 and instructions[0] == 0xa9 \
169169
and type(instructions[1]) == bytes and len(instructions[1]) == 20 \
170170
and instructions[2] == 0x87:
171-
# we execute the next three op codes
171+
# we execute the next three opcodes
172172
instructions.pop()
173173
h160 = instructions.pop()
174174
instructions.pop()

code-ch10/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse(cls, s):
8585
instructions.append(s.read(data_length))
8686
count += data_length + 2
8787
else:
88-
# we have an op code. set the current byte to op_code
88+
# we have an opcode. set the current byte to op_code
8989
op_code = current_byte
9090
# add the op_code to the list of instructions
9191
instructions.append(op_code)
@@ -98,15 +98,15 @@ def raw_serialize(self):
9898
result = b''
9999
# go through each instruction
100100
for instruction in self.instructions:
101-
# if the instruction is an integer, it's an op code
101+
# if the instruction is an integer, it's an opcode
102102
if type(instruction) == int:
103103
# turn the instruction into a single byte integer using int_to_little_endian
104104
result += int_to_little_endian(instruction, 1)
105105
else:
106106
# otherwise, this is an element
107107
# get the length in bytes
108108
length = len(instruction)
109-
# for large lengths, we have to use a pushdata op code
109+
# for large lengths, we have to use a pushdata opcode
110110
if length < 75:
111111
# turn the length into a single byte integer
112112
result += int_to_little_endian(length, 1)
@@ -140,7 +140,7 @@ def evaluate(self, z):
140140
while len(instructions) > 0:
141141
instruction = instructions.pop(0)
142142
if type(instruction) == int:
143-
# do what the op code says
143+
# do what the opcode says
144144
operation = OP_CODE_FUNCTIONS[instruction]
145145
if instruction in (99, 100):
146146
# op_if/op_notif require the instructions array
@@ -168,7 +168,7 @@ def evaluate(self, z):
168168
if len(instructions) == 3 and instructions[0] == 0xa9 \
169169
and type(instructions[1]) == bytes and len(instructions[1]) == 20 \
170170
and instructions[2] == 0x87:
171-
# we execute the next three op codes
171+
# we execute the next three opcodes
172172
instructions.pop()
173173
h160 = instructions.pop()
174174
instructions.pop()

code-ch11/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def parse(cls, s):
8585
instructions.append(s.read(data_length))
8686
count += data_length + 2
8787
else:
88-
# we have an op code. set the current byte to op_code
88+
# we have an opcode. set the current byte to op_code
8989
op_code = current_byte
9090
# add the op_code to the list of instructions
9191
instructions.append(op_code)
@@ -98,15 +98,15 @@ def raw_serialize(self):
9898
result = b''
9999
# go through each instruction
100100
for instruction in self.instructions:
101-
# if the instruction is an integer, it's an op code
101+
# if the instruction is an integer, it's an opcode
102102
if type(instruction) == int:
103103
# turn the instruction into a single byte integer using int_to_little_endian
104104
result += int_to_little_endian(instruction, 1)
105105
else:
106106
# otherwise, this is an element
107107
# get the length in bytes
108108
length = len(instruction)
109-
# for large lengths, we have to use a pushdata op code
109+
# for large lengths, we have to use a pushdata opcode
110110
if length < 75:
111111
# turn the length into a single byte integer
112112
result += int_to_little_endian(length, 1)
@@ -140,7 +140,7 @@ def evaluate(self, z):
140140
while len(instructions) > 0:
141141
instruction = instructions.pop(0)
142142
if type(instruction) == int:
143-
# do what the op code says
143+
# do what the opcode says
144144
operation = OP_CODE_FUNCTIONS[instruction]
145145
if instruction in (99, 100):
146146
# op_if/op_notif require the instructions array
@@ -168,7 +168,7 @@ def evaluate(self, z):
168168
if len(instructions) == 3 and instructions[0] == 0xa9 \
169169
and type(instructions[1]) == bytes and len(instructions[1]) == 20 \
170170
and instructions[2] == 0x87:
171-
# we execute the next three op codes
171+
# we execute the next three opcodes
172172
instructions.pop()
173173
h160 = instructions.pop()
174174
instructions.pop()

0 commit comments

Comments
 (0)