crossdomain

package
v0.10.14 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Standard ABI types
	Uint256Type, _ = abi.NewType("uint256", "", nil)
	BytesType, _   = abi.NewType("bytes", "", nil)
	AddressType, _ = abi.NewType("address", "", nil)
	Bytes32Type, _ = abi.NewType("bytes32", "", nil)
)
View Source
var (
	SentMessageEventABI               = "SentMessage(address,address,bytes,uint256)"
	SentMessageEventABIHash           = crypto.Keccak256Hash([]byte(SentMessageEventABI))
	SentMessageExtension1EventABI     = "SentMessage(address,uint256)"
	SentMessageExtension1EventABIHash = crypto.Keccak256Hash([]byte(SentMessageExtension1EventABI))
	MessagePassedEventABI             = "MessagePassed(uint256,address,address,uint256,uint256,bytes,bytes32)"
	MessagePassedEventABIHash         = crypto.Keccak256Hash([]byte(MessagePassedEventABI))
)
View Source
var (
	// NonceMask represents a mask used to extract version bytes from the nonce
	NonceMask, _ = new(big.Int).SetString("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)
)

Functions

func ApplyL1ToL2Alias

func ApplyL1ToL2Alias(address common.Address) common.Address

ApplyL1ToL2Alias will apply the alias applied to L1 to L2 messages when it originates from a contract address

func DecodeVersionedNonce

func DecodeVersionedNonce(versioned *big.Int) (*big.Int, *big.Int)

DecodeVersionedNonce will decode the version that is encoded in the nonce

func EncodeCrossDomainMessageV0

func EncodeCrossDomainMessageV0(
	target *common.Address,
	sender *common.Address,
	message []byte,
	nonce *big.Int,
) ([]byte, error)

EncodeCrossDomainMessageV0 will encode the calldata for "relayMessage(address,address,bytes,uint256)",

func EncodeCrossDomainMessageV1

func EncodeCrossDomainMessageV1(
	nonce *big.Int,
	sender *common.Address,
	target *common.Address,
	value *big.Int,
	gasLimit *big.Int,
	data []byte,
) ([]byte, error)

EncodeCrossDomainMessageV1 will encode the calldata for "relayMessage(uint256,address,address,uint256,uint256,bytes)",

func EncodeVersionedNonce

func EncodeVersionedNonce(nonce, version *big.Int) *big.Int

EncodeVersionedNonce will encode the version into the nonce

func HashCrossDomainMessageV0

func HashCrossDomainMessageV0(
	target *common.Address,
	sender *common.Address,
	data []byte,
	nonce *big.Int,
) (common.Hash, error)

HashCrossDomainMessageV0 computes the pre bedrock cross domain messaging hashing scheme.

func HashCrossDomainMessageV1

func HashCrossDomainMessageV1(
	nonce *big.Int,
	sender *common.Address,
	target *common.Address,
	value *big.Int,
	gasLimit *big.Int,
	data []byte,
) (common.Hash, error)

HashCrossDomainMessageV1 computes the first post bedrock cross domain messaging hashing scheme.

func MigrateWithdrawals

func MigrateWithdrawals(withdrawals []*LegacyWithdrawal, db vm.StateDB, l1CrossDomainMessenger *common.Address, noCheck bool) error

MigrateWithdrawals will migrate a list of pending withdrawals given a StateDB.

func UndoL1ToL2Alias

func UndoL1ToL2Alias(address common.Address) common.Address

UndoL1ToL2Alias will remove the alias applied to L1 to L2 messages when it originates from a contract address

Types

type Backends

type Backends struct {
	L1 bind.ContractBackend
	L2 bind.ContractBackend
}

Backends represents a set of backends for L1 and L2. These are used as the backends for the Messengers

func NewBackends

func NewBackends(l1, l2 bind.ContractBackend) *Backends

type CrossDomainMessage

type CrossDomainMessage struct {
	Nonce    *big.Int        `json:"nonce"`
	Sender   *common.Address `json:"sender"`
	Target   *common.Address `json:"target"`
	Value    *big.Int        `json:"value"`
	GasLimit *big.Int        `json:"gasLimit"`
	Data     []byte          `json:"data"`
}

CrossDomainMessage represents a cross domain message used by the CrossDomainMessenger. The version is encoded in the nonce. Version 0 messages do not have a value, version 1 messages have a value and the most significant byte of the nonce is a 1

func NewCrossDomainMessage

func NewCrossDomainMessage(
	nonce *big.Int,
	sender, target *common.Address,
	value, gasLimit *big.Int,
	data []byte,
) *CrossDomainMessage

NewCrossDomainMessage creates a CrossDomainMessage.

func (*CrossDomainMessage) Encode

func (c *CrossDomainMessage) Encode() ([]byte, error)

Encode will encode a cross domain message based on the version.

func (*CrossDomainMessage) Hash

func (c *CrossDomainMessage) Hash() (common.Hash, error)

Hash will compute the hash of the CrossDomainMessage

func (*CrossDomainMessage) HashV1 added in v0.10.12

func (c *CrossDomainMessage) HashV1() (common.Hash, error)

HashV1 forces using the V1 hash even if its a legacy hash. This is used for the migration process.

func (*CrossDomainMessage) ToWithdrawal

func (c *CrossDomainMessage) ToWithdrawal() (WithdrawalMessage, error)

ToWithdrawal will turn a CrossDomainMessage into a Withdrawal. This only works for version 0 CrossDomainMessages as not all of the data is present for version 1 CrossDomainMessages to be turned into Withdrawals.

func (*CrossDomainMessage) Version

func (c *CrossDomainMessage) Version() uint64

Version will return the version of the CrossDomainMessage. It does this by looking at the first byte of the nonce.

type LegacyWithdrawal

type LegacyWithdrawal struct {
	Target *common.Address `json:"target"`
	Sender *common.Address `json:"sender"`
	Data   hexutil.Bytes   `json:"data"`
	Nonce  *big.Int        `json:"nonce"`
}

LegacyWithdrawal represents a pre bedrock upgrade withdrawal.

func NewLegacyWithdrawal

func NewLegacyWithdrawal(target, sender *common.Address, data []byte, nonce *big.Int) *LegacyWithdrawal

NewLegacyWithdrawal will construct a LegacyWithdrawal

func PreCheckWithdrawals added in v0.10.7

func PreCheckWithdrawals(db *state.StateDB, withdrawals []*LegacyWithdrawal) ([]*LegacyWithdrawal, error)

PreCheckWithdrawals checks that the given list of withdrawals represents all withdrawals made in the legacy system and filters out any extra withdrawals not included in the legacy system.

func (*LegacyWithdrawal) CrossDomainMessage added in v0.10.11

func (w *LegacyWithdrawal) CrossDomainMessage() *CrossDomainMessage

CrossDomainMessage turns the LegacyWithdrawal into a CrossDomainMessage. LegacyWithdrawals do not have the concept of value or gaslimit, so set them to 0.

func (*LegacyWithdrawal) Decode

func (w *LegacyWithdrawal) Decode(data []byte) error

Decode will decode a serialized LegacyWithdrawal

func (*LegacyWithdrawal) Encode

func (w *LegacyWithdrawal) Encode() ([]byte, error)

Encode will serialze the Withdrawal in the legacy format so that it is suitable for hashing. This assumes that the message is being withdrawn through the standard optimism cross domain messaging system by hashing in the L2CrossDomainMessenger address.

func (*LegacyWithdrawal) Hash

func (w *LegacyWithdrawal) Hash() (common.Hash, error)

Hash will compute the legacy style hash that is computed in the OVM_L2ToL1MessagePasser.

func (*LegacyWithdrawal) StorageSlot

func (w *LegacyWithdrawal) StorageSlot() (common.Hash, error)

StorageSlot will compute the storage slot that is set to true in the legacy L2ToL1MessagePasser.

func (*LegacyWithdrawal) Value

func (w *LegacyWithdrawal) Value() (*big.Int, error)

Value returns the ETH value associated with the withdrawal. Since ETH was represented as an ERC20 token before the Bedrock upgrade, the sender and calldata must be observed and the value must be parsed out if "finalizeETHWithdrawal" is the method.

type Messengers

type Messengers struct {
	L1 *bindings.L1CrossDomainMessenger
	L2 *bindings.L2CrossDomainMessenger
}

Messengers represents a pair of L1 and L2 cross domain messengers that are connected to the correct contract addresses

func NewMessengers

func NewMessengers(backends *Backends, l1CrossDomainMessenger common.Address) (*Messengers, error)

NewMessengers constructs Messengers. Passing in the address of the L1CrossDomainMessenger is required to connect to the

type PendingWithdrawal

type PendingWithdrawal struct {
	LegacyWithdrawal `json:"withdrawal"`
	TransactionHash  common.Hash `json:"transactionHash"`
}

A PendingWithdrawal represents a withdrawal that has not been finalized on L1

func GetPendingWithdrawals

func GetPendingWithdrawals(messengers *Messengers, version *big.Int, start, end uint64) ([]PendingWithdrawal, error)

GetPendingWithdrawals will fetch pending withdrawals by getting L2CrossDomainMessenger `SentMessage` events and then checking to see if the cross domain message hash has been finalized on L1. It will return a slice of PendingWithdrawals that have not been finalized on L1.

type Withdrawal

type Withdrawal struct {
	Nonce    *big.Int        `json:"nonce"`
	Sender   *common.Address `json:"sender"`
	Target   *common.Address `json:"target"`
	Value    *big.Int        `json:"value"`
	GasLimit *big.Int        `json:"gasLimit"`
	Data     hexutil.Bytes   `json:"data"`
}

Withdrawal represents a withdrawal transaction on L2

func MigrateWithdrawal

func MigrateWithdrawal(withdrawal *LegacyWithdrawal, l1CrossDomainMessenger *common.Address) (*Withdrawal, error)

MigrateWithdrawal will turn a LegacyWithdrawal into a bedrock style Withdrawal.

func NewWithdrawal

func NewWithdrawal(
	nonce *big.Int,
	sender, target *common.Address,
	value, gasLimit *big.Int,
	data []byte,
) *Withdrawal

NewWithdrawal will create a Withdrawal

func (*Withdrawal) Decode

func (w *Withdrawal) Decode(data []byte) error

Decode will deserialize a Withdrawal

func (*Withdrawal) Encode

func (w *Withdrawal) Encode() ([]byte, error)

Encode will serialize the Withdrawal so that it is suitable for hashing.

func (*Withdrawal) Hash

func (w *Withdrawal) Hash() (common.Hash, error)

Hash will hash the Withdrawal. This is the hash that is computed in the L2ToL1MessagePasser. The encoding is the same as the v1 cross domain message encoding without the 4byte selector prepended.

func (*Withdrawal) StorageSlot

func (w *Withdrawal) StorageSlot() (common.Hash, error)

StorageSlot will compute the storage slot that will be set to true in the L2ToL1MessagePasser. The withdrawal proof sent to L1 will prove that this storage slot is set to "true".

func (*Withdrawal) WithdrawalTransaction added in v0.10.5

func (w *Withdrawal) WithdrawalTransaction() bindings.TypesWithdrawalTransaction

WithdrawalTransaction will convert the Withdrawal to a type suitable for sending a transaction.

type WithdrawalMessage

type WithdrawalMessage interface {
	Encode() ([]byte, error)
	Decode([]byte) error
	Hash() (common.Hash, error)
	StorageSlot() (common.Hash, error)
}

WithdrawalMessage represents a Withdrawal. The Withdrawal and LegacyWithdrawal types must implement this interface.

Jump to

Keyboard shortcuts

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