Calldata format#
Calldata is a format that is used within GenVM to exchange data between contracts and VMs. It is designed with following in mind: - be safe to load - be dynamically typed and json-like - be binary and compact - support blockchain specific types
Types#
Calldata is one of:
arbitrary big integer
raw bytes
utf8 string
array of Calldata
mapping from strings to Calldata
Address (20 bytes)
Format#
“uleb128”#
“unsigned little endian base 128” is a variable-length code compression used to store arbitrarily large integers
Encoding: split number into groups of 7 bits, little-endian, zero extend the biggest one. For each except the biggest one (rightmost), set 8th bit to one and concatenate
Examples:
0 ↔ 0x00
1 ↔ 0x01
128 ↔ 0x80 0x01
Calldata#
Each calldata value starts with uleb128 number, which is treated as follows:
least significant 3 bits |
interpreted as type |
number shifted by this 3 bits |
followed by |
|---|---|---|---|
0 |
atom |
0 ⇒ 1 ⇒ 2 ⇒ 3 ⇒ followed by address _ ⇒ reserved for future use |
nothing nothing nothing 20 bytes of address reserved for future use |
1 |
positive int or 0 |
|
nothing |
2 |
negative int |
|
nothing |
3 |
bytes |
|
|
4 |
string |
|
|
5 |
array |
|
|
6 |
map |
|
|
7 |
reserved for future use |
FastString is encoded as uleb128 length followed by utf8 encoded bytes (difference is that it does not have a type)