types

package
v1.19.6 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package types holds the OP-Stack-specific transaction and receipt types. Consumers import it as optypes.

Index

Constants

View Source
const DepositTxType = 0x7E

DepositTxType is the EIP-2718 type byte of OP Stack deposit transactions.

View Source
const PostExecPayloadVersion uint64 = 1

PostExecPayloadVersion is the only PostExecPayload version the Go decoder accepts. Must stay in lock-step with POST_EXEC_PAYLOAD_VERSION in rust/op-alloy.

View Source
const PostExecTxType = 0x7D

PostExecTxType is the EIP-2718 type byte of OP Stack post-execution transactions.

Variables

This section is empty.

Functions

func IsDepositTx

func IsDepositTx(tx *types.Transaction) bool

IsDepositTx reports whether tx is an OP Stack deposit transaction.

func IsPostExecTx

func IsPostExecTx(tx *types.Transaction) bool

IsPostExecTx reports whether tx is an OP Stack post-execution transaction.

Like the deposit helpers in deposit_tx.go, this is transition-only: a go-ethereum *types.Transaction can hold a post-exec tx only while the build resolves to op-geth. After the cutover to upstream go-ethereum the 0x7D type is rejected on decode, so this is removed; the durable shape decodes raw bytes via UnmarshalPostExecTx.

func IsSystemTx

func IsSystemTx(tx *types.Transaction) (bool, error)

IsSystemTx reports whether tx is a deposit that is a system transaction, exempt from the L2 gas limit. It errors if tx is not a deposit transaction.

func Mint

func Mint(tx *types.Transaction) (*big.Int, error)

Mint returns the ETH minted by a deposit transaction. A deposit that mints nothing yields zero, never nil: the wire encoding does not distinguish a nil from a zero mint, and the transaction is decoded from its wire bytes. It errors if tx is not a deposit transaction.

func SourceHash

func SourceHash(tx *types.Transaction) (common.Hash, error)

SourceHash returns the source hash of a deposit transaction. It errors if tx is not a deposit transaction.

Types

type DepositTx

type DepositTx struct {
	// SourceHash uniquely identifies the source of the deposit.
	SourceHash common.Hash
	// From is the sender address, determined by the deposit's origin instead of a signature.
	From common.Address
	// To is the recipient; nil means contract creation.
	To *common.Address `rlp:"nil"`
	// Mint is minted on L2, locked on L1; nil if no minting. Note that nil and
	// zero share the same wire encoding and decode to zero.
	Mint *big.Int `rlp:"nil"`
	// Value is transferred from the L2 balance, executed after Mint (if any).
	Value *big.Int
	// Gas is the gas limit.
	Gas uint64
	// IsSystemTransaction indicates the transaction is exempt from the L2 gas limit.
	IsSystemTransaction bool
	// Data is the calldata.
	Data []byte
}

DepositTx is an OP Stack deposit transaction, derived from L1 (or generated for network upgrades) rather than signed by a user. Its canonical encoding is DepositTxType || RLP(fields), matching op-geth's types.DepositTx wire format.

func UnmarshalDepositTx

func UnmarshalDepositTx(raw []byte) (*DepositTx, error)

UnmarshalDepositTx decodes a deposit transaction from its EIP-2718 encoding.

func (*DepositTx) Hash added in v1.19.5

func (d *DepositTx) Hash() common.Hash

Hash returns the transaction hash: the keccak-256 hash of the canonical EIP-2718 encoding. A well-formed deposit cannot fail to encode, so an encoding error is unreachable and panics; this keeps the signature free of an error return, matching how a transaction hash is used at call sites.

func (*DepositTx) MarshalBinary

func (d *DepositTx) MarshalBinary() ([]byte, error)

MarshalBinary returns the canonical EIP-2718 encoding of the deposit transaction.

func (*DepositTx) MarshalJSON added in v1.19.5

func (d *DepositTx) MarshalJSON() ([]byte, error)

