Debugger Failed to Start
Usually there is a problem with the input parameters of launch.json, such as:
The number of parameters does not match
Parameter type does not match
Parameter input format incorrect
Forgot to provide Transaction Context
When this error occurs, open the launch.json file and check whether the parameters are filled in correctly.
Abnormal Automatic Interrupt
When the debugger encounters an exception in the code during execution, it will automatically interrupt the execution and keep the scene to facilitate the diagnosis of the exception. You can diagnose the exception by viewing the variable value, call stack, and monitored expression at the interrupt site, and you can also execute the code in the debug console to analyze the exception.
For some typical exceptions, the debugger provides more information and methods for analysis and diagnosis of exceptions.
Signature Check Failed
A common type of error is checkSig
failure. reasons may be:
A wrong private key that does not match the public key was used to sign the transaction
Signed the wrong Preimage (Preimage).
The debugging console will prompt auxiliary information.
The above prompt information covers the main checkpoints when resolving signature errors, namely:
Determine whether the private key used to generate the signature is correct.
Confirm whether the preimage of the tx to be signed (automatically calculated according to the transaction context) is consistent with the incoming parameters. The trick here is: insert a piece of code where the input parameter preimage is generated, and compare it with the preimage output in the above exception prompt, and then find out the possible differences between the two. As shown in the following code:
1const { getPreimage, SigHashPreimage, signTx } = require('scryptlib');
2
3...
4
5const preimage = getPreimage(tx_, token.lockingScript.toASM(), inputSatoshis, inputIndex)
6const sig = signTx(tx_, privKey, token.lockingScript.toASM(), inputSatoshis)
7console.log(preimage.toJSON())
What needs to be reminded here is that the fields under the debugger startup configuration txContext
(transaction context) attribute will affect the calculation of preimage, so when troubleshooting, you need to compare and confirm whether they are consistent.
Transaction Preimage Check Failed
Another common type of error is the checkPreimage
exception. The usual reason is that the value passed in the startup configuration parameter pubFuncArgs
is inconsistent with the result calculated by the parameters in the txContext
used.
As shown in the figure above, Sighash Preimage is composed of multiple parts. If the two pre-images are inconsistent, some of the fields must be different. When such an exception occurs, the Debug Console will automatically print an error message, in which there will be a table containing all the different fields of the two pre-images. If the scriptCode
field is different, the comparison result of the two scriptCode
fields will also be printed. With these error messages, you can quickly analyze the cause of the exception.
Inconsistent Transaction Output Hash
This is usually due to the fact that one or more transaction outputs of the current transaction do not sign the constraints on output by the logic of the contract itself. For example, the following example:
Counter contract constraint satoshis in output must be equal to the unlock parameter amount
, the actual output satoshis is 222222
, and the value of unlock parameter amount
is 2222222
.
Since the contract checks whether the hashes are consistent, when this type of error occurs, you can only know that the output hashes are inconsistent, and you cannot directly locate the difference between the two.
The debug console provides the :diffoutputs
built-in command, which can compare the output generated by the contract with the output from the current transaction, and quickly find out the possible differences between the two.