fast

package
v0.0.0-...-91385b4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	VMStatusValid      = 0
	VMStatusInvalid    = 1
	VMStatusPanic      = 2
	VMStatusUnfinished = 3
)

Variables

This section is empty.

Functions

func HashPair

func HashPair(left, right [32]byte) [32]byte

func PatchVM

func PatchVM(f *elf.File, vmState *VMState) error

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) 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) 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() []byte

func (*InstrumentedState) Step

func (m *InstrumentedState) Step(proof bool) (wit *StepWitness, err error)

type LocalContext

type LocalContext common.Hash

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

func NewMemory

func NewMemory() *Memory

func (*Memory) AllocPage

func (m *Memory) AllocPage(pageIndex uint64) *CachedPage

func (*Memory) ForEachPage

func (m *Memory) ForEachPage(fn func(pageIndex uint64, page *Page) error) error

func (*Memory) GetUnaligned

func (m *Memory) GetUnaligned(addr uint64, dest []byte)

func (*Memory) Invalidate

func (m *Memory) Invalidate(addr uint64)

func (*Memory) MarshalJSON

func (m *Memory) MarshalJSON() ([]byte, error)

func (*Memory) MerkleProof

func (m *Memory) MerkleProof(addr uint64) (out [ProofLen * 32]byte)

func (*Memory) MerkleRoot

func (m *Memory) MerkleRoot() [32]byte

func (*Memory) MerkleizeSubtree

func (m *Memory) MerkleizeSubtree(gindex uint64) [32]byte

func (*Memory) PageCount

func (m *Memory) PageCount() int

func (*Memory) ReadMemoryRange

func (m *Memory) ReadMemoryRange(addr uint64, count uint64) io.Reader

func (*Memory) SetMemoryRange

func (m *Memory) SetMemoryRange(addr uint64, r io.Reader) error

func (*Memory) SetUnaligned

func (m *Memory) SetUnaligned(addr uint64, dat []byte)

TODO: we never do unaligned writes, this should be simplified

func (*Memory) UnmarshalJSON

func (m *Memory) UnmarshalJSON(data []byte) error

func (*Memory) Usage

func (m *Memory) Usage() string

type Page

type Page [PageSize]byte

func (*Page) MarshalText

func (p *Page) MarshalText() ([]byte, error)

func (*Page) UnmarshalText

func (p *Page) UnmarshalText(dat []byte) error

type PreimageOracle

type PreimageOracle interface {
	Hint(v []byte)
	GetPreimage(k [32]byte) []byte
}

type SortedSymbols

type SortedSymbols []elf.Symbol

func Symbols

func Symbols(f *elf.File) (SortedSymbols, error)

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

func (StateWitness) StateHash

func (sw StateWitness) StateHash() (common.Hash, error)

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 U256

type U256 = uint256.Int

type U64

type U64 = uint64

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    [32]byte `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 [32]byte `json:"stateHash,omitempty"`
}

func LoadELF

func LoadELF(f *elf.File) (*VMState, error)

func NewVMState

func NewVMState() *VMState

func (*VMState) EncodeWitness

func (state *VMState) EncodeWitness() StateWitness

func (*VMState) GetStep

func (state *VMState) GetStep() uint64

func (*VMState) Instr

func (state *VMState) Instr() uint32

func (*VMState) SetWitnessAndStateHash

func (state *VMState) SetWitnessAndStateHash() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL