core

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContractNotDeployed     = errors.New("contract not deployed")
	ErrContractAlreadyDeployed = errors.New("contract already deployed")
)
View Source
var ErrCheckHeadState = errors.New("check head state")

Functions

func BlockHash added in v0.10.0

func BlockHash(b *Block) (*felt.Felt, error)

BlockHash assumes block.SequencerAddress is not nil as this is called with post v0.12.0 and by then issues with unverifiable block hash were resolved. In future, this may no longer be required.

func ContractAddress

func ContractAddress(callerAddress, classHash, salt *felt.Felt, constructorCallData []*felt.Felt) *felt.Felt

ContractAddress computes the address of a Starknet contract.

func ContractClassHash added in v0.7.5

func ContractClassHash(addr *felt.Felt, txn db.Transaction) (*felt.Felt, error)

ContractClassHash returns hash of the class that the contract at the given address instantiates.

func ContractNonce added in v0.7.5

func ContractNonce(addr *felt.Felt, txn db.Transaction) (*felt.Felt, error)

ContractNonce returns the amount transactions sent from this contract. Only account contracts can have a non-zero nonce.

func ContractRoot added in v0.7.5

func ContractRoot(addr *felt.Felt, txn db.Transaction) (*felt.Felt, error)

ContractRoot returns the root of the contract storage.

func ContractStorage added in v0.7.5

func ContractStorage(addr, key *felt.Felt, txn db.Transaction) (*felt.Felt, error)

func EventsBloom added in v0.3.1

func EventsBloom(receipts []*TransactionReceipt) *bloom.BloomFilter

func MarshalBlockNumber added in v0.4.0

func MarshalBlockNumber(blockNumber uint64) []byte

func ParseBlockVersion added in v0.3.1

func ParseBlockVersion(protocolVersion string) (*semver.Version, error)

ParseBlockVersion computes the block version, defaulting to "0.0.0" for empty strings

func SegmentedBytecodeHash added in v0.11.0

func SegmentedBytecodeHash(bytecode []*felt.Felt, segmentLengths []SegmentLengths) *felt.Felt

func TransactionHash added in v0.4.0

func TransactionHash(transaction Transaction, n *utils.Network) (*felt.Felt, error)

func VerifyClassHashes added in v0.2.1

func VerifyClassHashes(classes map[felt.Felt]Class) error

func VerifyTransactions added in v0.2.1

func VerifyTransactions(txs []Transaction, n *utils.Network, protocolVersion string) error

Types

type Block

type Block struct {
	*Header
	Transactions []Transaction
	Receipts     []*TransactionReceipt
}

type BlockCommitments added in v0.6.0

type BlockCommitments struct {
	TransactionCommitment *felt.Felt
	EventCommitment       *felt.Felt
}

func VerifyBlockHash

func VerifyBlockHash(b *Block, network *utils.Network) (*BlockCommitments, error)

VerifyBlockHash verifies the block hash. Due to bugs in Starknet alpha, not all blocks have verifiable hashes.

type BuiltinInstanceCounter

type BuiltinInstanceCounter struct {
	Pedersen     uint64
	RangeCheck   uint64
	Bitwise      uint64
	Output       uint64
	Ecsda        uint64
	EcOp         uint64
	Keccak       uint64
	Poseidon     uint64
	SegmentArena uint64
}

type Cairo0Class added in v0.2.1

type Cairo0Class struct {
	Abi json.RawMessage
	// External functions defined in the class.
	Externals []EntryPoint
	// Functions that receive L1 messages. See
	// https://www.cairo-lang.org/docs/hello_starknet/l1l2.html#receiving-a-message-from-l1
	L1Handlers []EntryPoint
	// Constructors for the class. Currently, only one is allowed.
	Constructors []EntryPoint
	// Base64 encoding of compressed Program
	Program string
}

Cairo0Class unambiguously defines a [Contract]'s semantics.

func (*Cairo0Class) Hash added in v0.2.1

func (c *Cairo0Class) Hash() (*felt.Felt, error)

func (*Cairo0Class) Version added in v0.2.1

func (c *Cairo0Class) Version() uint64

type Cairo1Class added in v0.2.1

