data

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: 9 Imported by: 0

Documentation

Overview

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

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

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

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

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

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

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

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

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

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

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

func BitWidthOf

func BitWidthOf[S symbol.Symbol[S]](t Type[S], env Environment[S]) (bitwidth util.Option[uint])

BitWidthOf determines the bitwidth of the given type in the given environment. NOTE: should a typing cycle exist involving the given type, then this will enter an infinite loop.

NOTE: this function assumes that t1 and t2 are well-formed under the given environment.

func DecodeAll

func DecodeAll[S symbol.Symbol[S]](datatype Type[S], bytes []byte, env Environment[S]) []vm.Uint

DecodeAll decodes the given set of bytes as big integer values according to the given data type(s). Observe that values are assumed to be packed tightly (i.e. without any padding). Consider the following input byte array:

| 00 | 01 | 02 | 03 | +------+------+------+------+ | 0x31 | 0xf0 | 0x0e | 0x1d |

Then, decoding this into a u4 array will produce the following:

| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +-----+-----+-----+-----+-----+-----+-----+-----+ | 0x3 | 0x1 | 0xf | 0x0 | 0x0 | 0xe | 0x1 | 0xd |

If the input array is not a multiple of the bitwidth

func EncodeAll

func EncodeAll[S symbol.Symbol[S]](datatype Type[S], values []vm.Uint, env Environment[S]) []byte

EncodeAll encodes the given set of word values as packed bytes according to the given data type(s). This is the inverse of DecodeAll. Consider the following input array of u4 values:

| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | +-----+-----+-----+-----+-----+-----+-----+-----+ | 0x3 | 0x1 | 0xf | 0x0 | 0x0 | 0xe | 0x1 | 0xd |

Then, encoding this as a u4 array will produce the following bytes:

| 00 | 01 | 02 | 03 | +------+------+------+------+ | 0x31 | 0xf0 | 0x0e | 0x1d |

func EquiTypes

func EquiTypes[S symbol.Symbol[S]](t1, t2 Type[S], env Environment[S]) bool

EquiTypes performs an equivalence check, denoted "t1 ~ t2", in a given typing environment. In most cases, this amounts to check that the two types are equivalent. For example, "u8 ~ u8" holds but "u4 ~ u8" does not. The only real challenge is the presence of open (i.e. existential) types such as "u8+". For such types, we have that e.g. "u8 ~ u4+" hold and, likewise, that "u8+ ~ u16". To understand this, we can interpret "u8+" as saying "this can be any type which is at least a u8" Thus, the query "u8+ ~ u16" can be read as saying "is there a type which is at least a u8 equivalent to a u16?". The answer, of course, is yes: u16. However, we note that "u16+ ~ u8" does not hold.

NOTE: this function assumes that t1 and t2 are well-formed under the given environment.

func SubtypeOf

func SubtypeOf[S symbol.Symbol[S]](t1, t2 Type[S], env Environment[S]) bool

SubtypeOf performs a subtype check, denoted "t1 <: t2", in a given typing environment. A subtype check can be view as a subset relationship, where "t1 <: t2" is read as saying: the set of values in t1 is a subset of those in t2. For example, it follows that "u4 <: u8" holds since "{0..15} ⊆ {0..255}" holds. Furthermore, "u4 <: u1" does not hold as "{0..15} ⊆ {0..1}" does not. Finally, the subtype operator follows the general algebraic properties of the subset operator. For example, it is reflesive and, hence, "u4 <: u4" holds.

The only real challenge is the presence of open (i.e. existential) types such as "u4+". For example, does "u4+ <: u8" hold? To understand this, we can interpret "u4+" as saying "this can be any type which is at least a u4" Thus, the query "u4+ <: u8" can be read as saying "is there a type which is at least a u4 that is a subtype of u8?". The answer, of course, is yes: u8.

NOTE: this function assumes that t1 and t2 are well-formed under the given environment.

Types

type Alias

type Alias[I symbol.Symbol[I]] struct {
	Name I
}

Alias captures the alias of a language type. Ref points to the symbol for the type-alias declaration if resolved.

func NewAlias

func NewAlias[I symbol.Symbol[I]](name I) *Alias[I]

NewAlias constructs an alias for a given Type.

func (*Alias[I]) AsAlias

func (p *Alias[I]) AsAlias(Environment[I]) *Alias[I]

AsAlias implementation for Type interface

func (*Alias[I]) AsField

func (p *Alias[I]) AsField(env Environment[I]) *FieldElement[I]

AsField implementation for Type interface

func (*Alias[I]) AsFixedArray

func (p *Alias[I]) AsFixedArray(env Environment[I]) *FixedArray[I]

AsFixedArray implementation for Type interface

func (*Alias[I]) AsTuple

func (p *Alias[I]) AsTuple(Environment[I]) *Tuple[I]

AsTuple implementation for Type interface

func (*Alias[I]) AsUint

func (p *Alias[I]) AsUint(env Environment[I]) *UnsignedInt[I]

AsUint implementation for Type interface

func (*Alias[I]) Resolve

func (p *Alias[I]) Resolve(env Environment[I]) Type[I]

Resolve returns the type that this alias refers to in the given environment.

func (*Alias[I]) String

func (p *Alias[I]) String(Environment[I]) string

type Environment

type Environment[S symbol.Symbol[S]] interface {
	// TypeOf resolves the type of an external identifier.
	TypeOf(S) Type[S]
	// WellFormed is used to check whether a given type is well-formed under the
	// given environment.  This is necessary to protected against various problems
	// in methods such as Bitwidth, SubtypeOf and EquiTypes.
	WellFormed(t Type[S]) bool
}

Environment provides a typing environment for externally defined types, such as for type aliases.

type FieldElement

type FieldElement[S symbol.Symbol[S]] struct{}

FieldElement captures the native field element type. A field element is any element within the prime field used by the verifier. Unlike unsigned integer types, the range of valid values depends on the choice of prime field.

func NewFieldElement

func NewFieldElement[S symbol.Symbol[S]]() *FieldElement[S]

NewFieldElement constructs a field element type.

func (*FieldElement[S]) AsAlias

func (p *FieldElement[S]) AsAlias(Environment[S]) *Alias[S]

AsAlias implementation for Type interface

func (*FieldElement[S]) AsField

func (p *FieldElement[S]) AsField(Environment[S]) *FieldElement[S]

AsField implementation for Type interface

func (*FieldElement[I]) AsFixedArray

func (p *FieldElement[I]) AsFixedArray(Environment[I]) *FixedArray[I]

AsFixedArray implementation for Type interface

func (*FieldElement[S]) AsTuple

func (p *FieldElement[S]) AsTuple(Environment[S]) *Tuple[S]

AsTuple implementation for Type interface

func (*FieldElement[S]) AsUint

func (p *FieldElement[S]) AsUint(Environment[S]) *UnsignedInt[S]

AsUint implementation for Type interface

func (*FieldElement[S]) String

func (p *FieldElement[S]) String(_ Environment[S]) string

type FixedArray

type FixedArray[I symbol.Symbol[I]] struct {
	DataType Type[I]
	// Size holds either a numeric literal or a symbolic name for the array
	// size.  The latter (if present) must be resolved during linking.
	Size util.Union[uint, I]
}

FixedArray captures a fixed sized array type.

func NewFixedArray

func NewFixedArray[I symbol.Symbol[I]](datatype Type[I], size util.Union[uint, I]) *FixedArray[I]

NewFixedArray constructs a fixed-size array Type.

func (*FixedArray[I]) AsAlias

func (p *FixedArray[I]) AsAlias(Environment[I]) *Alias[I]

AsAlias implementation for Type interface

