diff --git a/bip-taproot.mediawiki b/bip-taproot.mediawiki index ba546897..48279566 100644 --- a/bip-taproot.mediawiki +++ b/bip-taproot.mediawiki @@ -134,14 +134,14 @@ As the message for signature verification, transaction digest is ''hashTapS *** amount (8): value of the previous output spent by this input. *** nSequence (4): nSequence of this input. ** If the SIGHASH_ANYONECANPAY flag is not set: -*** input_index (2): index of this input in the transaction input vector. Index of the first input is 0. +*** input_index (4): index of this input in the transaction input vector. Index of the first input is 0. ** If the bit-1 of spend_type is set: *** sha_annex (32): the SHA256 of (compact_size(size of annex) || annex). * Data about this output: ** If the SIGHASH_SINGLE flag is set: *** sha_single_output (32): the SHA256 of the corresponding output in CTxOut format. -The total number of bytes hashed is at most ''209'''''What is the number of bytes hashed for the signature hash?''' The total size of the input to ''hashTapSighash'' (excluding the initial 64-byte hash tag) can be computed using the following formula: ''176 - is_anyonecanpay * 50 - is_none * 32 + has_annex * 32''.. +The total number of bytes hashed is at most ''211'''''What is the number of bytes hashed for the signature hash?''' The total size of the input to ''hashTapSighash'' (excluding the initial 64-byte hash tag) can be computed using the following formula: ''178 - is_anyonecanpay * 50 - is_none * 32 + has_annex * 32''.. In summary, the semantics of the BIP143 sighash types remain unchanged, except the following: # The way and order of serialization is changed.'''Why is the serialization in the transaction digest changed?''' Hashes that go into the digest and the digest itself are now computed with a single SHA256 invocation instead of double SHA256. There is no expected security improvement by doubling SHA256 because this only protects against length-extension attacks against SHA256 which are not a concern for transaction digests because there is no secret data. Therefore doubling SHA256 is a waste of resources. The digest computation now follows a logical order with transaction level data first, then input data and output data. This allows to efficiently cache the transaction part of the digest across different inputs using the SHA256 midstate. Additionally, digest computation avoids unnecessary hashing as opposed to BIP143 digests in which parts may be set zero and before hashing them. Despite that, collisions are made impossible by committing to the length of the data (implicit in hash_type and spend_type) before the variable length data. diff --git a/bip-tapscript.mediawiki b/bip-tapscript.mediawiki index 1d3e6fa5..da5dc180 100644 --- a/bip-tapscript.mediawiki +++ b/bip-tapscript.mediawiki @@ -108,9 +108,9 @@ The one-byte spend_type has a different value, specifically at bit As additional pieces of data, added at the end of the input to the ''hashTapSighash'' function: * tapleaf_hash (32): the tapleaf hash as defined in bip-taproot * key_version (1): a constant value 0x00 representing the current version of public keys in the tapscript signature opcode execution. -* codeseparator_position (2): the opcode position of the last executed OP_CODESEPARATOR before the currently executed signature opcode, with the value in little endian (or 0xffff if none executed). The first opcode in a script has a position of 0. A multi-byte push opcode is counted as one opcode, regardless of the size of data being pushed. +* codeseparator_position (4): the opcode position of the last executed OP_CODESEPARATOR before the currently executed signature opcode, with the value in little endian (or 0xffffffff if none executed). The first opcode in a script has a position of 0. A multi-byte push opcode is counted as one opcode, regardless of the size of data being pushed. -The total number of bytes hashed is at most ''244'''''What is the number of bytes hashed for the signature hash?''' The total size of the input to ''hashTapSighash'' (excluding the initial 64-byte hash tag) can be computed using the following formula: ''211 - is_anyonecanpay * 50 - is_none * 32 + has_annex * 32''.. +The total number of bytes hashed is at most ''248'''''What is the number of bytes hashed for the signature hash?''' The total size of the input to ''hashTapSighash'' (excluding the initial 64-byte hash tag) can be computed using the following formula: ''215 - is_anyonecanpay * 50 - is_none * 32 + has_annex * 32''.. In summary, the semantics of the BIP143 sighash types remain unchanged, except the following: # The exceptions mentioned in bip-taproot.