Frames
Frame
s are the lowest level data format in the OP Stack protocol.
Where Frames fit in the OP Stack
Transactions posted to the data availability layer of the rollup contain one or multiple Frames. Frames are chunks of raw data that belong to a given Channel, the next, higher up data format in the OP Stack protocol. Importantly, a given transaction can contain a variety of frames from different channels, allowing maximum flexibility when breaking up channels into batcher transactions.
Contents of a Frame
A Frame is comprised of the following items.
- A
ChannelId
which is a 16 byte long identifier for the channel that the given frame belongs to. - A
number
that identifies the index of the frame within the channel. Frames are 0-indexed and are bound tou16
size limit. data
contains the raw data within the frame.is_last
marks if the frame is the last within the channel.
Frame Encoding
When frames are posted through a batcher transaction, they are encoded as a contiguous list with a single byte prefix denoting the derivation version. The encoding can be represented as the following concatenated bytes.
encoded = DERIVATION_VERSION_0 ++ encoded_frame_0 ++ encoded_frame_1 ++ ..
Where DERIVATION_VERSION_0
is a single byte (0x00
) indicating the derivation
version including how the frames are encoded. Currently, the only supported
derivation version is 0
.
encoded_frame_0
, encoded_frame_1
, and so on, are all Frame
s encoded
as raw bytes. A single encoded Frame
can be represented by the following
concatenation of it's fields.
encoded_frame = channel_id ++ frame_number ++ frame_data_length ++ frame_data ++ is_last
Where ++
represents concatenation. The frame's fields map to it's encoding.
channel_id
is the 16 byte longFrame::id
.frame_number
is the 2 byte long (oru16
)Frame::number
.frame_data_length
andframe_data
provide the necessary details to decode theFrame::data
, whereframe_data_length
is 4 bytes long (oru32
).is_last
is a single byteFrame::is_last
.
op-alloy's Frame
Type
op-alloy-protocol
provides the Frame
type with a few useful
methods. Frame
s can be encoded and decoded using the Frame::encode
and Frame::decode
methods. Given the raw batcher transaction data or blob data
containing the concatenated derivation version and contiguous list of encoded frames,
the Frame::parse_frame
and Frame::parse_frames
methods
provide ways to decode single and multiple frames, respectively.