builtins

package
v0.0.0-...-167dadd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Base16 = 16
	Base10 = 10
)
View Source
const (
	RangeCheckName   = "range_check"
	RangeCheck96Name = "range_check96"

	// Each range check instance consists of RangeCheckNParts 16-bit parts. INNER_RC_BOUND_SHIFT and INNER_RC_BOUND_MASK are used to extract 16-bit parts from the field elements stored in the range check segment.
	INNER_RC_BOUND_SHIFT = 16
	INNER_RC_BOUND_MASK  = (1 << 16) - 1
)
View Source
const (
	BitwiseName = "bitwise"
)
View Source
const CELLS_PER_MOD = 7

number of memory cells per modulo builtin 4(felts) + 1(values_ptr) + 1(offsets_ptr) + 1(n) = 7

View Source
const (
	ECDSAName = "ecdsa"
)
View Source
const (
	EcOpName = "ec_op"
)
View Source
const (
	KeccakName = "keccak"
)
View Source
const MAX_N = 100000

The maximum n value that the function fill_memory accepts

View Source
const ModuloName = "Mod"
View Source
const N_OFFSET = 6
View Source
const N_WORDS = 4

This is the number of felts in a UInt384 struct

View Source
const OFFSETS_PTR_OFFSET = 5
View Source
const OutputName = "output"
View Source
const (
	PedersenName = "pedersen"
)
View Source
const PoseidonName = "poseidon"
View Source
const (
	SegmentArenaName string = "segment_arena"
)
View Source
const VALUES_PTR_OFFSET = 4

These are the offsets in the array, which is used here as ModBuiltinInputs : INPUT_NAMES = [

"p0",
"p1",
"p2",
"p3",
"values_ptr",
"offsets_ptr",
"n",

]

Variables

This section is empty.

Functions

func FillMemory

func FillMemory(mem *memory.Memory, addModInputAddress memory.MemoryAddress, nAddMods uint64, mulModInputAddress memory.MemoryAddress, nMulMods uint64) error

Fills the memory with inputs to the builtin instances based on the inputs to the first instance, pads the offsets table to fit the number of operations written in the input to the first instance, and calculates missing values in the values table.

The number of operations written to the input of the first instance n should be at least n and a multiple of batch_size. Previous offsets are copied to the end of the offsets table to make its length 3n'.

func GetBuiltinAllocatedInstances

func GetBuiltinAllocatedInstances(ratio uint64, cellsPerInstance uint64, segmentUsedSize uint64, instancesPerComponent uint64, vmCurrentStep uint64) (uint64, error)

GetBuiltinAllocatedInstances calculates the number of instances of given builtin for current step and builtin ratio. Ratio parameter defines the ratio between the number of steps to the number of builtin instances. It means that this builtin is expected to be used once every 'ratio' steps of the execution. cellsPerInstance defines the number of cells that one instance of the builtin occupies. segmentUsedSize defines the real number of cells used in the segment. instancesPerComponent defines the number of instances per component (segment or a part of the Cairo program that makes use of builtins).

func KeccakF1600

func KeccakF1600(a *[25]uint64)

keccakF1600 applies the Keccak permutation to a 1600b-wide state represented as a slice of 25 uint64s.

func PoseidonPerm

func PoseidonPerm(x, y, z *fp.Element) []fp.Element

func Runner

func Runner(name BuiltinType) memory.BuiltinRunner

Types

type AirPrivateBuiltinBitwise

type AirPrivateBuiltinBitwise struct {
	Index int    `json:"index"`
	X     string `json:"x"`
	Y     string `json:"y"`
}

type AirPrivateBuiltinECDSA

type AirPrivateBuiltinECDSA struct {
	Index          int                                  `json:"index"`
	PubKey         string                               `json:"pubkey"`
	Msg            string                               `json:"msg"`
	SignatureInput AirPrivateBuiltinECDSASignatureInput `json:"signature_input"`
}

type AirPrivateBuiltinECDSASignatureInput

type AirPrivateBuiltinECDSASignatureInput struct {
	R string `json:"r"`
	W string `json:"w"`
}

type AirPrivateBuiltinEcOp

type AirPrivateBuiltinEcOp struct {
	Index int    `json:"index"`
	PX    string `json:"p_x"`
	PY    string `json:"p_y"`
	M     string `json:"m"`
	QX    string `json:"q_x"`
	QY    string `json:"q_y"`
}

type AirPrivateBuiltinKeccak

