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 (an i64) is first interpreted as a u64 via its two's complement representation, which is then decomposed as with and represented as where is the canonical projection.

We use -1 as a tag in the last limb in order to distinguish the encoding of 0 from an empty value with zeroes. -1 in the GoldilocksField has the canonical projection of 18446744069414584320 = 0xffffffff00000000.

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. 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 that1

the mapping is given by

and is the canonical mapping of a string to its UTF-8 representation.

Keys and predicates

A PublicKey (an elliptic curve point) and a SecretKey (a scalar) are represented by the Poseidon hash of their field element representation. A Predicate is represented by the hash of the predicate (see custom predicates).

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.

1

Definitions of drop and take may be found here and here.