Backend types
On the backend, there is only a single type: Value
.
A Value
is simply a tuple of field elements. With the plonky2 backend, a Value
is a tuple of 4 field elements. In general, the backend will expose a constant VALUE_SIZE
, and a Value
will be a tuple of VALUE_SIZE
field elements.
Integers and booleans
The backend encoding stores integers in such a way that arithmetic operations (addition, multiplication, comparison) are inexpensive to verify in-circuit.
In the case of the Plonky2 backend, an integer is decomposed as with and represented as where is the canonical projection.
On the backend, a boolean is stored as an integer, either 0 or 1; so logical operations on booleans are also inexpensive.
Strings
The backend encoding stores strings as hashes, using a hash function that might not be zk-friendly. For this reason, string operations (substrings, accessing individual characters) are hard to verify in-circuit. The POD2 system does not provide methods for manipulating strings.
In other words: As POD2 sees it, two strings are either equal or not equal. There are no other relationships between strings.
In the case of the Plonky2 backend, a string is converted to a sequence of bytes with the byte 0x01
appended as padding, then the bytes are split into 7-byte chunks starting from the left, these chunks then being interpreted as integers in little-endian form, each of which is naturally an element of GoldilocksField
, whence the resulting sequence may be hashed via the Poseidon hash function. Symbolically, given a string , its hash is defined by
where poseidon
is the Poseidon instance used by Plonky2, is as above, is defined such that[^aux]
the mapping is given by
and is the canonical mapping of a string to its UTF-8 representation.
Compound types
The three front-end compound types (Dictionary
, Array
, Set
) are all represented as Merkle roots on the backend. The details of the representation are explained on a separate Merkle tree page.