Scribble
Search…
Annotations
In Scribble you can formalise properties by writing annotations for contracts, state variables and functions. In addition you can add auxilary annotations that define helper functions to be used in properties, or that give hints to the backend tools that try to check the properties you wrote.
All annotations appear in docstrings, and begin with the pound sign # followed by a specific keyword. There are several different kinds of annotations at your disposal:
If you place an annotation in a normal comment ( /* */ or //), instead of a docstring comment (/** **/ or ///) it will be ignored!
Note that if you forget the pound sign (#) your annotation will also be ignored! Scribble will issue a warning in most cases when this happens.
Solidity recently added the @custom: natspec tag. As of Scribble v0.6.1 we also support annotations prefixed with @custom:scribble. Note that the pound sign before keywords is still requried! (i.e. you need to write @custom:scribble #if_succeeds ... instead of @custom:scribble if_succeeds ...).

Function Annotations

Function annotations are what you can use to describe how a function should behave. You'll commonly use them to ensure that the function has the right side-effects, and that the return values are correct.

Example

1
/// #if_succeeds $result > 0;
2
function positiveNumber() external returns (uint) {
3
...
4
}
Copied!
Read more about function annotations here:

State Variable Annotations

State variable annotations allow you to describe properties that should hold for a particular variable whenver its updated. For example, you might specify that a variable can only change under particular circumstances.

Example

1
contract Example {
2
// #if_updated msg.sender == owner || owner == address(0);
3
address owner;
4
}
Copied!
Read more about state variable annotations here:

Contract Annotations

Contract annotations allow you to describe properties that concern multiple variables and functions. The most common contract annotation will be an invariant, which is used to describe properties that hold before and after each transaction.

Example

1
/// #invariant sum(balances) == totalSupply;
2
contract Token {
3
...
4
}
Copied!
Read more about contract annotations here:

Scribble Functions

Scribble functions are a utility feature which enables you to reduce code duplication between annotations. They also make annotations much easier to read!

Example

1
/// #define add10(uint x) uint = x + 10;
2
contract Example {
3
/// #if_succeeds add10(1) == 11;
4
function example() public {}
5
}
Copied!
Read more about Scribble functions here:

Assert Annotations

Assert annotations allow users to insert an annotation in the middle of a function, before a specific statement. They can refer to any local variable in scope

Example

1
contract Example {
2
mapping(address=>uint) balances;
3
function setBalances(address memory[] addrs, uint[] memory amounts) public {
4
for (uint i = 0; i < addrs.length; i++) {
5
/// #assert amounts[i] > 0;
6
balances[addrs[i]] = amounts[i];
7
}
8
}
9
}
Copied!
Read more about Scribble functions here:

Macros

Macro annotations allow applying a whole set of pre-defined annotations to a contract. Macro annotations are defined in .yaml files and applied to a contract with the /// #macro name(var1, var2, ...). annotation.

Example

1
/// #macro erc20(_balances);
2
contract MyERC20Token {
3
mapping(address=>uint256) _balances;
4
....
5
}
Copied!
Read more about Scribble macros here:

Hints

Sometimes a user needs to provide guidance to the backend tools that are attempting to check the annotated properties. Scribble supports providing guidance with 2 types of annotations:
  1. 1.
    Limiting the types of input with a #require annotations
  2. 2.
    Suggesting inputs for the tools to try with #try annotations
Read more about giving hints to the backend tools here: