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
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
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 ¶
- Variables
- func LimbWidths(maxWidth, regWidth uint) []uint
- func LimbsMapToString(p LimbsMap) string
- func MapToString(p Map) string
- func NewLimbsMap[F any](field field.Config, module Map) limbsMap
- func SplitConstant(constant big.Int, limbWidths ...uint) []big.Int
- func ToString(rid Id) string
- func WidthOfRegisters(regs []Register, rids []Id) uint
- func WidthsOfLimbs(mapping LimbsMap, lids []LimbId) []uint
- type AccessId
- type Allocator
- type ConstMap
- type DynamicPolynomial
- type Id
- type Limb
- type LimbId
- type LimbsMap
- type Map
- type Polynomial
- type Ref
- type Refs
- type Register
- func New(kind Type, name string, bitwidth uint, padding big.Int) Register
- func NewComputed(name string, bitwidth uint, padding big.Int) Register
- func NewConst(value uint8) Register
- func NewInput(name string, bitwidth uint, padding big.Int) Register
- func NewNative(kind Type, name string, padding big.Int) Register
- func NewOutput(name string, bitwidth uint, padding big.Int) Register
- func SplitIntoLimbs(maxWidth uint, r Register) []Register
- func (p *Register) Bound() *big.Int
- func (p *Register) ConstValue() uint8
- func (p *Register) IsComputed() bool
- func (p *Register) IsInput() bool
- func (p *Register) IsInputOutput() bool
- func (p *Register) IsNative() bool
- func (p *Register) IsOutput() bool
- func (p *Register) IsU1Const() bool
- func (p Register) Kind() Type
- func (p *Register) MarshalBinary() (data []byte, err error)
- func (p *Register) MaxValue() *big.Int
- func (p Register) Name() string
- func (p *Register) Padding() *big.Int
- func (p Register) QualifiedName(mod Map) string
- func (p *Register) SetPadding(padding *big.Int)
- func (p Register) String() string
- func (p *Register) UnmarshalBinary(data []byte) error
- func (p Register) Width() uint
- func (p Register) WidthOrNative() uint
- type Type
- type Vector
- func (p Vector) AsRegister() Id
- func (p Vector) BitWidth(fn Map) uint
- func (p Vector) Clone() Vector
- func (p Vector) Last() Id
- func (p Vector) Len() uint
- func (p *Vector) MarshalBinary() (data []byte, err error)
- func (p Vector) Registers() []Id
- func (p Vector) Split(mapping LimbsMap) Vector
- func (p Vector) String(fn Map) string
- func (p *Vector) UnmarshalBinary(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // INPUT_REGISTER signals a register used for holding the input values of a // function. INPUT_REGISTER = Type{uint8(0)} // OUTPUT_REGISTER signals a register used for holding the output values of // a function. OUTPUT_REGISTER = Type{uint8(1)} // COMPUTED_REGISTER signals a register whose values are computed from one // (or more) assignments during trace expansion. COMPUTED_REGISTER = Type{uint8(2)} // ZERO_REGISTER signals a register whose value is always 0. ZERO_REGISTER = Type{uint8(3)} // ONE_REGISTER signals a register whose value is always 1. ONE_REGISTER = Type{uint8(4)} )
Functions ¶
func LimbWidths ¶
LimbWidths determines the limb widths for any register of the given size.
func LimbsMapToString ¶
LimbsMapToString provides a default method for converting a register limbs map into a simple string representation.
func MapToString ¶
MapToString provides a default method for converting a register map into a simple string representation.
func NewLimbsMap ¶
NewLimbsMap constructs an appropriate register map for a given module and parameter combination.
func SplitConstant ¶
SplitConstant splits a given constant into a number of "limbs". For example, consider splitting the constant 0x7b2d into 8bit limbs. Then, this function returns the array [0x2d,0x7b]. Observe that the least significant limb is always returned first (i.e. at index zero in the resulting array).
func ToString ¶
ToString provides a simplistic default string implementation for a RegisterId. This is useful primarily for debugging where we want to e.g. print a constraint but don't have access to an appropriate mapping, etc.
func WidthOfRegisters ¶
WidthOfRegisters returns the combined bitwidth of the given registers. For example, suppose we have three registers: x:u8, y:u8, z:u11. Then the combined width is 8+8+11=27.
func WidthsOfLimbs ¶
WidthsOfLimbs returns the limb bitwidths corresponding to a given set of identifiers.
Types ¶
type AccessId ¶
type AccessId = trace.ColumnAccessId
AccessId is a wrapper around a column Id which adds a "relative shift" and "bitwidth window". That is, it identifies a column on a relative row from the given row, and allows only a portion of the original variable to be accessed.
type Allocator ¶
type Allocator[T any] interface { Map // Allocate a fresh register of the given width within the target module. // This is presumed to be a computed register, and automatically assigned a // unique name. No assignment is included for the allocated register Allocate(prefix string, width uint) Id // Allocate n registers of the given width within the target module. // This is presumed to be a computed register, and automatically assigned a // unique name. No assignment is included for the allocated register AllocateN(prefix string, widths []uint) []Id // Allocate a fresh register of the given width within the target module // *with* an assignment. This is declared as computed register, and // automatically assigned a unique name. AllocateWith(prefix string, width uint, assignment T) Id // Allocate n registers of the given width within the target module *with* // an assignment. These are all declared as computed registers, and // automatically assigned unique names. AllocateWithN(prefix string, assignment T, widths ...uint) []Id // Assignments returns any metadata assigned to an allocated register. Assignments() []util.Pair[[]Id, T] // Reset back to a given number of registers. This is essentially for // "undoing" allocations in algorithms that perform speculative allocation. Reset(uint) }
Allocator extends a register mapping with the ability to allocate new registers as necessary. This is useful, for example, in the context of register splitting for introducing new carry registers.
func NewAllocator ¶
NewAllocator converts a mapping into a full allocator simply by wrapping the two fields.
type ConstMap ¶
type ConstMap interface {
Map
// ConstRegister returns the ID of a constant register which is either
// always zero or always one (no other constants are supported at this
// time). If such a register does not already exist, then one is created.
// This ensures constant registers are only included when they are actually
// needed.
ConstRegister(constant uint8) Id
}
ConstMap is a register map which additionally provides guaranteed access to a constant (binary) register. That is, a register which is always either "0" or always either "1".
type DynamicPolynomial ¶
type DynamicPolynomial = Polynomial[AccessId]
DynamicPolynomial represents a polynomial over "relative registers". That is, it can refer to registers on the current row or on a row relative to the current row (e.g. the next row, or the previous row, etc).
type Id ¶
Id captures the notion of a register index. That is, for each module, every register is allocated a given index starting from 0. The purpose of the wrapper is to avoid confusion between uint values and things which are expected to identify Columns.
type Limb ¶
type Limb = Register
Limb is just an alias for Register, but it helps to clarify when we are referring to a register after subdivision.
type LimbId ¶
type LimbId = Id
LimbId is just an alias for register.RegisterId, but it helps to clarify when we are referring to a register after subdivision.
func ApplyLimbsMap ¶
ApplyLimbsMap applies a given mapping to a set of registers producing a corresponding set of limbs. In essence, each register is convert to its limbs in turn, and these are all appended together in order of ococurence.
type LimbsMap ¶
type LimbsMap interface {
Map
// Field returns the underlying field configuration used for this mapping.
// This includes the field bandwidth (i.e. number of bits available in
// underlying field) and the maximum register width (i.e. width at which
// registers are capped).
Field() field.Config
// Limbs identifies the limbs into which a given register is divided.
// Observe that limbs are ordered by their position in the original
// register. In particular, the first limb (i.e. at index 0) is always
// least significant limb, and the last always most significant.
LimbIds(Id) []LimbId
// Limbs returns information about a given limb (i.e. a register which
// exists after the split).
Limb(LimbId) Limb
// Limbs returns all limbs in the mapping.
Limbs() []Limb
// LimbsMap returns a register map for the limbs themselves. This is useful
// where we need a register map over the limbs, rather than the original
// registers.
LimbsMap() Map
}
LimbsMap provides a high-level mapping of all registers before and after subdivision occurs within a given module. That is, it maps a given register to those limbs into which it was subdivided.
type Map ¶
type Map interface {
fmt.Stringer
// Name returns the name given to the enclosing entity (i.e. module or
// function), along with its multiplier.
Name() trace.ModuleName
// HasRegister checks whether a register with the given name exists and, if
// so, returns its register identifier. Otherwise, it returns false.
HasRegister(name string) (Id, bool)
// Access a given register in this module.
Register(Id) Register
// Registers providers access to the underlying registers of this map.
Registers() []Register
}
Map provides a generic interface for entities which hold information about registers.
type Polynomial ¶
type Polynomial[T util.Comparable[T]] = *poly.ArrayPoly[T]
Polynomial defines the type of polynomials over which packets (and register splitting in general) operate.
type Ref ¶
Ref abstracts a complete (i.e. global) register identifier.
func AsRefArray ¶
AsRefArray converts a register refs array into an array of register ref.
type Refs ¶
type Refs struct {
// contains filtered or unexported fields
}
Refs is a "registers reference" which abstracts a set of registers in a given module.
type Register ¶
type Register struct {
// contains filtered or unexported fields
}
Register represents a specific register in the schema that, eventually, will be mapped to one (or more) columns in the trace. Observe that multiple registers can end up being mapped to the same column via "register allocation". Likewise, a single register can end up being mapped across multiple columns as a result of subdivision to ensure field agnosticity. Hence, why they are referred to as registers rather than columns --- they are similar, but not identical, concepts.
func New ¶
New constructs a new register of a given kind (i.e. input, output or computed) with the given name and bitwidth.
func NewComputed ¶
NewComputed constructs a new computed register with the given name and bitwidth.
func NewConst ¶
NewConst constructs a new "constant register". That is a register which always holds a constant value. Currently, only constants 0 or 1 are supported.
func NewNative ¶
NewNative constructs a new "native" register. That is, a register backed by a field element rather than a fixed-width unsigned integer. Such registers have no fixed bitwidth and can hold any value representable in the underlying field.
func SplitIntoLimbs ¶
SplitIntoLimbs splits a register into a number of limbs with the given maximum bitwidth. For the resulting array, the least significant register is first. Since registers are always split to the maximum width as much as possible, it is only the most significant register which may (in some cases) have fewer bits than the maximum allowed.
func (*Register) Bound ¶
Bound returns the first value which cannot be represented by the given bitwidth. For example, the bound of an 8bit register is 256.
func (*Register) ConstValue ¶
ConstValue determines the constant value for a given constant register.
func (*Register) IsComputed ¶
IsComputed determines whether or not this is a computed register. Observer that "zero" registers are included in this, since they are neither input nor output registers.
func (*Register) IsInputOutput ¶
IsInputOutput determines whether or not this is an input or output register
func (*Register) IsNative ¶
IsNative determines whether or not this is a "native" register. That is, a register backed by a field element rather than a fixed-width unsigned integer.
func (*Register) IsU1Const ¶ added in v1.2.21
IsU1Const determines whether or not this is a constant "zero" or "one" register
func (*Register) MarshalBinary ¶
MarshalBinary converts a register into binary data
func (*Register) MaxValue ¶
MaxValue returns the largest value expressible in this register (i.e. Bound() - 1). For example, the max value of an 8bit register is 255.
func (Register) QualifiedName ¶
QualifiedName returns the fully qualified name of this register
func (*Register) SetPadding ¶
SetPadding updates the padding value to use for this register.
func (*Register) UnmarshalBinary ¶
UnmarshalBinary unmarshals a register
func (Register) Width ¶
Width determines the bitwidth of this register. This panics if called on a native register, since such registers have no fixed bitwidth. Callers should guard with IsNative() if the register may be native.
func (Register) WidthOrNative ¶ added in v1.2.21
WidthOrNative returns the bitwidth of this register, or math.MaxUint if it is a native register.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type captures the type of a given register, such as whether it represents an input column, and output column or a computed register, etc.
func (Type) Cmp ¶
Cmp implementation for register types, where inputs come first, followed by outputs then computed registers.
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector represents a sequence of one or more registers which are imagined to be concatenated together, with the least significant having the least index in the vector. For example, we might have a vector hi::lo where lo has index 0, and hi has index 1.
func NewVector ¶
NewVector constructs a new vector from a given sequence of registers, where the least significant register has the lowest index.
func (Vector) AsRegister ¶
AsRegister returns this vector as a single register. Observe that this will panic if the vector contains more than one register.
func (*Vector) MarshalBinary ¶
MarshalBinary converts a vector into binary data.
func (Vector) Registers ¶
Registers provides raw access to the underlying register array wrapped in this vector.
func (*Vector) UnmarshalBinary ¶
UnmarshalBinary unmarshals a vector.