Documentation
¶
Index ¶
- Variables
- type BuiltinRunner
- type Memory
- func (memory *Memory) AllocateBuiltinSegment(builtinRunner BuiltinRunner) MemoryAddress
- func (memory *Memory) AllocateEmptySegment() MemoryAddress
- func (memory *Memory) AllocateEmptyTemporarySegment() MemoryAddress
- func (memory *Memory) AllocateSegment(data []*f.Element) (MemoryAddress, error)
- func (memory *Memory) FindSegmentWithBuiltin(builtinName string) (*Segment, bool)
- func (memory *Memory) GetConsecutiveMemoryValues(addr MemoryAddress, size uint64) ([]MemoryValue, error)
- func (memory *Memory) KnownValue(segment uint64, offset uint64) bool
- func (memory *Memory) KnownValueAtAddress(address *MemoryAddress) bool
- func (memory *Memory) Peek(segmentIndex uint64, offset uint64) (MemoryValue, error)
- func (memory *Memory) PeekFromAddress(address *MemoryAddress) (MemoryValue, error)
- func (memory *Memory) Read(segmentIndex uint64, offset uint64) (MemoryValue, error)
- func (memory *Memory) ReadAsAddress(address *MemoryAddress) (MemoryAddress, error)
- func (memory *Memory) ReadAsElement(segmentIndex uint64, offset uint64) (f.Element, error)
- func (memory *Memory) ReadFromAddress(address *MemoryAddress) (MemoryValue, error)
- func (memory *Memory) ReadFromAddressAsAddress(address *MemoryAddress) (MemoryAddress, error)
- func (memory *Memory) ReadFromAddressAsElement(address *MemoryAddress) (f.Element, error)
- func (memory *Memory) RelocationOffsets() ([]uint64, uint64)
- func (memory *Memory) ResolveAsBigInt3(valAddr MemoryAddress) ([3]*f.Element, error)
- func (memory *Memory) ResolveAsBigInt5(valAddr MemoryAddress) ([5]*f.Element, error)
- func (memory *Memory) ResolveAsEcPoint(valAddr MemoryAddress) ([2]*f.Element, error)
- func (memory *Memory) Write(segmentIndex uint64, offset uint64, value *MemoryValue) error
- func (memory *Memory) WriteToAddress(address *MemoryAddress, value *MemoryValue) error
- func (memory *Memory) WriteToNthStructField(addr MemoryAddress, value MemoryValue, field int16) error
- func (memory *Memory) WriteUint256ToAddress(addr MemoryAddress, low, high *f.Element) error
- type MemoryAddress
- func (address *MemoryAddress) Add(lhs *MemoryAddress, rhs *f.Element) error
- func (address *MemoryAddress) AddOffset(offset int16) (MemoryAddress, error)
- func (address *MemoryAddress) Cmp(other *MemoryAddress) int
- func (address *MemoryAddress) Equal(other *MemoryAddress) bool
- func (address *MemoryAddress) Relocate(segmentsOffset []uint64) *f.Element
- func (address MemoryAddress) String() string
- func (address *MemoryAddress) Sub(lhs *MemoryAddress, rhs *f.Element) error
- func (address *MemoryAddress) SubAddress(other *MemoryAddress) (uint64, error)
- type MemoryValue
- func EmptyMemoryValueAs(address bool) MemoryValue
- func EmptyMemoryValueAsAddress() MemoryValue
- func EmptyMemoryValueAsFelt() MemoryValue
- func MemoryValueFromAny(anyType any) (MemoryValue, error)
- func MemoryValueFromFieldElement(felt *f.Element) MemoryValue
- func MemoryValueFromInt[T constraints.Integer](v T) MemoryValue
- func MemoryValueFromMemoryAddress(address *MemoryAddress) MemoryValue
- func MemoryValueFromSegmentAndOffset[T constraints.Integer](segmentIndex, offset T) MemoryValue
- func MemoryValueFromUint[T constraints.Unsigned](v T) MemoryValue
- func (mv *MemoryValue) Add(lhs, rhs *MemoryValue) error
- func (mv *MemoryValue) Any() any
- func (mv *MemoryValue) Div(lhs, rhs *MemoryValue) error
- func (mv *MemoryValue) Equal(other *MemoryValue) bool
- func (mv *MemoryValue) FieldElement() (*f.Element, error)
- func (mv *MemoryValue) IsAddress() bool
- func (mv *MemoryValue) IsFelt() bool
- func (mv *MemoryValue) IsZero() bool
- func (mv *MemoryValue) Known() bool
- func (mv *MemoryValue) MemoryAddress() (*MemoryAddress, error)
- func (mv *MemoryValue) Mul(lhs, rhs *MemoryValue) error
- func (mv MemoryValue) String() string
- func (mv *MemoryValue) Sub(lhs, rhs *MemoryValue) error
- func (mv *MemoryValue) Uint64() (uint64, error)
- type NoBuiltin
- func (b *NoBuiltin) CheckWrite(segment *Segment, offset uint64, value *MemoryValue) error
- func (b *NoBuiltin) GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error)
- func (b *NoBuiltin) GetCellsPerInstance() uint64
- func (b *NoBuiltin) GetStopPointer() uint64
- func (b *NoBuiltin) InferValue(segment *Segment, offset uint64) error
- func (b *NoBuiltin) SetStopPointer(stopPointer uint64)
- func (b *NoBuiltin) String() string
- type PublicMemoryOffset
- type Segment
- func (segment *Segment) Finalize(newSize uint64, publicMemoryOffsets []PublicMemoryOffset)
- func (segment *Segment) IncreaseSegmentSize(newSize uint64)
- func (segment *Segment) Len() uint64
- func (segment *Segment) Peek(offset uint64) MemoryValue
- func (segment *Segment) Read(offset uint64) (MemoryValue, error)
- func (segment *Segment) RealLen() uint64
- func (segment *Segment) String() string
- func (segment *Segment) WithBuiltinRunner(builtinRunner BuiltinRunner) *Segment
- func (segment *Segment) Write(offset uint64, value *MemoryValue) error
Constants ¶
This section is empty.
Variables ¶
var UnknownAddress = MemoryAddress{}
var UnknownValue = MemoryValue{}
Functions ¶
This section is empty.
Types ¶
type BuiltinRunner ¶
type BuiltinRunner interface { fmt.Stringer CheckWrite(segment *Segment, offset uint64, value *MemoryValue) error InferValue(segment *Segment, offset uint64) error GetAllocatedSize(segmentUsedSize uint64, vmCurrentStep uint64) (uint64, error) GetCellsPerInstance() uint64 GetStopPointer() uint64 SetStopPointer(stopPointer uint64) }
type Memory ¶
type Memory struct { Segments []*Segment // TemporarySegments is a map of temporary segments, key is the segment index, value is the segment TemporarySegments []*Segment }
Represents the whole VM memory divided into segments
func InitializeEmptyMemory ¶
func InitializeEmptyMemory() *Memory
todo(rodro): can the amount of segments be known before hand?
func (*Memory) AllocateBuiltinSegment ¶
func (memory *Memory) AllocateBuiltinSegment(builtinRunner BuiltinRunner) MemoryAddress
Allocate a Builtin segment
func (*Memory) AllocateEmptySegment ¶
func (memory *Memory) AllocateEmptySegment() MemoryAddress
Allocates an empty segment and returns its index
func (*Memory) AllocateEmptyTemporarySegment ¶
func (memory *Memory) AllocateEmptyTemporarySegment() MemoryAddress
Allocates an empty temporary segment and returns its index
func (*Memory) AllocateSegment ¶
func (memory *Memory) AllocateSegment(data []*f.Element) (MemoryAddress, error)
Allocates a new segment providing its initial data and returns its index
func (*Memory) FindSegmentWithBuiltin ¶
It finds a segment with a given builtin name, it returns the segment and true if found
func (*Memory) GetConsecutiveMemoryValues ¶
func (memory *Memory) GetConsecutiveMemoryValues(addr MemoryAddress, size uint64) ([]MemoryValue, error)
func (*Memory) KnownValue ¶
Given a segment index and offset returns true if the value at that address is known
func (*Memory) KnownValueAtAddress ¶
func (memory *Memory) KnownValueAtAddress(address *MemoryAddress) bool
Given an address returns true if it contains a known value
func (*Memory) Peek ¶
func (memory *Memory) Peek(segmentIndex uint64, offset uint64) (MemoryValue, error)
Given a segment index and offset, returns the memory value at that position, without modifying it in any way. Errors if peeking from an unallocated segment
func (*Memory) PeekFromAddress ¶
func (memory *Memory) PeekFromAddress(address *MemoryAddress) (MemoryValue, error)
Given an address returns the memory value at that position, without modifying it in any way. Errors if peeking from an unallocated segment
func (*Memory) Read ¶
func (memory *Memory) Read(segmentIndex uint64, offset uint64) (MemoryValue, error)
Reads a memory value given the segment index and offset. Errors if reading from an unallocated segment or if reading an unknown memory value
func (*Memory) ReadAsAddress ¶
func (memory *Memory) ReadAsAddress(address *MemoryAddress) (MemoryAddress, error)
Works the same as `Read` but `MemoryValue` is converted to `MemoryAddress` first
func (*Memory) ReadAsElement ¶
Works the same as `Read` but `MemoryValue` is converted to `Element` first
func (*Memory) ReadFromAddress ¶
func (memory *Memory) ReadFromAddress(address *MemoryAddress) (MemoryValue, error)
Reads a memory value given an address. Errors if reading from an unallocated segment or if reading an unknown memory value
func (*Memory) ReadFromAddressAsAddress ¶
func (memory *Memory) ReadFromAddressAsAddress(address *MemoryAddress) (MemoryAddress, error)
Works the same as `ReadFromAddress` but `MemoryValue` is converted to `MemoryAddress` first
func (*Memory) ReadFromAddressAsElement ¶
func (memory *Memory) ReadFromAddressAsElement(address *MemoryAddress) (f.Element, error)
Works the same as `ReadFromAddress` but `MemoryValue` is converted to `Element` first
func (*Memory) RelocationOffsets ¶
It returns all segment offsets and max memory used
func (*Memory) ResolveAsBigInt3 ¶
func (memory *Memory) ResolveAsBigInt3(valAddr MemoryAddress) ([3]*f.Element, error)
func (*Memory) ResolveAsBigInt5 ¶
func (memory *Memory) ResolveAsBigInt5(valAddr MemoryAddress) ([5]*f.Element, error)
func (*Memory) ResolveAsEcPoint ¶
func (memory *Memory) ResolveAsEcPoint(valAddr MemoryAddress) ([2]*f.Element, error)
func (*Memory) Write ¶
func (memory *Memory) Write(segmentIndex uint64, offset uint64, value *MemoryValue) error
Writes to a given segment index and offset a new memory value. Errors if writing to an unallocated segment or if overwriting a different memory value
func (*Memory) WriteToAddress ¶
func (memory *Memory) WriteToAddress(address *MemoryAddress, value *MemoryValue) error
Writes to a memory address a new memory value. Errors if writing to an unallocated segment or if overwriting a different memory value
func (*Memory) WriteToNthStructField ¶
func (memory *Memory) WriteToNthStructField(addr MemoryAddress, value MemoryValue, field int16) error
func (*Memory) WriteUint256ToAddress ¶
func (memory *Memory) WriteUint256ToAddress(addr MemoryAddress, low, high *f.Element) error
type MemoryAddress ¶
Represents a Memory Address of the Cairo VM. Because memory is split between different segments during execution, addresses has two locators: the segment they belong to and the location inside that segment
func (*MemoryAddress) Add ¶
func (address *MemoryAddress) Add(lhs *MemoryAddress, rhs *f.Element) error
Adds a memory address and a field element
func (*MemoryAddress) AddOffset ¶
func (address *MemoryAddress) AddOffset(offset int16) (MemoryAddress, error)
It crates a new memory address with the modified offset
func (*MemoryAddress) Cmp ¶
func (address *MemoryAddress) Cmp(other *MemoryAddress) int
func (*MemoryAddress) Equal ¶
func (address *MemoryAddress) Equal(other *MemoryAddress) bool
func (*MemoryAddress) Relocate ¶
func (address *MemoryAddress) Relocate(segmentsOffset []uint64) *f.Element
func (MemoryAddress) String ¶
func (address MemoryAddress) String() string
func (*MemoryAddress) Sub ¶
func (address *MemoryAddress) Sub(lhs *MemoryAddress, rhs *f.Element) error
Subtracts a memory address and a field element
func (*MemoryAddress) SubAddress ¶
func (address *MemoryAddress) SubAddress(other *MemoryAddress) (uint64, error)
type MemoryValue ¶
Stores all posible types that can be stored in a Memory cell,
- either a Felt value (an `f.Element`),
- or a pointer to another Memory Cell (a `MemoryAddress`) both values share the same underlying memory, which is a f.Element
func EmptyMemoryValueAs ¶
func EmptyMemoryValueAs(address bool) MemoryValue
func EmptyMemoryValueAsAddress ¶
func EmptyMemoryValueAsAddress() MemoryValue
func EmptyMemoryValueAsFelt ¶
func EmptyMemoryValueAsFelt() MemoryValue
func MemoryValueFromAny ¶
func MemoryValueFromAny(anyType any) (MemoryValue, error)
func MemoryValueFromFieldElement ¶
func MemoryValueFromFieldElement(felt *f.Element) MemoryValue
func MemoryValueFromInt ¶
func MemoryValueFromInt[T constraints.Integer](v T) MemoryValue
func MemoryValueFromMemoryAddress ¶
func MemoryValueFromMemoryAddress(address *MemoryAddress) MemoryValue
func MemoryValueFromSegmentAndOffset ¶
func MemoryValueFromSegmentAndOffset[T constraints.Integer](segmentIndex, offset T) MemoryValue
creates a memory value from an index and an offset. If either is negative the result is undefined
func MemoryValueFromUint ¶
func MemoryValueFromUint[T constraints.Unsigned](v T) MemoryValue
func (*MemoryValue) Add ¶
func (mv *MemoryValue) Add(lhs, rhs *MemoryValue) error
Adds two memory values if the second one is a Felt
func (*MemoryValue) Any ¶
func (mv *MemoryValue) Any() any
func (*MemoryValue) Div ¶
func (mv *MemoryValue) Div(lhs, rhs *MemoryValue) error
func (*MemoryValue) Equal ¶
func (mv *MemoryValue) Equal(other *MemoryValue) bool
func (*MemoryValue) FieldElement ¶
func (mv *MemoryValue) FieldElement() (*f.Element, error)
func (*MemoryValue) IsAddress ¶
func (mv *MemoryValue) IsAddress() bool
func (*MemoryValue) IsFelt ¶
func (mv *MemoryValue) IsFelt() bool
func (*MemoryValue) IsZero ¶
func (mv *MemoryValue) IsZero() bool
func (*MemoryValue) Known ¶
func (mv *MemoryValue) Known() bool
func (*MemoryValue) MemoryAddress ¶
func (mv *MemoryValue) MemoryAddress() (*MemoryAddress, error)
func (*MemoryValue) Mul ¶
func (mv *MemoryValue) Mul(lhs, rhs *MemoryValue) error
func (MemoryValue) String ¶
func (mv MemoryValue) String() string
func (*MemoryValue) Sub ¶
func (mv *MemoryValue) Sub(lhs, rhs *MemoryValue) error
Subs two memory values if they're in the same segment or the rhs is a Felt.
func (*MemoryValue) Uint64 ¶
func (mv *MemoryValue) Uint64() (uint64, error)
Returns a MemoryValue holding a felt as uint if it fits
type NoBuiltin ¶
type NoBuiltin struct{}
func (*NoBuiltin) CheckWrite ¶
func (b *NoBuiltin) CheckWrite(segment *Segment, offset uint64, value *MemoryValue) error
func (*NoBuiltin) GetAllocatedSize ¶
func (*NoBuiltin) GetCellsPerInstance ¶
func (*NoBuiltin) GetStopPointer ¶
func (*NoBuiltin) InferValue ¶
func (*NoBuiltin) SetStopPointer ¶
type PublicMemoryOffset ¶
type Segment ¶
type Segment struct { Data []MemoryValue // the max index where a value was written LastIndex int BuiltinRunner BuiltinRunner PublicMemoryOffsets []PublicMemoryOffset }
func EmptySegment ¶
func EmptySegment() *Segment
func EmptySegmentWithLength ¶
func (*Segment) Finalize ¶
func (segment *Segment) Finalize(newSize uint64, publicMemoryOffsets []PublicMemoryOffset)
func (*Segment) IncreaseSegmentSize ¶
Increase a segment allocated space. Panics if the new size is smaller
func (*Segment) Len ¶
returns the effective size of a segment length i.e the rightmost element index + 1
func (*Segment) Peek ¶
func (segment *Segment) Peek(offset uint64) MemoryValue
func (*Segment) Read ¶
func (segment *Segment) Read(offset uint64) (MemoryValue, error)
Reads a memory value from a specified offset at the segment
func (*Segment) WithBuiltinRunner ¶
func (segment *Segment) WithBuiltinRunner(builtinRunner BuiltinRunner) *Segment