type Cairo1Class struct {
	Abi         string
	AbiHash     *felt.Felt
	EntryPoints struct {
		Constructor []SierraEntryPoint
		External    []SierraEntryPoint
		L1Handler   []SierraEntryPoint
	}
	Program         []*felt.Felt
	ProgramHash     *felt.Felt
	SemanticVersion string
	Compiled        *CompiledClass
}

Cairo1Class unambiguously defines a [Contract]'s semantics.

func (*Cairo1Class) Hash added in v0.2.1

func (c *Cairo1Class) Hash() (*felt.Felt, error)

func (*Cairo1Class) Version added in v0.2.1

func (c *Cairo1Class) Version() uint64

type Class

type Class interface {
	Version() uint64
	Hash() (*felt.Felt, error)
}

Class unambiguously defines a [Contract]'s semantics.

type CompiledClass added in v0.9.3

type CompiledClass struct {
	Bytecode               []*felt.Felt
	PythonicHints          json.RawMessage
	CompilerVersion        string
	Hints                  json.RawMessage
	Prime                  *big.Int
	External               []CompiledEntryPoint
	L1Handler              []CompiledEntryPoint
	Constructor            []CompiledEntryPoint
	BytecodeSegmentLengths SegmentLengths
}

func (*CompiledClass) Hash added in v0.9.3

func (c *CompiledClass) Hash() *felt.Felt

type CompiledEntryPoint added in v0.9.3

type CompiledEntryPoint struct {
	Offset   uint64
	Builtins []string
	Selector *felt.Felt
}

type ContractUpdater added in v0.7.5

type ContractUpdater struct {
	// Address that this contract instance is deployed to
	Address *felt.Felt
	// contains filtered or unexported fields
}

ContractUpdater is a helper to update an existing contract instance.

func DeployContract added in v0.2.1

func DeployContract(addr, classHash *felt.Felt, txn db.Transaction) (*ContractUpdater, error)

DeployContract sets up the database for a new contract.

func NewContractUpdater added in v0.7.5

func NewContractUpdater(addr *felt.Felt, txn db.Transaction) (*ContractUpdater, error)

NewContractUpdater creates an updater for the contract instance at the given address. Deploy should be called for contracts that were just deployed to the network.

func (*ContractUpdater) Purge added in v0.7.5

func (c *ContractUpdater) Purge() error

Purge eliminates the contract instance, deleting all associated data from storage assumes storage is cleared in revert process

func (*ContractUpdater) Replace added in v0.7.5

func (c *ContractUpdater) Replace(classHash *felt.Felt) error

Replace replaces the class that the contract instantiates

func (*ContractUpdater) UpdateNonce added in v0.7.5

func (c *ContractUpdater) UpdateNonce(nonce *felt.Felt) error

UpdateNonce updates the nonce value in the database.

func (*ContractUpdater) UpdateStorage added in v0.7.5

func (c *ContractUpdater) UpdateStorage(diff map[felt.Felt]*felt.Felt, cb OnValueChanged) error

UpdateStorage applies a change-set to the contract storage.

type DataAvailability added in v0.11.0

type DataAvailability struct {
	L1Gas     uint64
	L1DataGas uint64
}

type DataAvailabilityMode added in v0.8.0

type DataAvailabilityMode uint32
const (
	DAModeL1 DataAvailabilityMode = iota
	DAModeL2
)

type DeclareTransaction

type DeclareTransaction struct {
	TransactionHash *felt.Felt
	// The class hash
	ClassHash *felt.Felt
	// The address of the account initiating the transaction.
	SenderAddress *felt.Felt
	// The maximum fee that the sender is willing to pay for the transaction.
	MaxFee *felt.Felt
	// Additional information given by the sender, used to validate the transaction.
	TransactionSignature []*felt.Felt
	// The transaction nonce.
	Nonce *felt.Felt
	// The transaction’s version. Possible values are 0, 1, 2, or 3.
	// When the fields that comprise a transaction change,
	// either with the addition of a new field or the removal of an existing field,
	// then the transaction version increases.
	// Transaction version 0 is deprecated and will be removed in a future version of Starknet.
	Version *TransactionVersion

	// Version 2 fields
	CompiledClassHash *felt.Felt

	// Version 3 fields
	// See InvokeTransaction for descriptions of the fields.
	ResourceBounds        map[Resource]ResourceBounds
	Tip                   uint64
	PaymasterData         []*felt.Felt
	AccountDeploymentData []*felt.Felt
	NonceDAMode           DataAvailabilityMode
	FeeDAMode             DataAvailabilityMode
}

