types

package
v0.0.230 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package types contains common types

Index

Constants

View Source
const (
	// BaseMessageTipsOffset is the tips offset.
	BaseMessageTipsOffset = 0
	// BaseMessageSenderOffset is the sender offset.
	BaseMessageSenderOffset = 32
	// BaseMessageRecipientOffset is the recipient offset.
	BaseMessageRecipientOffset = 64
	// BaseMessageRequestOffset is the request offset.
	BaseMessageRequestOffset = BaseMessageRecipientOffset + TipsSize
	// BaseMessageContentOffset is the content offset.
	BaseMessageContentOffset = BaseMessageRequestOffset + RequestSize
)
View Source
const (
	// MessageFlagSize if the size in bytes of a message flag.
	MessageFlagSize = 1
	// MessageHeaderSize is the size in bytes of a message header.
	MessageHeaderSize = 4*4 + MessageFlagSize
)
View Source
const (
	// VersionOffset is the offset of the version.
	VersionOffset = 0
	// GasLimitOffset if the offset of the gas limit.
	GasLimitOffset = 4
	// GasDropOffset is the gas drop offset.
	GasDropOffset = 12
	// RequestSize is the size of the request.
	RequestSize = 24
)
View Source
const (
	// MessageBodyOffset is the message body offset.
	MessageBodyOffset = MessageHeaderSize
)
View Source
const SignatureLength = int(65)

SignatureLength for ecdsa signature.

View Source
const (
	// TipsSize is the size of the tips in bytes.
	TipsSize = 8 * 4
)

Variables

This section is empty.

Functions

func EncodeAgentStatus added in v0.0.171

func EncodeAgentStatus(agentStatus AgentStatus) ([]byte, error)

EncodeAgentStatus encodes a agent status.

func EncodeAttestation

func EncodeAttestation(attestation Attestation) ([]byte, error)

EncodeAttestation encodes an attestation.

func EncodeBaseMessage added in v0.0.171

func EncodeBaseMessage(m BaseMessage) ([]byte, error)

EncodeBaseMessage encodes a base message.

func EncodeChainGas added in v0.0.171

func EncodeChainGas(chainGas ChainGas) ([]byte, error)

EncodeChainGas encodes a chaingas.

func EncodeGasData added in v0.0.171

func EncodeGasData(gasData GasData) ([]byte, error)

EncodeGasData encodes a gasdata.

func EncodeHeader

func EncodeHeader(header Header) ([]byte, error)

EncodeHeader encodes a message header.

func EncodeMessage

func EncodeMessage(m Message) ([]byte, error)

EncodeMessage encodes a message.

func EncodeRequest added in v0.0.171

func EncodeRequest(m Request) ([]byte, error)

EncodeRequest encodes a request.

func EncodeSignature

func EncodeSignature(sig Signature) ([]byte, error)

EncodeSignature encodes a signature.

func EncodeSnapshot added in v0.0.130

func EncodeSnapshot(snapshot Snapshot) ([]byte, error)

EncodeSnapshot encodes a snapshot.

func EncodeState added in v0.0.130

func EncodeState(state State) ([]byte, error)

EncodeState encodes a state.

func EncodeTips

func EncodeTips(tips Tips) ([]byte, error)

EncodeTips encodes a list of tips.

func HashRawBytes added in v0.0.58

func HashRawBytes(rawBytes []byte) (common.Hash, error)

HashRawBytes takes the raw bytes and produces a hash.

func TotalTips

func TotalTips(tips Tips) *big.Int

TotalTips gets the combined value of the tips.

Types

type AgentFlagType added in v0.0.185

type AgentFlagType uint8

AgentFlagType is the type for the Agent Status Flag.

const (
	// AgentFlagUnknown means agent is not part of agent set.
	AgentFlagUnknown AgentFlagType = iota
	// AgentFlagActive means agent is active.
	AgentFlagActive
	// AgentFlagUnstaking means agent is unstaking.
	AgentFlagUnstaking
	// AgentFlagResting means agent has staked but not currently doing any work.
	AgentFlagResting
	// AgentFlagFraudulent means agent has been accused of fraud and is awaiting fraud resolution.
	AgentFlagFraudulent
	// AgentFlagSlashed means that the agent has been slashed and will not be a part of agent set in the next epoch.
	AgentFlagSlashed
)

func (AgentFlagType) String added in v0.0.185

func (i AgentFlagType) String() string

type AgentStatus added in v0.0.171

