Skip to main content

Cap

Enum Cap 

Source
pub enum Cap {
    Instance(InstanceCap),
    Image(ImageCap),
    Data(DataCap),
    CNode(CNodeCap),
}
Expand description

One of the four v3 cap kinds.

SSZ note: the HashTreeRoot derive treats Cap as an SSZ Union over the four variants. Each variant’s selector provides the domain separation that the legacy byte-protocol kind tags (0x10..0x50) provided; the per-variant root is computed by that variant’s own HashTreeRoot impl. We do not derive Encode + Decode on Cap itself; caps move through the cache by direct allocation and aren’t wire-transmitted at this SSZ-encoded layer.

rkyv note: the Archive/Serialize/Deserialize derives provide the I/O-boundary wire form. Serialization errors out (no panic) if any slot target is an inline CapHashOrRef::Owned cap — see the module docs.

Clone: the derived Clone recursively clones field-by-field. An inline Owned(Box<Cap>) slot deep-clones the boxed cap. Drop is symmetric.

Variants§

§

Instance(InstanceCap)

§

Image(ImageCap)

§

Data(DataCap)

§

CNode(CNodeCap)

Implementations§

Source§

impl Cap

Source

pub fn cap_hash(&self) -> CapHash

32-byte content hash. Walks the cap tree via SSZ HashTreeRoot with SHA-256 as the digest; the four variants get their domain separation from the SSZ Union selector.

Substitution invariants preserved by hand-written HashTreeRoot impls on page::PageSlot, page::PageBytes, and super::cache::CapHashOrRef:

  • PageSlot::Loaded(p) hashes identically to PageSlot::Missing(p.hash) — a freshly-loaded page substitutes for a missing page without changing the enclosing cap’s hash.
  • CapHashOrRef::Hash(h) hashes to h exactly — a freshly- published cap blob substitutes for a content reference without changing the enclosing cap’s hash.

In-flight Owned caps panic: hashing a Cap whose graph still contains an inline CapHashOrRef::Owned(_) target will panic in the SSZ path. Callers must settle the cap graph first. (The rkyv serialise path is fallible for the same case — see the module docs.)

Image hash distinction: Cap::Image(_).cap_hash() and crate::image::image_content_hash hash different types — the cap-resident ImageCap has a flatter layout than the SSZ Image. The cache publishes by cap_hash; the image-hash chain protocol uses image_content_hash.

Source

pub fn data_inline(bytes: &[u8]) -> Self

Build a heap Cap::Data whose content is bytes padded up to the next PAGE_SIZE boundary with zeros. The backing allocation is page-aligned so the kernel can later map the cap’s pages directly into a ring-3 PT.

DataCap.content_len() returns the padded length (always a 4 KiB-multiple). There is no separate logical-size field; callers needing a shorter logical payload (e.g. variable-length args) interpret the meaningful prefix themselves.

Source

pub fn data_inline_with_size(bytes: &[u8], target_size: u64) -> Self

Build a heap Cap::Data whose logical size is at least target_size bytes (rounded up to the next page boundary). bytes fills the low bytes; the remainder is zero (sparse).

Source

pub fn data_from_desc(arena: &[u8], desc: &DataDesc) -> Self

Build a heap Cap::Data from a page-granular crate::image::DataDesc over an Image arena: each named page is materialized from its PAGE_SIZE arena window, omitted pages are the canonical zero page. The single materialization point for Image data slots; the resulting cap hash equals data_inline_with_size(equivalent_contiguous_content, size). The caller must have validated the descriptor (crate::image::DataDesc::validate) against arena.len().

Source

pub fn empty_cnode() -> Self

Build an empty heap Cap::CNode. A CNode is an unbounded hash-keyed map (bounded by storage quota), so there is no size_log to declare.

Source

pub fn image_with_slots( image: &Image, pinned_hashes: &[(Key, CapHash)], initial_hashes: &[(Key, CapHash)], ) -> Result<Self, ImageConvertError>