func (*DeclareTransaction) Hash

func (d *DeclareTransaction) Hash() *felt.Felt

func (*DeclareTransaction) Signature

func (d *DeclareTransaction) Signature() []*felt.Felt

func (*DeclareTransaction) TxVersion added in v0.8.0

func (d *DeclareTransaction) TxVersion() *TransactionVersion

type DeclaredClass added in v0.3.0

type DeclaredClass struct {
	At    uint64
	Class Class
}

type DeployAccountTransaction

type DeployAccountTransaction struct {
	DeployTransaction
	// The maximum fee that the sender is willing to pay for the transaction.
	MaxFee *felt.Felt
	// Additional information given by the sender, used to validate the transaction.
	TransactionSignature []*felt.Felt
	// The transaction nonce.
	Nonce *felt.Felt

	// Version 3 fields
	// See InvokeTransaction for descriptions of the fields.
	ResourceBounds map[Resource]ResourceBounds
	Tip            uint64
	PaymasterData  []*felt.Felt
	NonceDAMode    DataAvailabilityMode
	FeeDAMode      DataAvailabilityMode
}

func (*DeployAccountTransaction) Hash

func (d *DeployAccountTransaction) Hash() *felt.Felt

func (*DeployAccountTransaction) Signature

func (d *DeployAccountTransaction) Signature() []*felt.Felt

type DeployTransaction

type DeployTransaction struct {
	TransactionHash *felt.Felt
	// A random number used to distinguish between different instances of the contract.
	ContractAddressSalt *felt.Felt
	// The address of the contract.
	ContractAddress *felt.Felt
	// The hash of the class which defines the contract’s functionality.
	ClassHash *felt.Felt
	// The arguments passed to the constructor during deployment.
	ConstructorCallData []*felt.Felt
	// The transaction’s version. Possible values are 1 or 0.
	//
	// When the fields that comprise a transaction change,
	// either with the addition of a new field or the removal of an existing field,
	// then the transaction version increases.
	// Transaction version 0 is deprecated and will be removed in a future version of Starknet.
	Version *TransactionVersion
}

func (*DeployTransaction) Hash

func (d *DeployTransaction) Hash() *felt.Felt

func (*DeployTransaction) Signature

func (d *DeployTransaction) Signature() []*felt.Felt

func (*DeployTransaction) TxVersion added in v0.8.0

func (d *DeployTransaction) TxVersion() *TransactionVersion

type EntryPoint

type EntryPoint struct {
	// starknet_keccak hash of the function signature.
	Selector *felt.Felt
	// The offset of the instruction in the class's bytecode.
	Offset *felt.Felt
}

EntryPoint uniquely identifies a Cairo function to execute.

type Event

type Event struct {
	Data []*felt.Felt
	From *felt.Felt
	Keys []*felt.Felt
}

type ExecutionResources

type ExecutionResources struct {
	BuiltinInstanceCounter BuiltinInstanceCounter
	MemoryHoles            uint64
	Steps                  uint64
	DataAvailability       *DataAvailability
}

type FeeUnit added in v0.8.0

type FeeUnit byte
const (
	WEI FeeUnit = iota
	STRK
)

WEI is the default value since ETH is the first native currency. This allows us to avoid a costly database migration.

type GasPrice added in v0.11.0

