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
Index ¶
- func RequiredPaddingRows[F any](module uint, defensive bool, schema AnySchema[F]) uint
- type AnySchema
- type Assignment
- type Constraint
- type Failure
- type Module
- type ModuleId
- type ModuleView
- type Schema
- type Table
- func (p *Table[F, C]) AddAssignments(assignments ...Assignment[F])
- func (p *Table[F, C]) AddConstraints(constraints ...C)
- func (p *Table[F, C]) AddRegisters(registers ...register.Register)
- func (p *Table[F, C]) AllowPadding() bool
- func (p *Table[F, C]) Assignments() iter.Iterator[Assignment[F]]
- func (p *Table[F, C]) Consistent(fieldWidth uint, schema AnySchema[F]) []error
- func (p *Table[F, C]) ConstRegister(constant uint8) register.Id
- func (p *Table[F, C]) Constraints() iter.Iterator[Constraint[F]]
- func (p *Table[F, M]) GobDecode(data []byte) error
- func (p *Table[F, M]) GobEncode() (data []byte, err error)
- func (p *Table[F, C]) HasRegister(name string) (register.Id, bool)
- func (p *Table[F, C]) Init(name module.Name, padding, public, synthetic, native, static bool, keys uint) *Table[F, C]
- func (p *Table[F, C]) IsNative() bool
- func (p *Table[F, C]) IsPublic() bool
- func (p *Table[F, C]) IsStatic() bool
- func (p *Table[F, C]) IsSynthetic() bool
- func (p *Table[F, C]) Keys() uint
- func (p *Table[F, C]) Name() module.Name
- func (p *Table[F, C]) RawAssignments() []Assignment[F]
- func (p *Table[F, C]) RawConstraints() []C
- func (p *Table[F, C]) Register(id register.Id) register.Register
- func (p *Table[F, C]) Registers() []register.Register
- func (p *Table[F, C]) SetStaticContents(contents [][]F)
- func (p *Table[F, C]) StaticContents() [][]F
- func (p *Table[F, C]) String() string
- func (p *Table[F, C]) Substitute(mapping map[string]F)
- func (p *Table[F, C]) Width() uint
- type UniformSchema
- func (p UniformSchema[F, M]) Assignments() iter.Iterator[Assignment[F]]
- func (p UniformSchema[F, M]) Consistent(fieldWidth uint) []error
- func (p UniformSchema[F, M]) Constraints() iter.Iterator[Constraint[F]]
- func (p *UniformSchema[F, M]) GobDecode(data []byte) error
- func (p UniformSchema[F, M]) GobEncode() (data []byte, err error)
- func (p UniformSchema[F, M]) HasModule(name module.Name) (ModuleId, bool)
- func (p UniformSchema[F, M]) Module(module uint) Module[F]
- func (p UniformSchema[F, M]) Modules() iter.Iterator[Module[F]]
- func (p UniformSchema[F, M]) RawModules() []M
- func (p UniformSchema[F, M]) Register(ref register.Ref) register.Register
- func (p UniformSchema[F, M]) Width() uint
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequiredPaddingRows ¶
RequiredPaddingRows determines the number of additional (spillage / padding) rows that will be added during trace expansion. The exact value depends on whether defensive padding is enabled or not.
Types ¶
type AnySchema ¶
type AnySchema[F any] Schema[F, Constraint[F]]
AnySchema captures a generic view of a schema, which is useful in situations where exactly details about the schema are not important.
type Assignment ¶
type Assignment[F any] interface { // For the given module, determine any well-definedness bounds implied by // this assignment in 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 assignment evaluating this expression on that first row // is also undefined. Bounds(ModuleId) util.Bounds // ComputeColumns computes the values of columns defined by this assignment. // In order for this computation to makes sense, all columns on which this // assignment depends must exist (e.g. are either inputs or have been // computed already). Computed columns do not exist in the original trace, // but are added during trace expansion to form the final trace. Compute(tr.Trace[F], AnySchema[F]) ([]array.MutArray[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. Consistent(AnySchema[F]) []error // Identifier registers which are expanded by this assignment. A register // is expanded when its length maybe changed. For example, when going from // a trace which contains only rows of input/output values to a trace where // each function instance can occupy more than one row. Then the I/O // columns are said to be "expanded". RegistersExpanded() []register.Ref // Returns the set of columns that this assignment depends upon. That can // include both input columns, as well as other computed columns. RegistersRead() []register.Ref // Identifier registers assigned by this assignment. RegistersWritten() []register.Ref // Substitute any matchined labelled constants within this assignment Substitute(map[string]F) // Lisp converts this schema element into a simple S-Expression, for example // so it can be printed. Lisp(AnySchema[F]) sexp.SExp }
Assignment represents an arbitrary computation which determines the values for one (or more) computed registers. For any computed register, there should only ever be one assignment. Likewise, every computed register should have an associated assignment. A good example of an assignment is computed the multiplicative inverse of a column in order to implement a non-zero check.
type Constraint ¶
type Constraint[F any] interface { // Accepts determines whether a given constraint accepts a given trace or // not. If not, a failure is produced. Otherwise, a bitset indicating // branch coverage is returned. Accepts(trace.Trace[F], AnySchema[F]) (bit.Set, Failure) // Determine the well-definedness bounds for this constraint in 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) Bounds(module uint) util.Bounds // Consistent applies a number of internal consistency checks. Whilst not // strictly necessary, these can highlight otherwise hidden problems as an aid // to debugging. Consistent(AnySchema[F]) []error // 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). Contexts() []ModuleId // Name returns a unique name for a given constraint. This is useful purely // for identifying constraints in reports, etc. Name() string // Lisp converts this schema element into a simple S-Expression, for example // so it can be printed. Lisp(AnySchema[F]) sexp.SExp // Substitute any matchined labelled constants within this constraint Substitute(map[string]F) }
Constraint represents an element which can "accept" a trace, or either reject with an error (or eventually perhaps report a warning).
type Failure ¶
type Failure interface {
// Provides a suitable error message
Message() string
}
Failure embodies structured information about a failing constraint. This includes the constraint itself, along with the row
func Accepts ¶
func Accepts[F field.Element[F], C Constraint[F]](parallel bool, batchsize uint, schema Schema[F, C], trace tr.Trace[F]) []Failure
Accepts determines whether this schema will accept a given trace. That is, whether or not the given trace adheres to the schema constraints. A trace can fail to adhere to the schema for a variety of reasons, such as having a constraint which does not hold.
type Module ¶
type Module[F any] interface { ModuleView // AllowPadding determines whether the given module allows an initial // padding row, or not. AllowPadding() bool // Assignments returns an iterator over the assignments of this module. // These are the computations used to assign values to all computed columns // in this module. Assignments() iter.Iterator[Assignment[F]] // Constraints provides access to those constraints associated with this // module. Constraints() iter.Iterator[Constraint[F]] // Consistent applies a number of internal consistency checks. Whilst not // strictly necessary, these can highlight otherwise hidden problems as an aid // to debugging. Consistent(fieldWidth uint, schema AnySchema[F]) []error // Keys returns the number n of key columns in this module. Key columns are // always the first n columns in a module. Such columns have the property // that they can be used in conjunction with Find. Keys() uint // StaticContents returns the contents of this module, assuming it // corresponds with a static reference table. Each entry in the entries // array returned should have Width() elements and correspond to a row in // the static module. NOTE: this will panic when IsStatic() is false (i.e. // since only static modules can have contents). StaticContents() (entries [][]F) // Substitute any matchined labelled constants within this module Substitute(map[string]F) }
Module represents a "table" within a schema which contains zero or more rows for a given set of registers.
type ModuleView ¶
type ModuleView interface {
register.Map
// Module name
Name() module.Name
// IsPublic indicates whether or not this module is externally visible.
IsPublic() bool
// IsSynthetic modules are generated during compilation, rather than being
// provided by the user.
IsSynthetic() bool
// IsNative indicates whether this module corresponds to a function backed
// by a native circuit (i.e. declared with the @native annotation in ZkC).
// Only modules produced by the ZkC pipeline can ever be native; modules
// from any other source always return false.
IsNative() bool
// IsStatic indicates whether this module represents a static reference
// table whose contents are fixed at compile time. Static modules carry
// their data in StaticContents() (queried via the field-parameterised
// schema.Module interface).
IsStatic() bool
// Returns the number of registers in this module.
Width() uint
}
ModuleView provides access to certain structural information about a module.
type Schema ¶
type Schema[F any, C any] interface { // Assignments returns an iterator over the assignments of this schema. // That is, the set of computations used to determine values for all // computed columns. Assignments() iter.Iterator[Assignment[F]] // Consistent applies a number of internal consistency checks. Whilst not // strictly necessary, these can highlight otherwise hidden problems as an aid // to debugging. Consistent(fieldWidth uint) []error // Constraints returns an iterator over all constraints defined in this // schema. Observe that this does include assertions which, strictly // speaking, are not constraints in the true sense. That is, they are never // compiled into vanishing polynomials but, instead, are used purely for // debugging. Constraints() iter.Iterator[C] // HasModule checks whether a module with the given name exists and, if so, // returns its module identifier. Otherwise, it returns false. HasModule(name module.Name) (ModuleId, bool) // Access a given module in this schema. Module(module uint) Module[F] // Modules returns an iterator over the declared set of modules within this // schema. Modules() iter.Iterator[Module[F]] // Access a given register in this schema. Register(register.Ref) register.Register // Returns the number of modules in this schema. Width() uint }
Schema provides a fundamental interface which attempts to capture the essence of an arithmetisation. For simplicity, a schema consists entirely of one or more modules, where each module comprises some number of registers, constraints and assignments. Registers can be loosely thought of as columns in the final trace, whilst constraints are properties which should hold for any acceptable trace. Finally, assignments represent arbitrary computations which "assign" values to registers during "trace expansion".
type Table ¶
type Table[F field.Element[F], C Constraint[F]] struct { // contains filtered or unexported fields }
Table provides a straightforward, reusable module implementation. There is nothing fancy here: we simply have a set of registers, constraints and assignments. A table is a field agnostic module with a simple strategy of subdividing registers "in place". For example, suppose we have registers X and Y (in that order) where both are to be halfed. Then, the result is X'0, X'1, Y'0. Y'1 (in that order). Hence, predicting the new register indices is relatively straightforward.
func (*Table[F, C]) AddAssignments ¶
func (p *Table[F, C]) AddAssignments(assignments ...Assignment[F])
AddAssignments adds a new assignments to this table.
func (*Table[F, C]) AddConstraints ¶
func (p *Table[F, C]) AddConstraints(constraints ...C)
AddConstraints adds new constraints to this table.
func (*Table[F, C]) AddRegisters ¶
AddRegisters adds new registers to this table.
func (*Table[F, C]) AllowPadding ¶
AllowPadding determines whether the given module supports padding at the beginning of the module. This is necessary because legacy modules expect an initial padding row, and allow defensive padding as well.
func (*Table[F, C]) Assignments ¶
func (p *Table[F, C]) Assignments() iter.Iterator[Assignment[F]]
Assignments provides access to those assignments defined as part of this table.
func (*Table[F, C]) Consistent ¶
Consistent applies a number of internal consistency checks. Whilst not strictly necessary, these can highlight otherwise hidden problems as an aid to debugging.
func (*Table[F, C]) ConstRegister ¶
ConstRegister implementation for register.ConstMap interface
func (*Table[F, C]) Constraints ¶
func (p *Table[F, C]) Constraints() iter.Iterator[Constraint[F]]
Constraints provides access to those constraints associated with this module.
func (*Table[F, M]) GobEncode ¶
GobEncode an option. This allows it to be marshalled into a binary form.
func (*Table[F, C]) HasRegister ¶
HasRegister checks whether a register with the given name exists and, if so, returns its register identifier. Otherwise, it returns false.
func (*Table[F, C]) Init ¶
func (p *Table[F, C]) Init(name module.Name, padding, public, synthetic, native, static bool, keys uint) *Table[F, C]
Init implementation for ir.InitModule interface. The native flag indicates that this module corresponds to a function backed by a native circuit; only the ZkC pipeline should ever pass true. The static flag indicates that this module is a static reference table whose contents are fixed at compile time and are populated separately via SetStaticContents.
func (*Table[F, C]) IsNative ¶
IsNative reports whether this module corresponds to a function backed by a native circuit (i.e. declared with the @native annotation in ZkC).
func (*Table[F, C]) IsPublic ¶
IsPublic identifies whether or not this module is externally visible.
func (*Table[F, C]) IsStatic ¶
IsStatic reports whether this module is a static reference table whose contents are fixed at compile time.
func (*Table[F, C]) IsSynthetic ¶
IsSynthetic modules are generated during compilation, rather than being provided by the user.
func (*Table[F, C]) RawAssignments ¶
func (p *Table[F, C]) RawAssignments() []Assignment[F]
RawAssignments provides raw access to those assignments defined as part of this table.
func (*Table[F, C]) RawConstraints ¶
func (p *Table[F, C]) RawConstraints() []C
RawConstraints provides raw access to those constraints associated with this module.
func (*Table[F, C]) Registers ¶
Registers returns an iterator over the underlying registers of this schema. Specifically, the index of a register in this array is its register index.
func (*Table[F, C]) SetStaticContents ¶
func (p *Table[F, C]) SetStaticContents(contents [][]F)
SetStaticContents sets the contents of this static reference table. It panics if invoked on a non-static module.
func (*Table[F, C]) StaticContents ¶
func (p *Table[F, C]) StaticContents() [][]F
StaticContents returns the contents of this static reference table. It panics if invoked on a non-static module, since no contents are stored in that case.
func (*Table[F, C]) Substitute ¶
Substitute any matchined labelled constants within this module
type UniformSchema ¶
UniformSchema represents the simplest kind of schema which contains only modules of the same kind (e.g. all MIR modules).
func NewUniformSchema ¶
func NewUniformSchema[F any, M Module[F]](modules []M) UniformSchema[F, M]
NewUniformSchema constructs a new schema comprising the given modules.
func (UniformSchema[F, M]) Assignments ¶
func (p UniformSchema[F, M]) Assignments() iter.Iterator[Assignment[F]]
Assignments returns an iterator over the assignments of this schema These are the computations used to assign values to all computed columns in this schema.
func (UniformSchema[F, M]) Consistent ¶
func (p UniformSchema[F, M]) Consistent(fieldWidth uint) []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 (UniformSchema[F, M]) Constraints ¶
func (p UniformSchema[F, M]) Constraints() iter.Iterator[Constraint[F]]
Constraints returns an iterator over all constraints defined in this schema.
func (*UniformSchema[F, M]) GobDecode ¶
func (p *UniformSchema[F, M]) GobDecode(data []byte) error
GobDecode a previously encoded option
func (UniformSchema[F, M]) GobEncode ¶
func (p UniformSchema[F, M]) GobEncode() (data []byte, err error)
GobEncode an option. This allows it to be marshalled into a binary form.
func (UniformSchema[F, M]) HasModule ¶
func (p UniformSchema[F, M]) HasModule(name module.Name) (ModuleId, bool)
HasModule checks whether a module with the given name exists and, if so, returns its module identifier. Otherwise, it returns false.
func (UniformSchema[F, M]) Module ¶
func (p UniformSchema[F, M]) Module(module uint) Module[F]
Module provides access to a given module in this schema.
func (UniformSchema[F, M]) Modules ¶
func (p UniformSchema[F, M]) Modules() iter.Iterator[Module[F]]
Modules returns an iterator over the declared set of modules within this schema.
func (UniformSchema[F, M]) RawModules ¶
func (p UniformSchema[F, M]) RawModules() []M
RawModules provides access to the underlying modules of this schema.
func (UniformSchema[F, M]) Register ¶
func (p UniformSchema[F, M]) Register(ref register.Ref) register.Register
Register returns the given register in this schema.
func (UniformSchema[F, M]) Width ¶
func (p UniformSchema[F, M]) Width() uint
Width returns the number of modules in this schema.