Skip to content

Specifications

yulongaion edited this page Feb 2, 2018 · 1 revision

Aion FastVM

Aion FastVM is a 128 bit virtual machine, which is based on Ethereum virtual machine. In this wiki, we detail the architecture design, instruction set and energy price sepcifications.

Address and Hash

In Aion, wallet address takes 32 bytes for stronger security. It's structured into two data words inside the Aion FastVM, based on the following conventions:

<    stack_top   >
<address[ 0...16)>
<address[16...32)>

Similarly, hashes are organized as

<  stack_top  >
<hash[ 0...16)>
<hash[16...32)>

Instructions

The semantics of instructions has been kept intact, but the specification has been updated to align with our architecture change, especially the number of stack items one instruction requires and produces. For the original definition of instructions, we refer readers to the Ethereum yellow paper.

Value  Mnemonic             δ     α    Note
-----------------------------------------------------------------
0x00   STOP                 0     0   
0x01   ADD                  2     1   Arithmetic operations are based on 128-bit dataword
0x02   MUL                  2     1   
0x03   SUB                  2     1   
0x04   DIV                  2     1   
0x05   SDIV                 2     1   
0x06   MOD                  2     1   
0x07   SMOD                 2     1   
0x08   ADDMOD               3     1   
0x09   MULMOD               3     1   
0x0a   EXP                  2     1   
0x0b   SIGNEXTEND           2     1   
0x10   LT                   2     1   
0x11   GT                   2     1   
0x12   SLT                  2     1   
0x13   SGT                  2     1   
0x14   EQ                   2     1   
0x15   ISZERO               1     1   
0x16   AND                  2     1   
0x17   OR                   2     1   
0x18   XOR                  2     1   
0x19   NOT                  1     1   
0x1a   BYTE                 2     1   
0x20   KECCAK256            2     2   Compute the KECCAK256 hash of a memory chunk; produces two stack items 
0x30   ADDRESS              0     2   The contract address takes two stack items
0x31   BALANCE              2     1   
0x32   ORIGIN               0     2   
0x33   CALLER               0     2   
0x34   CALLVALUE            0     1   
0x35   CALLDATALOAD         1     1   
0x36   CALLDATASIZE         0     1   
0x37   CALLDATACOPY         3     0   
0x38   CODESIZE             0     1   
0x39   CODECOPY             3     0   
0x3d   RETURNDATASIZE       0     1   
0x3e   RETURNDATACOPY       3     0   
0x3a   GASPRICE             0     1   
0x3b   EXTCODESIZE          1     1   
0x3c   EXTCODECOPY          4     0   
0x40   BLOCKHASH            1     2   Returns the hash of the given block; produces two stack items
0x41   COINBASE             0     2   
0x42   TIMESTAMP            0     1   
0x43   NUMBER               0     1   
0x44   DIFFICULTY           0     1   
0x45   GASLIMIT             0     1   
0x50   POP                  1     0   
0x51   MLOAD                1     1   
0x52   MSTORE               2     0   
0x53   MSTORE8              2     0   
0x54   SLOAD                1     1   Store a key-value pair in contract storage
0x55   SSTORE               2     0   
0x56   JUMP                 1     0   
0x57   JUMPI                2     0   
0x58   PC                   0     1   
0x59   MSIZE                0     1   
0x5a   GAS                  0     1   
0x5b   JUMPDEST             0     0   
0x60   PUSH1                0     1   
0x61   PUSH2                0     1   
0x62   PUSH3                0     1   
0x63   PUSH4                0     1   
0x64   PUSH5                0     1   
0x65   PUSH6                0     1   
0x66   PUSH7                0     1   
0x67   PUSH8                0     1   
0x68   PUSH9                0     1   
0x69   PUSH10               0     1   
0x6a   PUSH11               0     1   
0x6b   PUSH12               0     1   
0x6c   PUSH13               0     1   
0x6d   PUSH14               0     1   
0x6e   PUSH15               0     1   
0x6f   PUSH16               0     1   
0x70   PUSH17               0     2   Will produce two stack items for PUSH17+
0x71   PUSH18               0     2   
0x72   PUSH19               0     2   
0x73   PUSH20               0     2   
0x74   PUSH21               0     2   
0x75   PUSH22               0     2   
0x76   PUSH23               0     2   
0x77   PUSH24               0     2   
0x78   PUSH25               0     2   
0x79   PUSH26               0     2   
0x7a   PUSH27               0     2   
0x7b   PUSH28               0     2   
0x7c   PUSH29               0     2   
0x7d   PUSH30               0     2   
0x7e   PUSH31               0     2   
0x7f   PUSH32               0     2   
0x80   DUP1                 1     2   
0x81   DUP2                 2     3   
0x82   DUP3                 3     4   
0x83   DUP4                 4     5   
0x84   DUP5                 5     6   
0x85   DUP6                 6     7   
0x86   DUP7                 7     8   
0x87   DUP8                 8     9   
0x88   DUP9                 9    10   
0x89   DUP10               10    11   
0x8a   DUP11               11    12   
0x8b   DUP12               12    13   
0x8c   DUP13               13    14   
0x8d   DUP14               14    15   
0x8e   DUP15               15    16   
0x8f   DUP16               16    17   
0x90   SWAP1                2     2   
0x91   SWAP2                3     3   
0x92   SWAP3                4     4   
0x93   SWAP4                5     5   
0x94   SWAP5                6     6   
0x95   SWAP6                7     7   
0x96   SWAP7                8     8   
0x97   SWAP8                9     9   
0x98   SWAP9               10    10   
0x99   SWAP10              11    11   
0x9a   SWAP11              12    12   
0x9b   SWAP12              13    13   
0x9c   SWAP13              14    14   
0x9d   SWAP14              15    15   
0x9e   SWAP15              16    16   
0x9f   SWAP16              17    17   
0xa0   LOG0                 2     0   
0xa1   LOG1                 3     0   Each additional topic takes two stack items
0xa2   LOG2                 4     0   
0xa3   LOG3                 5     0   
0xa4   LOG4                 6     0   
0xf0   CREATE               3     1   
0xf1   CALL                 7     1   Each the callee takes two stack items for CALL/CALLCODE/DELEGATECALL/STATICCALL
0xf2   CALLCODE             7     1   
0xf3   RETURN               2     0   
0xf4   DELEGATECALL         6     1   
0xfa   STATICCALL           6     1   
0xfd   REVERT               2     0   
0xff   SELFDESTRUCT         1     0   

