predicate

package
v0.5.9-rc.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0, LGPL-3.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	Version        = uint16(0)
	MaxResultsSize = units.MiB
)

Variables

View Source
var (
	ErrInvalidAllZeroBytes = fmt.Errorf("predicate specified invalid all zero bytes")
	ErrInvalidPadding      = fmt.Errorf("predicate specified invalid padding")
	ErrInvalidEndDelimiter = fmt.Errorf("invalid end delimiter")
	ErrorInvalidExtraData  = fmt.Errorf("header extra data too short for predicate verification")
)
View Source
var EndByte = byte(0xff)

EndByte is used as a delimiter for the bytes packed into a precompile predicate. Precompile predicates are encoded in the Access List of transactions in the access tuples which means that its length must be a multiple of 32 (common.HashLength). For messages with a length that does not comply to that, this delimiter is used to append/remove padding.

Functions

func GetPredicateResultBytes

func GetPredicateResultBytes(extraData []byte) ([]byte, bool)

GetPredicateResultBytes returns the predicate result bytes from the extra data and true iff the predicate results bytes have non-zero length.

func NewPredicateTx

func NewPredicateTx(
	chainID *big.Int,
	nonce uint64,
	to *common.Address,
	gas uint64,
	gasFeeCap *big.Int,
	gasTipCap *big.Int,
	value *big.Int,
	data []byte,
	accessList types.AccessList,
	predicateAddress common.Address,
	predicateBytes []byte,
) *types.Transaction

NewPredicateTx returns a transaction with the predicateAddress/predicateBytes tuple packed and added to the access list of the transaction.

func PackPredicate

func PackPredicate(predicateBytes []byte) []byte

PackPredicate packs predicate by delimiting the actual message with [PredicateEndByte] and zero padding to reach a length that is a multiple of 32.

func PreparePredicateStorageSlots

func PreparePredicateStorageSlots(rules params.Rules, list types.AccessList) map[common.Address][][]byte

PreparePredicateStorageSlots populates the the predicate storage slots of a transaction's access list Note: if an address is specified multiple times in the access list, each storage slot for that address is appended to a slice of byte slices. Each byte slice represents a predicate, making it a slice of predicates for each access list address, and every predicate in the slice goes through verification.

func UnpackPredicate

func UnpackPredicate(paddedPredicate []byte) ([]byte, error)

UnpackPredicate unpacks a predicate by stripping right padded zeroes, checking for the delimter, ensuring there is not excess padding, and returning the original message. Returns an error if it finds an incorrect encoding.

Types

type Results

type Results struct {
	Results map[common.Hash]TxResults `serialize:"true"`
}

Results encodes the precompile predicate results included in a block on a per transaction basis. Results is not thread-safe.

func NewResults

func NewResults() *Results

NewResults returns an empty predicate results.

func NewResultsFromMap

func NewResultsFromMap(results map[common.Hash]TxResults) *Results

func ParseResults

func ParseResults(b []byte) (*Results, error)

ParseResults parses [b] into predicate results.

func (*Results) Bytes

func (r *Results) Bytes() ([]byte, error)

Bytes marshals the current state of predicate results

func (*Results) DeleteTxResults

func (r *Results) DeleteTxResults(txHash common.Hash)

DeleteTxResults deletes the predicate results for the given [txHash].

func (*Results) GetResults

func (r *Results) GetResults(txHash common.Hash, address common.Address) []byte

GetResults returns the byte array results for [txHash] from precompile [address] if available.

func (*Results) SetTxResults

func (r *Results) SetTxResults(txHash common.Hash, txResults TxResults)

SetTxResults sets the predicate results for the given [txHash]. Overrides results if present.

func (*Results) String

func (r *Results) String() string

type TxResults

type TxResults map[common.Address][]byte

TxResults is a map of results for each precompile address to the resulting byte array.

Jump to

Keyboard shortcuts

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