1. Introduction
Hyperledger Besu is an Ethereum client (open source) written in Java. It can run well on the Ethereum MainNet and test networks like Rinkeby, Rospten and Görli.
So what is the specific Ethereum Client?
The Ethereum Client is the software that implements the protocols of the Ethereum network or the software that runs the EVM virtual machine. If you want to participate directly in the Ethereum network without using a third party such as Infura, or use Metamask … then you must download the Ethereum Client to install on your computer.
Currently, there are many versions of Ethereum Client written in many different languages.
- Main release by Ethereum
- Aleth – C ++ client: https://github.com/ethereum/aleth
- Geth – Golang client of the go-ethereum project: https://github.com/ethereum/go-ethereum
- Trinity – Python client: https://github.com/ethereum/trinity
- Published by 3rd party
- EthereumJ – Java client by the ether.camp team: https://github.com/ethereum/ethereumj
- EthereumJS VM – Javascript Ethereum Virtual Machine: https://github.com/ethereumjs/ethereumjs-vm
- Besu https://github.com/hyperledger/besu
- Mana – Elixir by POA Network – https://github.com/mana-ethereum/mana
- Minimal – Go client by umbracle – https://github.com/umbracle/minimal
- Nethermind – C # / .NET by Nethermind
- Parity Ethereum – Rust client by Parity Technologies: https://www.parity.io/ethereum/
A basic Ethereum Client has the following features:
- Transaction processing, smart contract with EVM environment
- Data storage of networks (blocks)
- Connect P2P to other nodes in the network to synchronize data or broadcast events to the network.
- Provide APIs for developers to interact with the blockchain network
2. Architecture
Besu’s architecture is divided into 4 main parts: Storage , Ethereum Core , Networking and User-facing APIs
- Storage : Besu uses RocksDB to store key-value data. Data stored in storage divided into 2 parts.
- Blockchain : Save a sequence of blocks (including header and body block).
- World State : Save StateTree (mapping address account with state of account (eg balance)).
- Ethereum Core :
- EVM: Compile and process smart contracts as well as transactions.
- Consensus Algorithms: Support 3 algorithms: Proof of Work (Ethash) , Clique and IBFT 2.0 .
- Networking
- Discovery: Protocol based on UDP to find peers on the network
- RLPx: TCP-based protocol that interacts with other peers. Depending on the consensus algorithm, the node will use ETH Sub-protocol or IBF Sub-protocol .
- User-facing APIs
- The application side can use HTTP JSON-RPC , WebSocket JSON-RPC or GrapgQL to interact with the blockchain network. When developing dapp with Besu we can use familiar tools like Truffle , Remix or web3 .
3. Privacy
In addition to being able to work normally on the Ethereum mainet and testnet like other versions of Ethereum Client. Hyperledger Besu also allows users to create a private network (private network) and conduct private transactions on that network.
Orion
We will first explore Orion, an important concept for handling private transactions in Besu.
Orion is an open source software for managing private transactions (private transaction managers) written in Java.
Orion ‘s function:
- Create and maintain public key pairs (private / public keypairs)
- Storing details about
privacy group
(we will learn what is privacy group later) - Connect to other Orio nodes in the network
- Provide API to connect with the Ethereum Client as well as Orion nodes.
Privacy Group
The Privacy Group is a collection of nodes identified by a unique id.
The besu node in this case stores the public world state
of the publics network and the private state
for each privacy group. Data in private state will be accessed from external components.
Private Transactions
Private transactions are transactions that take place in Privacy Groups , the data and status of private transactions will be stored in some private state of Besu node as described above.
Features of private transactions
- Private transactions are only successful when the nodes participating in the transactions are online (verbatim:
All private transaction participants must be online for a private transaction to be successfully distributed
) - Private transactions can only be deploy contracts or call functions in contracts. ETH transfers cannot be private transactions.
- To make private transactions, each Besu node needs a corresponding Orion node.
1 2 3 4 5 6 7 8 9 10 11 12 | <span class="token punctuation">{</span> <span class="token property">"to"</span> <span class="token operator">:</span> <span class="token null">null</span> <span class="token punctuation">,</span> <span class="token property">"from"</span> <span class="token operator">:</span> <span class="token string">"0xfe3b557e8fb62b89f4916b721be55ceb828dbd73"</span> <span class="token punctuation">,</span> <span class="token property">"gas"</span> <span class="token operator">:</span> <span class="token string">"0x7600"</span> <span class="token punctuation">,</span> <span class="token property">"gasPrice"</span> <span class="token operator">:</span> <span class="token string">"0x0"</span> <span class="token punctuation">,</span> <span class="token property">"data"</span> <span class="token operator">:</span> <span class="token string">"0x608060405234801561001057600080fd5b5060dc8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514604e57806355241077146076575b600080fd5b348015605957600080fd5b50606060a0565b6040518082815260200191505060405180910390f35b348015608157600080fd5b50609e6004803603810190808035906020019092919050505060a6565b005b60005481565b80600081905550505600a165627a7a723058202bdbba2e694dba8fff33d9d0976df580f57bff0a40e25a46c398f8063b4c00360029"</span> <span class="token punctuation">,</span> <span class="token property">"nonce"</span> <span class="token operator">:</span> <span class="token string">"0x0"</span> <span class="token punctuation">,</span> <span class="token property">"privateFrom"</span> <span class="token operator">:</span> <span class="token string">"negmDcN2P4ODpqn/6WkJ02zT/0w0bjhGpkZ8UP6vARk="</span> <span class="token punctuation">,</span> <span class="token property">"privateFor"</span> <span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">"g59BmTeJIn7HIcnq8VQWgyh/pDbvbt2eyP0Ii60aDDw="</span> <span class="token punctuation">,</span> <span class="token string">"6fg8q5rWMBoAT2oIiU3tYJbk4b7oAr7dxaaVY7TeM3U="</span> <span class="token punctuation">]</span> <span class="token punctuation">,</span> <span class="token property">"restriction"</span> <span class="token operator">:</span> <span class="token string">"restricted"</span> <span class="token punctuation">}</span> |
In addition to some schools similar to public transactions, private transactions have the following additional schools:
privateFrom
: The Orion public key of the senderprivateFor
: – The Orion public keys of the recipientprivacyGroupId
restriction
: One of 2restricted
orunrestricted
valuesrestricted
: Only nodes participating in the transaction receive a payloadunrestricted
: All nodes in the network receive a payload of private transactions, but only nodes that are part of the transaction can read it.
The process of handling a private transaction
The process of handling a private transaction includes:
- Precompiled Contract : Smart contract is compiled into EVM bytecode and stored at the Ethereum node for further processing.
- Privacy Marker Transaction : A public Ethereum transaction with payload accompanied by a enclave key. The Enclave key is a pointer, it points to the private transaction at the Orion node. The
to
field in the Privacy Marker Transaction is the address of the contract compiled above.
The Privacy Marker Transaction is signed with a random key or a key specified via the command-line
Note : Private transactions are still public on the Ethereum network and close into normal blocks like other public transactions. The only difference is that when in the Privacy group , the nodes will use the private state
instead of the public state
of the Ethereum network.
- Private transactions are submitted using eea_sendRawTransaction
- Private transactions are forwarded to the Private Transaction Handler in the Besu node via JSON-RPC.
- Private Transaction Handler sends private transactions to the Orion node corresponding to the current Besu node.
- The Orion node sends private transactions directly to the recipient’s Orion node (point-to-point) or the Orion nodes in the privacy group (subject to the
restriction
field in private transactions). Orion nodes receive and store private transactions in key-value form. - The Orion node returns transactions hash to the Private Transaction Handler .
- Private Transaction Handler creates a Privacy Marker Transaction . The Private Transaction Handler will broadcast the Privacy Marker Transaction throughout the public network via P2P protocol.
- Miner will close the Privacy Marker Transaction to the block and broadcast it over the network
- With the storage nodes
contract
with the same address with the address in the contract Privacy Privacy Marker Marker Transaction Transaction will retain and further processing. The remaining nodes will ignore the Privacy Marker Transaction . - Contract queries the Orion node for information and
private transaction
andprivacy group ID
using transaction hashes. - Contract converts the private transaction into Private Transaction Processor
- Private Transaction Processor executes transactions. The Private Transaction Processor can read and write to the
private world state
and can only be read from thepublic world state
.
References
https://www.hyperledger.org/blog/2019/08/29/announcing-hyperledger-besu https://besu.hyperledger.org/en/stable/