Understanding Power of Horizen EON's Stateful Model: User Experience in Account-Based Transactions
Tags: web3, blockchain, ux, cryptocurrency
Published: 2024-02-28 17:49:21



## TL;DR 

In blockchain, we have two major accounting models, UTXO which views the state as a flow of assets between addresses while in the account-based model, the state changes with each transaction adjusting account balances accordingly. Horizen’s EON is a powerful EVM (Ethereum Virtual Machine) sidechain that is able to send and receive $ZEN via the Cross Chain Transfer Protocol using zero knowledge cryptography.   Some of the many advantages of Horizen EON is to improve user experience,reduce development complexities and provide a set of tools and ecosystem to integrate with different dApps and deploy smart contracts on top of the network. 

### **Introduction**

Blockchain space has been growing faster than we anticipated. The infrastructure for Web3 applications must be enhanced to manage a greater volume of transactions, improve performance, and maintain privacy. The user experience is the highlight of any product, users want to have full ownership of every function as well as their funds.

In order to support this demand for true decentralization, enhanced security and transaction efficiency, [Horizen](https://eon.horizen.io) has created a new paradigm for developers and end-users. 

> [Horizen](https://www.horizen.io/what-is-horizen/) is an interoperable blockchain ecosystem that prioritizes security  and the ability to scale. At its core, it employs the zero-knowledge-proof protocol, specifically zk-SNARKs, to secure communications and ensure that inter-chain conversations remain safe.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j96d45vvyvzu9wp8vhrg.jpeg)

To defend against potential blockchain attacks like the 51% attack, Horizen has implemented a robust set of security measures. This includes a carefully designed consensus mechanism, the notarization of blocks across multiple chains, and TLS end-to-end encryption to shield data from prying eyes.

It also uses the largest and most decentralized multi-tiered node network in the industry, ensuring reliability and maintaining a distributed ecosystem.

- Horizen is compatible with the Ethereum Virtual Machine (EVM) via  Horizen EON, which is a sidechain and is a smart contract platform for developers to support the blockchain trilemma for decentralization, scalability and privacy and uses Horizen’s massive computational power.

Throughout this article, we will explore how the EON sidechain from Horizen supports an account-based model for web3 users and examine the broader implications this has on transactions and decentralized applications.

To learn more on Horizen’s architecture, you can check out the official docs [here](https://www.horizen.io/technology/). 

### Evolution of blockchain models

Blockchain is a distributed ledger of transactions, fully immutable and always available. Now, to prove the source of transaction and the balances of cryptocurrency a user owns on a network, we have two models of keeping a record for transactions: the Unspent Transaction Output (UTXO) model and the account-based model. From a blockchain architecture perspective, they play a role in maintaining the accurate “ledger” of transactions while ensuring privacy.

To give a brief of both models, the UTXO model is simple and privacy-focused, treating each coin as a unique transaction output. Bitcoin, for instance, uses the UTXO model. Each transaction creates a new set of UTXOs, and the ownership of these UTXOs is what represents a user's cryptocurrency balance. Now, once a transaction is completed on the blockchain, the tokens or funds that were spent get removed from the UTXO database. UTXOs can be considered individual chunks of funds that can be combined and broken down to process transactions.

In the account-based model, which is followed by Ethereum, the assets are represented as balances with accounts. You can think of this model as a simple banking process where a bank being a ledger, records the transfer of the assets or funds as debit and credit in the respective user accounts. In other words, account-based blockchains would technically not track any of the tokens you own but notify changes on the accounts or wallet addresses. Therefore, the user's identity, represented by their unique account address, becomes integral to the transaction process.

Let’s take a look at how the stateful architecture of an account-based model impacts the overall user experience.

## Stateful model and potential of account-based blockchains 

Before we jump into the stateful architecture and state mechanisms, it's essential to understand the basic structure of a blockchain. This structure is adhered to regardless of whether the blockchain is based on UTXO or accounts.

Transactions are disseminated across the network:

- A new block is generated
- Transactions are permanently recorded on the chain
- Smart Contracts are the backbone of the blockchain systems.
 
The stateful model connects with the “memory” of smart contracts to remember information about its ‘previous interactions’ on the blockchain.

> For instance, Ethereum uses a stateful architecture in which all the miners on the blockchain network update their copy of the network each time a new transaction occurs on the blockchain. 

Comparatively, in the UTXO model of Bitcoin, the smart contracts are inherently stateless. This is why a UTXO is destroyed once it has been spent.

Smart contracts, owing to their stateful nature, are capable of managing interactions with more programmable logic than their stateless counterparts. They can also store and update chain values. 

Platforms like Horizen, thanks to the account-based model, can build applications effectively. Its public proof-of-stake sidechain, EON, is fully compatible with EVM smart contracts. This compatibility aids in the development and deployment of decentralized apps on Horizen while maximizing the advantages of the Ethereum ecosystem.

The stateful model introduces two distinct account types: Externally Owned Accounts (EOAs) and Contract Accounts. 

EOAs are created when a user initiates their wallet, whereas Contract Accounts are established when a user deploys a smart contract. In later sections, we will dive deeper into these and understand how they impact the overall user experience on stateful blockchains.


## Blockchain as a “state” machine 

In a blockchain context, the term "state" refers to a snapshot of all information on the blockchain at a particular point in time. This includes the current status of all accounts and transactions in the network. It's a dynamic concept, continuously updated with each new block added to the blockchain, ensuring it reflects the latest transactions and account balances.

Now, let's discuss the difference in how the UTXO and the account-based models handle state.

The UTXO model, used by Bitcoin, captures the state as an set of Unspent Transaction Outputs, which are the outputs of past transactions that have not been spent. Each transaction modifies the state by consuming some UTXOs and producing new ones. The state in the UTXO model is thus a flow of assets between addresses, represented as a directed acyclic graph (DAG).

On the other hand, the account-based model, used by Ethereum, reflects the state as the current balances of all accounts on the network. When a transaction occurs, the state changes, with the sender's account balance decreasing and the receiver's account balance increasing. The state in the account-based model is essentially a snapshot of all account balances at a given moment, maintained as a database of network states.

## Future of account based models - EOAs and Contract Accounts
 
Externally Owned Accounts (EOAs) are created when a user initiates their wallet in the Ethereum network. EOAs are directly controlled by private keys and primarily serve the purpose of initiating transactions. They offer users full control over their assets, as they can freely transfer funds to other accounts or interact with Contract Accounts.

The Ethereum Virtual Machine (EVM) features a BALANCE operation, which enables us to easily look up an address's balance inside the code running on the EVM. This is a much simpler process than adding all unspent transaction outputs that list a particular address as their recipient.

In addition to the balance, each Ethereum address also includes a nonce. The nonce is a count of all transactions sent from that specific address. This factor is pivotal in differentiating the account-based and UTXO models, where such a count is not maintained. The nonce provides a sequence number for transactions, ensuring their correct order and preventing double-spending and replay attacks.

On the other hand, Contract Accounts are established when a user deploys a smart contract on the Ethereum network. Unlike EOAs, Contract Accounts are governed by their contract code and can only perform actions when triggered by an EOA. They hold both the contract code and its associated data.
The balances, storage, and code space within these accounts are the foundation for efficient and versatile transactions within the stateful model.

A contract account can preserve the address of another contract with which it needs to interact. As this address is stored, it can be modified through transactions. Thus, it's feasible to upgrade a system by launching new contracts and executing a transaction to update references to the new addresses. This process, often called smart contract upgradeability, can be somewhat complex.

## User Experience for account-based model vs UTXO 

For any user, transaction fees are the starting point to compare the user experience. The method of calculating transaction fees under the account-based model differs significantly from that under the UTXO model. Instead of imposing fees for data storage, the account-based model charges based on the computational resources necessary for processing and validating the transaction. 

This approach is facilitated by global state tracking, a comprehensive database detailing all accounts, keys, contract codes, and balances across the network. Having this complete perspective allows the computational expenses associated with state transitions to form the basis for fee calculation. 
In contrast, UTXO-based systems can only access the overall network state's local transaction inputs and outputs. 

The essential components of accounts on Ethereum include: 

- Balance: The quantity of ETH held by the account. 
- Nonce: A counter indicating the number of confirmed transactions. 
- Storage: The storage space occupied by the smart contract code. 
- Code: This applies exclusively to contract accounts.

In essence, each account undergoes direct value and information transfers during state transitions, which dynamically affects the status of the network.

As a developer, another reason why choosing an account-based model chain, such as using Horizen’s EON sidechain, would make more sense is because of the underlying tech of how Ethereum uses a Turing complete programming language and allows the arbitrary logic added to smart contracts for more flexibility as well as simplicity to offer decentralized applications serving custom purpose. 

In contrast to the UTXO model, each transaction in the account model requires just a single reference and signature, resulting in only one output. This leads to considerable space savings, a critical factor for a large and complex blockchain like Ethereum. 

To sum it up, the stateful architecture eliminates the complexities of handling individual transaction outputs and calculating "change," making the transaction process more intuitive and user-friendly. The account-based model is pivotal in EON's blockchain architecture with its nuanced account types - Externally Owned Accounts and Contract Accounts.

With the support of an account-based model and Horizen’s largest node network for a decentralized and secure experience across the ecosystem, we can truly say that the future of web3 is going to be simplified without compromising on blockchain trilemma and developers can opt for a modular settlement layer with EVM compatible sidechain EON for a seamless experience.

Checkout some of the [developer examples](https://docs.horizen.io/horizen_eon/tutorials/todolist) in the [official documentation](https://docs.horizen.io/). Join the Horizen’s community on [discord](https://discord.com/invite/horizen) to start learning more about EON sidechain and building with the best infrastructure out there.