type AgentStatus interface {
	// Flag is the current status flag of the agent.
	Flag() uint8
	// Domain that agent is assigned to.
	Domain() uint32
	// Index of the agent in list of agents.
	Index() uint32
}

AgentStatus is the agent status interface.

func DecodeAgentStatus added in v0.0.171

func DecodeAgentStatus(toDecode []byte) (AgentStatus, error)

DecodeAgentStatus decodes an agent status.

func NewAgentStatus added in v0.0.171

func NewAgentStatus(flag uint8, domain, index uint32) AgentStatus

NewAgentStatus creates a new agent status.

type Attestation

type Attestation interface {
	// SnapshotRoot is the root of the Snapshot Merkle Tree.
	SnapshotRoot() [32]byte
	// DataHash is the agent root and SnapGasHash combined into a single hash.
	DataHash() [32]byte
	// Nonce is the attestation nonce.
	Nonce() uint32
	// BlockNumber is the block number when the attestation was created in Summit.
	BlockNumber() *big.Int
	// Timestamp is the timestamp when the attestation was created in Summit.
	Timestamp() *big.Int
	// SignAttestation signs the attestation
	SignAttestation(ctx context.Context, signer signer.Signer) (signer.Signature, []byte, common.Hash, error)
}

Attestation is the attestation interface.

func DecodeAttestation

func DecodeAttestation(toDecode []byte) (Attestation, error)

DecodeAttestation decodes an attestation.

func NewAttestation

func NewAttestation(snapshotRoot [32]byte, dataHash [32]byte, nonce uint32, blockNumber *big.Int, timestamp *big.Int) Attestation

NewAttestation creates a new attestation.

type AttestationSubmitted

type AttestationSubmitted interface {
	// Notary gets the notary of the attestation.
	Notary() common.Hash
	// Attestation gets the raw bytes of the attestation.
	Attestation() []byte
}

AttestationSubmitted is the type emitted by the AttestationCollector when an attestation is submitted.

func NewAttestationSubmitted

func NewAttestationSubmitted(notary common.Hash, attestation []byte) AttestationSubmitted

NewAttestationSubmitted creates a new attestation submitted type.

type BaseMessage added in v0.0.171

type BaseMessage interface {
	// Sender address on origin chain.
	Sender() [32]byte
	// Recipient address on destination chain.
	Recipient() [32]byte
	// Tips paid on the origin chain.
	Tips() Tips
	// Request gets the message request.
	Request() Request
	// Content to be passed to recipient.
	Content() []byte

	// BodyLeaf gets the message body.
	BodyLeaf() ([]byte, error)
	// Leaf gets the message leaf.
	Leaf() ([32]byte, error)
}

BaseMessage is an interface that contains the base message.

func DecodeBaseMessage added in v0.0.171

func DecodeBaseMessage(toDecode []byte) (BaseMessage, error)

DecodeBaseMessage decodes a base message typed mem view.

func NewBaseMessage added in v0.0.171

func NewBaseMessage(sender, recipient [32]byte, tips Tips, request Request, content []byte) BaseMessage

NewBaseMessage creates a new message from fields passed in.

type ChainGas added in v0.0.171

type ChainGas interface {
	// GasData is the gas data for the chain.
	GasData() GasData
	// Domain is domain id of the chain.
	Domain() uint32
}

ChainGas is the ChainGas interface.

func DecodeChainGas added in v0.0.171

func DecodeChainGas(toDecode []byte) (ChainGas, error)

DecodeChainGas decodes a chainGas.

func NewChainGas added in v0.0.171

func NewChainGas(gasData GasData, domain uint32) ChainGas

NewChainGas creates a new chaingas.

type ChainType

type ChainType uint8

ChainType is the type of chain being used (e.g. evm).

const (
	// EVM is a chain that conforms to the evm standard.
	EVM ChainType = 0
)

func AllChainTypes

func AllChainTypes() []ChainType

AllChainTypes gets all chain types for the chain.

func (ChainType) String

func (i ChainType) String() string

type CommittedMessage

type CommittedMessage interface {
	// Message is the fully detailed message that was committed
	Message() []byte
	// Leaf gets a leaf
	Leaf() [32]byte
	// Encode encodes a message
	Encode() ([]byte, error)
}

CommittedMessage is the message that got committed.

func DecodeCommittedMessage

func DecodeCommittedMessage(rawMessage []byte) (CommittedMessage, error)

DecodeCommittedMessage decodes a committed message into a struct.

func NewCommittedMessage

func NewCommittedMessage(message []byte) CommittedMessage

NewCommittedMessage creates a new committed message.

type CommittedMessageEncoder