func (*FixedArray[S]) AsField

func (p *FixedArray[S]) AsField(Environment[S]) *FieldElement[S]

AsField implementation for Type interface

func (*FixedArray[I]) AsFixedArray

func (p *FixedArray[I]) AsFixedArray(Environment[I]) *FixedArray[I]

AsFixedArray implementation for Type interface

func (*FixedArray[I]) AsTuple

func (p *FixedArray[I]) AsTuple(Environment[I]) *Tuple[I]

AsTuple implementation for Type interface

func (*FixedArray[I]) AsUint

func (p *FixedArray[I]) AsUint(env Environment[I]) *UnsignedInt[I]

AsUint implementation for Type interface

func (*FixedArray[I]) Resolve

func (p *FixedArray[I]) Resolve(Environment[I]) Type[I]

Resolve returns the type that this fixed-size array refers to in the given environment.

func (*FixedArray[I]) SizeString

func (p *FixedArray[I]) SizeString() string

SizeString returns the size of this string as a symbol.

func (*FixedArray[I]) String

func (p *FixedArray[I]) String(env Environment[I]) string

type ResolvedAlias

type ResolvedAlias = Alias[symbol.Resolved]

ResolvedAlias represents an alias which contains only resolved identifiers.

type ResolvedEnvironment

type ResolvedEnvironment = Environment[symbol.Resolved]

ResolvedEnvironment represents a typing environment which contains only resolved identifiers.

type ResolvedFieldElement

type ResolvedFieldElement = FieldElement[symbol.Resolved]

ResolvedFieldElement represents a field element type with only resolved identifiers.

type ResolvedFixedArray

type ResolvedFixedArray = FixedArray[symbol.Resolved]

ResolvedFixedArray represents a fixed-size array which contains only resolved identifiers.

type ResolvedType

type ResolvedType = Type[symbol.Resolved]

ResolvedType represents a type which contains only resolved identifiers.

type Tuple

type Tuple[S symbol.Symbol[S]] struct {
	// contains filtered or unexported fields
}

Tuple represents the composition of zero or more types together. For example, (u8,u16) is a tuple type consisting of two elements: the first being a u8, and the second being a u16. The overall width of the tuple is therefore the sum of the widths of the elements.

func (*Tuple[S]) AsAlias

func (p *Tuple[S]) AsAlias(Environment[S]) *Alias[S]

AsAlias implementation for Type interface

func (*Tuple[S]) AsField

func (p *Tuple[S]) AsField(Environment[S]) *FieldElement[S]

AsField implementation for Type interface

func (*Tuple[S]) AsFixedArray

func (p *Tuple[S]) AsFixedArray(Environment[S]) *FixedArray[S]

AsFixedArray implementation for Type interface

func (*Tuple[S]) AsTuple

func (p *Tuple[S]) AsTuple(Environment[S]) *Tuple[S]

AsTuple implementation for Type interface

func (*Tuple[S]) AsUint

func (p *Tuple[S]) AsUint(Environment[S]) *UnsignedInt[S]

AsUint implementation for Type interface

func (*Tuple[S]) Flatten

func (p *Tuple[S]) Flatten(prefix string, env Environment[S], constructor func(name string, bitwidth uint))

Flatten implementation for Type interface

func (*Tuple[S]) Ith

func (p *Tuple[S]) Ith(index uint) Type[S]

Ith returns the ith element in this tuple

func (*Tuple[S]) String

func (p *Tuple[S]) String(env Environment[S]) string

func (*Tuple[S]) Types

func (p *Tuple[S]) Types() []Type[S]

Types provides access to the underlying array of types. This has been defensively cloned before returning.

func (*Tuple[S]) Width

func (p *Tuple[S]) Width() uint

Width returns the number of elements in this tuple.

type Type