type AirPrivateBuiltinKeccak struct {
	Index   int    `json:"index"`
	InputS0 string `json:"input_s0"`
	InputS1 string `json:"input_s1"`
	InputS2 string `json:"input_s2"`
	InputS3 string `json:"input_s3"`
	InputS4 string `json:"input_s4"`
	InputS5 string `json:"input_s5"`
	InputS6 string `json:"input_s6"`
	InputS7 string `json:"input_s7"`
}

type AirPrivateBuiltinPedersen

type AirPrivateBuiltinPedersen struct {
	Index int    `json:"index"`
	X     string `json:"x"`
	Y     string `json:"y"`
}

type AirPrivateBuiltinPoseidon

type AirPrivateBuiltinPoseidon struct {
	Index   int    `json:"index"`
	InputS0 string `json:"input_s0"`
	InputS1 string `json:"input_s1"`
	InputS2 string `json:"input_s2"`
}

type AirPrivateBuiltinRangeCheck

type AirPrivateBuiltinRangeCheck struct {
	Index int    `json:"index"`
	Value string `json:"value"`
}

type Bitwise

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

func (*Bitwise) CheckWrite

func (b *Bitwise) CheckWrite(
	segment *memory.Segment, offset uint64, value *memory.MemoryValue,
) error

func (*Bitwise) GetAirPrivateInput

func (b *Bitwise) GetAirPrivateInput(bitwiseSegment *memory.Segment) []AirPrivateBuiltinBitwise

func (*Bitwise) GetAllocatedSize

func (b *Bitwise) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*Bitwise) InferValue

func (b *Bitwise) InferValue(segment *memory.Segment, offset uint64) error

func (*Bitwise) String

func (b *Bitwise) String() string

type BuiltinType

type BuiltinType uint8
const (
	OutputType BuiltinType = iota + 1
	RangeCheckType
	PedersenType
	ECDSAType
	KeccakType
	BitwiseType
	ECOPType
	PoseidonType
	SegmentArenaType
	RangeCheck96Type
	AddModeType
	MulModType
)

func (BuiltinType) MarshalJSON

func (b BuiltinType) MarshalJSON() ([]byte, error)

func (*BuiltinType) UnmarshalJSON

func (b *BuiltinType) UnmarshalJSON(data []byte) error

type ECDSA

type ECDSA struct {
	Signatures map[uint64]ecdsa.Signature
	// contains filtered or unexported fields
}

func (*ECDSA) AddSignature

func (e *ECDSA) AddSignature(pubOffset uint64, r, s *fp.Element) error

Hint that will call this function looks like this:

"hints": {
    "6": [
        {
            "accessible_scopes": [
                "starkware.cairo.common.signature",
                "starkware.cairo.common.signature.verify_ecdsa_signature"
            ],
            "code": "ecdsa_builtin.add_signature(ids.ecdsa_ptr.address_, (ids.signature_r, ids.signature_s))",
            "flow_tracking_data": {
                "ap_tracking": {
                    "group": 2,
                    "offset": 0
                },
                "reference_ids": {
                    "starkware.cairo.common.signature.verify_ecdsa_signature.ecdsa_ptr": 4,
                    "starkware.cairo.common.signature.verify_ecdsa_signature.message": 0,
                    "starkware.cairo.common.signature.verify_ecdsa_signature.public_key": 1,
                    "starkware.cairo.common.signature.verify_ecdsa_signature.signature_r": 2,
                    "starkware.cairo.common.signature.verify_ecdsa_signature.signature_s": 3
                }
            }
        }
    ]
},

func (*ECDSA) CheckWrite

func (e *ECDSA) CheckWrite(segment *memory.Segment, offset uint64, value *memory.MemoryValue) error

verify_ecdsa_signature(message_hash, public_key, sig_r, sig_s)

func (*ECDSA) GetAirPrivateInput

func (e *ECDSA) GetAirPrivateInput(ecdsaSegment *memory.Segment) ([]AirPrivateBuiltinECDSA, error)

func (*ECDSA) GetAllocatedSize

func (e *ECDSA) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*ECDSA) InferValue

func (e *ECDSA) InferValue(segment *memory.Segment, offset uint64) error

func (*ECDSA) String

func (e *ECDSA) String() string

type EcOp

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

func (*EcOp) CheckWrite

func (e *EcOp) CheckWrite(segment *mem.Segment, offset uint64, value *mem.MemoryValue) error

func (*EcOp) GetAirPrivateInput

func (e *EcOp) GetAirPrivateInput(ecOpSegment *mem.Segment) []AirPrivateBuiltinEcOp

func (*EcOp) GetAllocatedSize

func (e *EcOp) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*EcOp) InferValue

func (e *EcOp) InferValue(segment *mem.Segment, offset uint64) error

func (*EcOp) String

func (e *EcOp) String() string

type Keccak

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

func (*Keccak) CheckWrite