type CommittedMessageEncoder struct {
	CommittedRoot common.Hash
	Message       []byte
}

CommittedMessageEncoder is used to export fields for struct encoding.

type GasData added in v0.0.171

type GasData interface {
	// GasPrice is the gas price for the chain (in Wei per gas unit).
	GasPrice() uint16
	// DataPrice is the calldata price (in Wei per byte of content).
	DataPrice() uint16
	// ExecBuffer is the tx fee safety buffer for message execution (in Wei).
	ExecBuffer() uint16
	// AmortAttCost is the amortized cost for attestation submission (in Wei).
	AmortAttCost() uint16
	// EtherPrice is the chain's Ether Price / Mainnet Ether Price (in BWAD).
	EtherPrice() uint16
	// Markup is the markup for the message execution (in BWAD).
	Markup() uint16
}

GasData is the GasData interface.

func DecodeGasData added in v0.0.171

func DecodeGasData(toDecode []byte) (GasData, error)

DecodeGasData decodes a gasData.

func NewGasData added in v0.0.171

func NewGasData(gasPrice, dataPrice, execBuffer, amortAttCost, etherPrice, markup uint16) GasData

NewGasData creates a new gasdata.

type Header interface {
	// Flag is the flag of the message
	Flag() MessageFlag
	// OriginDomain is the origin domain of the message
	OriginDomain() uint32
	// Nonce is the nonce of the message
	Nonce() uint32
	// DestinationDomain is the destination domain of the message
	DestinationDomain() uint32
	// OptimisticSeconds is the optimistic time period of the message in seconds
	OptimisticSeconds() uint32

	// Leaf is the leaf of the header.
	Leaf() ([32]byte, error)
}

Header contains information of a message.

func DecodeHeader

func DecodeHeader(header []byte) (Header, error)

DecodeHeader decodes a header from a byte slice.

func NewHeader

func NewHeader(flag MessageFlag, originDomain uint32, nonce uint32, destinationDomain uint32, optimisticSeconds uint32) Header

NewHeader creates a new header type.

type Message

type Message interface {
	// Header gets the message header
	Header() Header
	// BaseMessage is the base message if the flag indicates the type is a base message
	BaseMessage() BaseMessage
	// Body gets the message body
	Body() []byte

	// OriginDomain returns the Slip-44 ID
	OriginDomain() uint32
	// Nonce is the count of all previous messages to the destination
	Nonce() uint32
	// DestinationDomain is the slip-44 id of the destination
	DestinationDomain() uint32
	// ToLeaf converts a leaf to a keccac256
	ToLeaf() (leaf [32]byte, err error)
	// OptimisticSeconds gets the optimistic seconds count
	OptimisticSeconds() uint32
}

Message is an interface that contains the message.

func DecodeMessage

func DecodeMessage(message []byte) (Message, error)

DecodeMessage decodes a message from a byte slice.

func NewMessage

func NewMessage(header Header, baseMessage BaseMessage, body []byte) Message

NewMessage creates a new message from fields passed in. TODO: Set up different initializers. One for BaseMessage and one for ManagerMessage.

func NewMessageFromBaseMessage added in v0.0.184

func NewMessageFromBaseMessage(header Header, baseMessage BaseMessage) (Message, error)

NewMessageFromBaseMessage creates a generic message given a base message.

func NewMessageFromManagerMessage added in v0.0.184

func NewMessageFromManagerMessage(header Header, payload []byte) (Message, error)

NewMessageFromManagerMessage creates a generic message given a manager message.

type MessageFlag added in v0.0.171

type MessageFlag uint8

MessageFlag indicates if the message is normal "Base" message or "Manager" message.

const (
	// MessageFlagBase is the normal message that has tips.
	MessageFlagBase MessageFlag = iota
	// MessageFlagManager is manager message and will not have tips.
	MessageFlagManager
)

type NotaryAttestation added in v0.0.171

type NotaryAttestation interface {
	// AttPayload is raw bytes of the attestation payload.
	AttPayload() []byte
	// AgentRoot is the agent root.
	AgentRoot() [32]byte
	// SnapGas is the snap gas.
	SnapGas() []*big.Int
	// Attestation is the decoded attestation from the AttPayload
	Attestation() Attestation
}

NotaryAttestation is the notary attestation interface.

func NewNotaryAttestation added in v0.0.171

func NewNotaryAttestation(attPayload []byte, agentRoot [32]byte, snapGas []*big.Int) (NotaryAttestation, error)

NewNotaryAttestation creates a new notary attestation.

type Proof

