Documentation ¶
Overview ¶
Package crossdomain provides libraries useful for managing L1 <> L2 cross domain communication. This library is very low level and most users will not these abstractions directly. They were used for the migration to Bedrock from the legacy Optimism system. The bindings subpackage will never need to be updated as they are only used for the migration tooling.
Index ¶
- Variables
- func ApplyL1ToL2Alias(address common.Address) common.Address
- func DecodeVersionedNonce(versioned *big.Int) (*big.Int, *big.Int)
- func EncodeCrossDomainMessageV0(target common.Address, sender common.Address, message []byte, nonce *big.Int) ([]byte, error)
- func EncodeCrossDomainMessageV1(nonce *big.Int, sender common.Address, target common.Address, value *big.Int, ...) ([]byte, error)
- func EncodeVersionedNonce(nonce, version *big.Int) *big.Int
- func HashCrossDomainMessageV0(target common.Address, sender common.Address, data []byte, nonce *big.Int) (common.Hash, error)
- func HashCrossDomainMessageV1(nonce *big.Int, sender common.Address, target common.Address, value *big.Int, ...) (common.Hash, error)
- func UndoL1ToL2Alias(address common.Address) common.Address
- type CrossDomainMessage
- type LegacyReceipt
- type Withdrawal
- type WithdrawalMessage
Constants ¶
This section is empty.
Variables ¶
var ( // Standard ABI types Uint256Type, _ = abi.NewType("uint256", "", nil) BytesType, _ = abi.NewType("bytes", "", nil) AddressType, _ = abi.NewType("address", "", nil) Bytes32Type, _ = abi.NewType("bytes32", "", nil) )
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)) )
var (
// NonceMask represents a mask used to extract version bytes from the nonce
NonceMask, _ = new(big.Int).SetString("0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16)
)
Functions ¶
func ApplyL1ToL2Alias ¶
ApplyL1ToL2Alias will apply the alias applied to L1 to L2 messages when it originates from a contract address
func DecodeVersionedNonce ¶
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 ¶
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.
Types ¶
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 ¶
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) 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 LegacyReceipt ¶
type LegacyReceipt struct { // Consensus fields: These fields are defined by the Yellow Paper PostState []byte `json:"root"` Status uint64 `json:"status"` CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"` Bloom types.Bloom `json:"logsBloom" gencodec:"required"` Logs []*types.Log `json:"logs" gencodec:"required"` // Implementation fields: These fields are added by geth when processing a transaction. // They are stored in the chain database. TxHash common.Hash `json:"transactionHash" gencodec:"required"` ContractAddress common.Address `json:"contractAddress"` GasUsed uint64 `json:"gasUsed" gencodec:"required"` // Inclusion information: These fields provide information about the inclusion of the // transaction corresponding to this receipt. BlockHash common.Hash `json:"blockHash,omitempty"` BlockNumber *big.Int `json:"blockNumber,omitempty"` TransactionIndex uint `json:"transactionIndex"` // UsingOVM L1GasPrice *big.Int `json:"l1GasPrice" gencodec:"required"` L1GasUsed *big.Int `json:"l1GasUsed" gencodec:"required"` L1Fee *big.Int `json:"l1Fee" gencodec:"required"` FeeScalar *big.Float `json:"l1FeeScalar" gencodec:"required"` }
func ReadLegacyReceipts ¶
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 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 ¶
func (w *Withdrawal) WithdrawalTransaction() bindings.TypesWithdrawalTransaction
WithdrawalTransaction will convert the Withdrawal to a type suitable for sending a transaction.