Build a heap Cap::Image from an SSZ Image plus the caller-resolved pinned/initial slot CapHash pairs.

Source

pub fn instance_with_mem( image_hash_chain: CapHash, image_hash: CapHash, root_cnode: CapHash, mem: DataCap, regs: [u64; 13], pc: u64, gas_remaining: u64, ) -> Self

Build a heap Cap::Instance directly from field values.

mem is the Instance’s read-write memory image (a dense DataCap covering the data extent; pinned read-only mappings are not part of it — see instance::InstanceCap::mem).

Trait Implementations§

Source§

impl Archive for Cap
where InstanceCap: Archive, ImageCap: Archive, DataCap: Archive, CNodeCap: Archive,

Source§

type Archived = ArchivedCap

The archived representation of this type. Read more
Source§

type Resolver = CapResolver

The resolver for this type. It must contain all the additional information from serializing needed to make the archived type from the normal type.
Source§

fn resolve( &self, resolver: <Self as Archive>::Resolver, out: Place<<Self as Archive>::Archived>, )

Creates the archived version of this value at the given position and writes it to the given output. Read more
§

const COPY_OPTIMIZATION: CopyOptimization<Self> = _

An optimization flag that allows the bytes of this type to be copied directly to a writer instead of calling serialize. Read more
Source§

impl Clone for Cap

Source§

fn clone(&self) -> Cap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Cap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<__D: Fallible + ?Sized> Deserialize<Cap, __D> for Archived<Cap>
where InstanceCap: Archive, <InstanceCap as Archive>::Archived: Deserialize<InstanceCap, __D>, ImageCap: Archive, <ImageCap as Archive>::Archived: Deserialize<ImageCap, __D>, DataCap: Archive, <DataCap as Archive>::Archived: Deserialize<DataCap, __D>, CNodeCap: Archive, <CNodeCap as Archive>::Archived: Deserialize<CNodeCap, __D>,

Source§

fn deserialize( &self, deserializer: &mut __D, ) -> Result<Cap, <__D as Fallible>::Error>

Deserializes using the given deserializer
Source§

impl HashTreeRoot for Cap

Source§

fn hash_tree_root<__D: Digest<OutputSize = U32>>(&self) -> [u8; 32]

Compute the hash tree root using D as the underlying hash.
Source§

impl ResidentCap for Cap

Source§

fn from_cap(cap: Cap) -> Self

Wrap a public wire cap for resident storage.
Source§

fn as_cap(&self) -> &Cap

Borrow the public wire cap.
Source§

fn into_cap(self) -> Cap

Consume the resident payload back into its wire cap.
Source§

impl<__S: Fallible + ?Sized> Serialize<__S> for Cap
where InstanceCap: Serialize<__S>, ImageCap: Serialize<__S>, DataCap: Serialize<__S>, CNodeCap: Serialize<__S>,

Source§

fn serialize( &self, serializer: &mut __S, ) -> Result<<Self as Archive>::Resolver, <__S as Fallible>::Error>

Writes the dependencies for the object and returns a resolver that can create the archived type.
Source§

impl WireOwned for Box<Cap>

Auto Trait Implementations§

§

impl Freeze for Cap

§

impl RefUnwindSafe for Cap

§

impl Send for Cap

§

impl Sync for Cap

§

impl Unpin for Cap

§

impl UnsafeUnpin for Cap

§

impl UnwindSafe for Cap

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
§

impl<T> ArchiveUnsized for T
where T: Archive,

§

type Archived = <T as Archive>::Archived

The archived counterpart of this type. Unlike Archive, it may be unsized. Read more
§

fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata

Creates the archived version of the metadata for this value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SerializeUnsized<S> for T
where T: Serialize<S>, S: Fallible + Writer + ?Sized,

§

fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>

Writes the object and returns the position of the archived type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.