MarshalJSON encodes the deposit transaction in op-geth's RPC transaction format, including the transaction hash. The nonce is always null: the effective deposit nonce that mined deposits carry on the RPC wire is not part of this type (or of the canonical encoding), so a decode/encode round-trip does not preserve it.

func (*DepositTx) UnmarshalJSON added in v1.19.5

func (d *DepositTx) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes a deposit transaction from op-geth's RPC transaction format, applying the same field validation as op-geth. A nonce field — the effective deposit nonce that post-Regolith RPC responses carry — is accepted and ignored: it is not part of the canonical transaction encoding.

type PostExecPayload added in v1.19.5

type PostExecPayload struct {
	Version          uint64        `json:"version"`
	BlockNumber      uint64        `json:"block_number,omitempty"`
	GasRefundEntries []SDMGasEntry `json:"gas_refund_entries"`
}

PostExecPayload is the payload RLP-encoded into the Data of a PostExecTx. Field order must match op-alloy's PostExecPayload.

func DecodePostExecPayload added in v1.19.5

func DecodePostExecPayload(input []byte) (*PostExecPayload, error)

DecodePostExecPayload decodes the bytes that follow the PostExecTxType type byte, mirroring op-alloy's framing and version checks: one well-formed RLP value with no trailing bytes, at a supported version.

This validates the encoding only. Whether a payload is *correct* for its block — that entries stay in bounds, target non-deposit transactions, and claim no more gas than execution actually earned — is settled by the execution layer, which is the only place holding the full transaction list and the gas accounting.

type PostExecTx

type PostExecTx struct {
	Data []byte
}

PostExecTx is a synthetic, unsigned OP Stack transaction used to carry post-execution metadata in SDM blocks. Its canonical encoding is PostExecTxType || Data, where Data is appended verbatim with no outer RLP envelope, matching op-geth's types.PostExecTx wire format. Data is itself an RLP-encoded payload, but op-geth (and this type) treat it as opaque bytes and never parse it; use DecodePostExecPayload to decode Data. NB: the Rust side (op-alloy TxPostExec) parses and validates the payload on decode — malformed payload bytes are accepted here but rejected there, a Go-lenient/Rust-strict wire-acceptance divergence inherited from op-geth's design.

func UnmarshalPostExecTx

func UnmarshalPostExecTx(raw []byte) (*PostExecTx, error)

UnmarshalPostExecTx decodes a post-exec transaction from its EIP-2718 encoding. Like op-geth, it rejects an empty payload.

func (*PostExecTx) Hash added in v1.19.5

func (p *PostExecTx) Hash() common.Hash

Hash returns the transaction hash: the keccak-256 hash of the canonical EIP-2718 encoding — the rule every typed transaction follows, shared with op-reth (see TestPostExecTxHashGoldenVector). See DepositTx.Hash for the panic rationale.

func (*PostExecTx) MarshalBinary

func (p *PostExecTx) MarshalBinary() ([]byte, error)

MarshalBinary returns the canonical EIP-2718 encoding of the post-exec transaction.

func (*PostExecTx) MarshalJSON added in v1.19.5

func (p *PostExecTx) MarshalJSON() ([]byte, error)

MarshalJSON encodes the post-exec transaction in op-geth's RPC transaction format, including the transaction hash.

func (*PostExecTx) UnmarshalJSON added in v1.19.5

func (p *PostExecTx) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes a post-exec transaction from op-geth's RPC transaction format, applying the same field validation as op-geth, plus one stricter check: the input must not be empty. Empty input would encode to the one-byte value 0x7D, which the binary decoders (UnmarshalPostExecTx, op-geth, op-alloy) all reject — accepting it here would produce a transaction with no canonical encoding.

type Receipt

