Solidity
Notes on the Solidity smart contracting language used by Ethereum.
Types
- Numbers in Solidity are 256-bits large (
uint
andint
). - The
address
type is a 160-bit value.
Accounts
-
Types of accounts:
- External accounts: controlled by public-private key paris (i.e., humans).
- Contract accounts: controlled by code stored together with account.
-
Addresses of accounts:
- Address of an external account is determined from the public key.
- Address of a contract is determined at the time the contract is created (creator address plus number of transactions sent).
-
A transaction is a message that is sent from one account to another account. It can include binary data (its payload) and Ether.
-
If the target account contains code, that code is executed and the payload is provided as input data.
-
If the target account is the zero-account (the account with the address
0
), the transaction creates a new contract. -
Every account has a persistent key-value store mapping 256-bit words to 256-bit words called storage:
- Storage is a key-value store that maps 256-bit words to 256-bit words.
- It is not possible to enumerate storage from within a contract and it is comparatively costly to read and even more so, to modify storage.
- A contract can neither read nor write to any storage apart from its own.
-
Every account has a balance in Ether.
-
Second memory area is memory (fresh for each message call):
- Memory is linear and can be addressed at byte level.
- Reads are limited to a width of 256 bits
- Writes can be either 8 bits or 256 bits wide.
- Memory is expanded by a word (256-bit), when accessing a previously untouched memory word.
- At the time of expansion, the cost in gas must be paid.
- Memory is more costly the larger it grows (it scales quadratically).
-
The Ethereum Virtual Machine (EVM) is stack machine, it has a maximum size of 1024 elements (256-bit words).