corset

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: 18 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

Index

Constants

View Source
const DISPLAY_BYTES = uint(2)

DISPLAY_BYTES shows values as bytes.

View Source
const DISPLAY_CUSTOM = uint(256)

DISPLAY_CUSTOM selects a custom layout

View Source
const DISPLAY_DEC = uint(1)

DISPLAY_DEC shows values in dec

View Source
const DISPLAY_HEX = uint(0)

DISPLAY_HEX shows values in hex

Variables

View Source
var OPCODE_ENUMERATION map[uint64]string = map[uint64]string{}

OPCODE_ENUMERATION provides a default enumeration for the existing ":opcode" display modifier.

View Source
var STDLIB []byte

STDLIB is an import of the standard library.

Functions

func CompileSourceFile

func CompileSourceFile(config CompilationConfig, srcfile source.File) (asm.MicroHirProgram, SourceMap, []SyntaxError)

CompileSourceFile compiles exactly one source file into a schema. This is really helper function for e.g. the testing environment. This process can fail if the source file is mal-formed, or contains syntax errors or other forms of error (e.g. type errors).

func CompileSourceFiles

func CompileSourceFiles(config CompilationConfig, srcfiles []source.File,
) (asm.MicroHirProgram, SourceMap, []SyntaxError)

CompileSourceFiles compiles one or more source files into a schema. This process can fail if the source files are mal-formed, or contain syntax errors or other forms of error (e.g. type errors).

func ContextOf

func ContextOf(name string) ast.Context

ContextOf attempts to reconstruct an AST context from a given module name. This is helpful if we want to know the "root" module for a given family of related modules (i.e. modules from the same Corset module which have different length multipliers).

Types

type CompilationConfig

type CompilationConfig = compiler.Config

CompilationConfig encapsulates various options which can affect compilation.

type Compiler

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

Compiler packages up everything needed to compile a given set of module definitions down into an HIR schema. Observe that the compiler may fail if the modules definitions are malformed in some way (e.g. fail type checking).

func NewCompiler

func NewCompiler(circuit ast.Circuit, srcmaps *source.Maps[ast.Node]) *Compiler

NewCompiler constructs a new compiler for a given set of modules.

func (*Compiler) Compile

func (p *Compiler) Compile(config compiler.Config) (asm.MicroHirProgram, SourceMap, []SyntaxError)

Compile is the top-level function for the corset compiler which actually compiles the given modules down into a schema. This can fail in a variety of ways if the given modules are malformed in some way. For example, if some expression refers to a non-existent module or column, or is not well-typed, etc.

func (*Compiler) SetAllocator

func (p *Compiler) SetAllocator(allocator func(compiler.RegisterAllocation)) *Compiler

SetAllocator overrides the default register allocator.

func (*Compiler) SetDebug

func (p *Compiler) SetDebug(flag bool) *Compiler

SetDebug enables or disables debug mode. In debug mode, debug constraints will be compiled in.

type Enumeration

type Enumeration map[uint64]string

Enumeration is a mapping from field elements to explicitly given names. For example, mapping opcode bytes to their names.

type SourceColumn

type SourceColumn struct {
	Name string
	// Length Multiplier of source-level column.
	Multiplier uint
	// Underlying bitwidth of the source-level column.
	Bitwidth uint
	// Provability requirement for source-level column.
	MustProve bool
	// Determines whether this is a Computed column.
	Computed bool
	// Display modifier for column. Here 0-256 are reserved, and values >256 are
	// entries in Enumerations map.  More specifically, 0=hex, 1=dec, 2=bytes.
	Display uint
	// Register in the generate schema to which this Corset register is mapped.
	// Observe that this has to be a reference, rather than just an ID.  This is
	// because a column in a given corset module may map into a different module
	// in the underlying schema (i.e. for interleavings).
	Register register.Ref
}

SourceColumn represents a source-level column which is mapped to a given MIR register. Observe that multiplie source-level columns can be mapped to the same register.

