Streamline Your Smart Contract Development with Scribble

Streamline Your Smart Contract Development with Scribble

The world of smart contract development can be overwhelming, with countless lines of code to write and endless testing to ensure everything works as intended. But what if there was a tool that could make the process easier and more efficient? Look no further than Scribble.

Scribble is a runtime verification tool for Solidity that allows developers to annotate their code with properties, essentially adding additional layers of automated testing. By transforming annotations in the Scribble specification language into concrete assertions that check the specification, Scribble ensures that your code behaves as intended.

But what sets Scribble apart from other verification tools? For one, it allows you to write annotations directly in your smart contract code, instead of having to write them in a separate file. This makes it easier to keep track of your annotations and ensures that they stay up-to-date as your code changes.

In addition, Scribble has multiple output modes, including flat mode, files mode, and json mode, making it easy to integrate into your workflow. And with tools like Diligence Fuzzing, you can automate testing and ensure that your contracts are working as planned.

How to Get Started with Scribble

The first step to using Scribble is to install it using NPM. Be sure to use the correct version of NodeJS - Scribble 0.6.4 and earlier work with NodeJS versions between 10.0.0 and 12.0.0, while Scribble 0.6.5 and later work with NodeJS 16.0.x. To install, simply run the following command:

npm install -g eth-scribble

Once Scribble is installed, you can start annotating your code with properties. Here's an example of how to do so:

import "scribble/Spec.sol";

contract MyContract {
   uint256 public myVar;

   constructor(uint256 _myVar) {
      myVar = _myVar;
   }

   /// #if_succeeds {:msg "MyVar increased by specified value."} myVar == old(myVar) + _value;
   function increaseMyVar(uint256 _value) public {
      myVar += _value;
   }
}

In this example, we're using the #if_succeeds annotation to specify a property that checks whether myVar has been increased by the specified amount. When you run Scribble, it will transform this annotation into a concrete assertion that verifies the specification.

But what if you already have existing property-based tests? That's where Scribble Generator comes in. This tool adds annotations to all of your existing fuzz test cases, instantly enabling any Scribble-compatible tool to check the properties. To install Scribble Generator, run the following command:

npm install -g scribble-generator

Once installed, you can use the scribble-generate command to add annotations for all fuzz tests that weren't annotated yet. For example:

cd /path/to/directory
scribble-generate

This will add Scribble annotations for all fuzz tests which weren't annotated yet.

Integrating Scribble into Your Workflow

Scribble has multiple output modes to choose from, depending on your needs. The flat mode is useful for submitting the instrumented code to services like Mythril or MythX. In files mode, Scribble emits an instrumented version of each file containing contracts with annotations in the same directory. Json mode behaves similarly to flat mode, but outputs the AST of the flattened file instead.

For example, to emit a flat instrumented file, run:

scribble Foo.sol --output-mode flat --output Foo.flat.sol

This will instrument Foo.sol and output the result to the Foo.flat.sol file.

To emit instrumented files in-place, run:

scribble /path/to/directory --output-mode files

This will instrument all relevant contracts in the directory and output the result to .instrumented.sol files in the same directory.

Conclusion

Scribble is a powerful tool that can streamline your smart contract development by adding automated testing with annotations. With its multiple output modes and compatibility with other tools like Diligence Fuzzing, it's easy to integrate into your workflow. And with Scribble Generator, you can even add annotations to existing property-based tests. Give Scribble a try and take your smart contract development to the next level. To learn more, check out the official documentation at https://docs.scribble.codes/.