predicate

package
v1.13.6-rc.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Predicate

This package contains the predicate data structure and its encoding and helper functions to unpack/pack the data structure.

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

Results

This defines how to encode PredicateResults within the block header's Extra data field.

For more information on the motivation for encoding the results of predicate verification within a block, see here.

Serialization

Results have a maximum size of 1MB enforced by the codec. The actual size depends on how much data the Precompile predicates may put into the results, the gas cost they charge, and the block gas limit. PredicateResults are encoded using the AvalancheGo codec, which serializes a map by serializing the length of the map as a uint32 and then serializes each key-value pair sequentially.

PredicateResults:

Field Type Size
codecID uint16 2 bytes
results map[[32]byte]TxPredicateResults 4 + size(results) bytes
Total 6 + size(results)
  • codecID is the codec version used to serialize the payload and is hardcoded to 0x0000
  • results is a map of transaction hashes to the corresponding TxPredicateResults

TxPredicateResults

Field Type Size
txPredicateResults map[[20]byte][]byte 4 + size(txPredicateResults) bytes
  • txPredicateResults is a map of precompile addresses to the corresponding byte array returned by the predicate
Examples
Empty Predicate Results Map
// codecID
0x00, 0x00,
// results length
0x00, 0x00, 0x00, 0x00
Predicate Map with a Single Transaction Result
// codecID
0x00, 0x00,
// Results length
0x00, 0x00, 0x00, 0x01,
// txHash (key in results map)
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// TxPredicateResults (value in results map)
// TxPredicateResults length
0x00, 0x00, 0x00, 0x01,
// precompile address (key in TxPredicateResults map)
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// Byte array results (value in TxPredicateResults map)
// Length of bytes result
0x00, 0x00, 0x00, 0x03,
// bytes
0x01, 0x02, 0x03
Predicate Map with Two Transaction Results
// codecID
0x00, 0x00,
// Results length
0x00, 0x00, 0x00, 0x02,
// txHash (key in results map)
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// TxPredicateResults (value in results map)
// TxPredicateResults length
0x00, 0x00, 0x00, 0x01,
// precompile address (key in TxPredicateResults map)
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// Byte array results (value in TxPredicateResults map)
// Length of bytes result
0x00, 0x00, 0x00, 0x03,
// bytes
0x01, 0x02, 0x03
// txHash2 (key in results map)
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
// TxPredicateResults (value in results map)
// TxPredicateResults length
0x00, 0x00, 0x00, 0x01,
// precompile address (key in TxPredicateResults map)
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// Byte array results (value in TxPredicateResults map)
// Length of bytes result
0x00, 0x00, 0x00, 0x03,
// bytes
0x01, 0x02, 0x03

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromAccessList

func FromAccessList(rules Predicates, list types.AccessList) map[common.Address][]Predicate

FromAccessList extracts predicates from a transaction's access list.

If an address is specified multiple times in the access list, each set of storage keys for that address is considered an individual predicate.

Types

type BlockResults

type BlockResults map[common.Hash]PrecompileResults

BlockResults maps the transactions in a block to their precompile results.

func ParseBlockResults

func ParseBlockResults(b []byte) (BlockResults, error)

ParseBlockResults parses bytes into predicate results.

func (*BlockResults) Bytes

func (b *BlockResults) Bytes() ([]byte, error)

Bytes marshals the predicate results.

func (*BlockResults) Get

func (b *BlockResults) Get(txHash common.Hash, address common.Address) set.Bits

Get returns the predicate results for txHash from precompile address.

func (*BlockResults) Set

func (b *BlockResults) Set(txHash common.Hash, txResults PrecompileResults)

Set sets the predicate results for the given txHash. Results are overwritten, not merged.

type PrecompileResults

type PrecompileResults map[common.Address]set.Bits

PrecompileResults is a map of results for each precompile address to the resulting bitset.

type Predicate

type Predicate []common.Hash

Predicate is a message padded with the delimiter and zeros and chunked into 32-byte chunks.

func New

func New(b []byte) Predicate

New constructs a predicate from raw predicate bytes.

It chunks the predicate by appending predicate.Delimiter and zero-padding to a multiple of 32 bytes.

func (Predicate) Bytes

func (p Predicate) Bytes() ([]byte, error)

Bytes converts the chunked predicate into the original message.

Returns an error if it finds an incorrect encoding.

type Predicates

type Predicates interface {
	HasPredicate(address common.Address) bool
}

Jump to

Keyboard shortcuts

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