predicateutils

package
v0.5.3-coreth-sync-rc Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: GPL-3.0, LGPL-3.0 Imports: 2 Imported by: 0

README

Predicate Utils

This package provides simple helpers to pack/unpack byte slices for a predicate transaction, where a byte slice of size N is encoded in the access list of a transaction.

Encoding

A byte slice of size N is encoded as:

  1. Slice of N bytes
  2. Delimiter byte 0xff
  3. Appended 0s to the nearest multiple of 32 bytes

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PredicateEndByte = byte(0xff)

PredicateEndByte 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 BytesToHashSlice

func BytesToHashSlice(b []byte) []common.Hash

BytesToHashSlice packs [b] into a slice of hash values with zero padding to the right if the length of b is not a multiple of 32.

func HashSliceToBytes

func HashSliceToBytes(hashes []common.Hash) []byte

HashSliceToBytes serializes a []common.Hash into a tightly packed byte array.

func PackPredicate

func PackPredicate(predicate []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 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

This section is empty.

Jump to

Keyboard shortcuts

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