lookup

package
v1.2.23 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Copyright Consensys Software Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint[F field.Element[F], E term.Evaluable[F]] struct {
	// Handle returns the handle for this lookup constraint which is simply an
	// identifier useful when debugging (i.e. to know which lookup failed, etc).
	Handle string
	// Targets returns the target expressions which are used to lookup into the
	// target expressions.  NOTE: the first element here is *always* the target
	// selector.
	Targets []Vector[F, E]
	// Sources returns the source expressions which are used to lookup into the
	// target expressions.  NOTE: the first element here is *always* the source
	// selector.
	Sources []Vector[F, E]
}

Constraint (sometimes also called an inclusion constraint) constrains two sets of columns (potentially in different modules). Specifically, every row in the source columns must match a row in the target columns (but not vice-versa). As such, the number of source columns must be the same as the number of target columns. Furthermore, every source column must be in the same module, and likewise for target modules. However, the source columns can be in a different module from the target columns.

Lookup constraints are typically used to "connect" modules together. We can think of them (in some ways) as being a little like function calls. In this analogy, the source module is making a "function call" into the target module. That is, the target module contains the set of valid input/output pairs (and perhaps other constraints to ensure the required relationship) and the source module is just checking that a given set of input/output pairs makes sense.

func NewConstraint

func NewConstraint[F field.Element[F], E term.Evaluable[F]](handle string, targets []Vector[F, E],
	sources []Vector[F, E]) Constraint[F, E]

NewConstraint creates a new lookup constraint with a given handle.

func (Constraint[F, E]) Accepts

func (p Constraint[F, E]) Accepts(tr trace.Trace[F], sc schema.AnySchema[F]) (bit.Set, schema.Failure)

Accepts checks whether a lookup constraint into the target columns holds for all rows of the source columns.

func (Constraint[F, E]) Bounds

func (p Constraint[F, E]) Bounds(module uint) util.Bounds

Bounds determines the well-definedness bounds for this constraint for both the negative (left) or positive (right) directions. For example, consider an expression such as "(shift X -1)". This is technically undefined for the first row of any trace and, by association, any constraint evaluating this expression on that first row is also undefined (and hence must pass).

func (Constraint[F, E]) Consistent

func (p Constraint[F, E]) Consistent(_ schema.AnySchema[F]) []error

Consistent applies a number of internal consistency checks. Whilst not strictly necessary, these can highlight otherwise hidden problems as an aid to debugging.

func (Constraint[F, E]) Contexts

func (p Constraint[F, E]) Contexts() []schema.ModuleId

Contexts returns the evaluation contexts (i.e. enclosing module + length multiplier) for this constraint. Most constraints have only a single evaluation context, though some (e.g. lookups) have more. Note that all constraints have at least one context (which we can call the "primary" context).

func (Constraint[F, E]) Lisp

func (p Constraint[F, E]) Lisp(mapping schema.AnySchema[F]) sexp.SExp

Lisp converts this schema element into a simple S-Expression, for example so it can be printed.

func (Constraint[F, E]) Name

func (p Constraint[F, E]) Name() string

Name returns a unique name for a given constraint. This is useful purely for identifying constraints in reports, etc.

func (Constraint[F, E]) Substitute

func (p Constraint[F, E]) Substitute(mapping map[string]F)

Substitute any matchined labelled constants within this constraint

type Failure

type Failure[F any] struct {
	// Handle of the failing constraint
	Handle string
	// Relevant context for source expressions.
	Context schema.ModuleId
	// Source expressions which were missing
	Sources []term.Evaluable[F]
	// Row on which the constraint failed
	Row uint
}

Failure provides structural information about a failing lookup constraint.

func (*Failure[F]) Message

func (p *Failure[F]) Message() string

Message provides a suitable error message

func (*Failure[F]) RequiredCells

func (p *Failure[F]) RequiredCells(_ trace.Trace[F]) *set.AnySortedSet[trace.CellRef]

RequiredCells identifies the cells required to evaluate the failing constraint at the failing row.

func (*Failure[F]) String

func (p *Failure[F]) String() string

type Geometry

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

Geometry defines the "geometry" of a lookup. That is the maximum bitwidth for each source-target pairing in the lookup. For example, consider a lookup where (X Y) looksup into (A B). Suppose X is 16bit and Y is 32bit, whilst A is 64bit and B is 8bit. Then, the geometry of the lookup is [16,32].

func NewGeometry

func NewGeometry[F field.Element[F], E term.Evaluable[F], T register.Map](c Constraint[F, E],
	mapping module.Map[T]) Geometry

NewGeometry returns the calculated "geometry" for this lookup. That is, for each source/target pair, the maximum bitwidth of any source or target value.

func (*Geometry) BandWidth

func (p *Geometry) BandWidth() uint

BandWidth returns maximum field bandwidth available in the field.

func (*Geometry) LimbWidths

func (p *Geometry) LimbWidths(i uint) []uint

LimbWidths returns the bitwidths for the required limbs for a given source/target pairing in the lookup.

func (*Geometry) RegisterWidth

func (p *Geometry) RegisterWidth() uint

RegisterWidth returns maximum permitted register width for the field.

type State

type State[F field.Element[F], E term.Evaluable[F]] struct {
	// contains filtered or unexported fields
}

State is just bringing somethings together to make life simpler

type Vector

type Vector[F any, E term.Evaluable[F]] struct {
	// Module in which all terms are evaluated.
	Module schema.ModuleId
	// Selector for this vector (optional)
	Selector util.Option[E]
	// Terms making up this vector.
	Terms []E
}

Vector encapsulates all columns on one side of a lookup (i.e. it represents all source columns or all target columns).

func FilteredVector

func FilteredVector[F any, E term.Evaluable[F]](mid schema.ModuleId, selector E, terms ...E) Vector[F, E]

FilteredVector constructs a new vector in a given context which has a selector.

func NewVector

func NewVector[F any, E term.Evaluable[F]](mid schema.ModuleId, selector util.Option[E], terms ...E) Vector[F, E]

NewVector constructs a new vector in a given context with an optional selector.

func UnfilteredVector

func UnfilteredVector[F any, E term.Evaluable[F]](mid schema.ModuleId, terms ...E) Vector[F, E]

UnfilteredVector constructs a new vector in a given context which has no selector.

func (*Vector[F, E]) Bounds

func (p *Vector[F, E]) Bounds(module uint) util.Bounds

Bounds determines the well-definedness bounds for all terms within this vector.

func (*Vector[F, E]) Context

func (p *Vector[F, E]) Context() schema.ModuleId

Context returns the conterxt in which all terms of this vector must be evaluated.

func (*Vector[F, E]) HasSelector

func (p *Vector[F, E]) HasSelector() bool

HasSelector determines whether or not this lookup vector has a selector or not.

func (*Vector[F, E]) Ith

func (p *Vector[F, E]) Ith(index uint) E

Ith returns the ith term in this vector.

func (*Vector[F, E]) Len

func (p *Vector[F, E]) Len() uint

Len returns the number of items in this lookup vector. Note this doesn't include the selector (since this is optional anyway).

func (*Vector[F, E]) Lisp

func (p *Vector[F, E]) Lisp(mapping schema.AnySchema[F]) sexp.SExp

Lisp returns a textual representation of this vector.

func (*Vector[F, E]) Substitute

func (p *Vector[F, E]) Substitute(mapping map[string]F)

Substitute any matchined labelled constants within this vector

Jump to

Keyboard shortcuts

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