preimage

package module
v0.0.0-...-b39dc7f Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HClientRFd = 3
	HClientWFd = 4
	PClientRFd = 5
	PClientWFd = 6
)

Variables

This section is empty.

Functions

func CreateBidirectionalChannel

func CreateBidirectionalChannel() (FileChannel, FileChannel, error)

CreateBidirectionalChannel creates a pair of FileChannels that are connected to each other.

func Keccak256

func Keccak256(v []byte) (out [32]byte)

Types

type FileChannel

type FileChannel interface {
	io.ReadWriteCloser
	// Reader returns the file that is used for reading.
	Reader() *os.File
	// Writer returns the file that is used for writing.
	Writer() *os.File
}

FileChannel is a unidirectional channel for file I/O

type Hint

type Hint interface {
	Hint() string
}

Hint is an interface to enable any program type to function as a hint, when passed to the Hinter interface, returning a string representation of what data the host should prepare pre-images for.

type HintReader

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

HintReader reads the hints of HintWriter and passes them to a router for preparation of the requested pre-images. Onchain the written hints are no-op.

func NewHintReader

func NewHintReader(rw io.ReadWriter) *HintReader

func (*HintReader) NextHint

func (hr *HintReader) NextHint(router func(hint string) error) error

type HintWriter

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

HintWriter writes hints to an io.Writer (e.g. a special file descriptor, or a debug log), for a pre-image oracle service to prepare specific pre-images.

func NewHintWriter

func NewHintWriter(rw io.ReadWriter) *HintWriter

func (*HintWriter) Hint

func (hw *HintWriter) Hint(v Hint)

type Hinter

type Hinter interface {
	Hint(v Hint)
}

Hinter is an interface to write hints to the host. This may be implemented as a no-op or logging hinter if the program is executing in a read-only environment where the host is expected to have all pre-images ready.

type HinterFn

type HinterFn func(v Hint)

func (HinterFn) Hint

func (fn HinterFn) Hint(v Hint)

type Keccak256Key

type Keccak256Key [32]byte

Keccak256Key wraps a keccak256 hash to use it as a typed pre-image key.

func (Keccak256Key) PreimageKey

func (k Keccak256Key) PreimageKey() (out [32]byte)

func (Keccak256Key) String

func (k Keccak256Key) String() string

func (Keccak256Key) TerminalString

func (k Keccak256Key) TerminalString() string

type Key

type Key interface {
	// PreimageKey changes the Key commitment into a
	// 32-byte type-prefixed preimage key.
	PreimageKey() [32]byte
}

type KeyType

type KeyType byte

KeyType is the key-type of a pre-image, used to prefix the pre-image key with.

const (

	// LocalKeyType is for input-type pre-images, specific to the local program instance.
	LocalKeyType KeyType = 1
	// Keccak256KeyType is for keccak256 pre-images, for any global shared pre-images.
	Keccak256KeyType KeyType = 2
)

type LocalIndexKey

type LocalIndexKey uint64

LocalIndexKey is a key local to the program, indexing a special program input.

func (LocalIndexKey) PreimageKey

func (k LocalIndexKey) PreimageKey() (out [32]byte)

type Oracle

type Oracle interface {
	// Get the full pre-image of a given pre-image key.
	// This returns no error: the client state-transition
	// is invalid if there is any missing pre-image data.
	Get(key Key) []byte
}

type OracleClient

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

OracleClient implements the Oracle by writing the pre-image key to the given stream, and reading back a length-prefixed value.

func NewOracleClient

func NewOracleClient(rw io.ReadWriter) *OracleClient

func (*OracleClient) Get

func (o *OracleClient) Get(key Key) []byte

type OracleFn

type OracleFn func(key Key) []byte

func (OracleFn) Get

func (fn OracleFn) Get(key Key) []byte

type OracleServer

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

OracleServer serves the pre-image requests of the OracleClient, implementing the same protocol as the onchain VM.

func NewOracleServer

func NewOracleServer(rw io.ReadWriter) *OracleServer

func (*OracleServer) NextPreimageRequest

func (o *OracleServer) NextPreimageRequest(getPreimage func(key [32]byte) ([]byte, error)) error

type ReadWritePair

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

func ClientHinterChannel

func ClientHinterChannel() *ReadWritePair

func ClientPreimageChannel

func ClientPreimageChannel() *ReadWritePair

ClientPreimageChannel returns a FileChannel for the preimage oracle in a detached context

func NewReadWritePair

func NewReadWritePair(r *os.File, w *os.File) *ReadWritePair

NewReadWritePair creates a new FileChannel that uses the given files

func (*ReadWritePair) Close

func (rw *ReadWritePair) Close() error

func (*ReadWritePair) Read

func (rw *ReadWritePair) Read(p []byte) (int, error)

func (*ReadWritePair) Reader

func (rw *ReadWritePair) Reader() *os.File

func (*ReadWritePair) Write

func (rw *ReadWritePair) Write(p []byte) (int, error)

func (*ReadWritePair) Writer

func (rw *ReadWritePair) Writer() *os.File

Jump to

Keyboard shortcuts

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