multithreaded

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MEMROOT_WITNESS_OFFSET                    = 0
	PREIMAGE_KEY_WITNESS_OFFSET               = MEMROOT_WITNESS_OFFSET + 32
	PREIMAGE_OFFSET_WITNESS_OFFSET            = PREIMAGE_KEY_WITNESS_OFFSET + 32
	HEAP_WITNESS_OFFSET                       = PREIMAGE_OFFSET_WITNESS_OFFSET + arch.WordSizeBytes
	LL_RESERVATION_ACTIVE_OFFSET              = HEAP_WITNESS_OFFSET + arch.WordSizeBytes
	LL_ADDRESS_OFFSET                         = LL_RESERVATION_ACTIVE_OFFSET + 1
	LL_OWNER_THREAD_OFFSET                    = LL_ADDRESS_OFFSET + arch.WordSizeBytes
	EXITCODE_WITNESS_OFFSET                   = LL_OWNER_THREAD_OFFSET + arch.WordSizeBytes
	EXITED_WITNESS_OFFSET                     = EXITCODE_WITNESS_OFFSET + 1
	STEP_WITNESS_OFFSET                       = EXITED_WITNESS_OFFSET + 1
	STEPS_SINCE_CONTEXT_SWITCH_WITNESS_OFFSET = STEP_WITNESS_OFFSET + 8
	WAKEUP_WITNESS_OFFSET                     = STEPS_SINCE_CONTEXT_SWITCH_WITNESS_OFFSET + 8
	TRAVERSE_RIGHT_WITNESS_OFFSET             = WAKEUP_WITNESS_OFFSET + arch.WordSizeBytes
	LEFT_THREADS_ROOT_WITNESS_OFFSET          = TRAVERSE_RIGHT_WITNESS_OFFSET + 1
	RIGHT_THREADS_ROOT_WITNESS_OFFSET         = LEFT_THREADS_ROOT_WITNESS_OFFSET + 32
	THREAD_ID_WITNESS_OFFSET                  = RIGHT_THREADS_ROOT_WITNESS_OFFSET + 32

	// 172 and 196 bytes for 32 and 64-bit respectively
	STATE_WITNESS_SIZE = THREAD_ID_WITNESS_OFFSET + arch.WordSizeBytes
)

STATE_WITNESS_SIZE is the size of the state witness encoding in bytes.

View Source
const (
	THREAD_ID_STATE_WITNESS_OFFSET           = 0
	THREAD_EXIT_CODE_WITNESS_OFFSET          = THREAD_ID_STATE_WITNESS_OFFSET + arch.WordSizeBytes
	THREAD_EXITED_WITNESS_OFFSET             = THREAD_EXIT_CODE_WITNESS_OFFSET + 1
	THREAD_FUTEX_ADDR_WITNESS_OFFSET         = THREAD_EXITED_WITNESS_OFFSET + 1
	THREAD_FUTEX_VAL_WITNESS_OFFSET          = THREAD_FUTEX_ADDR_WITNESS_OFFSET + arch.WordSizeBytes
	THREAD_FUTEX_TIMEOUT_STEP_WITNESS_OFFSET = THREAD_FUTEX_VAL_WITNESS_OFFSET + arch.WordSizeBytes
	THREAD_FUTEX_CPU_WITNESS_OFFSET          = THREAD_FUTEX_TIMEOUT_STEP_WITNESS_OFFSET + 8
	THREAD_REGISTERS_WITNESS_OFFSET          = THREAD_FUTEX_CPU_WITNESS_OFFSET + (4 * arch.WordSizeBytes)

	// SERIALIZED_THREAD_SIZE is the size of a serialized ThreadState object
	// 166 and 322 bytes for 32 and 64-bit respectively
	SERIALIZED_THREAD_SIZE = THREAD_REGISTERS_WITNESS_OFFSET + (32 * arch.WordSizeBytes)

	// THREAD_WITNESS_SIZE is the size of a thread witness encoded in bytes.
	//
	//	It consists of the active thread serialized and concatenated with the
	//	32 byte hash onion of the active thread stack without the active thread
	THREAD_WITNESS_SIZE = SERIALIZED_THREAD_SIZE + 32
)

Variables

View Source
var EmptyThreadsRoot common.Hash = common.HexToHash("0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5")

The empty thread root - keccak256(bytes32(0) ++ bytes32(0))

Functions

func GetStateHashFn added in v1.9.1

func GetStateHashFn() mipsevm.HashFn

Types

type InstrumentedState

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

func NewInstrumentedState

func NewInstrumentedState(state *State, po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, log log.Logger, meta mipsevm.Metadata) *InstrumentedState

func (*InstrumentedState) CheckInfiniteLoop

func (m *InstrumentedState) CheckInfiniteLoop() bool

func (*InstrumentedState) GetDebugInfo

func (m *InstrumentedState) GetDebugInfo() *mipsevm.DebugInfo

func (*InstrumentedState) GetState

func (m *InstrumentedState) GetState() mipsevm.FPVMState

func (*InstrumentedState) InitDebug

func (m *InstrumentedState) InitDebug() error

func (*InstrumentedState) LastPreimage

func (m *InstrumentedState) LastPreimage() ([32]byte, []byte, arch.Word)

func (*InstrumentedState) LookupSymbol added in v1.9.1

func (m *InstrumentedState) LookupSymbol(addr arch.Word) string

func (*InstrumentedState) Step

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

func (*InstrumentedState) Traceback

func (m *InstrumentedState) Traceback()

type LLReservationStatus added in v1.9.5

type LLReservationStatus uint8
const (
	LLStatusNone        LLReservationStatus = 0x0
	LLStatusActive32bit LLReservationStatus = 0x1
	LLStatusActive64bit LLReservationStatus = 0x2
)