type GasPrice struct {
	PriceInWei *felt.Felt
	PriceInFri *felt.Felt
}
type Header struct {
	// The hash of this block
	Hash *felt.Felt
	// The hash of this block’s parent
	ParentHash *felt.Felt
	// The number (height) of this block
	Number uint64
	// The state commitment after this block
	GlobalStateRoot *felt.Felt
	// The Starknet address of the sequencer who created this block
	SequencerAddress *felt.Felt
	// The amount Transactions and Receipts stored in this block
	TransactionCount uint64
	// The amount of events stored in transaction receipts
	EventCount uint64
	// The time the sequencer created this block before executing transactions
	Timestamp uint64
	// The version of the Starknet protocol used when creating this block
	ProtocolVersion string
	// Bloom filter on the events emitted this block
	EventsBloom *bloom.BloomFilter
	// Amount of WEI charged per Gas spent
	GasPrice *felt.Felt
	// Sequencer signatures
	Signatures [][]*felt.Felt
	// Amount of STRK charged per Gas spent
	GasPriceSTRK *felt.Felt
	// The mode of the L1 data availability
	L1DAMode L1DAMode
	// The gas price for L1 data availability
	L1DataGasPrice *GasPrice
}

type InvokeTransaction

type InvokeTransaction struct {
	TransactionHash *felt.Felt
	// The arguments that are passed to the validated and execute functions.
	CallData []*felt.Felt
	// Additional information given by the sender, used to validate the transaction.
	TransactionSignature []*felt.Felt
	// The maximum fee that the sender is willing to pay for the transaction
	MaxFee *felt.Felt
	// The address of the contract invoked by this transaction.
	ContractAddress *felt.Felt
	// When the fields that comprise a transaction change,
	// either with the addition of a new field or the removal of an existing field,
	// then the transaction version increases.
	Version *TransactionVersion

	// Version 0 fields
	// The encoding of the selector for the function invoked (the entry point in the contract)
	EntryPointSelector *felt.Felt

	// Version 1 fields
	// The transaction nonce.
	Nonce *felt.Felt
	// The address of the sender of this transaction
	SenderAddress *felt.Felt

	// Version 3 fields (there was no version 2)
	ResourceBounds map[Resource]ResourceBounds
	Tip            uint64
	// From the RPC spec: data needed to allow the paymaster to pay for the transaction in native tokens
	PaymasterData []*felt.Felt
	// From RPC spec: data needed to deploy the account contract from which this tx will be initiated
	AccountDeploymentData []*felt.Felt
	// From RPC spec: The storage domain of the account's nonce (an account has a nonce per DA mode)
	NonceDAMode DataAvailabilityMode
	// From RPC spec: The storage domain of the account's balance from which fee will be charged
	FeeDAMode DataAvailabilityMode
}

func (*InvokeTransaction) Hash

func (i *InvokeTransaction) Hash() *felt.Felt

func (*InvokeTransaction) Signature

func (i *InvokeTransaction) Signature() []*felt.Felt

func (*InvokeTransaction) TxVersion added in v0.8.0

func (i *InvokeTransaction) TxVersion() *TransactionVersion

type L1DAMode added in v0.11.0

type L1DAMode uint
const (
	Calldata L1DAMode = iota
	Blob
)

type L1HandlerTransaction

type L1HandlerTransaction struct {
	TransactionHash *felt.Felt
	// The address of the contract.
	ContractAddress *felt.Felt
	// The encoding of the selector for the function invoked (the entry point in the contract)
	EntryPointSelector *felt.Felt
	// The transaction nonce.
	Nonce *felt.Felt
	// The arguments that are passed to the validated and execute functions.
	CallData []*felt.Felt
	// When the fields that comprise a transaction change,
	// either with the addition of a new field or the removal of an existing field,
	// then the transaction version increases.
	Version *TransactionVersion
}

func (*L1HandlerTransaction) Hash

func (l *L1HandlerTransaction) Hash() *felt.Felt

func (*L1HandlerTransaction) MessageHash added in v0.7.0

func (l *L1HandlerTransaction) MessageHash() []byte

func (*L1HandlerTransaction) Signature

func (l *L1HandlerTransaction) Signature() []*felt.Felt

func (*L1HandlerTransaction) TxVersion added in v0.8.0

func (l *L1HandlerTransaction) TxVersion() *TransactionVersion

type L1Head added in v0.4.0

type L1Head struct {
	BlockNumber uint64
	BlockHash   *felt.Felt
	StateRoot   *felt.Felt
}

type L1ToL2Message

type L1ToL2Message struct {
	From     common.Address
	Nonce    *felt.Felt
	Payload  []*felt.Felt
	Selector *felt.Felt
	To       *felt.Felt
}

type L2ToL1Message