Energy price

Energy is the execution fee for every operation made on Aion blockchain. The table below summarized the energy price of instructions.

zero = 0             --> 0
base = 2             --> 1
verylow = 3          --> 1
low = 5              --> 1
mid = 8              --> 1
high = 10            --> 1
extcode = 700        --> 1000     DB read, min = 10000000 / (3000 / 0.2) = 666
balance = 400        --> 1000     account state read, worst case DB read, min = 666
sload = 200          --> 1000     account storage read, worst case DB read, min = 666
jumpdest = 1         --> 1
sset = 20,000        --> 20,000   account storage write, trie update, worst cast DB write,
                                  storage space increase, min = 10000000 / (3000 / 2) = 6666
sreset = 5,000       --> 8,000    account storage key delete, trie update, worst case DB write,
                                  storage space unchanged/decrease, min = 10000000 / (3000 / 2) = 6666
sclear = 15,000      --> 15,000   REFUND, needs to make sure `sset + ssreset - sclear > min`
suicide = 24,000     --> 24,000   REFUND
suicide = 5,000      --> 5,000
create = 32,000      --> 200,000  require JIT compilation, min = 10000000 / (3000 / 50) = 166666
codedeposit = 200    --> 1,000    update the callback to charge energy
call = 700           --> 1,000    db read, min = 666
callvalue = 9,000    --> 15,000   two DB read, two DB write, state trie update, min = 666 x 2 + 6666 x 2 = 14,664
callstipend = 2,300  --> 2,300
newaccount = 25000   --> 25,000   new account state, new trie, DB write
exp =  10            --> 1
expbyte = 10         --> 1
memory = 3           --> 1        1 * x + x * x / 512 = 10,000,000, the x = 80,000 * 32 = 2400,000 B = 2.4 MB
txcreate = 32,000    --> 200,000  update the basic transaction cost for CREATE transactions
txdatazero = 4       --> 4        storage space increase
txdatanonzero = 68   --> 64       storage space increase
transaction = 21,000 --> 21,000   coin transfer cost, two database write
log = 375            --> 500      storage space increase
logdata = 8          --> 20       storage space increase
logtopic = 375       --> 500      storage space increase
sha3 = 30            --> 30
sha3word = 6         --> 6
copy = 3             --> 3
blockhash = 20       --> 20

Solidity

ABI types

Elementary types:

  • uint<M>: unsigned integer type of M bits, 0 < M <= 128, M % 8 == 0. e.g. uint8, uint32, uint128.
  • int<M>: two's complement signed integer type of M bits, 0 < M <= 128, M % 8 == 0.
  • address: equivalent to bytes32.
  • uint, int: synonyms for uint128, int128 respectively.
  • bool: equivalent to uint8 restricted to the values 0 and 1.
  • bytes<M>: binary type of M bytes, 0 < M <= 32.
  • function: an address, followed by a 4 bytes function selector

Fixed-size array types:

  • <type>[M]: a fixed-length array of the given fixed-length type.

Dynamic-size array types:

  • bytes: dynamic sized byte sequence.
  • string: dynamic sized unicode string assumed to be UTF-8 encoded.
  • <type>[]: a variable-length array of the given fixed-length type.

ABI encoding

bool type: size = 16
int/uint type: size = 16, default to 128 bit, max 128 bit
address: no change
bytesX: size = 16 or 32 depending on X, left-aligned
string: [length] + [16-bytes-aligned byte array], sizeof(length) = 16
bytes: [length] + [16-bytes-aligned byte array], sizeof(length) = 16

T[N]: static array, size = sizeof(base_type) * length
T[]: dynamic array, [length] + (base is static)[element_0][element_1][element_N]
                               (base is dynamic)[offset_0][offset_1][offset_N][element_0][element_1][element_N],
                    sizeof(length) = 16

Event encoding

topic1 := hash(event_external_signature)
topic2 := ext(1st_indexed_parameter)
topic3 := ext(2nd_indexed_parameter)
topic4 := ext(3rd_indexed_parameter)
data := abi_encode(non_indexed_parameters)

ext := extend to two data words by adding zeros
Clone this wiki locally