type Receipt struct {
	types.Receipt
	// DepositNonce was introduced in Regolith to store the actual nonce used by
	// deposit transactions.
	DepositNonce *uint64 `json:"depositNonce,omitempty"`
	// DepositReceiptVersion was introduced in Canyon to indicate an update to
	// how receipt hashes should be computed when set; nil when not set.
	DepositReceiptVersion *uint64 `json:"depositReceiptVersion,omitempty"`
	// L1GasPrice is present from pre-bedrock; the L1 base fee after Bedrock.
	L1GasPrice *big.Int `json:"l1GasPrice,omitempty"`
	// L1BlobBaseFee is nil prior to the Ecotone hardfork.
	L1BlobBaseFee *big.Int `json:"l1BlobBaseFee,omitempty"`
	// L1GasUsed is present from pre-bedrock, deprecated as of Fjord.
	L1GasUsed *big.Int `json:"l1GasUsed,omitempty"`
	// L1Fee is present from pre-bedrock.
	L1Fee *big.Int `json:"l1Fee,omitempty"`
	// FeeScalar is present from pre-bedrock to Ecotone; nil after Ecotone.
	FeeScalar *big.Float `json:"l1FeeScalar,omitempty"`
	// L1BaseFeeScalar is nil prior to the Ecotone hardfork.
	L1BaseFeeScalar *uint64 `json:"l1BaseFeeScalar,omitempty"`
	// L1BlobBaseFeeScalar is nil prior to the Ecotone hardfork.
	L1BlobBaseFeeScalar *uint64 `json:"l1BlobBaseFeeScalar,omitempty"`
	// OperatorFeeScalar is nil prior to the Isthmus hardfork.
	OperatorFeeScalar *uint64 `json:"operatorFeeScalar,omitempty"`
	// OperatorFeeConstant is nil prior to the Isthmus hardfork.
	OperatorFeeConstant *uint64 `json:"operatorFeeConstant,omitempty"`
	// DAFootprintGasScalar is nil prior to the Jovian hardfork.
	DAFootprintGasScalar *uint64 `json:"daFootprintGasScalar,omitempty"`
}

Receipt extends go-ethereum's receipt with the OP Stack fields that L2 endpoints include in eth_getTransactionReceipt responses. The full op-geth field set is carried — not just the fields the monorepo services read — so receipt JSON round-trips completely. JSON field names match op-geth's types.Receipt verbatim for wire compatibility; values are hex-encoded on the wire, hence the custom JSON methods.

While the go.mod replace still points at op-geth, the embedded types.Receipt carries identically-named fields. UnmarshalJSON populates both copies consistently; when marshaling, the outer fields take precedence.

func FromGethReceipt added in v1.19.5

func FromGethReceipt(r *types.Receipt) *Receipt

FromGethReceipt wraps a go-ethereum receipt. The receipt struct is shallow-copied (reference fields like Logs still alias the source). While go-ethereum resolves to op-geth, the deposit receipt fields are mirrored to the authoritative outer copies so consensus encoding stays correct; those two assignments stop compiling at the final cutover and are removed then.

Use this rather than wrapping by hand: a Receipt built as &Receipt{Receipt: *r} leaves the outer deposit fields nil and encodes a deposit receipt without them.

func (*Receipt) DecodeRLP added in v1.19.5

func (r *Receipt) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, overriding the promoted go-ethereum decoder so the OP Stack synthetic receipt types route through this package's OP-aware decode. Inverse of EncodeRLP.

func (*Receipt) DeriveFields added in v1.19.5

func (r *Receipt) DeriveFields(signer types.Signer, context types.DeriveReceiptContext)

DeriveFields overrides the promoted go-ethereum method, which reads the deposit nonce for contract-address derivation off the embedded receipt — the shadow of the wrapper's authoritative outer field. While go-ethereum resolves to op-geth, the shadows are synced before delegating; the two assignments stop compiling at the final cutover and the method is rewritten then.

func (*Receipt) EncodeRLP added in v1.19.5