func (k *Keccak) CheckWrite(segment *memory.Segment, offset uint64, value *memory.MemoryValue) error

func (*Keccak) GetAirPrivateInput

func (k *Keccak) GetAirPrivateInput(keccakSegment *memory.Segment) []AirPrivateBuiltinKeccak

func (*Keccak) GetAllocatedSize

func (k *Keccak) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*Keccak) InferValue

func (k *Keccak) InferValue(segment *memory.Segment, offset uint64) error

func (*Keccak) String

func (k *Keccak) String() string

type Layout

type Layout struct {
	// Name of the layout
	Name string
	// Number of range check units allowed per step
	RcUnits uint64
	// List of builtins to be included in given layout
	Builtins []LayoutBuiltin
}

func GetLayout

func GetLayout(layout string) (Layout, error)

type LayoutBuiltin

type LayoutBuiltin struct {
	// Runner for the builtin
	Runner memory.BuiltinRunner
	// Builtin id from starknet parser
	Builtin BuiltinType
}

type ModBuiltin

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

func NewModBuiltin

func NewModBuiltin(ratio uint64, wordBitLen uint64, batchSize uint64, modBuiltinType ModBuiltinType) *ModBuiltin

func (*ModBuiltin) CheckWrite

func (m *ModBuiltin) CheckWrite(segment *memory.Segment, offset uint64, value *memory.MemoryValue) error

func (*ModBuiltin) GetAllocatedSize

func (m *ModBuiltin) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*ModBuiltin) InferValue

func (m *ModBuiltin) InferValue(segment *memory.Segment, offset uint64) error

func (*ModBuiltin) String

func (m *ModBuiltin) String() string

type ModBuiltinInputs

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

type ModBuiltinType

type ModBuiltinType string
const (
	Add ModBuiltinType = "Add"
	Mul ModBuiltinType = "Mul"
)

type Output

type Output struct{}

func (*Output) CheckWrite

func (o *Output) CheckWrite(segment *memory.Segment, offset uint64, value *memory.MemoryValue) error

func (*Output) GetAllocatedSize

func (o *Output) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*Output) InferValue

func (o *Output) InferValue(segment *memory.Segment, offset uint64) error

func (*Output) String

func (o *Output) String() string

type Pedersen

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

func (*Pedersen) CheckWrite

func (p *Pedersen) CheckWrite(segment *mem.Segment, offset uint64, value *mem.MemoryValue) error

func (*Pedersen) GetAirPrivateInput

func (p *Pedersen) GetAirPrivateInput(pedersenSegment *mem.Segment) []AirPrivateBuiltinPedersen

func (*Pedersen) GetAllocatedSize

func (p *Pedersen) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*Pedersen) InferValue

func (p *Pedersen) InferValue(segment *mem.Segment, offset uint64) error

func (*Pedersen) String

func (p *Pedersen) String() string

type Poseidon

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

func (*Poseidon) CheckWrite

func (p *Poseidon) CheckWrite(segment *mem.Segment, offset uint64, value *mem.MemoryValue) error

func (*Poseidon) GetAirPrivateInput

func (p *Poseidon) GetAirPrivateInput(poseidonSegment *mem.Segment) []AirPrivateBuiltinPoseidon

func (*Poseidon) GetAllocatedSize

func (p *Poseidon) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*Poseidon) InferValue

func (p *Poseidon) InferValue(segment *mem.Segment, offset uint64) error

func (*Poseidon) String

func (p *Poseidon) String() string

type RangeCheck

type RangeCheck struct {
	RangeCheckNParts uint64
	// contains filtered or unexported fields
}

func (*RangeCheck) CheckWrite

func (r *RangeCheck) CheckWrite(segment *memory.Segment, offset uint64, value *memory.MemoryValue) error

func (*RangeCheck) GetAirPrivateInput

func (r *RangeCheck) GetAirPrivateInput(rangeCheckSegment *memory.Segment) []AirPrivateBuiltinRangeCheck

func (*RangeCheck) GetAllocatedSize

func (r *RangeCheck) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)

func (*RangeCheck) GetRangeCheckUsage

func (r *RangeCheck) GetRangeCheckUsage(rangeCheckSegment *memory.Segment) (uint16, uint16)

GetRangeCheckUsage returns the min and max values used in the range check segment. Since each range check instance consists of 16-bit parts, the min and max values are calculated by iterating over the segment data and extracting the 16-bit parts from each field element.

func (*RangeCheck) InferValue

func (r *RangeCheck) InferValue(segment *memory.Segment, offset uint64) error

func (*RangeCheck) String

func (r *RangeCheck) String() string

Jump to

Keyboard shortcuts

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