Debugger Failed to Start

Usually there is a problem with the input parameters of launch.json, such as:

  1. The number of parameters does not match

  2. Parameter type does not match

  3. Parameter input format incorrect

  4. Forgot to provide Transaction Context

_images/launchfail.gif

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.

_images/stoponexception.png

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:

  1. A wrong private key that does not match the public key was used to sign the transaction

  2. Signed the wrong Preimage (Preimage).

The debugging console will prompt auxiliary information.

_images/checksig.png

The above prompt information covers the main checkpoints when resolving signature errors, namely:

  1. Determine whether the private key used to generate the signature is correct.

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

_images/sighashpreimage.png

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.

_images/checkpreimagefail.png

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.

_images/diffoutputs.gif