Analyzing Solidity Smart Contracts with Piet

Heiko Burkhardt
slock.it Blog
Published in
3 min readAug 7, 2019

If you develop, audit, or use complex smart contracts, you may have wished for:

  • a graphical representation of a smart contract architecture that helps you communicate with coworkers or clients (or even just document it);
  • an easily understandable inheritance structure;
  • a fast way to interact with contracts through a graphical user interface (e.g., read the state, send transactions, or list events);
  • a compelling way to create smart contract documentation from NatSpec annotations.

Piet, our new software, fills these needs by parsing Solidity code, graphically representing contracts and their relations, and providing a smart contract inspector.

Live demo

GitHub Repository

Warning: Piet has not yet undergone in-depth testing and may contain serious bugs.

Getting Started

Piet supports Solidity source files, Truffle build files, and piet container files. To load these files, click on Load in the Files tab.

You can also use Piet is to retrieve the Solidity sources directly from a public GitHub repository. To do so, pass the GitHub account and repository name as the URL parameters gitHubUser andgitHubRepo. Optionally, you can use the URL parameter subDir to pass a path to the repository directory containing the contracts. This prevents Piet from scanning the complete repository for Solidity files. Similarly, you can use the parameter container to load a Piet container file.

For example:

https://piet.slock.it/?gitHubUser=gnosis&gitHubRepo=safe-contracts&subDir=contractshttps://piet.slock.it/?container=examples%2Fexport1562664060589.piet.json

If available, Piet uses an injected web3 object to interact with a blockchain. You can also use RPCs or Incubed to connect to a chain. To change the connection method, click on the connection icon in the lower-left corner.

Inheritance Structure

Inheritance graph

This view shows the inheritance structure of the Gnosis Safe smart contracts and the structs and enumeration defined in these contracts. In the example above, the contract DailyLimitModule inherits the contract members from the contract Module and defines the struct DailyLimit.

Contract Inspector

Calling a function

If a contract is selected by clicking on its name in the graph view, the contract inspector shows the member elements of the selected contract (e.g., state variables, functions, modifiers, and events). Documentation labels derived from NatSpec annotations in the Solidity code will also be shown.

You can retrieve the state of a contract instance and send transactions via the contract inspector. To enable these interactions, provide the address of the contract by clicking on the edit icon and pasting the address.

Piet Container File

If you have loaded a lot of contracts, moved around the boxes in the inheritance graph, or added instance addresses to contracts you can create a Piet container file to save your work. To create a container file, click on Save in the File tab.

Additional Features

Piet also provides the following features:

  • Event browser
  • NatSpec to Markdown documentation generator
  • Node inspection via JSON RPC calls
  • Transaction history view
  • Code and ABI view

CHECK OUT PIET

Event browser
Node inspection
Documentation generator

--

--