mirror of
https://github.com/bitcoin/bips.git
synced 2024-11-19 09:50:06 +01:00
[BIP-119] Use mediawiki syntax highlighting, add comment to spec
This commit is contained in:
parent
b1791c24aa
commit
c8c8e27c2c
@ -167,31 +167,40 @@ OP_CHECKTEMPLATEVERIFY as implemented in C++ in the context of Bitcoin Core can
|
|||||||
be seen in the reference implementation.
|
be seen in the reference implementation.
|
||||||
|
|
||||||
The execution of the opcode is as follows:
|
The execution of the opcode is as follows:
|
||||||
def execute_bip_119(self):
|
<source lang="python">
|
||||||
|
def execute_bip_119(self):
|
||||||
# Before soft-fork activation / failed activation
|
# Before soft-fork activation / failed activation
|
||||||
|
# continue to treat as NOP4
|
||||||
if not self.flags.script_verify_default_check_template_verify_hash:
|
if not self.flags.script_verify_default_check_template_verify_hash:
|
||||||
# Potentially set for node-local policy to discourage premature use
|
# Potentially set for node-local policy to discourage premature use
|
||||||
if self.flags.script_verify_discourage_upgradable_nops:
|
if self.flags.script_verify_discourage_upgradable_nops:
|
||||||
return self.errors_with(errors.script_err_discourage_upgradable_nops)
|
return self.errors_with(errors.script_err_discourage_upgradable_nops)
|
||||||
return self.return_as_nop()
|
return self.return_as_nop()
|
||||||
|
|
||||||
# CTV always requires at least one stack argument
|
# CTV always requires at least one stack argument
|
||||||
if len(self.stack) < 1:
|
if len(self.stack) < 1:
|
||||||
return self.errors_with(errors.script_err_invalid_stack_operation)
|
return self.errors_with(errors.script_err_invalid_stack_operation)
|
||||||
|
|
||||||
# CTV only verifies the hash against a 32 byte argument
|
# CTV only verifies the hash against a 32 byte argument
|
||||||
if len(self.stack[-1]) == 32:
|
if len(self.stack[-1]) == 32:
|
||||||
# Ensure the precomputed data required for anti-DoS is available,
|
# Ensure the precomputed data required for anti-DoS is available,
|
||||||
# or cache it on first use
|
# or cache it on first use
|
||||||
if self.context.precomputed_ctv_data == None:
|
if self.context.precomputed_ctv_data == None:
|
||||||
self.context.precomputed_ctv_data = self.context.tx.get_default_check_template_precomputed_data()
|
self.context.precomputed_ctv_data = self.context.tx.get_default_check_template_precomputed_data()
|
||||||
|
|
||||||
|
# If the hashes do not match, return error
|
||||||
if stack[-1] != self.context.tx.get_default_check_template_hash(self.context.nIn, self.context.precomputed_ctv_data)
|
if stack[-1] != self.context.tx.get_default_check_template_hash(self.context.nIn, self.context.precomputed_ctv_data)
|
||||||
return self.errors_with(errors.script_err_template_mismatch)
|
return self.errors_with(errors.script_err_template_mismatch)
|
||||||
|
|
||||||
return self.return_as_nop()
|
return self.return_as_nop()
|
||||||
|
|
||||||
# future upgrade can add semantics for this opcode with different length args
|
# future upgrade can add semantics for this opcode with different length args
|
||||||
# so discourage use when applicable
|
# so discourage use when applicable
|
||||||
if self.flags.script_verify_discourage_upgradable_nops:
|
if self.flags.script_verify_discourage_upgradable_nops:
|
||||||
return self.errors_with(errors.script_err_discourage_upgradable_nops)
|
return self.errors_with(errors.script_err_discourage_upgradable_nops)
|
||||||
else:
|
else:
|
||||||
return self.return_as_nop()
|
return self.return_as_nop()
|
||||||
|
</source>
|
||||||
|
|
||||||
The computation of this hash can be implemented as specified below (where self
|
The computation of this hash can be implemented as specified below (where self
|
||||||
is the transaction type). Care must be taken that in any validation context,
|
is the transaction type). Care must be taken that in any validation context,
|
||||||
@ -202,7 +211,8 @@ including hashes of the scriptsigs, sequences, and outputs. See the section
|
|||||||
"Denial of Service and Validation Costs" below. This is not a performance
|
"Denial of Service and Validation Costs" below. This is not a performance
|
||||||
optimization.
|
optimization.
|
||||||
|
|
||||||
def get_default_check_template_precomputed_data(self):
|
<source lang="python">
|
||||||
|
def get_default_check_template_precomputed_data(self):
|
||||||
result = {}
|
result = {}
|
||||||
# If there are no scriptSigs we do not need to precompute a hash
|
# If there are no scriptSigs we do not need to precompute a hash
|
||||||
if any(inp.scriptSig for inp in self.vin):
|
if any(inp.scriptSig for inp in self.vin):
|
||||||
@ -213,8 +223,8 @@ optimization.
|
|||||||
result["outputs"] = sha256(b"".join(out.serialize() for out in self.vout))
|
result["outputs"] = sha256(b"".join(out.serialize() for out in self.vout))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# parameter precomputed must be passed in for DoS resistance
|
# parameter precomputed must be passed in for DoS resistance
|
||||||
def get_default_check_template_hash(self, nIn, precomputed = None):
|
def get_default_check_template_hash(self, nIn, precomputed = None):
|
||||||
if precomputed == None:
|
if precomputed == None:
|
||||||
precomputed = self.get_default_check_template_precomputed_data()
|
precomputed = self.get_default_check_template_precomputed_data()
|
||||||
r = b""
|
r = b""
|
||||||
@ -235,13 +245,16 @@ optimization.
|
|||||||
# pack as 4 byte unsigned integer
|
# pack as 4 byte unsigned integer
|
||||||
r += struct.pack("<I", nIn)
|
r += struct.pack("<I", nIn)
|
||||||
return sha256(r)
|
return sha256(r)
|
||||||
|
</source>
|
||||||
|
|
||||||
|
|
||||||
A PayToBareDefaultCheckTemplateVerifyHash output matches the following template:
|
A PayToBareDefaultCheckTemplateVerifyHash output matches the following template:
|
||||||
|
|
||||||
# Extra-fast test for pay-to-basic-standard-template CScripts:
|
<source lang="python">
|
||||||
def is_pay_to_bare_default_check_template_verify_hash(self):
|
# Extra-fast test for pay-to-basic-standard-template CScripts:
|
||||||
|
def is_pay_to_bare_default_check_template_verify_hash(self):
|
||||||
return len(self) == 34 and self[0] == 0x20 and self[-1] == OP_CHECKTEMPLATEVERIFY
|
return len(self) == 34 and self[0] == 0x20 and self[-1] == OP_CHECKTEMPLATEVERIFY
|
||||||
|
</source>
|
||||||
|
|
||||||
|
|
||||||
==Deployment==
|
==Deployment==
|
||||||
|
Loading…
Reference in New Issue
Block a user