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
Index ¶
Constants ¶
const BINFILE_MAJOR_VERSION uint16 = 11
BINFILE_MAJOR_VERSION is the major version of the binary file format. Regardless of version, the file always begins with the ZKBINARY identifier followed by a hand-rolled binary Header. The encoding of everything after the header is determined by the major version.
const BINFILE_MINOR_VERSION uint16 = 0
BINFILE_MINOR_VERSION is the minor version of the binary file format. Files with a lower minor version remain readable by this implementation, but files produced by this implementation may not be readable by older versions.
Variables ¶
var ZKBINARY [8]byte = [8]byte{'z', 'k', 'b', 'i', 'n', 'a', 'r', 'y'}
ZKBINARY is used as the file identifier for binary file types. This just helps us identify actual binary files from corrupted files.
Functions ¶
func GetAttribute ¶
func GetAttribute[T Attribute](binf *BinaryFile) (T, bool)
GetAttribute returns the first instance of a given attribute, or nil if none exists.
func IsBinaryFile ¶
IsBinaryFile checks whether the given data file begins with the expected "zkbinary" identifier.
Types ¶
type Attribute ¶
type Attribute interface {
// AttributeName returns the name of this attribute.
AttributeName() string
}
Attribute is an extension point for storing arbitrary metadata alongside the compiled schema. Typical uses include source-to-column mappings and debug/profiling annotations. Attribute values must be gob-encodable.
type BinaryFile ¶
type BinaryFile struct {
// Header holds the magic identifier, version numbers, and optional JSON
// metadata for the file.
Header Header
// Attributes carry supplementary information that is not required for
// constraint checking but may be useful for tooling (e.g. source-column
// mappings for debug output).
Attributes []Attribute
// Schema is the compiled constraint program, combining micro-level assembly
// instructions with a HIR constraint schema.
Schema asm.MicroHirProgram
}
BinaryFile is the in-memory representation of a compiled constraint binary. It is produced by the go-corset compiler and consumed by the checker/prover. The on-disk layout is: a custom binary Header, followed by a gob-encoded attribute list, followed by a gob-encoded MicroHirProgram schema.
func NewBinaryFile ¶
func NewBinaryFile(metadata []byte, attributes []Attribute, schema asm.MicroHirProgram, ) *BinaryFile
NewBinaryFile constructs a BinaryFile with a header stamped at the current major/minor version. metadata is an optional JSON blob stored verbatim in the header (pass nil for none).
func (*BinaryFile) MarshalBinary ¶
func (p *BinaryFile) MarshalBinary() ([]byte, error)
MarshalBinary converts the BinaryFile into a sequence of bytes.
func (*BinaryFile) UnmarshalBinary ¶
func (p *BinaryFile) UnmarshalBinary(data []byte) error
UnmarshalBinary initialises this BinaryFile from a given set of data bytes. This should match exactly the encoding above.
type Header ¶
type Header struct {
// Identifier is the 8-byte magic constant "zkbinary" that marks the file type.
Identifier [8]byte
// MajorVersion must match BINFILE_MAJOR_VERSION exactly for the file to be
// considered compatible.
MajorVersion uint16
// MinorVersion must be ≤ BINFILE_MINOR_VERSION for the file to be
// considered compatible (older minor versions remain readable).
MinorVersion uint16
// MetaData is an optional JSON blob carrying key/value pairs (e.g. the
// source file path, compiler version, or build timestamp).
MetaData []byte
}
Header is the fixed-layout prefix of every binary file. It is serialised using a hand-rolled big-endian encoding (not gob) so that the magic identifier and version numbers can be read without a full decode.
func (*Header) GetMetaData ¶
GetMetaData attempts to parse the metadata bytes as JSON which is then unmarshalled into a map. This can fail if the embedded metadata bytes are not, in fact, JSON. Observe that, if there are no metadata bytes, then nil will be returned.
func (*Header) IsCompatible ¶
IsCompatible reports whether this header can be decoded by the current version of go-corset. Compatibility requires the "zkbinary" magic identifier, an exact match on the major version, and a minor version no greater than the current minor version.
func (*Header) MarshalBinary ¶
MarshalBinary converts the BinaryFile Header into a sequence of bytes. Observe that we don't use GobEncoding here to avoid being tied to that encoding scheme.
func (*Header) SetMetaData ¶
SetMetaData attempts to set the metadata bytes for this header, using a JSON encoding of the given map. If this fails, an error is returned and the metadata bytes are unaffected.