preimage

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: MIT Imports: 11 Imported by: 5

README

op-preimage

op-preimage offers simple Go bindings to interact as client or server over the Pre-image Oracle ABI.

Read more about the Preimage Oracle in the specs.

See op-program and Cannon client examples for client-side usage. See Cannon mipsevm for server-side usage.

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrIncorrectData      = errors.New("incorrect data")
	ErrUnsupportedKeyType = errors.New("unsupported key type")
)

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 BlobKey added in v1.5.1

type BlobKey [32]byte

BlobKey is the hash of a blob commitment and `z` value to use as a preimage key for `y`.

func (BlobKey) PreimageKey added in v1.5.1

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

func (BlobKey) String added in v1.5.1

func (k BlobKey) String() string

func (BlobKey) TerminalString added in v1.5.1

func (k BlobKey) TerminalString() string

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 FilePoller added in v1.1.6

type FilePoller struct {
	File FileChannel
	// contains filtered or unexported fields
}

FilePoller is a ReadWriteCloser that polls the underlying file channel for reads and writes until its context is done. This is useful to detect when the other end of a blocking pre-image channel is no longer available.

func NewFilePoller added in v1.1.6

func NewFilePoller(ctx context.Context, f FileChannel, pollTimeout time.Duration) *FilePoller

NewFilePoller returns a FilePoller that polls the underlying file channel for reads and writes until the provided ctx is done. The poll timeout is the maximum amount of time to wait for I/O before the operation is halted and the context is checked for cancellation.

func (*FilePoller) Close added in v1.1.6

func (p *FilePoller) Close() error

func (*FilePoller) Read added in v1.1.6

func (f *FilePoller) Read(b []byte) (int, error)

func (*FilePoller) Write added in v1.1.6

func (f *FilePoller) Write(b []byte) (int, error)

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 HintHandler

type HintHandler func(hint string) error

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 HintHandler) 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
	// GlobalGenericKeyType is a reserved key type for generic global data.
	GlobalGenericKeyType KeyType = 3
	// Sha256KeyType is for sha256 pre-images, for any global shared pre-images.
	Sha256KeyType KeyType = 4
	// BlobKeyType is for blob point pre-images.
	BlobKeyType KeyType = 5
	// PrecompileKeyType is for precompile result pre-images.
	PrecompileKeyType KeyType = 6
)

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 PreimageGetter) error

type PrecompileKey added in v1.7.2

type PrecompileKey [32]byte

PrecompileKey is the hash of precompile address and its input data

func (PrecompileKey) PreimageKey added in v1.7.2

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

func (PrecompileKey) String added in v1.7.2

func (k PrecompileKey) String() string

func (PrecompileKey) TerminalString added in v1.7.2

func (k PrecompileKey) TerminalString() string

type PreimageGetter

type PreimageGetter func(key [32]byte) ([]byte, error)

func WithVerification added in v1.4.2

func WithVerification(source PreimageGetter) PreimageGetter

WithVerification wraps the supplied source to verify that the returned data is a valid pre-image for the key.

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

type Sha256Key added in v1.5.1

type Sha256Key [32]byte

Sha256Key wraps a sha256 hash to use it as a typed pre-image key.hash

func (Sha256Key) PreimageKey added in v1.5.1

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

func (Sha256Key) String added in v1.5.1

func (k Sha256Key) String() string

func (Sha256Key) TerminalString added in v1.5.1

func (k Sha256Key) TerminalString() string

Jump to

Keyboard shortcuts

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