type L2ToL1Message struct {
	From    *felt.Felt
	Payload []*felt.Felt
	To      common.Address
}

type OnValueChanged added in v0.3.0

type OnValueChanged = func(location, oldValue *felt.Felt) error

type Resource added in v0.8.0

type Resource uint32
const (
	ResourceL1Gas Resource = iota + 1
	ResourceL2Gas
)

func (Resource) String added in v0.8.0

func (r Resource) String() string

type ResourceBounds added in v0.8.0

type ResourceBounds struct {
	MaxAmount uint64
	// MaxPricePerUnit is technically a uint128
	MaxPricePerUnit *felt.Felt
}

From the RPC spec: The max amount and max price per unit of gas used in this transaction.

func (ResourceBounds) Bytes added in v0.8.0

func (rb ResourceBounds) Bytes(resource Resource) []byte

type SegmentLengths added in v0.11.0

type SegmentLengths struct {
	Children []SegmentLengths
	Length   uint64
}

type SierraEntryPoint added in v0.2.1

type SierraEntryPoint struct {
	Index    uint64
	Selector *felt.Felt
}

type State

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

func NewState

func NewState(txn db.Transaction) *State

func (*State) Class added in v0.3.0

func (s *State) Class(classHash *felt.Felt) (*DeclaredClass, error)

Class returns the class object corresponding to the given classHash

func (*State) ContractClassHash added in v0.2.1

func (s *State) ContractClassHash(addr *felt.Felt) (*felt.Felt, error)

ContractClassHash returns class hash of a contract at a given address.

func (State) ContractClassHashAt added in v0.6.0

func (h State) ContractClassHashAt(contractAddress *felt.Felt, height uint64) (*felt.Felt, error)

func (*State) ContractIsAlreadyDeployedAt added in v0.3.0

func (s *State) ContractIsAlreadyDeployedAt(addr *felt.Felt, blockNumber uint64) (bool, error)

ContractIsAlreadyDeployedAt returns if contract at given addr was deployed at blockNumber

func (*State) ContractNonce added in v0.2.1

func (s *State) ContractNonce(addr *felt.Felt) (*felt.Felt, error)

ContractNonce returns nonce of a contract at a given address.

func (State) ContractNonceAt added in v0.6.0

func (h State) ContractNonceAt(contractAddress *felt.Felt, height uint64) (*felt.Felt, error)

func (*State) ContractStorage added in v0.3.0

func (s *State) ContractStorage(addr, key *felt.Felt) (*felt.Felt, error)

ContractStorage returns value of a key in the storage of the contract at the given address.

func (State) ContractStorageAt added in v0.6.0

func (h State) ContractStorageAt(contractAddress, storageLocation *felt.Felt, height uint64) (*felt.Felt, error)

ContractStorageAt returns the value of a storage location of the given contract at the height `height`

func (State) DeleteContractClassHashLog added in v0.6.0

func (h State) DeleteContractClassHashLog(contractAddress *felt.Felt, height uint64) error

func (State) DeleteContractNonceLog added in v0.6.0

func (h State) DeleteContractNonceLog(contractAddress *felt.Felt, height uint64) error

func (State) DeleteContractStorageLog added in v0.6.0

func (h State) DeleteContractStorageLog(contractAddress, storageLocation *felt.Felt, height uint64) error

DeleteContractStorageLog deletes the log at the given height

func (State) LogContractClassHash added in v0.6.0

func (h State) LogContractClassHash(contractAddress, oldValue *felt.Felt, height uint64) error

func (State) LogContractNonce added in v0.6.0

func (h State) LogContractNonce(contractAddress, oldValue *felt.Felt, height uint64) error

func (State) LogContractStorage added in v0.6.0

func (h State) LogContractStorage(contractAddress, storageLocation, oldValue *felt.Felt, height uint64) error

LogContractStorage logs the old value of a storage location for the given contract which changed on height `height`

func (*State) Revert added in v0.4.0

func (s *State) Revert(blockNumber uint64, update *StateUpdate) error

func (*State) Root

func (s *State) Root() (*felt.Felt, error)

Root returns the state commitment.

func (*State) Update

func (s *State) Update(blockNumber uint64, update *StateUpdate, declaredClasses map[felt.Felt]Class) error

