📝
smartbch
  • Introduction
  • Whitepaper
  • FAQ
  • Mainnet
  • Testnets
  • Join Amber testnet as a Validator
  • Developer's Guide
    • Introduction
    • Deploy contracts using Truffle
    • Deploy contracts using Remix
    • JSON-RPC Endpoints
    • Staking Scheme
    • XHedge Smart Contract
    • Decision of the minimum gas price
  • Sha-Gate Bridge
    • Sha-Gate Specification
    • Sha-Gate Risk Analysis
    • Sha-Gate's Covenant
  • In-Depth Design Documents
    • Introduction
    • MoeingADS's General Ideas
    • MoeingADS's RabbitStore
    • MoeingADS's internal architecture
    • Benchmarking MoeingADS
    • Benchmarking MoeingEVM and MoeingADS
    • Benchmarking Testnet
    • Transaction Reordering in smartBCH
    • Transaction Parallel Execution in smartBCH
    • Send back-to-back Transactions
    • Data structures in world state
  • SmartBCH Evolution Proposals (SEPs)
    • SEP101: Store values with arbitrary length
    • SEP102: Adjustment of Used Gas
    • SEP109: On-chain Verification of Verifiable Random Functions
    • SEP18: Blockchain cheques on smartBCH
    • SEP20: Tokens on smartBCH
    • SEP206: Manipulate Native Token as a SEP20 Token
    • SEP201: Simple Stochastic Payment
  • Archives
    • Single Node Private Testnet
    • Multi-Node Testnet
    • Fake RPC Server for Testing
    • Test using MetaMask
Powered by GitBook
On this page
  • Basic Information of an Account
  • Creation Counter
  • Storage in Smart Contract Accounts
  • Bytecode
  • Standby Queue's Start&End Positions
  • Standby Queue's Content
  • Current Block's basic information

Was this helpful?

  1. In-Depth Design Documents

Data structures in world state

In this article, we describe the different kinds of key-value pairs which are stored in smartBCH's world state.

In the following descriptions, we use "+" to denote concatenation.

Basic Information of an Account

Key: byte(23) + 20-byte-address

Value:

  1. 32-byte Balance (Big Endian)

  2. 8-byte Nonce (Big Endian)

  3. 8-byte Sequence (Big Endian). For EOA, the sequence is always uint64(-1). For contract account, the sequence is assigned a unique value when created.

Creation Counter

Key: byte(21) + first-byte-of-address

Values: 8-byte Counter (Big Endian)

All the smart contracts who have the same value in the first byte of address share one counter. Each time a new contract is created, this counter get increased by one. And the address of the new contract is calculated by: new-value-of-counter * 256 + first-byte-of-address.

Storage in Smart Contract Accounts

Key: byte(27) + 8-byte-account-sequence + 32-byte-key

Value: Non-zero-length byte string (not required to be 32 bytes)

Please note after a smart contract's self-destruction, there will never be another contract which can have the same account sequence as it. So the self-destructed contract's storage slots can never be accessed.

Bytecode

Key: byte(25) + 20-byte-address

Value: arbitrary-length byte string

EOA has no bytecode. We only store byte codes for smart contracts.

Standby Queue's Start&End Positions

Key: byte(102)

Value:

  1. 8-byte start position (Big Endian)

  2. 8-byte end position (Big Endian)

You can find a standby transaction at a position in the range [start, end)

Standby Queue's Content

Key: byte(100) + 8-byte-position

Value: serialized bytes for a transaction

Current Block's basic information

Key: byte(29)

Value: serialized bytes of current Block's basic information

PreviousSend back-to-back TransactionsNextSEP101: Store values with arbitrary length

Last updated 4 years ago

Was this helpful?