Skip to main content

Module bytes_like

Module bytes_like 

Source
Expand description

Bytes-like (Bytes, String) implementation for the storage traits.

§Storage Layout

Bytes-like types use Solidity-compatible: Short strings (≤31 bytes) are stored inline in a single slot:

  • Bytes 0..len: UTF-8 string data (left-aligned)
  • Byte 31 (LSB): length * 2 (bit 0 = 0 indicates short string)

Long strings (≥32 bytes) use keccak256-based storage:

  • Base slot: stores length * 2 + 1 (bit 0 = 1 indicates long string)
  • Data slots: stored at keccak256(main_slot) + i for each 32-byte chunk

Structs§

BytesLikeHandler
Handler for bytes-like types (Bytes, String) that provides efficient length queries.