📖 Before reading this section of the book, it is advised to read the Fault Proof Program Environment section to familiarize yourself with the PreimageOracle IO pattern.Kona is effectively split into three parts:
- OP Stack state transition logic (
kona-derive,kona-executor,kona-mpt) - OP Stack state transition proof SDK (
kona-preimage,kona-proof) - Fault Proof VM IO and utilities
(
kona-std-fpvm,kona-std-fpvm-proc)
kona-std-fpvm and kona-preimage to facilitate communication between host and client
for programs running on top of the FPVM targets.
Host and Client Communication API
The FPVM system API is built on several layers. In this document, we’ll cover these layers, from lowest-level to highest-level API.kona-std-fpvm
kona-std-fpvm implements raw syscall dispatch, a default global memory allocator, and a blocking async runtime.
kona-std-fpvm relies on a minimal linux backend to function, supporting only the syscalls required to implement the
PreimageOracle ABI (read, write, exit_group).
These syscalls are exposed to the user through the io module directly, with each supported platform implementing the
BasicKernelInterface trait.
To directly dispatch these syscalls, the io module
exposes a safe API:
kona-preimage
when developing programs that target the FPVMs, barring needs like printing directly to
stdout.
kona-preimage
kona-preimage is an implementation of the PreimageOracle ABI. This crate enables synchronous
communication between the host and client program, described in
Host - Client Communication in the FPP Dev environment section of the
book.
The crate is built around the Channel trait,
which serves as a single end of a bidirectional pipe (see: pipe manpage).
Through this handle, the higher-level constructs can read and write data to the counterparty holding on to the other end
of the channel, following the protocol below:
The interfaces of each part of the above protocol are described by the following traits:
PreimageOracleClient- To-spec implementation:
OracleReader
- To-spec implementation:
HintWriterClient- To-spec implementation:
HintWriter
- To-spec implementation:
PreimageOracleServer- To-spec implementation:
OracleServer
- To-spec implementation:
HintReaderServer- To-spec implementation:
HintReader
- To-spec implementation:
kona-proof - Oracle-backed sources (example)
Finally, in kona-proof, implementations of data source traits from kona-derive and kona-executor are provided
to pull in untyped data from the host by PreimageKey. These data source traits are covered in more detail within
the Custom Backend section, but we’ll quickly gloss over them here to build intuition.
Let’s take, for example, OracleL1ChainProvider.
The ChainProvider trait in kona-derive
defines a simple interface for fetching information about the L1 chain. In the OracleL1ChainProvider, this information
is pulled in over the PreimageOracle ABI. There are many other examples of these data source traits,
namely the L2ChainProvider, BlobProvider, TrieProvider, and TrieHinter, which enable the creation of different
data-source backends.
As an example, let’s look at OracleL1ChainProvider::header_by_hash, built on top of the CommsClient trait, which
is a composition trait of the PreimageOracleClient + HintReaderServer traits outlined above.
header_by_hash, we use the inner HintWriter to send a hint to the host to prepare the block hash preimage.
Then, once we’ve received an acknowledgement from the host that the preimage has been prepared, we reach out for
the RLP (which is the preimage of the hash). After the RLP is received, we decode the Header type, and return
it to the user.