EVM -> Solana

EVM vs. SVM: Accounts

Посмотрите, как accounts differ when building on Ethereum and Solana.

As blockchain networks, Ethereum and Solana possess unique data structures, functioning as global public world computers that store and share data on their networks. In this chapter, we aim to explore how these chains structure their data sets.

'Account' in Ethereum

В Ethereum «аккаунт» относится к сущности, которая владеет Ether и может отправлять транзакции. Он включает баланс, nonce (счётчик транзакций), код (для контрактных аккаунтов) и хранилище данных. Существует два типа аккаунтов: Externally Owned Accounts (EOA), контролируемые приватными ключами, и Contract Accounts (CA), управляемые кодом смарт-контракта.

  • EOA (Externally Owned Account): An account owned externally, possessing a private key. Think of it as an account for an individual's wallet.
  • CA (Contract Account): An account for contracts, holding smart contract code.

A key difference between EOA and CA in Ethereum is that EOA, not being a smart contract, typically does not have its own storage. Therefore, the code hash of an EOA is set to a 'null' hash, indicating that the account does not have storage.

An Externally Owned Account (EOA) is an account with a private key, and possessing a private key means controlling access to funds or contracts. The private key implies control over access to funds or contracts.

The following data are included in an EOA:

FieldDescription
addressAn Account's address
balanceThe amount of ETH (in wei) an address owns.
nonceA counter that shows the number of transactions sent from the account to ensure transactions are processed only once. With smart contracts, it reflects the number of contracts created by the account.
code hashThe code of an account on the EVM.
storage hash (storage root)A 256-bit hash of the root node of a Merkle Patricia Tree that encodes the storage contents of the account. This tree encodes the hash of the storage contents of this account, and is empty by default.

A Contract Account contains smart contract code that simply cannot be held by an EOA. Additionally, a Contract Account does not have a private key. Instead, it is controlled by the logic of the smart contract code. This smart contract code, recorded on the Ethereum blockchain when the Contract Account is created, is a software program executed by the EVM.

Like an EOA, a Contract Account has an address and can send and receive Ether. However, when a transaction's destination is a Contract Account address, the transaction and transaction data are used as input for the contract to be executed in the EVM. In addition to Ether, the transaction can include data indicating a specific function of the contract to execute and parameters to pass to that function. Thus, a transaction can call functions within a contract. If requested by an EOA, contracts can also call other contracts. However, since a Contract Account does not have a private key, it cannot sign for transactions and cannot initiate transactions on its own. The relationships are summarized as follows:

  • EOA -> EOA (OK)
  • EOA -> CA (OK)
  • EOA -> CA -> CA (OK)
  • CA -> CA (Impossible)

'Account' in Solana

The concept of an Account in Solana is somewhat broader than in Ethereum. In Solana, all data is stored and executed based on Accounts. This means that in every case where state needs to be stored between transactions, it is saved using accounts. Similar to files in operating systems like Linux, accounts can store arbitrary data that persists beyond the lifespan of a program. Additionally, like a file, an account contains metadata that informs the runtime about who can access the data and how.

In Solana's Sealevel VM, all accounts are capable of storing data. So, where can smart contract разработчиков store their data? They can store data in non-executable accounts (PDAs) owned by an executable account. Developers can create new accounts by assigning an owner identical to the address of their executable account to store data.

FieldDescription
lamportsThe number of lamports owned by this account. The equivalent of balance.
ownerThe program owner of this account.
executableWhether this account can process instructions.
dataThe raw data byte array stored by this account.
rent_epochThe next epoch that this account will owe rent.

Accounts that store data pay for the space they use. Every account holds a balance in lamports (the smallest unit of SOL) and must keep a minimum balance proportional to its data size, known as the rent-exempt threshold. Ongoing rent collection is disabled on Solana, so this minimum works as a refundable deposit rather than a recurring fee: you deposit it when you create the account and get it back when you close the account. An account whose balance drops to zero is removed from the ledger.

Solana's accounts are divided into the following two types, similar to Ethereum:

  • Executable account (program account): These are smart contracts that store code, often referred to more simply as "programs".
  • Non-executable account (data account): These can receive tokens or data but cannot execute code, as the executable variable is set to 'false'.

(*Unlike Ethereum, Solana uses the term 'Program' instead of 'Contract'.)

A comparison of the account structures in each chain reveals the following differences.

Ethereum's AccountSolana's Account
Accountowner
balancelamports
nonce[no equivalent]
code hashexecutable && data
storage hashdata
[no equivalent]rent_epoch

EOA (Externally Owned Account, Wallet)

  • -> non-executable, data accounts
  • However, individual wallets on Solana are composed of a collection of data accounts, which are a broader concept than EOA.

CA (Contract Account)

  • -> executable, program accounts
  • While sharing the same concept, Ethereum's CA cannot execute transactions on their own; they must be executed by EOA.

Account abstraction

Ethereum давно исследует концепцию абстракции аккаунтов. Существует два типа аккаунтов в Ethereum: Externally Owned Accounts (EOA) и Contract Accounts (CA). EOA контролируются приватными ключами, тогда как CA управляются кодом смарт-контракта. Абстракция аккаунтов стремится устранить это различие, позволяя пользователям взаимодействовать с блокчейном через CA, что обеспечивает более гибкую и программируемую модель управления аккаунтами.

Consequently, the following adjustments can be made to the chart:

  • EOA -> EOA (OK)
  • EOA -> CA (OK)
  • EOA -> CA -> CA (OK)
  • EOA + CA (AA) -> CA (now, OK!)

For example, multisig wallets or smart contract wallets need to store a small amount of Ethereum in a separate EOA to pay for transaction fees, leading to the inconvenience of having to replenish it over time. Account abstraction allows a single account to execute contracts and issue transactions, improving this inconvenience.

Vitalik Buterin and others proposed ERC-4337 in 2021, and its EntryPoint contract went live on Ethereum mainnet in March 2023.

In summary, account abstraction offers the following benefits:

  • Others paying my transaction fees, or me paying for others.
  • Paying fees with ERC-20 tokens
  • Setting custom security rules.
  • Account recovery in case of key loss.
  • Sharing account security among trusted devices or individuals.
  • Batch transactions (e.g., authorizing and executing a swap in one go).
  • More opportunities for dapp and wallet разработчиков to innovate the user experience.

Is account abstraction implemented in Solana?

Solana реализовала абстракцию аккаунтов (AA) с момента своего запуска. Как обсуждалось ранее, Solana хранит все данные в единицах, называемых «аккаунтами», которые делятся на исполняемые (program account) и неисполняемые (data account). С самого начала Solana поддерживала возможность для программ создавать и управлять определёнными аккаунтами (т.е. напрямую инициировать транзакции). Эта функция, расширяющая возможности абстракции аккаунтов в Solana, известна как Program Derived Address (PDA). Программы Solana, в отличие от data account, представляют собой исполняемые аккаунты, содержащие исполняемый код. С PDA разработчики могут устанавливать правила и механизмы для подписей транзакций, позволяя различным действиям в блокчейне автономно авторизовываться от имени контролируемого аккаунта (PDA), признанного и одобренного сетью Solana. Таким образом, в отличие от Ethereum, Solana позволяет напрямую управлять другой программой на основе программы Solana без громоздкого наслоения.

Summary

  • Solana's Account concept structures all data on the chain, with all data being based on Accounts.
  • Solana covers the goals of account abstraction natively: any account can pay fees, transactions carry several instructions and signers, and programs sign for PDAs through cross-program invocation.
EVM to SVM: Accounts | Solana