func (r *Receipt) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder, overriding the promoted go-ethereum encoder so the OP Stack synthetic receipt types encode from this package — the deposit arm reads the authoritative OUTER nonce/version fields. Like go-ethereum, a typed receipt is encoded as an RLP byte string wrapping its consensus envelope; legacy receipts delegate.

func (*Receipt) MarshalBinary added in v1.19.5

func (r *Receipt) MarshalBinary() ([]byte, error)

MarshalBinary returns the consensus encoding of the receipt, routing the OP Stack synthetic receipt types (0x7E deposit, 0x7D post-exec) to this package and everything else to go-ethereum. The deposit encoding reads the authoritative OUTER DepositNonce/DepositReceiptVersion fields and — unlike the receipts-root derivation in EncodeIndex — always includes the nonce when set, matching op-geth's MarshalBinary. Inverse of UnmarshalBinary.

func (Receipt) MarshalJSON

func (r Receipt) MarshalJSON() ([]byte, error)

MarshalJSON encodes the embedded go-ethereum receipt and merges the OP Stack extension fields into the same JSON object, so the encoding round-trips.

func (*Receipt) Size added in v1.19.5

func (r *Receipt) Size() common.StorageSize

Size overrides the promoted go-ethereum method, which measures only the embedded receipt: it adds the wrapper's OP Stack extension fields and their pointees, so cache accounting does not undercount wrapped receipts.

func (*Receipt) UnmarshalBinary added in v1.19.5

func (r *Receipt) UnmarshalBinary(b []byte) error

UnmarshalBinary decodes the consensus encoding of a receipt, routing the OP Stack synthetic receipt types (0x7E deposit, 0x7D post-exec) to this package and everything else to go-ethereum. The OP JSON-only fee fields (L1GasPrice, OperatorFeeScalar, ...) are not part of the consensus encoding and remain nil.

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(input []byte) error

UnmarshalJSON decodes both the embedded go-ethereum receipt and the OP Stack extension fields from the same JSON object.

type Receipts added in v1.19.5

type Receipts []*Receipt

Receipts implements types.DerivableList so the receipts root of an OP Stack block can be recomputed with types.DeriveSha. The OP Stack synthetic receipt types are encoded by this package; everything else delegates to go-ethereum.

The encoding reads the OUTER Receipt fields (DepositNonce, DepositReceiptVersion) — they are authoritative, per the Receipt contract. Receipts must be produced through this package's decoders; a wrapper hand-built around a receipt whose deposit fields live only on the embedded struct encodes without them.

func FromGethReceipts added in v1.19.5

func FromGethReceipts(rs types.Receipts) Receipts

FromGethReceipts wraps go-ethereum receipts into Receipts, per FromGethReceipt.

func (Receipts) EncodeIndex added in v1.19.5

func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer)

EncodeIndex encodes the i'th receipt to w, for receipts-root derivation.

The deposit arms must not be changed to delegate to a receipt's MarshalBinary: for a deposit receipt with non-nil DepositNonce but nil DepositReceiptVersion (post-Regolith, pre-Canyon), the hash preimage deliberately EXCLUDES the nonce while MarshalBinary includes it — preserving backwards compatibility of the receipts-root computation, matching op-geth.

func (Receipts) Geth added in v1.19.5

func (rs Receipts) Geth() types.Receipts

Geth returns a view of the embedded go-ethereum receipts, for boundaries that operate on standard receipt fields only. The elements alias the receivers' embedded structs — mutations are visible in both.

func (Receipts) Len added in v1.19.5

func (rs Receipts) Len() int

Len returns the number of receipts in the list.

type SDMGasEntry added in v1.19.5

type SDMGasEntry struct {
	Index     uint64 `json:"index"`
	GasRefund uint64 `json:"gas_refund"`
}

SDMGasEntry is one per-transaction gas refund entry. Index is block-global, so it counts the deposit transactions that derivation prepends ahead of the batched ones.

Jump to

Keyboard shortcuts

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