Update applies a StateUpdate to the State object. State is not updated if an error is encountered during the operation. If update's old or new root does not match the state's old or new roots, [ErrMismatchedRoot] is returned.

type StateDiff

type StateDiff struct {
	StorageDiffs      map[felt.Felt]map[felt.Felt]*felt.Felt // addr -> {key -> value, ...}
	Nonces            map[felt.Felt]*felt.Felt               // addr -> nonce
	DeployedContracts map[felt.Felt]*felt.Felt               // addr -> class hash
	DeclaredV0Classes []*felt.Felt                           // class hashes
	DeclaredV1Classes map[felt.Felt]*felt.Felt               // class hash -> compiled class hash
	ReplacedClasses   map[felt.Felt]*felt.Felt               // addr -> class hash
}

func EmptyStateDiff added in v0.7.5

func EmptyStateDiff() *StateDiff

func (*StateDiff) Commitment added in v0.7.0

func (d *StateDiff) Commitment() *felt.Felt

type StateHistoryReader added in v0.3.0

type StateHistoryReader interface {
	StateReader

	ContractStorageAt(addr, key *felt.Felt, blockNumber uint64) (*felt.Felt, error)
	ContractNonceAt(addr *felt.Felt, blockNumber uint64) (*felt.Felt, error)
	ContractClassHashAt(addr *felt.Felt, blockNumber uint64) (*felt.Felt, error)
	ContractIsAlreadyDeployedAt(addr *felt.Felt, blockNumber uint64) (bool, error)
}

type StateReader added in v0.3.0

type StateReader interface {
	ContractClassHash(addr *felt.Felt) (*felt.Felt, error)
	ContractNonce(addr *felt.Felt) (*felt.Felt, error)
	ContractStorage(addr, key *felt.Felt) (*felt.Felt, error)
	Class(classHash *felt.Felt) (*DeclaredClass, error)
}

func NewStateSnapshot added in v0.3.0

func NewStateSnapshot(state StateHistoryReader, blockNumber uint64) StateReader

type StateUpdate

type StateUpdate struct {
	BlockHash *felt.Felt
	NewRoot   *felt.Felt
	OldRoot   *felt.Felt
	StateDiff *StateDiff
}

type Transaction

type Transaction interface {
	Hash() *felt.Felt
	Signature() []*felt.Felt
	TxVersion() *TransactionVersion
}

type TransactionReceipt

type TransactionReceipt struct {
	Fee                *felt.Felt
	FeeUnit            FeeUnit
	Events             []*Event
	ExecutionResources *ExecutionResources
	L1ToL2Message      *L1ToL2Message
	L2ToL1Message      []*L2ToL1Message
	TransactionHash    *felt.Felt
	Reverted           bool
	RevertReason       string
}

type TransactionVersion added in v0.6.2

type TransactionVersion felt.Felt

Keep in mind that this is used as a storage type, make sure you migrate the DB if you change the underlying type

func (*TransactionVersion) AsFelt added in v0.6.2

func (v *TransactionVersion) AsFelt() *felt.Felt

func (*TransactionVersion) HasQueryBit added in v0.6.2

func (v *TransactionVersion) HasQueryBit() bool

func (*TransactionVersion) Is added in v0.6.2

func (v *TransactionVersion) Is(u64 uint64) bool

Is compares the version (without query bit) with the given value

func (*TransactionVersion) MarshalCBOR added in v0.6.2

func (v *TransactionVersion) MarshalCBOR() ([]byte, error)

func (*TransactionVersion) SetUint64 added in v0.6.2

func (v *TransactionVersion) SetUint64(u64 uint64) *TransactionVersion

func (*TransactionVersion) String added in v0.6.2

func (v *TransactionVersion) String() string

func (*TransactionVersion) UnmarshalCBOR added in v0.6.2

func (v *TransactionVersion) UnmarshalCBOR(data []byte) error

func (*TransactionVersion) WithoutQueryBit added in v0.6.2

func (v *TransactionVersion) WithoutQueryBit() TransactionVersion

Directories

Path Synopsis
Package trie implements a dense Merkle Patricia Trie.
Package trie implements a dense Merkle Patricia Trie.

Jump to

Keyboard shortcuts

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