type Proof interface {
	// Leaf is the leaf in the proof
	Leaf() common.Hash
	// Index is the index in the tree
	Index() uint32
	// Path is the merkle branch
	Path() common.Hash
	// Encode encodes a message
	Encode() ([]byte, error)
}

Proof is a merkle proof object. The leaf it's path to the root and its index in the tree.

func DecodeProof

func DecodeProof(rawProof []byte) (Proof, error)

DecodeProof decodes a proof.

func NewProof

func NewProof(leaf common.Hash, index uint32, path common.Hash) Proof

NewProof creates a new merkle proof.

type ProofEncoder

type ProofEncoder struct {
	Leaf  common.Hash
	Index uint32
	Path  common.Hash
}

ProofEncoder is exported to allow proofs to be encoded/deoded from binary.

type Request added in v0.0.171

type Request interface {
	// Version is the base message version to pass to the recipient.
	Version() uint32
	// GasLimit is the minimum amount of gas units to supply for execution.
	GasLimit() uint64
	// GasDrop is the minimum amount of gas token to drop to the recipient.
	GasDrop() *big.Int
}

Request is an interface that contains the request from the base message.

func DecodeRequest added in v0.0.171

func DecodeRequest(toDecode []byte) Request

DecodeRequest decodes a request typed mem view.

func NewRequest added in v0.0.171

func NewRequest(version uint32, gasLimit uint64, gasDrop *big.Int) Request

NewRequest creates a new request from fields passed in.

type Signature

type Signature interface {
	// V gets the v value of the signature
	V() *big.Int
	// R is the r value of the signature
	R() *big.Int
	// S is the s value of the signature
	S() *big.Int
}

Signature creates a new signature.

func DecodeSignature

func DecodeSignature(toDecode []byte) (sig Signature, err error)

DecodeSignature decodes a signature.

func NewSignature

func NewSignature(v, r, s *big.Int) Signature

NewSignature creates a new signature.

type Snapshot added in v0.0.130

type Snapshot interface {
	// States are the states of the snapshot.
	States() []State

	// SnapshotRootAndProofs returns the snapshot root, calculated from the states, as well as each state's proof.
	SnapshotRootAndProofs() ([32]byte, [][][]byte, error)
	// SignSnapshot returns the signature of the snapshot payload signed by the signer
	SignSnapshot(ctx context.Context, signer signer.Signer) (signer.Signature, []byte, common.Hash, error)
}

Snapshot is the snapshot interface.

func DecodeSnapshot added in v0.0.130

func DecodeSnapshot(toDecode []byte) (Snapshot, error)

DecodeSnapshot decodes a snapshot.

func NewSnapshot added in v0.0.130

func NewSnapshot(states []State) Snapshot

NewSnapshot creates a new snapshot.

type State added in v0.0.130

type State interface {
	// Root is the root of the Origin Merkle Tree.
	Root() [32]byte
	// Origin is the domain where Origin is located.
	Origin() uint32
	// Nonce is the amount of sent messages.
	Nonce() uint32
	// BlockNumber is the block of the last sent message.
	BlockNumber() *big.Int
	// Timestamp is the unix time of the last sent message.
	Timestamp() *big.Int
	// GasData is the gas data from the chain's gas oracle.
	GasData() GasData

	// Hash returns the hash of the state.
	Hash() ([32]byte, error)
	// SubLeaves returns the left and right sub-leaves of the state.
	SubLeaves() (leftLeaf, rightLeaf [32]byte, err error)
}

State is the state interface.

func DecodeState added in v0.0.130

func DecodeState(toDecode []byte) (State, error)

DecodeState decodes a state.

func NewState added in v0.0.130

func NewState(root [32]byte, origin uint32, nonce uint32, blockNumber *big.Int, timestamp *big.Int, gasData GasData) State

NewState creates a new state.

type Tips

type Tips interface {
	// SummitTip gets the tips for the agent work on summit
	SummitTip() *big.Int
	// AttestationTip gets the tips for the doing the attestation
	AttestationTip() *big.Int
	// ExecutionTip gets the tips for executing the message
	ExecutionTip() *big.Int
	// DeliveryTip gets the tips for delivering the message receipt to summit
	DeliveryTip() *big.Int
}

Tips contain tips used for scientizing different agents.

func DecodeTips

func DecodeTips(toDecode []byte) (Tips, error)

DecodeTips decodes a tips typed mem view.

func NewTips

func NewTips(summitTip, attestationTip, executionTip, deliveryTip *big.Int) Tips

NewTips creates a new tips type.

Jump to

Keyboard shortcuts

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