-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
txscript: Zero alloc optimization refactor. #1656
txscript: Zero alloc optimization refactor. #1656
Commits on Mar 26, 2019
-
txscript: Deprecate HasP2SHScriptSigStakeOpCodes.
This function is only useful for internal consensus purposes within the script engine and as such should not be exported.
Configuration menu - View commit details
-
Copy full SHA for 60d41d1 - Browse repository at this point
Copy the full SHA 60d41d1View commit details -
txscript: Deprecate IsStakeOutput.
This function is only useful for internal consensus purposes within the script engine and as such should not be exported. While here, also add a comment to specify to the script version semantics.
Configuration menu - View commit details
-
Copy full SHA for b1b64d9 - Browse repository at this point
Copy the full SHA b1b64d9View commit details -
txscript: Deprecate GetMultisigMandN.
This deprecates the GetMultisigMandN function which should never have been added since the CalcMultiSigStats function already existed for this purpose. While here, redefine the function in terms of CalcMultiSigStats.
Configuration menu - View commit details
-
Copy full SHA for 7f1da3b - Browse repository at this point
Copy the full SHA 7f1da3bView commit details -
Configuration menu - View commit details
-
Copy full SHA for e6a5701 - Browse repository at this point
Copy the full SHA e6a5701View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2f8f078 - Browse repository at this point
Copy the full SHA 2f8f078View commit details -
txscript: Introduce zero-alloc script tokenizer.
This implements an efficient and zero-allocation script tokenizer that is exported to both provide a new capability to tokenize scripts to external consumers of the API as well as to serve as a base for refactoring the existing highly inefficient internal code. It is important to note that this tokenizer is intended to be used in consensus critical code in the future, so it must exactly follow the existing semantics. The current script parsing mechanism used throughout the txscript module is to fully tokenize the scripts into an array of internal parsed opcodes which are then examined and passed around in order to implement virtually everything related to scripts. While that approach does simplify the analysis of certain scripts and thus provide some nice properties in that regard, it is both extremely inefficient in many cases, and makes it impossible for external consumers of the API to implement any form of custom script analysis without manually implementing a bunch of error prone tokenizing code or, alternatively, the script engine exposing internal structures. For example, as shown by profiling the total memory allocations of an initial sync, the existing script parsing code allocates a total of around 295.12GB, which equates to around 50% of all allocations performed. The zero-alloc tokenizer this introduces will allow that to be reduced to virtually zero. The following is a before and after comparison of tokenizing a large script with a high opcode count using the existing code versus the tokenizer this introduces for both speed and memory allocations: benchmark old ns/op new ns/op delta ------------------------------------------------------------ BenchmarkScriptParsing 153099 961 -99.37% benchmark old allocs new allocs delta ------------------------------------------------------------ BenchmarkScriptParsing 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------ BenchmarkScriptParsing 466945 0 -100.00% The following is an overview of the changes: - Introduce new error code ErrUnsupportedScriptVersion - Implement zero-allocation script tokenizer - Add a full suite of tests to ensure the tokenizer works as intended and follows the required consensus semantics - Add an example of using the new tokenizer to count the number of opcodes in a script - Update README.md to include the new example - Update script parsing benchmark to use the new tokenizer
Configuration menu - View commit details
-
Copy full SHA for cb86bc0 - Browse repository at this point
Copy the full SHA cb86bc0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9b2ec27 - Browse repository at this point
Copy the full SHA 9b2ec27View commit details -
txscript: Optimize script disasm.
This converts the DisasmString function to make use of the new zero-allocation script tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. In order to facilitate this, the opcode disassembly functionality is split into a separate function called disasmOpcode that accepts the opcode struct and data independently as opposed to requiring a parsed opcode. The new function also accepts a pointer to a string builder so the disassembly can be more efficiently be built. While here, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of a large script: benchmark old ns/op new ns/op delta ---------------------------------------------------------- BenchmarkDisasmString 288729 94157 -67.39% benchmark old bytes new bytes delta ---------------------------------------------------------- BenchmarkDisasmString 584611 177528 -69.63%
Configuration menu - View commit details
-
Copy full SHA for e332430 - Browse repository at this point
Copy the full SHA e332430View commit details -
txscript: Introduce raw script sighash calc func.
This introduces a new function named calcSignatureHashRaw which accepts the raw script bytes to calculate the script hash versus requiring the parsed opcode only to unparse them later in order to make it more flexible for working with raw scripts. Since there are several places in the rest of the code that currently only have access to the parsed opcodes, this modifies the existing calcSignatureHash to first unparse the script before calling the new function. Note that the code in the signature hash calculation to remove all instances of OP_CODESEPARATOR from the script is removed because that is a holdover from BTC code which does not apply to v0 Decred scripts since OP_CODESEPARATOR is completely disabled in Decred and thus there can never actually be one in the script. Finally, it removes the removeOpcode function and related tests since it is no longer used.
Configuration menu - View commit details
-
Copy full SHA for f306a72 - Browse repository at this point
Copy the full SHA f306a72View commit details -
txscript: Optimize CalcSignatureHash.
This modifies the CalcSignatureHash function to make use of the new signature hash calculation function that accepts raw scripts without needing to first parse them. Consequently, it also doubles as a slight optimization to the execution time and a significant reduction in the number of allocations. In order to convert the CalcScriptHash function and keep the same semantics, a new function named checkScriptParses is introduced which will quickly determine if a script can be fully parsed without failure and return the parse failure in the case it can't. The following is a before and after comparison of analyzing a large multiple input transaction: benchmark old ns/op new ns/op delta ------------------------------------------------------- BenchmarkCalcSigHash 2792057 2760042 -1.15% benchmark old allocs new allocs delta ------------------------------------------------------- BenchmarkCalcSigHash 1691 1068 -36.84% benchmark old bytes new bytes delta ------------------------------------------------------- BenchmarkCalcSigHash 521673 438604 -15.92%
Configuration menu - View commit details
-
Copy full SHA for c57dc2d - Browse repository at this point
Copy the full SHA c57dc2dView commit details -
txscript: Convert sighash calc tests.
This converts the tests for calculating signature hashes to use the exported function which handles the raw script versus the now deprecated variant requiring parsed opcodes.
Configuration menu - View commit details
-
Copy full SHA for 06f769e - Browse repository at this point
Copy the full SHA 06f769eView commit details -
txscript: Make isSmallInt accept raw opcode.
This converts the isSmallInt function to accept an opcode as a byte instead of the internal opcode data struct in order to make it more flexible for raw script analysis. The comment is modified to explicitly call out the script version semantics. Finally, it updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for 44cbc31 - Browse repository at this point
Copy the full SHA 44cbc31View commit details -
txscript: Make asSmallInt accept raw opcode.
This converts the asSmallInt function to accept an opcode as a byte instead of the internal opcode data struct in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for 0ed8e25 - Browse repository at this point
Copy the full SHA 0ed8e25View commit details -
txscript: Make isStakeOpcode accept raw opcode.
This converts the isStakeOpcode function to accept an opcode as a byte instead of the internal opcode data struct in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for 082d1ed - Browse repository at this point
Copy the full SHA 082d1edView commit details -
Configuration menu - View commit details
-
Copy full SHA for c705a0e - Browse repository at this point
Copy the full SHA c705a0eView commit details -
txscript: Optimize IsPayToScriptHash.
This converts the IsPayToScriptHash function to analyze the raw script instead of using the far less efficient parseScript thereby significantly optimizing the function. In order to accomplish this, it introduces two new functions. The first one is named extractScriptHash and works with the raw script bytes to simultaneously determine if the script is a p2sh script, and in the case it is, extract and return the hash. The second new function is named isScriptHashScript and is defined in terms of the former. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. Finally, this also deprecates the isScriptHash function that requires opcodes in favor of the new functions and modifies the comment on IsPayToScriptHash to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script that is not a p2sh script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 139961 0.66 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 9f2f038 - Browse repository at this point
Copy the full SHA 9f2f038View commit details -
Configuration menu - View commit details
-
Copy full SHA for 356492b - Browse repository at this point
Copy the full SHA 356492bView commit details -
txscript: Optimize IsMultisigScript.
This converts the IsMultisigScript function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. In order to accomplish this, it introduces two new functions. The first one is named extractMultisigScriptDetails and works with the raw script bytes to simultaneously determine if the script is a multisignature script, and in the case it is, extract and return the relevant details. The second new function is named isMultisigScript and is defined in terms of the former. The extract function accepts the script version, raw script bytes, and a flag to determine whether or not the public keys should also be extracted. The flag is provided because extracting pubkeys results in an allocation that the caller might wish to avoid. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. It is important to note that this new implementation intentionally has a semantic difference from the existing implementation in that it will now correctly identify a multisig script with zero pubkeys whereas previously it incorrectly required at least one pubkey. This change is acceptable because the function only deals with standardness rather than consensus rules. Finally, this also deprecates the isMultiSig function that requires opcodes in favor of the new functions and deprecates the error return on the export IsMultisigScript function since it really does not make sense given the purpose of the function. The following is a before and after comparison of analyzing both a large script that is not a multisig script and a 1-of-2 multisig public key script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------- BenchmarkIsMultisigScriptLarge 121599 8.63 -99.99% BenchmarkIsMultisigScript 797 72.8 -90.87% benchmark old allocs new allocs delta ------------------------------------------------------------------- BenchmarkIsMultisigScriptLarge 1 0 -100.00% BenchmarkIsMultisigScript 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------- BenchmarkIsMultisigScriptLarge 466944 0 -100.00% BenchmarkIsMultisigScript 2304 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 7b8259b - Browse repository at this point
Copy the full SHA 7b8259bView commit details -
Configuration menu - View commit details
-
Copy full SHA for d7492c3 - Browse repository at this point
Copy the full SHA d7492c3View commit details -
txscript: Optimize IsMultisigSigScript.
This converts the IsMultisigSigScript function to analyze the raw script and make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. In order to accomplish this, it first rejects scripts that can't possibly fit the bill due to the final byte of what would be the redeem script not being the appropriate opcode or the overall script not having enough bytes. Then, it uses a new function that is introduced named finalOpcodeData that uses the tokenizer to return any data associated with the final opcode in the signature script (which will be nil for non-push opcodes or if the script fails to parse) and analyzes it as if it were a redeem script when it is non nil. It is also worth noting that this new implementation intentionally has the same semantic difference from the existing implementation as the updated IsMultisigScript function in regards to allowing zero pubkeys whereas previously it incorrectly required at least one pubkey. Finally, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script that is not a multisig script and both a 1-of-2 multisig public key script (which should be false) and a signature script comprised of a pay-to-script-hash 1-of-2 multisig redeem script (which should be true): benchmark old ns/op new ns/op delta ----------------------------------------------------------------------- BenchmarkIsMultisigSigScriptLarge 158149 4 -100.00% BenchmarkIsMultisigSigScript 3445 202 -94.14% benchmark old allocs new allocs delta ----------------------------------------------------------------------- BenchmarkIsMultisigSigScriptLarge 9 0 -100.00% BenchmarkIsMultisigSigScript 3 0 -100.00% benchmark old bytes new bytes delta ----------------------------------------------------------------------- BenchmarkIsMultisigSigScriptLarge 533189 0 -100.00% BenchmarkIsMultisigSigScript 9472 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 462eea3 - Browse repository at this point
Copy the full SHA 462eea3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2d70450 - Browse repository at this point
Copy the full SHA 2d70450View commit details -
txscript: Optimize GetSigOpCount.
This converts the GetSigOpCount function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. A new function named countSigOpsV0 which accepts the raw script is introduced to perform the bulk of the work so it can be reused for precise signature operation counting as well in a later commit. It retains the same semantics in terms of counting the number of signature operations either up to the first parse error or the end of the script in the case it parses successfully as required by consensus. Finally, this also deprecates the getSigOpCount function that requires opcodes in favor of the new function and modifies the comment on GetSigOpCount to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ----------------------------------------------------------- BenchmarkGetSigOpCount 163896 1048 -99.36% benchmark old allocs new allocs delta ----------------------------------------------------------- BenchmarkGetSigOpCount 1 0 -100.00% benchmark old bytes new bytes delta ----------------------------------------------------------- BenchmarkGetSigOpCount 466945 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for ffa6fb9 - Browse repository at this point
Copy the full SHA ffa6fb9View commit details -
txscript: Add tests for stake-tagged script hash.
This adds tests to ensure the isAnyKindOfScriptHash function properly identifies the four stake-tagged pay-to-script-hash possibilities in addition to ensuring they are not misidentified as standard pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for 51f7639 - Browse repository at this point
Copy the full SHA 51f7639View commit details -
Configuration menu - View commit details
-
Copy full SHA for bc56df1 - Browse repository at this point
Copy the full SHA bc56df1View commit details -
txscript: Optimize isAnyKindOfScriptHash.
This converts the isAnyKindOfScriptHash function to analyze the raw script instead of requiring far less efficient parsed opcodes thereby significantly optimizing the function. Since the function relies on isStakeScriptHash to identify a stake tagged pay-to-script-hash, and is the only consumer of it, this also converts that function to analyze the raw script and renames it to isStakeScriptHashScript for more consistent naming. Finally, the tests are updated accordingly. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------- BenchmarkIsAnyKindOfScriptHash 101249 3.83 -100.00% benchmark old allocs new allocs delta ------------------------------------------------------------------- BenchmarkIsAnyKindOfScriptHash 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------- BenchmarkIsAnyKindOfScriptHash 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for a598838 - Browse repository at this point
Copy the full SHA a598838View commit details -
Configuration menu - View commit details
-
Copy full SHA for 93b039d - Browse repository at this point
Copy the full SHA 93b039dView commit details -
txscript: Optimize IsPushOnlyScript.
This converts the IsPushOnlyScript function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. It also deprecates the isPushOnly function that requires opcodes in favor of the new function and modifies the comment on IsPushOnlyScript to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 139961 0.66 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkIsPayToScriptHash 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 9e8bfd2 - Browse repository at this point
Copy the full SHA 9e8bfd2View commit details -
txscript: Optimize new engine push only script.
This modifies the check for whether or not a pay-to-script-hash signature script is a push only script to make use of the new and more efficient raw script function. Also, since the script will have already been checked further above when the ScriptVerifySigPushOnly flags is set, avoid checking it again in that case.
Configuration menu - View commit details
-
Copy full SHA for af67951 - Browse repository at this point
Copy the full SHA af67951View commit details -
txscript: Check p2sh push before parsing scripts.
This moves the check for non push-only pay-to-script-hash signature scripts before the script parsing logic when creating a new engine instance to avoid the extra overhead in the error case.
Configuration menu - View commit details
-
Copy full SHA for 281f794 - Browse repository at this point
Copy the full SHA 281f794View commit details -
Configuration menu - View commit details
-
Copy full SHA for 75e71d8 - Browse repository at this point
Copy the full SHA 75e71d8View commit details -
txscript: Optimize GetPreciseSigOpCount.
This converts the GetPreciseSigOpCount function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. In particular it uses the recently converted isScriptHashScript, IsPushOnlyScript, and countSigOpsV0 functions along with the recently added finalOpcodeData functions. It also modifies the comment to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------ BenchmarkGetPreciseSigOpCount 287939 1077 -99.63% benchmark old allocs new allocs delta ------------------------------------------------------------------ BenchmarkGetPreciseSigOpCount 3 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------ BenchmarkGetPreciseSigOpCount 934657 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for a1b24ad - Browse repository at this point
Copy the full SHA a1b24adView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4dc1ffb - Browse repository at this point
Copy the full SHA 4dc1ffbView commit details -
txscript: Make typeOfScript accept raw script.
This converts the typeOfScript function to accept a script version and raw script instead of an array of internal parsed opcodes in order to make it more flexible for raw script analysis. Also, this adds a comment to CalcScriptInfo to call out the specific version semantics and deprecates the function since nothing currently uses it, and the relevant information can now be obtained by callers more directly through the use of the new script tokenizer. All other callers are updated accordingly.
Configuration menu - View commit details
-
Copy full SHA for 4f27dfc - Browse repository at this point
Copy the full SHA 4f27dfcView commit details -
txscript: Optimize typeOfScript pay-to-script-hash.
This begins the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes with the intent of significantly optimizing the function. In order to ease the review process, each script type will be converted in a separate commit and the typeOfScript function will be updated such that the script is only parsed as a fallback for the cases that are not already converted to more efficient raw script variants. In particular, for this commit, since the ability to detect pay-to-script-hash via raw script analysis is now available, the function is simply updated to make use of it.
Configuration menu - View commit details
-
Copy full SHA for bdd51a0 - Browse repository at this point
Copy the full SHA bdd51a0View commit details -
Configuration menu - View commit details
-
Copy full SHA for efd7e2f - Browse repository at this point
Copy the full SHA efd7e2fView commit details -
txscript: Optimize typeOfScript multisig.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, for this commit, since the ability to detect multisig scripts via the new tokenizer is now available, the function is simply updated to make use of it.
Configuration menu - View commit details
-
Copy full SHA for 900af9b - Browse repository at this point
Copy the full SHA 900af9bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 07168b8 - Browse repository at this point
Copy the full SHA 07168b8View commit details -
Configuration menu - View commit details
-
Copy full SHA for c4a1527 - Browse repository at this point
Copy the full SHA c4a1527View commit details -
txscript: Optimize typeOfScript pay-to-pubkey.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of pay-to-pubkey scripts to use raw script analysis. In order to accomplish this, it introduces four new functions: extractCompressedPubKey, extractUncompressedPubKey, extractPubKey, and isPubKeyScript. The extractPubKey function makes use of extractCompressedPubKey and extractUncompressedPubKey to combine their functionality as a convenience and isPubKeyScript is defined in terms of extractPubKey. The extractCompressedPubKey works with the raw script bytes to simultaneously determine if the script is a pay-to-compressed-pubkey script, and in the case it is, extract and return the raw compressed pubkey bytes. Similarly, the extractUncompressedPubKey works in the same way except it determines if the script is a pay-to-uncompressed-pubkey script and returns the raw uncompressed pubkey bytes in the case it is. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------ BenchmarkIsPubKeyScript 124749 4.01 -100.00% benchmark old allocs new allocs delta ------------------------------------------------------------ BenchmarkIsPubKeyScript 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------ BenchmarkIsPubKeyScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 1b067cb - Browse repository at this point
Copy the full SHA 1b067cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for b273b83 - Browse repository at this point
Copy the full SHA b273b83View commit details -
Configuration menu - View commit details
-
Copy full SHA for e64e21c - Browse repository at this point
Copy the full SHA e64e21cView commit details -
txscript: Optimize typeOfScript pay-to-alt-pubkey.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of pay-to-alt-pubkey scripts to use raw script analysis. In order to accomplish this, it introduces two new functions. The first one is named extractPubKeyAltDetails and works with the raw script bytes to simultaneously determine if the script is a pay-to-alt-pubkey script, and in the case it is, extract and return the relevant details. The second new function is named isPubKeyAltScript and is defined in terms of the former. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. It is important to note that this new implementation intentionally tightens the following semantics as compared to the existing implementation: - The signature type must now be one of the two supported types versus allowing any single byte data push - The public key must now be of the correct length for the given signature type versus allowing any size up to 512 bytes - The public key for schnorr secp256k1 pubkeys must now be a compressed public key and adhere to the strict encoding requirements for them The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkIsAltPubKeyScript 143449 2.99 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkIsAltPubKeyScript 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkIsAltPubKeyScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 2602647 - Browse repository at this point
Copy the full SHA 2602647View commit details -
Configuration menu - View commit details
-
Copy full SHA for d07d626 - Browse repository at this point
Copy the full SHA d07d626View commit details -
txscript: Optimize typeOfScript pay-to-pubkey-hash.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of pay-to-pubkey-hash scripts to use raw script analysis. In order to accomplish this, it introduces two new functions. The first one is named extractPubKeyHash and works with the raw script bytes to simultaneously determine if the script is a pay-to-pubkey-hash script, and in the case it is, extract and return the hash. The second new function is named isPubKeyHashScript and is defined in terms of the former. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ---------------------------------------------------------------- BenchmarkIsPubKeyHashScript 165903 0.64 -100.00% benchmark old allocs new allocs delta ---------------------------------------------------------------- BenchmarkIsPubKeyHashScript 1 0 -100.00% benchmark old bytes new bytes delta ---------------------------------------------------------------- BenchmarkIsPubKeyHashScript 466945 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 406f851 - Browse repository at this point
Copy the full SHA 406f851View commit details -
Configuration menu - View commit details
-
Copy full SHA for ffe80c7 - Browse repository at this point
Copy the full SHA ffe80c7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 95175cb - Browse repository at this point
Copy the full SHA 95175cbView commit details -
txscript: Optimize typeOfScript pay-to-alt-pk-hash.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of pay-to-alt-pubkey-hash scripts to use raw script analysis. In order to accomplish this, it introduces two new functions. The first one is named extractPubKeyHashAltDetails and works with the raw script bytes to simultaneously determine if the script is a pay-to-alt-pubkey-hash script, and in the case it is, extract and return the hash and signature type. The second new function is named isPubKeyHashAltScript and is defined in terms of the former. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. It is important to note that this new implementation intentionally has a semantic difference from the existing implementation in that it will now only pass when one of two signature types currently supported by consensus are specified whereas previously it would allow any single byte data push. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------- BenchmarkIsAltPubKeyHashScript 107100 2.63 -100.00% benchmark old allocs new allocs delta ------------------------------------------------------------------- BenchmarkIsAltPubKeyHashScript 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------- BenchmarkIsAltPubKeyHashScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for e7a172c - Browse repository at this point
Copy the full SHA e7a172cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 15416b0 - Browse repository at this point
Copy the full SHA 15416b0View commit details -
txscript: Optimize typeOfScript nulldata detection.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of nulldata scripts to use both raw script analysis and the new tokenizer. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta -------------------------------------------------------------- BenchmarkIsNullDataScript 120800 3.81 -100.00% benchmark old allocs new allocs delta -------------------------------------------------------------- BenchmarkIsNullDataScript 1 0 -100.00% benchmark old bytes new bytes delta -------------------------------------------------------------- BenchmarkIsNullDataScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for f589dd8 - Browse repository at this point
Copy the full SHA f589dd8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 63e7418 - Browse repository at this point
Copy the full SHA 63e7418View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6de8d69 - Browse repository at this point
Copy the full SHA 6de8d69View commit details -
txscript: Optimize typeOfScript stakesub detection.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of stake submission scripts to use raw script analysis. In order to accomplish this, it introduces three new functions. The first one is named extractStakePubKeyHash and works with the raw script bytes to simultaneously determine if the script is a stake-tagged pay-to-pubkey-hash script tagged with a specified stake opcode, and in the case it is, extract and return the hash. The second new function, named extractStakeScriptHash, is similar except it detect a stake-tagged pay-to-script-hash script tagged with a specified stake opcode. Finally, the third function is named isStakeSubmissionScript and is defined in terms of the former two functions. The extract function approach was chosen because it is common for callers to want to only extract relevant details from a script if the script is of the specific type. Extracting those details requires performing the exact same checks to ensure the script is of the correct type, so it is more efficient to combine the two into one and define the type determination in terms of the result so long as the extraction does not require allocations. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta --------------------------------------------------------------------- BenchmarkIsStakeSubmissionScript 140308 4.20 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------------- BenchmarkIsStakeSubmissionScript 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------------- BenchmarkIsStakeSubmissionScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 5455dbc - Browse repository at this point
Copy the full SHA 5455dbcView commit details -
Configuration menu - View commit details
-
Copy full SHA for 974ae66 - Browse repository at this point
Copy the full SHA 974ae66View commit details -
Configuration menu - View commit details
-
Copy full SHA for c07f9cb - Browse repository at this point
Copy the full SHA c07f9cbView commit details -
txscript: Optimize typeOfScript stakegen detection.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of stake generation scripts to use raw script analysis. In order to accomplish this, it introduces a new function named isStakeGenScript which makes of the recently added extractStakePubKeyHash and extractStakeScriptHash functions. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta --------------------------------------------------------------------- BenchmarkIsStakeGenerationScript 121043 4.26 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------------- BenchmarkIsStakeGenerationScript 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------------- BenchmarkIsStakeGenerationScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 5a24f50 - Browse repository at this point
Copy the full SHA 5a24f50View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8468b0d - Browse repository at this point
Copy the full SHA 8468b0dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9b3f4c9 - Browse repository at this point
Copy the full SHA 9b3f4c9View commit details -
txscript: Optimize typeOfScript stakerev detection.
This continues the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of stake revocation scripts to use raw script analysis. In order to accomplish this, it introduces a new function named isStakeGenScript which makes of the recently added extractStakePubKeyHash and extractStakeScriptHash functions. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta --------------------------------------------------------------------- BenchmarkIsStakeRevocationScript 117699 4.58 -100.00% benchmark old allocs new allocs delta --------------------------------------------------------------------- BenchmarkIsStakeRevocationScript 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------------- BenchmarkIsStakeRevocationScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 8dfae89 - Browse repository at this point
Copy the full SHA 8dfae89View commit details -
Configuration menu - View commit details
-
Copy full SHA for 61872f9 - Browse repository at this point
Copy the full SHA 61872f9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 123a733 - Browse repository at this point
Copy the full SHA 123a733View commit details -
txscript: Optimize typeOfScript stakechange detect.
This completes the process of converting the typeOfScript function to use a combination of raw script analysis and the new tokenizer instead of the far less efficient parsed opcodes. In particular, it converts the detection of stake change scripts to use raw script analysis by introducing a new function named isStakeChangeScript which makes use of the recently added extractStakePubKeyHash and extractStakeScriptHash functions and removes the script parsing fallback from the typeOfScript function since this is the final case. The following is a before and after comparison of analyzing a large script for both the stake change script change and the overall GetScriptClass function which relies on the now fully converted typeOfScript function: benchmark old ns/op new ns/op delta ----------------------------------------------------------------- BenchmarkIsStakeChangeScript 133810 4.39 -100.00% BenchmarkGetScriptClass 145001 62.9 -99.96% benchmark old allocs new allocs delta ----------------------------------------------------------------- BenchmarkIsStakeChangeScript 1 0 -100.00% BenchmarkGetScriptClass 1 0 -100.00% benchmark old bytes new bytes delta ----------------------------------------------------------------- BenchmarkIsStakeChangeScript 466944 0 -100.00% BenchmarkGetScriptClass 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 89d4941 - Browse repository at this point
Copy the full SHA 89d4941View commit details -
Configuration menu - View commit details
-
Copy full SHA for 28765fa - Browse repository at this point
Copy the full SHA 28765faView commit details -
Configuration menu - View commit details
-
Copy full SHA for bfab5db - Browse repository at this point
Copy the full SHA bfab5dbView commit details -
txscript: Optimize ContainsStakeOpCodes.
This converts the ContainsStakeOpCodes function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------ BenchmarkContainsStakeOpCodes 134599 968 -99.28% benchmark old allocs new allocs delta ------------------------------------------------------------------ BenchmarkContainsStakeOpCodes 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------ BenchmarkContainsStakeOpCodes 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 0e021a9 - Browse repository at this point
Copy the full SHA 0e021a9View commit details -
Configuration menu - View commit details
-
Copy full SHA for ccd0a92 - Browse repository at this point
Copy the full SHA ccd0a92View commit details -
txscript: Optimize ExtractCoinbaseNullData.
This converts the ExtractCoinbaseNullData function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. The following is a before and after comparison of analyzing a typical coinbase script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------- BenchmarkExactCoinbaseNullData 227 31.0 -86.34% benchmark old allocs new allocs delta ------------------------------------------------------------------- BenchmarkExactCoinbaseNullData 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------- BenchmarkExactCoinbaseNullData 448 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 6a0a77f - Browse repository at this point
Copy the full SHA 6a0a77fView commit details -
txscript: Convert CalcScriptInfo.
This converts CalcScriptInfo and dependent expectedInputs to make use of the new script tokenizer as well as several of the other recently added raw script analysis functions in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether. It is worth noting that this has the side effect of significantly optimizing the function as well, however, since it is deprecated, no benchmarks are provided.
Configuration menu - View commit details
-
Copy full SHA for 8f44276 - Browse repository at this point
Copy the full SHA 8f44276View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7d8ce2d - Browse repository at this point
Copy the full SHA 7d8ce2dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5a4d9c9 - Browse repository at this point
Copy the full SHA 5a4d9c9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 04e70a1 - Browse repository at this point
Copy the full SHA 04e70a1View commit details -
txscript: Optimize CalcMultiSigStats.
This converts the CalcMultiSigStats function to make use of the new extractMultisigScriptDetails function instead of the far less efficient parseScript thereby significantly optimizing the function. The tests are also updated accordingly. The following is a before and after comparison of analyzing a standard multisig script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkCalcMultiSigStats 972 79.5 -91.82% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkCalcMultiSigStats 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkCalcMultiSigStats 2304 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for c596826 - Browse repository at this point
Copy the full SHA c596826View commit details -
Configuration menu - View commit details
-
Copy full SHA for b0f5561 - Browse repository at this point
Copy the full SHA b0f5561View commit details -
txscript: Optimize multi sig redeem script func.
This converts the MultisigRedeemScriptFromScriptSig function to make use of the new finalOpcodeData function instead of the far less efficient parseScript thereby significantly optimizing the function. It also deprecates the error return since it really does not make sense given the preconditions of the function. Finally, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a very large script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 153623 1830 -98.81% benchmark old allocs new allocs delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------ BenchmarkMultisigRedeemScript 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 1466a2a - Browse repository at this point
Copy the full SHA 1466a2aView commit details -
txscript: Convert GetScriptHashFromP2SHScript.
This converts GetScriptHashFromP2SHScript to make use of the new script tokenizer in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether. It also deprecates the function since the current semantics are not really ideal in that they simply return the data push just after the first HASH160 opcode which is only valid in the case the script is already known to be of the correct form and the task can be done more efficiently via raw script analysis such as how it is done in the recently added extractScriptHash function. Finally, it modifies the comment to explicitly call out the script version semantics as well as the aforemention precondition. It is worth noting that this has the side effect of significantly optimizing the function as well, however, since it is deprecated, no benchmarks are provided.
Configuration menu - View commit details
-
Copy full SHA for d82dfb7 - Browse repository at this point
Copy the full SHA d82dfb7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9b74ada - Browse repository at this point
Copy the full SHA 9b74adaView commit details -
txscript: Optimize PushedData.
This converts the PUshedData function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. Also, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of extracting the data from a very large script: benchmark old ns/op new ns/op delta ------------------------------------------------------- BenchmarkPushedData 132400 1619 -98.78% benchmark old allocs new allocs delta ------------------------------------------------------- BenchmarkPushedData 5 4 -20.00% benchmark old bytes new bytes delta ------------------------------------------------------- BenchmarkPushedData 467320 368 -99.92%
Configuration menu - View commit details
-
Copy full SHA for 9e7de33 - Browse repository at this point
Copy the full SHA 9e7de33View commit details -
Configuration menu - View commit details
-
Copy full SHA for a1da017 - Browse repository at this point
Copy the full SHA a1da017View commit details -
txscript: Optimize IsUnspendable.
This converts the IsUnspendable function to make use of a combination of raw script analysis and the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. It is important to note that this new implementation intentionally has a semantic difference from the existing implementation in that it will now report scripts that are larger than the max allowed script size are unspendable as well. Finally, the comment is modified to explicitly call out the script version semantics. The following is a before and after comparison of analyzing a large script: benchmark old ns/op new ns/op delta ----------------------------------------------------------- BenchmarkIsUnspendable 149899 860 -99.43% benchmark old allocs new allocs delta ----------------------------------------------------------- BenchmarkIsUnspendable 1 0 -100.00% benchmark old bytes new bytes delta ----------------------------------------------------------- BenchmarkIsUnspendable 466945 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for bb365f2 - Browse repository at this point
Copy the full SHA bb365f2View commit details -
txscript: Make canonicalPush accept raw opcode.
This renames the canonicalPush function to isCanonicalPush and converts it to accept an opcode as a byte and the associate data as a byte slice instead of the internal parse opcode data struct in order to make it more flexible for raw script analysis. It also updates all callers and tests accordingly.
Configuration menu - View commit details
-
Copy full SHA for 67d7385 - Browse repository at this point
Copy the full SHA 67d7385View commit details -
txscript: Add tests for atomic swap extraction.
This adds a fairly comprehensive set of tests to ensure the standard atomic swap script detection and extraction function works as intended.
Configuration menu - View commit details
-
Copy full SHA for ceb1f72 - Browse repository at this point
Copy the full SHA ceb1f72View commit details -
Configuration menu - View commit details
-
Copy full SHA for 605a9a4 - Browse repository at this point
Copy the full SHA 605a9a4View commit details -
txscript: Optimize ExtractAtomicSwapDataPushes.
This converts the ExtractAtomicSwapDataPushes function to make use of the new tokenizer instead of the far less efficient parseScript thereby significantly optimizing the function. The new implementation is designed such that it should be fairly easy to move the function into the atomic swap tools where it more naturally belongs now that the tokenizer makes it possible to analyze scripts outside of the txscript module. Consequently, this also deprecates the function. The following is a before and after comparison of attempting to extract from both a typical atomic swap script and a very large non-atomic swap script: benchmark old ns/op new ns/op delta ------------------------------------------------------------------------------ BenchmarkExtractAtomicSwapDataPushes 1330 410 -69.17% BenchmarkExtractAtomicSwapDataPushesLarge 136819 69.3 -99.95% benchmark old allocs new allocs delta ------------------------------------------------------------------------------ BenchmarkExtractAtomicSwapDataPushes 2 1 -50.00% BenchmarkExtractAtomicSwapDataPushesLarge 1 0 -100.00% benchmark old bytes new bytes delta ------------------------------------------------------------------------------ BenchmarkExtractAtomicSwapDataPushes 3168 96 -96.97% BenchmarkExtractAtomicSwapDataPushesLarge 466944 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 4774fda - Browse repository at this point
Copy the full SHA 4774fdaView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5e90e59 - Browse repository at this point
Copy the full SHA 5e90e59View commit details -
txscript: Optimize ExtractPkScriptAddrs scripthash.
This begins the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In order to ease the review process, the detection of each script type will be converted in a separate commit such that the script is only parsed as a fallback for the cases that are not already converted to more efficient variants. In particular, this converts the detection for pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for 49b3f9f - Browse repository at this point
Copy the full SHA 49b3f9fView commit details -
txscript: Optimize ExtractPkScriptAddrs pubkeyhash.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for pay-to-pubkey-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for bdd98b1 - Browse repository at this point
Copy the full SHA bdd98b1View commit details -
txscript: Optimize ExtractPkScriptAddrs altpubkeyhash.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for pay-to-alt-pubkey-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for bbca815 - Browse repository at this point
Copy the full SHA bbca815View commit details -
txscript: Optimize ExtractPkScriptAddrs pubkey.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for pay-to-pubkey scripts.
Configuration menu - View commit details
-
Copy full SHA for 9e5744d - Browse repository at this point
Copy the full SHA 9e5744dView commit details -
txscript: Optimize ExtractPkScriptAddrs altpubkey.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for pay-to-alt-pubkey scripts.
Configuration menu - View commit details
-
Copy full SHA for 8280e50 - Browse repository at this point
Copy the full SHA 8280e50View commit details -
txscript: Optimize ExtractPkScriptAddrs multisig.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for multisig scripts. Also, since the remaining slow path cases are all recursive calls, the parsed opcodes are no longer used, so parsing is removed.
Configuration menu - View commit details
-
Copy full SHA for 6c1c2d1 - Browse repository at this point
Copy the full SHA 6c1c2d1View commit details -
txscript: Optimize ExtractPkScriptAddrs stakesub.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for stake-submission-tagged pay-to-pubkey-hash and pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for 57219fc - Browse repository at this point
Copy the full SHA 57219fcView commit details -
txscript: Optimize ExtractPkScriptAddrs stakegen.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for stake-generation-tagged pay-to-pubkey-hash and pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for 8c763f1 - Browse repository at this point
Copy the full SHA 8c763f1View commit details -
txscript: Optimize ExtractPkScriptAddrs stakerev.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for stake-revocation-tagged pay-to-pubkey-hash and pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for a754af9 - Browse repository at this point
Copy the full SHA a754af9View commit details -
txscript: Optimize ExtractPkScriptAddrs stakechange.
This continues the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for stake-change-tagged pay-to-pubkey-hash and pay-to-script-hash scripts.
Configuration menu - View commit details
-
Copy full SHA for c9bce2a - Browse repository at this point
Copy the full SHA c9bce2aView commit details -
txscript: Optimize ExtractPkScriptAddrs nulldata.
This completes the process of converting the ExtractPkScriptAddrs function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. In particular, this converts the detection for nulldata scripts, removes the slow path fallback code since it is the final case, and modifies the comment to call out the script version semantics. The following is a before and after comparison of analyzing both a typical standard script and a very large non-standard script: benchmark old ns/op new ns/op delta ----------------------------------------------------------------------- BenchmarkExtractPkScriptAddrsLarge 132400 44.4 -99.97% BenchmarkExtractPkScriptAddrs 1265 231 -81.74% benchmark old allocs new allocs delta ----------------------------------------------------------------------- BenchmarkExtractPkScriptAddrsLarge 1 0 -100.00% BenchmarkExtractPkScriptAddrs 5 2 -60.00% benchmark old bytes new bytes delta ----------------------------------------------------------------------- BenchmarkExtractPkScriptAddrsLarge 466944 0 -100.00% BenchmarkExtractPkScriptAddrs 1600 48 -97.00%
Configuration menu - View commit details
-
Copy full SHA for d1944a9 - Browse repository at this point
Copy the full SHA d1944a9View commit details -
Configuration menu - View commit details
-
Copy full SHA for aaebc79 - Browse repository at this point
Copy the full SHA aaebc79View commit details -
txscript: Optimize ExtractPkScriptAltSigType.
This converts the ExtractPkScriptAltSigType function to use the optimized extraction functions recently introduced as part of the typeOfScript conversion. It is important to note that this new implementation intentionally has the same semantic differences from the existing implementation as discussed in the relevant commits that introduced the extraction functions. The following is a before and after comparison of analyzing a typical script: benchmark old ns/op new ns/op delta --------------------------------------------------------------- BenchmarkExtractAltSigType 497 12.8 -97.42% benchmark old allocs new allocs delta --------------------------------------------------------------- BenchmarkExtractAltSigType 1 0 -100.00% benchmark old bytes new bytes delta --------------------------------------------------------------- BenchmarkExtractAltSigType 896 0 -100.00%
Configuration menu - View commit details
-
Copy full SHA for 2fd1dcb - Browse repository at this point
Copy the full SHA 2fd1dcbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 007264e - Browse repository at this point
Copy the full SHA 007264eView commit details -
Configuration menu - View commit details
-
Copy full SHA for b19b6cb - Browse repository at this point
Copy the full SHA b19b6cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 9e3269e - Browse repository at this point
Copy the full SHA 9e3269eView commit details -
Configuration menu - View commit details
-
Copy full SHA for a247a52 - Browse repository at this point
Copy the full SHA a247a52View commit details -
txscript: mergeMultiSig function def order cleanup.
This moves the function definition for mergeMultiSig so it is more consistent with the preferred order used through the codebase. In particular, the functions are defined before they're first used and generally as close as possible to the first use when they're defined in the same file.
Configuration menu - View commit details
-
Copy full SHA for 251c9be - Browse repository at this point
Copy the full SHA 251c9beView commit details -
txscript: Use raw scripts in RawTxInSignature.
This converts RawTxInSignature to make use of the recently converted CalcSignatureHash function that works with raw scripts in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether and updates the comment to explicitly call out the script version semantics. It is worth noting that this has the side effect of optimizing the function as well, however, since this change is not focused on the optimization aspects, no benchmarks are provided.
Configuration menu - View commit details
-
Copy full SHA for 7cf42b0 - Browse repository at this point
Copy the full SHA 7cf42b0View commit details -
txscript: Use raw scripts in RawTxInSignatureAlt.
This converts RawTxInSignatureAlt to make use of the recently converted CalcSignatureHash function that works with raw scripts in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether and updates the comment to explicitly call out the script version semantics. It is worth noting that this has the side effect of optimizing the function as well, however, since this change is not focused on the optimization aspects, no benchmarks are provided.
Configuration menu - View commit details
-
Copy full SHA for 706b3a1 - Browse repository at this point
Copy the full SHA 706b3a1View commit details -
Configuration menu - View commit details
-
Copy full SHA for d8d561d - Browse repository at this point
Copy the full SHA d8d561dView commit details -
txscript: Use raw scripts in SignTxOutput.
This converts SignTxOutput and supporting funcs, namely sign, mergeScripts and mergeMultiSig, to make use of the new tokenizer as well as some recently added funcs that deal with raw scripts in order to remove the reliance on parsed opcodes as a step towards utlimately removing them altogether and updates the comments to explicitly call out the script version semantics. It is worth noting that this has the side effect of optimizing the function as well, however, since this change is not focused on the optimization aspects, no benchmarks are provided.
Configuration menu - View commit details
-
Copy full SHA for 85c7a9b - Browse repository at this point
Copy the full SHA 85c7a9bView commit details -
txscript: Implement efficient opcode data removal.
This introduces a new function named removeOpcodeByDataRaw which accepts the raw scripts and data to remove versus requiring the parsed opcodes to both significantly optimize it as well as make it more flexible for working with raw scripts. There are several places in the rest of the code that currently only have access to the parsed opcodes, so this only introduces the function for use in the future and deprecates the existing one. Note that, in practice, the script will never actually contain the data that is intended to be removed since the function is only used during signature verification to remove the signature itself which would require some incredibly non-standard code to create. Thus, as an optimization, it avoids allocating a new script unless there is actually a match that needs to be removed. Finally, it updates the tests to use the new function.
Configuration menu - View commit details
-
Copy full SHA for f93c1de - Browse repository at this point
Copy the full SHA f93c1deView commit details -
txscript: Make isDisabled accept raw opcode.
This converts the isDisabled function defined on a parsed opcode to a standalone function which accepts an opcode as a byte instead in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for d3518fc - Browse repository at this point
Copy the full SHA d3518fcView commit details -
txscript: Make alwaysIllegal accept raw opcode.
This converts the alwaysIllegal function defined on a parsed opcode to a standalone function named isOpcodeAlwaysIllegal which accepts an opcode as a byte instead in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for b626552 - Browse repository at this point
Copy the full SHA b626552View commit details -
txscript: Make isConditional accept raw opcode.
This converts the isConditional function defined on a parsed opcode to a standalone function named isOpcodeConditional which accepts an opcode as a byte instead in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for cfd3753 - Browse repository at this point
Copy the full SHA cfd3753View commit details -
txscript: Make min push accept raw opcode and data.
This converts the checkMinimalDataPush function defined on a parsed opcode to a standalone function which accepts an opcode and data slice instead in order to make it more flexible for raw script analysis. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for e915598 - Browse repository at this point
Copy the full SHA e915598View commit details -
txscript: Convert to use non-parsed opcode disasm.
This converts the engine's current program counter disasembly to make use of the standalone disassembly function to remove the dependency on the parsed opcode struct. It also updates the tests accordingly.
Configuration menu - View commit details
-
Copy full SHA for 280c062 - Browse repository at this point
Copy the full SHA 280c062View commit details -
txscript: Refactor engine to use raw scripts.
This refactors the script engine to store and step through raw scripts by making using of the new zero-allocation script tokenizer as opposed to the less efficient method of storing and stepping through parsed opcodes. It also improves several aspects while refactoring such as optimizing the disassembly trace, showing all scripts in the trace in the case of execution failure, and providing additional comments describing the purpose of each field in the engine. It should be noted that this is a step towards removing the parsed opcode struct and associated supporting code altogether, however, in order to ease the review process, this retains the struct and all function signatures for opcode execution which make use of an individual parsed opcode. Those will be updated in future commits. The following is an overview of the changes: - Modify internal engine scripts slice to use raw scripts instead of parsed opcodes - Introduce a tokenizer to the engine to track the current script - Remove no longer needed script offset parameter from the engine since that is tracked by the tokenizer - Add an opcode index counter for disassembly purposes to the engine - Update check for valid program counter to only consider the script index - Update tests for bad program counter accordingly - Rework the NewEngine function - Store the raw scripts - Setup the initial tokenizer - Explicitly check against version 0 instead of DefaultScriptVersion which would break consensus if changed - Check the scripts parse according to version 0 semantics to retain current consensus rules - Improve comments throughout - Rework the Step function - Use the tokenizer and raw scripts - Create a parsed opcode on the fly for now to retain existing opcode execution function signatures - Improve comments throughout - Update the Execute function - Explicitly check against version 0 instead of DefaultScriptVersion which would break consensus if changed - Improve the disassembly tracing in the case of error - Update the CheckErrorCondition function - Modify clean stack error message to make sense in all cases - Improve the comments - Update the DisasmPC and DisasmScript functions on the engine - Use the tokenizer - Optimize construction via the use of strings.Builder - Modify the subScript function to return the raw script bytes since the parsed opcodes are no longer stored - Update the various signature checking opcodes to use the raw opcode data removal and signature hash calculation functions since the subscript is now a raw script - opcodeCheckSig - opcodeCheckMultiSig - opcodeCheckSigAlt
Configuration menu - View commit details
-
Copy full SHA for 75c48ea - Browse repository at this point
Copy the full SHA 75c48eaView commit details -
Configuration menu - View commit details
-
Copy full SHA for bd040ae - Browse repository at this point
Copy the full SHA bd040aeView commit details -
txscript: Rename removeOpcodeByDataRaw func.
This renames the removeOpcodeByDataRaw to removeOpcodeByData now that the old version has been removed.
Configuration menu - View commit details
-
Copy full SHA for c598f59 - Browse repository at this point
Copy the full SHA c598f59View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2e082a8 - Browse repository at this point
Copy the full SHA 2e082a8View commit details -
txscript: Rename calcSignatureHashRaw func.
This renames the calcSignatureHashRaw to calcSignatureHash now that the old version has been removed.
Configuration menu - View commit details
-
Copy full SHA for d72f6d3 - Browse repository at this point
Copy the full SHA d72f6d3View commit details -
Configuration menu - View commit details
-
Copy full SHA for cef8086 - Browse repository at this point
Copy the full SHA cef8086View commit details -
txscript: Remove unused unparseScript func.
Also remove tests associated with unparsing opcodes accordingly.
Configuration menu - View commit details
-
Copy full SHA for 861032a - Browse repository at this point
Copy the full SHA 861032aView commit details -
Configuration menu - View commit details
-
Copy full SHA for ceb58f4 - Browse repository at this point
Copy the full SHA ceb58f4View commit details -
txscript: Remove unused parseScriptTemplate func.
Also remove tests associated with the func accordingly.
Configuration menu - View commit details
-
Copy full SHA for fcb1f3a - Browse repository at this point
Copy the full SHA fcb1f3aView commit details -
txscript: Make executeOpcode take opcode and data.
This converts the executeOpcode function defined on the engine to accept an opcode and data slice instead of a parsed opcode as a step towards removing the parsed opcode struct and associated supporting code altogether. It also updates all callers accordingly.
Configuration menu - View commit details
-
Copy full SHA for 5059be9 - Browse repository at this point
Copy the full SHA 5059be9View commit details -
txscript: Make op callbacks take opcode and data.
This converts the callback function defined on the internal opcode struct to accept the opcode and data slice instead of a parsed opcode as the final step towards removing the parsed opcode struct and associated supporting code altogether. It also updates all of the callbacks and tests accordingly and finally removes the now unused parsedOpcode struct.
Configuration menu - View commit details
-
Copy full SHA for 6adbaa6 - Browse repository at this point
Copy the full SHA 6adbaa6View commit details