Skip to content

Commit

Permalink
Refactor to replace Alethio with archive node with trace_replayTransa…
Browse files Browse the repository at this point in the history
…ction support

Formatting of function parameters including ABI v2 support
Proxy messages
Simplified value transfers and self-destruct
Added transaction details
  • Loading branch information
naddison36 committed Jan 4, 2021
1 parent e0123ec commit a2e0cb9
Show file tree
Hide file tree
Showing 87 changed files with 3,914 additions and 2,776 deletions.
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "avoid",
"semi": false,
"trailingComma": "es5",
"singleQuote": false,
"tabWidth": 4
}
95 changes: 63 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

[Unified Modeling Language (UML)](https://en.wikipedia.org/wiki/Unified_Modeling_Language) sequence diagram generator for Ethereum transaction.

The below example is of a Maker DAO CDP transaction with gas usages.
The below example transaction is a [mStable](https://mstable.org/) swap from 5,100 USD Coin (USDC) to 5,096 Tether USD (USDT).

```
tx2uml 0x4d953a8c531624e8336df5060239b7c0462b3d4d0cc5dcbb61af679ba81d161a -v -g -o makerDao
tx2uml 0xb2b0e7b286e83255928f81713ff416e6b8d0854706366b6a9ace46a88095f024
```

![Maker DAO CDP](./examples/makerDao.png)
![mStable USD Swap](./examples/mStableUSDSwap.png)

See a lot more examples [here](./examples/README.md#example-uml-sequence-diagrams)
See a lot more examples [here](./examples/README.md)

# Install

Expand Down Expand Up @@ -48,21 +48,21 @@ Use the `-h` option to see the `tx2uml` CLI usage options
$ tx2uml -h
Usage: tx2uml <transaction hash or comma separated list of hashes> [options]
Ethereum transaction visualizer that generates a UML sequence diagram from transaction contract calls.
Ethereum transaction visualizer that generates a UML sequence diagram of transaction contract calls from an Ethereum archive node and Etherscan API.
The transaction hashes have to be in hexadecimal format with a 0x prefix. If running for multiple transactions, the comma separated list of transaction hashes must not have white spaces. eg spaces or tags.
Options:
-f, --outputFormat <value> output file format: png, svg or puml (default: "png")
-o, --outputFileName <value> output file name
-n, --network <network> mainnet, ropsten, kovan or rinkeby (default: "mainnet")
-a, --alethioApiKey <key> Alethio API Key
-p, --params show function params and return values (default: false)
-g, --gas show gas usages (default: false)
-e, --ether show Ether value (default: false)
-t, --transfers only show ether and token transfers (default: false)
-o, --outputFileName <value> output file name. Defaults to the transaction hash.
-u, --url <url> URL of the archive node with trace transaction support. Can also be set with the ARCHIVE_NODE_ENV environment variable. (default: http://localhost:8545)
-p, --noParams Hide function params and return values (default: false)
-g, --noGas Hide gas usages (default: false)
-e, --noEther Hide ether values (default: false)
-t, --noTxDetails Hide transaction details like nonce, gas and tx fee (default: false)
-v, --verbose run with debugging statements (default: false)
-h, --help output usage information
```

# Syntax
Expand All @@ -79,11 +79,13 @@ Stereotypes are added for the contract and token name if they can be sourced. Th

There are five types of messages

- **Call** an external contract call shown as a filled arrow head at the to contract.
- **Return** of a call shown as a dotted line with the filled arrow head.
- **Value** transfer of Ether shown as an open arrow head with the amount in Ethers
- **Create** a new contract with
- **Selfdestruct** shown as a dotted lined with a filled arrow head
- **Call** is a solid or dotted line with a filled arrow head at the `to` contract.
- **Return** is a dotted line with a filled arrow head at the `from` contract.
- **Delegate** is a solid or dotted line with an open arrow head at the `to` contract.
- **Create** is a filled line with a filled arrow head and a circle at the contract being created.
- **Selfdestruct** is a solid line with a half filled arrow head looping back on itself with a `Self-Destruct` label.

Call and delegate messages with a dotted line are proxy calls that uses the calling contract's `fallback` function.

## Delegate Calls

Expand All @@ -95,45 +97,74 @@ In the sequence diagram, the lifeline of the delegated call will be in blue and

# Data Source

## Alethio
## Archive node that supports tracing transactions

`tx2uml` needs an Ethereum archive node that supports the [trace_replayTransaction](https://openethereum.github.io/JSONRPC-trace-module#trace_replaytransaction) JSON RPC API.
Known Ethereum node clients that support this are:
* [OpenEthereum](https://github.com/openethereum/openethereum)
* [Nethermind](https://nethermind.io/client)

The [Go-Ethereum (Geth)](https://github.com/ethereum/go-ethereum) node does not support tracing transactions. It only supports debugging with the [debug_tracetransaction](https://geth.ethereum.org/docs/rpc/ns-debug#debug_tracetransaction) API.
[Turbo-Geth](https://github.com/ledgerwatch/turbo-geth) is a fork of Geth and also does not support tracing.

[Hyperledger Besu](https://www.hyperledger.org/use/besu) supports tracing transactions but it's JSON RPC API is slightly different to Nethermind and OpenEthereum. It's method is [trace_transaction](https://besu.hyperledger.org/en/stable/Reference/API-Methods/#trace_transaction) and not `trace_replayTransaction`.

### Ethereum API providers

Most Ethereum API providers do not provide tracing and debugging APIs as they are resource intensive on the server side.

* [ArchiveNode.io](https://archivenode.io/) brings archive data on the Ethereum blockchain to small time developers who otherwise couldn't afford it. They offer both Nethermind and Turbo-Geth archive nodes. If you want to use one specifically, you can add either /nethermind or /turbogeth to the end of your endpoint.

All the contract calls are sourced from [Alethio](https://aleth.io/). Specifically, the [Contract Messages API](https://docs.aleth.io/api#tag/Contracts/paths/~1contracts~1{address}~1contractMessages/get) which as already done the hard work of parsing the transaction trace to extract the contract call details.
[Infura](https://infura.io/) does not support tracing transactions.

The Alethio API is free for volumes less than 10,000 calls a month. After that you'll need an API key from https://developers.aleth.io/. In order to trace large transactions, over a dozen Alethio calls can be made for one transaction as contract messages are limited to 100 messages per API call.
[Alchemy](https://alchemyapi.io/) does support tracing transactions on their paid [Growth plan](https://alchemyapi.io/pricing) but it was not reliable at the time of development.

## PlantUML
## Etherscan

[Etherscan](https://etherscan.io/) is used to get the Application Binary Interfaces (ABIs) for the contracts used in a transaction. Etherscan's [get contract ABI](https://etherscan.io/apis#contracts) API is used with module `contract` and action `getsourcecode`. For example
https://api.etherscan.io/api?module=contract&action=getsourcecode&address=0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413

# PlantUML

[PlantUML](https://plantuml.com/) is a Java program that can convert Plant UML syntax into png, svg or eps images. tx2uml pipes the PlantUML to the spawned Java process which then pipes the image outputs to a file.

[plantuml.jar version 1.2020.2](https://sourceforge.net/projects/plantuml/files/plantuml.1.2020.2.jar/download) is currently used and it shipped in the [lib](./lib) folder.
[plantuml.jar version 1.2020.26](http://sourceforge.net/projects/plantuml/files/plantuml.1.2020.26.jar/download) is currently shipped in the [lib](./lib) folder.

See [Recent changes](https://plantuml.com/changes) for PlantUML's release notes.

### PlantText
## PlantText

[PlantText](https://www.planttext.com/) is an online tool that generates diagrams from PlantUML.

### PlantUML extension for VS Code
## PlantUML extension for VS Code

[Jebbs PlantUML](https://marketplace.visualstudio.com/items?itemName=jebbs.plantuml) extension for VS Code is used to authoring the PlantUML diagrams.

`Alt-D` on Windows, or `Option-D` on Mac, to stat PlantUML preview in VS Code.

## Generate png files form puml

The following will generate png files for the above examples.

```
java -jar ./lib/plantuml.jar ./examples/syntax.puml ./examples/delegate.puml
```

# UML Syntax

Good online resources for learning UML

- [PlantUML Sequence diagrams](https://plantuml.com/sequence-diagram)
- [Ashley's PlantUML Doc](https://plantuml-documentation.readthedocs.io/en/latest/diagrams/sequence.html)
- [UML 2 Sequence Diagramming Guidelines](http://www.agilemodeling.com/style/sequenceDiagram.htm)
- [PlantUML Sequence diagrams](https://plantuml.com/sequence-diagram)
- [Ashley's PlantUML Doc](https://plantuml-documentation.readthedocs.io/en/latest/diagrams/sequence.html)
- [UML 2 Sequence Diagramming Guidelines](http://www.agilemodeling.com/style/sequenceDiagram.htm)

# Similar transaction visualisation tools

- [Parity Trace Decoder](https://github.com/k06a/parity-trace-decoder)
- [Tenderly](https://dashboard.tenderly.dev/)
- [EthTx info](http://ethtx.info/)
- [Bloxy](https://bloxy.info/)
- [Etherscan](https://etherscan.io/txs)
- [Parity Trace Decoder](https://github.com/k06a/parity-trace-decoder)
- [Tenderly](https://dashboard.tenderly.dev/)
- [EthTx info](http://ethtx.info/)
- [Bloxy](https://bloxy.info/)
- [Etherscan](https://etherscan.io/txs)

## Development

Expand Down
Binary file removed examples/0xUniverse.png
Binary file not shown.
Binary file added examples/1inchFailedInternal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/1inchSynth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a2e0cb9

Please sign in to comment.