CashScript Integrated Debug Tooling for Smart Contracts

CashScript Integrated Debug Tooling

CashScript is a high-level language for writing Bitcoin Cash smart contracts. Because of the lack of integrated (high-level) debug tooling for smart contracts written in CashScript, developers had to use external, low-level debugging tools when running into script errors.

With the release of CashScript v0.10.0 CashScript now uses Libauth for local transaction evalution and two-way mapping to show developers where in the high-level CashScript code the contract error occured.

Error before v0.10.0:

mandatory-script-verify-flag-failed (Script failed an OP_VERIFY operation) (code 16)

Error after v0.10.0:

HodlVault.cash:23 Require statement failed at input 0 in contract HodlVault.cash at line 23.
Failing statement: require(price >= priceTarget)
Bithauth IDE: [link]

Debugging Helpers

Console.log statements
When running your contracts locally using our new tooling, it is now possible to log values during the execution of your smart contract to better understand what is happening

Custom require error messages
Similar to console.log statements, custom require error messages make it much easier to understand which require statement is failing in your transaction.

Integrated tooling

BitahuthIDE

When console.log statements and custom error messages are not enough, we’ve also added an integration with the BitAuth IDE debugger for low-level debugging.

Prior Debugging Methods

Before the integrated debug tooling, low level debugging was possible by using either ‘Meep’ or BitauthIDE:

Meep is a a command line script debugger written in Go and reliant on the BCHD node, which was integrated lightly into CashScript but Meep wasn’t upgraded to support native introspection opcodes as it didn’t have access to the transaction context, similer to BCH it also became unmaintained. Good low-level understanding was still required to understand how the failing expression mapped to the high level CashScript code.

It has also been possible with some manual work to use the Bitauth IDE for debugging by converting the opcodes and bytestrings to the required format. This was of course without without any two way-mapping assistance so good low-level understanding was still required to understand how the failing expression mapped to the high level CashScript code.

Now Meep support has been fully removed and the BitauthIDE has been integrated to have the two way mapping integrated as a comment to the compiled code.

Fully Reworked Documentation

Lastly we have fully reworked the documentation on CashScript.org: overhauled the getting started and added new pages on debugging and contract optimiation

2 Likes

I made a new tutorial video showing the new debug tooling through the CashScript playgroud:
"CashScript Playground Tutorial (mocknet + debugging) "