type NoopThreadedStackTracker

type NoopThreadedStackTracker struct {
	exec.NoopStackTracker
}

func (*NoopThreadedStackTracker) DropThread

func (n *NoopThreadedStackTracker) DropThread(threadId Word)

type State

type State struct {
	Memory *memory.Memory

	PreimageKey    common.Hash
	PreimageOffset Word // note that the offset includes the 8-byte length prefix

	Heap                Word                // to handle mmap growth
	LLReservationStatus LLReservationStatus // Determines whether there is an active memory reservation, and what type
	LLAddress           Word                // The "linked" memory address reserved via the LL (load linked) op
	LLOwnerThread       Word                // The id of the thread that holds the reservation on LLAddress

	ExitCode uint8
	Exited   bool

	Step                        uint64
	StepsSinceLastContextSwitch uint64
	Wakeup                      Word

	TraverseRight    bool
	LeftThreadStack  []*ThreadState
	RightThreadStack []*ThreadState
	NextThreadId     Word

	// LastHint is optional metadata, and not part of the VM state itself.
	LastHint hexutil.Bytes
}

func CreateEmptyState

func CreateEmptyState() *State

func CreateInitialState

func CreateInitialState(pc, heapStart Word) *State

func (*State) CreateVM added in v1.9.3

func (s *State) CreateVM(logger log.Logger, po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, meta mipsevm.Metadata) mipsevm.FPVM

func (*State) Deserialize added in v1.9.3

func (s *State) Deserialize(in io.Reader) error

func (*State) EncodeThreadProof

func (s *State) EncodeThreadProof() []byte

func (*State) EncodeWitness

func (s *State) EncodeWitness() ([]byte, common.Hash)

func (*State) GetCpu added in v1.9.1

func (s *State) GetCpu() mipsevm.CpuScalars

func (*State) GetCurrentThread added in v1.9.1

func (s *State) GetCurrentThread() *ThreadState

func (*State) GetExitCode

func (s *State) GetExitCode() uint8

func (*State) GetExited

func (s *State) GetExited() bool

func (*State) GetHeap added in v1.9.1

func (s *State) GetHeap() Word

func (*State) GetLastHint added in v1.9.1

func (s *State) GetLastHint() hexutil.Bytes

func (*State) GetMemory

func (s *State) GetMemory() *memory.Memory

func (*State) GetPC

func (s *State) GetPC() Word

func (*State) GetPreimageKey added in v1.9.1

func (s *State) GetPreimageKey() common.Hash

func (*State) GetPreimageOffset added in v1.9.1

func (s *State) GetPreimageOffset() Word

func (*State) GetRegistersRef added in v1.9.1

func (s *State) GetRegistersRef() *[32]Word

func (*State) GetStep

func (s *State) GetStep() uint64

func (*State) Serialize added in v1.9.3

func (s *State) Serialize(out io.Writer) error

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.

StateVersion uint8(1) Memory As per Memory.Serialize PreimageKey [32]byte PreimageOffset Word Heap Word ExitCode uint8 Exited uint8 - 0 for false, 1 for true Step uint64 StepsSinceLastContextSwitch uint64 Wakeup Word TraverseRight uint8 - 0 for false, 1 for true NextThreadId Word len(LeftThreadStack) Word LeftThreadStack entries as per ThreadState.Serialize len(RightThreadStack) Word RightThreadStack entries as per ThreadState.Serialize len(LastHint) Word (0 when LastHint is nil) LastHint []byte

func (*State) ThreadCount added in v1.9.2

func (s *State) ThreadCount() int

func (*State) VMStatus

func (s *State) VMStatus() uint8

type StateWitness

type StateWitness []byte

func (StateWitness) StateHash

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

type ThreadState

type ThreadState struct {
	ThreadId         Word               `json:"threadId"`
	ExitCode         uint8              `json:"exit"`
	Exited           bool               `json:"exited"`
	FutexAddr        Word               `json:"futexAddr"`
	FutexVal         Word               `json:"futexVal"`
	FutexTimeoutStep uint64             `json:"futexTimeoutStep"`
	Cpu              mipsevm.CpuScalars `json:"cpu"`
	Registers        [32]Word           `json:"registers"`
}

func CreateEmptyThread

func CreateEmptyThread() *ThreadState

func (*ThreadState) Deserialize added in v1.9.3

func (t *ThreadState) Deserialize(in io.Reader) error

func (*ThreadState) Serialize added in v1.9.3

func (t *ThreadState) Serialize(out io.Writer) error

Serialize writes the ThreadState in a simple binary format which can be read again using Deserialize The format exactly matches the serialization generated by serializeThread used for thread proofs.

type ThreadedStackTracker

type ThreadedStackTracker interface {
	exec.TraceableStackTracker
	DropThread(threadId Word)
}

type ThreadedStackTrackerImpl

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

func NewThreadedStackTracker

func NewThreadedStackTracker(state *State, meta mipsevm.Metadata) (*ThreadedStackTrackerImpl, error)

func (*ThreadedStackTrackerImpl) DropThread

func (t *ThreadedStackTrackerImpl) DropThread(threadId Word)

func (*ThreadedStackTrackerImpl) PopStack

func (t *ThreadedStackTrackerImpl) PopStack()

func (*ThreadedStackTrackerImpl) PushStack

func (t *ThreadedStackTrackerImpl) PushStack(caller Word, target Word)

func (*ThreadedStackTrackerImpl) Traceback

func (t *ThreadedStackTrackerImpl) Traceback()

type Word added in v1.9.4

type Word = arch.Word

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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