core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCantVerifyBlockHash = errors.New("can not verify hash in block header")
View Source
var ErrUnknownTransaction = errors.New("unknown transaction")

Functions

func CalculateContractCommitment

func CalculateContractCommitment(storageRoot, classHash, nonce *felt.Felt) *felt.Felt

func ContractAddress

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

ContractAddress computes the address of a Starknet contract.

func VerifyBlockHash

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

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

Types

type Block

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

type BuiltinInstanceCounter

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

type Class

type Class struct {
	Abi any
	// 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
	// An ascii-encoded array of builtin names imported by the class.
	Builtins []*felt.Felt
	// The starknet_keccak hash of the ".json" file compiler output.
	ProgramHash *felt.Felt
	Bytecode    []*felt.Felt
}

Class unambiguously defines a Contract's semantics.

func (*Class) Hash

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

type Contract

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

Contract is an instance of a Class.

func NewContract

func NewContract(addr *felt.Felt, txn db.Transaction) *Contract

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

func (*Contract) ClassHash

func (c *Contract) ClassHash() (classHash *felt.Felt, err error)

ClassHash returns hash of the class that this contract instantiates.

func (*Contract) Deploy

func (c *Contract) Deploy(classHash *felt.Felt) error

Deploy sets up the database for a new contract.

func (*Contract) Nonce

func (c *Contract) Nonce() (nonce *felt.Felt, err error)

Nonce returns the number of transactions sent from this contract. Only account contracts can have a non-zero nonce.

func (*Contract) Storage

func (c *Contract) Storage() (*trie.Trie, error)

Storage returns the core.Trie that represents the storage of the contract.

func (*Contract) StorageRoot

func (c *Contract) StorageRoot() (*felt.Felt, error)

StorageRoot returns the root of the contract storage.

func (*Contract) UpdateNonce

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

UpdateNonce updates the nonce value in the database.

func (*Contract) UpdateStorage

func (c *Contract) UpdateStorage(diff []StorageDiff) error

UpdateStorage applies a change-set to the contract storage.

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 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 *felt.Felt
}

func (*DeclareTransaction) Hash

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

func (*DeclareTransaction) Signature

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

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
}

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 *felt.Felt
}

func (*DeployTransaction) Hash

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

func (*DeployTransaction) Signature

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

type DeployedContract

type DeployedContract struct {
	Address   *felt.Felt
	ClassHash *felt.Felt
}

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 ErrCantVerifyTransactionHash

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

func (ErrCantVerifyTransactionHash) Error

func (ErrCantVerifyTransactionHash) Unwrap

type ErrInvalidTransactionVersion

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

func (ErrInvalidTransactionVersion) Error

type ErrMismatchedRoot

type ErrMismatchedRoot struct {
	Want  *felt.Felt
	Got   *felt.Felt
	IsOld bool
}

func (*ErrMismatchedRoot) Error

func (e *ErrMismatchedRoot) Error() string

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
}
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
	// Extraneous data that might be useful for running transactions
	ExtraData *felt.Felt
}

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 *felt.Felt

	// 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
}

func (*InvokeTransaction) Hash

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

func (*InvokeTransaction) Signature

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

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 *felt.Felt
}

func (*L1HandlerTransaction) Hash

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

func (*L1HandlerTransaction) Signature

func (l *L1HandlerTransaction) Signature() []*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 State

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

func NewState

func NewState(txn db.Transaction) *State

func (*State) GetContractClass

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

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

func (*State) GetContractNonce

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

GetContractNonce returns nonce of a contract at a given address.

func (*State) Root

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

Root returns the state commitment.

func (*State) Update

func (s *State) Update(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][]StorageDiff
	Nonces            map[felt.Felt]*felt.Felt
	DeployedContracts []DeployedContract
	DeclaredClasses   []*felt.Felt
}

type StateUpdate

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

type StorageDiff

type StorageDiff struct {
	Key   *felt.Felt
	Value *felt.Felt
}

type Transaction

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

type TransactionReceipt

type TransactionReceipt struct {
	Fee                *felt.Felt
	Events             []*Event
	ExecutionResources *ExecutionResources
	L1ToL2Message      *L1ToL2Message
	L2ToL1Message      []*L2ToL1Message
	TransactionHash    *felt.Felt
}

type TransactionStorage

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

TransactionStorage is a database transaction on a trie.

func NewTransactionStorage

func NewTransactionStorage(txn db.Transaction, prefix []byte) *TransactionStorage

func (*TransactionStorage) Delete

func (t *TransactionStorage) Delete(key *bitset.BitSet) error

func (*TransactionStorage) Get

func (t *TransactionStorage) Get(key *bitset.BitSet) (node *trie.Node, err error)

func (*TransactionStorage) Put

func (t *TransactionStorage) Put(key *bitset.BitSet, value *trie.Node) error

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