Documentation ¶
Index ¶
- Constants
- func HashPair(left, right [32]byte) [32]byte
- func PatchVM(f *elf.File, vmState *VMState) error
- type CachedPage
- func (p *CachedPage) GenerateProof(addr uint64) [][32]byte
- func (p *CachedPage) Invalidate(pageAddr uint64)
- func (p *CachedPage) InvalidateFull()
- func (p *CachedPage) MerkleRoot() [32]byte
- func (p *CachedPage) MerkleizeNode(addr, gindex uint64) [32]byte
- func (p *CachedPage) MerkleizeSubtree(gindex uint64) [32]byte
- type InstrumentedState
- type L1
- type L2
- type L3
- type L4
- type L5
- type L6
- type L7
- type LargeRadixNode
- type LocalContext
- type MediumRadixNode
- type Memory
- func (m *Memory) AllocPage(pageIndex uint64) *CachedPage
- func (m *Memory) Deserialize(in io.Reader) error
- func (m *Memory) ForEachPage(fn func(pageIndex uint64, page *Page) error) error
- func (m *Memory) GenerateProof(addr uint64, proofs [][32]byte)
- func (m *Memory) GetUnaligned(addr uint64, dest []byte)
- func (m *Memory) Invalidate(addr uint64)
- func (m *Memory) MarshalJSON() ([]byte, error)
- func (m *Memory) MerkleProof(addr uint64) [ProofLen * 32]byte
- func (m *Memory) MerkleRoot() [32]byte
- func (m *Memory) MerkleizeNode(addr, gindex uint64) [32]byte
- func (m *Memory) PageCount() int
- func (m *Memory) ReadMemoryRange(addr uint64, count uint64) io.Reader
- func (m *Memory) Serialize(out io.Writer) error
- func (m *Memory) SetMemoryRange(addr uint64, r io.Reader) error
- func (m *Memory) SetUnaligned(addr uint64, dat []byte)
- func (m *Memory) UnmarshalJSON(data []byte) error
- func (m *Memory) Usage() string
- type Page
- type PreimageOracle
- type RadixNode
- type SmallRadixNode
- type SortedSymbols
- type StateWitness
- type StepWitness
- type U256
- type U64
- type UnrecognizedResourceErr
- type UnrecognizedSyscallErr
- type UnsupportedSyscallErr
- type VMState
Constants ¶
const ( PageAddrSize = 12 PageKeySize = 64 - PageAddrSize PageSize = 1 << PageAddrSize PageAddrMask = PageSize - 1 MaxPageCount = 1 << PageKeySize PageKeyMask = MaxPageCount - 1 ProofLen = 64 - 4 )
Note: 2**12 = 4 KiB, the minimum page-size in Unicorn for mmap as well as the Go runtime min phys page size.
const ( VMStatusValid = 0 VMStatusInvalid = 1 VMStatusPanic = 2 VMStatusUnfinished = 3 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CachedPage ¶
type CachedPage struct { Data *Page // intermediate nodes only Cache [PageSize / 32][32]byte // true if the intermediate node is valid Ok [PageSize / 32]bool }
func (*CachedPage) GenerateProof ¶ added in v1.1.0
func (p *CachedPage) GenerateProof(addr uint64) [][32]byte
func (*CachedPage) Invalidate ¶
func (p *CachedPage) Invalidate(pageAddr uint64)
func (*CachedPage) InvalidateFull ¶
func (p *CachedPage) InvalidateFull()
func (*CachedPage) MerkleRoot ¶
func (p *CachedPage) MerkleRoot() [32]byte
func (*CachedPage) MerkleizeNode ¶ added in v1.1.0
func (p *CachedPage) MerkleizeNode(addr, gindex uint64) [32]byte
func (*CachedPage) MerkleizeSubtree ¶
func (p *CachedPage) MerkleizeSubtree(gindex uint64) [32]byte
type InstrumentedState ¶
type InstrumentedState struct {
// contains filtered or unexported fields
}
func NewInstrumentedState ¶
func NewInstrumentedState(state *VMState, po PreimageOracle, stdOut, stdErr io.Writer) *InstrumentedState
func (*InstrumentedState) LastPreimage ¶
func (m *InstrumentedState) LastPreimage() ([32]byte, []byte, uint64)
func (*InstrumentedState) Step ¶
func (m *InstrumentedState) Step(proof bool) (wit *StepWitness, err error)
type L1 ¶ added in v1.1.0
type L1 = LargeRadixNode[L2]
type L2 ¶ added in v1.1.0
type L2 = *LargeRadixNode[L3]
type L3 ¶ added in v1.1.0
type L3 = *MediumRadixNode[L4]
type L4 ¶ added in v1.1.0
type L4 = *MediumRadixNode[L5]
type L5 ¶ added in v1.1.0
type L5 = *SmallRadixNode[L6]
type L6 ¶ added in v1.1.0
type L6 = *SmallRadixNode[L7]
type LargeRadixNode ¶ added in v1.1.0
type LargeRadixNode[C RadixNode] struct { Children [1 << 16]*C // Array of child nodes, indexed by 16-bit keys. Hashes [1 << 16][32]byte HashExists [(1 << 16) / 64]uint64 HashValid [(1 << 16) / 64]uint64 Depth uint64 }
LargeRadixNode is a radix trie node with a branching factor of 16 bits.
func (*LargeRadixNode[C]) GenerateProof ¶ added in v1.1.0
func (n *LargeRadixNode[C]) GenerateProof(addr uint64, proofs [][32]byte)
func (*LargeRadixNode[C]) InvalidateNode ¶ added in v1.1.0
func (n *LargeRadixNode[C]) InvalidateNode(gindex uint64)
func (*LargeRadixNode[C]) MerkleizeNode ¶ added in v1.1.0
func (n *LargeRadixNode[C]) MerkleizeNode(addr, gindex uint64) [32]byte
type LocalContext ¶
type MediumRadixNode ¶ added in v1.1.0
type MediumRadixNode[C RadixNode] struct { Children [1 << 6]*C // Array of child nodes, indexed by 6-bit keys. Hashes [1 << 6][32]byte HashExists uint64 HashValid uint64 Depth uint64 }
MediumRadixNode is a radix trie node with a branching factor of 6 bits.
func (*MediumRadixNode[C]) GenerateProof ¶ added in v1.1.0
func (n *MediumRadixNode[C]) GenerateProof(addr uint64, proofs [][32]byte)
func (*MediumRadixNode[C]) InvalidateNode ¶ added in v1.1.0
func (n *MediumRadixNode[C]) InvalidateNode(gindex uint64)
func (*MediumRadixNode[C]) MerkleizeNode ¶ added in v1.1.0
func (n *MediumRadixNode[C]) MerkleizeNode(addr, gindex uint64) [32]byte
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
func (*Memory) AllocPage ¶
func (m *Memory) AllocPage(pageIndex uint64) *CachedPage
AllocPage allocates a new page at the specified page index in memory.
func (*Memory) ForEachPage ¶
func (*Memory) GenerateProof ¶ added in v1.1.0
func (*Memory) GetUnaligned ¶
func (*Memory) Invalidate ¶
Invalidate invalidates the cache along the path from the specified address up to the root. It ensures that any cached hashes are recomputed when needed.
func (*Memory) MarshalJSON ¶
func (*Memory) MerkleProof ¶
MerkleProof generates the Merkle proof for the specified address in memory.
func (*Memory) MerkleRoot ¶
MerkleRoot computes the Merkle root hash of the entire memory.
func (*Memory) MerkleizeNode ¶ added in v1.1.0
func (*Memory) ReadMemoryRange ¶
func (*Memory) Serialize ¶ added in v1.1.0
Serialize writes the memory in a simple binary format which can be read again using Deserialize The format is a simple concatenation of fields, with prefixed item count for repeating items and using big endian encoding for numbers.
len(PageCount) uint64 For each page (order is arbitrary):
page index uint64 page Data [PageSize]byte
func (*Memory) SetUnaligned ¶
func (*Memory) UnmarshalJSON ¶
type PreimageOracle ¶
type RadixNode ¶ added in v1.1.0
type RadixNode interface { // GenerateProof generates the Merkle proof for the given address. GenerateProof(addr uint64, proofs [][32]byte) // MerkleizeNode computes the Merkle root hash for the node at the given generalized index. MerkleizeNode(addr, gindex uint64) [32]byte }
RadixNode is an interface defining the operations for a node in a radix trie.
type SmallRadixNode ¶ added in v1.1.0
type SmallRadixNode[C RadixNode] struct { Children [1 << 4]*C // Array of child nodes, indexed by 4-bit keys. Hashes [1 << 4][32]byte // Cached hashes for intermediate hash node. HashExists uint16 // Bitmask indicating if the intermediate hash exist (1 bit per intermediate node). HashValid uint16 // Bitmask indicating if the intermediate hashes are valid (1 bit per intermediate node). Depth uint64 // The depth of this node in the trie (number of bits from the root). }
SmallRadixNode is a radix trie node with a branching factor of 4 bits.
func (*SmallRadixNode[C]) GenerateProof ¶ added in v1.1.0
func (n *SmallRadixNode[C]) GenerateProof(addr uint64, proofs [][32]byte)
GenerateProof generates the Merkle proof for the given address. It collects the necessary sibling hashes along the path to reconstruct the Merkle proof.
func (*SmallRadixNode[C]) InvalidateNode ¶ added in v1.1.0
func (n *SmallRadixNode[C]) InvalidateNode(gindex uint64)
InvalidateNode invalidates the hash cache along the path to the specified address. It marks the necessary intermediate hashes as invalid, forcing them to be recomputed when needed.
func (*SmallRadixNode[C]) MerkleizeNode ¶ added in v1.1.0
func (n *SmallRadixNode[C]) MerkleizeNode(addr, gindex uint64) [32]byte
MerkleizeNode computes the Merkle root hash for the node at the given generalized index. It recursively computes the hash of the subtree rooted at the given index. Note: The 'addr' parameter represents the partial address accumulated up to this node, not the full address. It represents the path taken in the trie to reach this node.
type SortedSymbols ¶
func (SortedSymbols) FindSymbol ¶
func (s SortedSymbols) FindSymbol(addr uint64) elf.Symbol
FindSymbol finds the symbol that intersects with the given addr, or nil if none exists
type StateWitness ¶
type StateWitness []byte
type StepWitness ¶
type StepWitness struct { // encoded state witness State []byte MemProof []byte PreimageKey [32]byte // zeroed when no pre-image is accessed PreimageValue []byte // including the 8-byte length prefix PreimageOffset uint64 }
func (*StepWitness) EncodePreimageOracleInput ¶
func (wit *StepWitness) EncodePreimageOracleInput(localContext LocalContext) ([]byte, error)
func (*StepWitness) EncodeStepInput ¶
func (wit *StepWitness) EncodeStepInput(localContext LocalContext) ([]byte, error)
func (*StepWitness) HasPreimage ¶
func (wit *StepWitness) HasPreimage() bool
type UnrecognizedResourceErr ¶
type UnrecognizedResourceErr struct {
Resource U64
}
func (*UnrecognizedResourceErr) Error ¶
func (e *UnrecognizedResourceErr) Error() string
type UnrecognizedSyscallErr ¶
type UnrecognizedSyscallErr struct {
SyscallNum U64
}
func (*UnrecognizedSyscallErr) Error ¶
func (e *UnrecognizedSyscallErr) Error() string
type UnsupportedSyscallErr ¶
type UnsupportedSyscallErr struct {
SyscallNum U64
}
func (*UnsupportedSyscallErr) Error ¶
func (e *UnsupportedSyscallErr) Error() string
type VMState ¶
type VMState struct { Memory *Memory `json:"memory"` PreimageKey common.Hash `json:"preimageKey"` PreimageOffset uint64 `json:"preimageOffset"` PC uint64 `json:"pc"` ExitCode uint8 `json:"exit"` Exited bool `json:"exited"` Step uint64 `json:"step"` Heap uint64 `json:"heap"` // for mmap to keep allocating new anon memory LoadReservation uint64 `json:"loadReservation"` Registers [32]uint64 `json:"registers"` // LastHint is optional metadata, and not part of the VM state itself. // It is used to remember the last pre-image hint, // so a VM can start from any state without fetching prior pre-images, // and instead just repeat the last hint on setup, // to make sure pre-image requests can be served. // The first 4 bytes are a uin32 length prefix. // Warning: the hint MAY NOT BE COMPLETE. I.e. this is buffered, // and should only be read when len(LastHint) > 4 && uint32(LastHint[:4]) <= len(LastHint[4:]) LastHint hexutil.Bytes `json:"lastHint,omitempty"` // VMState must hold these values because if not, we must ask FPVM again to // compute these values. Witness []byte `json:"witness,omitempty"` StateHash common.Hash `json:"stateHash,omitempty"` }
func LoadVMStateFromFile ¶ added in v1.1.0
func NewVMState ¶
func NewVMState() *VMState
func (*VMState) EncodeWitness ¶
func (state *VMState) EncodeWitness() StateWitness
func (*VMState) Serialize ¶ added in v1.1.0
Serialize writes the state in a simple binary format which can be read again using Deserialize The format is a simple concatenation of fields, with prefixed item count for repeating items and using big endian encoding for numbers.
Memory As per Memory.Serialize PreimageKey [32]byte PreimageOffset uint64 PC uint64 ExitCode uint8 Exited bool - 0 for false, 1 for true Step uint64 Heap uint64 LoadReservation uint64 Registers. [32]uint64 len(LastHint) uint64 (0 when LastHint is nil) LastHint []byte len(Witness) uint64 (0 when Witness is nil) Witness []byte StateHash [32]byte