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%
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%
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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%
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.
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%
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%
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.
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%
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%
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.
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%
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%
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%
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%
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%
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%
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%