In Ethereum, the state is made up of objects called "accounts", with each account having
a 20-byte address and state transitions being direct transfers of value and information
between accounts. An Ethereum account contains four fields:
The nonce, a counter used to make sure each transaction can only be processed once
The account's current ether balance
The account's contract code, if present
The account's storage (empty by default)
"Ether" is the main internal crypto-fuel of Ethereum, and is used to pay transaction fees. In
general, there are two types of accounts: externally owned accounts, controlled by
private keys, and contract accounts, controlled by their contract code. An externally
owned account has no code, and one can send messages from an externally owned
account by creating and signing a transaction; in a contract account, every time the
contract account receives a message its code activates, allowing it to read and write to
internal storage and send other messages or create contracts in turn.
Note that "contracts" in Ethereum should not be seen as something that should be
"fulfilled" or "complied with"; rather, they are more like "autonomous agents" that live
inside of the Ethereum execution environment, always executing a specific piece of code
when "poked" by a message or transaction, and having direct control over their own ether
balance and their own key/value store to keep track of persistent variables.
Messages and Transactions
The term "transaction" is used in Ethereum to refer to the signed data package that stores
a message to be sent from an externally owned account. Transactions contain:
The recipient of the message
A signature identifying the sender
The amount of ether to transfer from the sender to the recipient
An optional data field
A STARTGAS value, representing the maximum number of computational steps the
transaction execution is allowed to take
A GASPRICE value, representing the fee the sender pays per computational step
The first three are standard fields expected in any cryptocurrency. The data field has no
function by default, but the virtual machine has an opcode which a contract can use to
access the data; as an example use case, if a contract is functioning as an on-blockchain
domain registration service, then it may wish to interpret the data being passed to it as
containing two "fields", the first field being a domain to register and the second field being
the IP address to register it to. The contract would read these values from the message
data and appropriately place them in storage.
The STARTGAS and GASPRICE fields are crucial for Ethereum's anti-denial of service
model. In order to prevent accidental or hostile infinite loops or other computational
wastage in code, each transaction is required to set a limit to how many computational
steps of code execution it can use. The fundamental unit of computation is "gas"; usually,
a computational step costs 1 gas, but some operations cost higher amounts of gas
because they are more computationally expensive, or increase the amount of data that
must be stored as part of the state. There is also a fee of 5 gas for every byte in the
transaction data. The intent of the fee system is to require an attacker to pay
proportionately for every resource that they consume, including computation, bandwidth
and storage; hence, any transaction that leads to the network consuming a greater
amount of any of these resources must have a gas fee roughly proportional to the
increment.
Messages
Contracts have the ability to send "messages" to other contracts. Messages are virtual
objects that are never serialized and exist only in the Ethereum execution environment. A
message contains:
The sender of the message (implicit)
The recipient of the message
The amount of ether to transfer alongside the message