type SourceConstant

type SourceConstant struct {
	Name string
	// value of the constant
	Value big.Int
	// Explicit bitwidth for this constant.  This maybe math.MaxUint if no type
	// was given and, instead, the type should be inferred from context.
	Bitwidth uint
	// Indicates whether this is an "externally visible" constant.  That is, one
	// whose value can be changed after the fact.
	Extern bool
}

SourceConstant provides information about constant values which are exposed to the trace generator. Such constants can, in some cases, be modified to reflect different environments (e.g. different chains, gas limits, etc).

type SourceMap

type SourceMap struct {
	// Root module correspond to the top-level HIR modules.  Thus, indicates into
	// this table correspond to HIR module indices, etc.
	Root SourceModule
	// Enumerations are custom types for display.  For example, we might want to
	// display opcodes as ADD, MUl, SUB, etc.
	Enumerations []Enumeration
}

SourceMap is a binary file attribute which provides debugging information about the relationship between registers and source-level columns. This is used, for example, within the inspector.

func (*SourceMap) AttributeName

func (p *SourceMap) AttributeName() string

AttributeName returns the name of the binary file attribute that this will generate. This is used, for example, when listing attributes contained within a binary file.

func (*SourceMap) Flatten

func (p *SourceMap) Flatten(predicate func(*SourceModule) bool) []SourceModule

Flatten modules in this tree matching a given criteria

func (*SourceMap) SubstituteConstants

func (p *SourceMap) SubstituteConstants(mapping map[string]big.Int)

SubstituteConstants updates the recorded value of constants within this source map. This is typically done in conjunction with a substitution through the schema, in order to keep them both in sync.

type SourceModule

type SourceModule struct {
	// Name of this submodule.
	Name string
	// Public indicates whether or not this module is externally visible or not.
	Public bool
	// Synthetic indicates whether or not this module was automatically
	// generated or not.
	Synthetic bool
	// Virtual indicates whether or not this is a "virtual" module.  That is, a
	// module which is artificially embedded in some outer (concrete) module.
	Virtual bool
	// Selector determines when this (sub)module is active.  Specifically, when
	// it evaluates to a non-zero value the module is active.
	Selector util.Option[string]
	// Submodules identifies any (virtual) submodules contained within this.
	// Currently, perspectives are the only form of submodule currently
	// supported.
	Submodules []SourceModule
	// Columns identifies any columns defined in this module.  Observe that
	// columns across modules are mapped to registers in a many-to-one fashion.
	Columns []SourceColumn
	// Constants identifiers any constants defined in this module.
	Constants []SourceConstant
}

SourceModule represents an entity at the source-level which groups together related columns. Modules can be either concrete (in which case they correspond with HIR modules) or virtual (in which case they are encoded within an HIR module).

func (*SourceModule) Flatten

func (p *SourceModule) Flatten(predicate func(*SourceModule) bool) []SourceModule

Flatten modules in this tree either including (or excluding) virtual modules.

func (*SourceModule) Registers

func (p *SourceModule) Registers(nModules uint) []SourceColumn

Registers returns the set of underlying registers declared in this module. This only makes sense for non-virtual modules, and essentially includes all columns declare in this module or any of its virtual children.

func (*SourceModule) Submodule

func (p *SourceModule) Submodule(name string) *SourceModule

Submodule returns the matching submodule with the given name, or nil if no such module exists.

func (*SourceModule) SubstituteConstants

func (p *SourceModule) SubstituteConstants(path file.Path, mapping map[string]big.Int)

SubstituteConstants updates the recorded value of constants within this source map. This is typically done in conjunction with a substitution through the schema, in order to keep them both in sync.

type SyntaxError

type SyntaxError = source.SyntaxError

SyntaxError defines the kind of errors that can be reported by this compiler. Syntax errors are always associated with some line in one of the original source files. For simplicity, we reuse existing notion of syntax error from the S-Expression library.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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