type Type[S symbol.Symbol[S]] interface {
	// AsUint determines whether or not this is an unsigned int.
	AsUint(Environment[S]) *UnsignedInt[S]
	// AsTuple determines whether or not this is a tuple
	AsTuple(Environment[S]) *Tuple[S]
	// AsAlias determines whether or not this is an alias.
	AsAlias(Environment[S]) *Alias[S]
	// AsField determines whether or not this is a field element.
	AsField(Environment[S]) *FieldElement[S]
	// AsFixedArray determines whether or not this is a fixed-size array.
	AsFixedArray(Environment[S]) *FixedArray[S]
	// String returns a string representation of this type.
	String(Environment[S]) string
}

Type provides an abstraction over raw words which, in principle, can be used to support richer forms of type (e.g. structs).

func FromTypes

func FromTypes[S symbol.Symbol[S]](types ...Type[S]) Type[S]

FromTypes constructs a single type representing the combination of potentially one or more types.

type UnresolvedAlias

type UnresolvedAlias = Alias[symbol.Unresolved]

UnresolvedAlias represents an alias which contains only unresolved identifiers.

type UnresolvedEnvironment

type UnresolvedEnvironment = Environment[symbol.Unresolved]

UnresolvedEnvironment represents a typing environment which may contain unresolved identifiers.

type UnresolvedFieldElement

type UnresolvedFieldElement = FieldElement[symbol.Unresolved]

UnresolvedFieldElement represents a field element type which may contain unresolved identifiers.

type UnresolvedFixedArray

type UnresolvedFixedArray = FixedArray[symbol.Unresolved]

UnresolvedFixedArray represents a fixed-size array which contains only unresolved identifiers.

type UnresolvedType

type UnresolvedType = Type[symbol.Unresolved]

UnresolvedType represents a type which may contain unresolved identifiers.

type UnsignedInt

type UnsignedInt[S symbol.Symbol[S]] struct {
	// contains filtered or unexported fields
}

UnsignedInt captures the fundamental data type of the language.

func NewUnsignedInt

func NewUnsignedInt[S symbol.Symbol[S]](bitwidth uint, open bool) *UnsignedInt[S]

NewUnsignedInt constructs an unsigned int type of a given width.

func (*UnsignedInt[S]) AsAlias

func (p *UnsignedInt[S]) AsAlias(Environment[S]) *Alias[S]

AsAlias implementation for Type interface

func (*UnsignedInt[S]) AsField

func (p *UnsignedInt[S]) AsField(Environment[S]) *FieldElement[S]

AsField implementation for Type interface

func (*UnsignedInt[S]) AsFixedArray

func (p *UnsignedInt[S]) AsFixedArray(Environment[S]) *FixedArray[S]

AsFixedArray implementation for Type interface

func (*UnsignedInt[S]) AsTuple

func (p *UnsignedInt[S]) AsTuple(Environment[S]) *Tuple[S]

AsTuple implementation for Type interface

func (*UnsignedInt[S]) AsUint

func (p *UnsignedInt[S]) AsUint(Environment[S]) *UnsignedInt[S]

AsUint implementation for Type interface

func (*UnsignedInt[S]) BitWidth

func (p *UnsignedInt[S]) BitWidth() uint

BitWidth returns the width of this unsigned int type (e.g. 8 for u8, etc)

func (*UnsignedInt[S]) Flatten

func (p *UnsignedInt[S]) Flatten(prefix string, env Environment[S], constructor func(name string, bitwidth uint))

Flatten implementation for Type interface

func (*UnsignedInt[S]) IsOpen

func (p *UnsignedInt[S]) IsOpen() bool

IsOpen determines whether or not this is an "open type" or not.

func (*UnsignedInt[S]) Join

func (p *UnsignedInt[S]) Join(q *UnsignedInt[S]) *UnsignedInt[S]

Join combines to uint types together

func (*UnsignedInt[S]) String

func (p *UnsignedInt[S]) String(_ Environment[S]) string

Jump to

Keyboard shortcuts

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