From 37a9564d6e1c0e5ed0b9db7ef69fd61a67014318 Mon Sep 17 00:00:00 2001 From: Joshua Gutow Date: Tue, 17 May 2022 14:40:19 -0700 Subject: [PATCH] core: Add version to DepositTx This adds a second byte after the EIP-2718 Type byte to deposit transactions that versions the deposit. It is placed prior to the start of the RLP to make it easier to extend the transaction in the future. We choose to version inside the EIP-2718 envelope to limit the number of EIP-2718 prefixes we take for deposit transactions. --- core/types/deposit_tx.go | 4 ++++ core/types/transaction.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/core/types/deposit_tx.go b/core/types/deposit_tx.go index 00d73c32b..4745f7a66 100644 --- a/core/types/deposit_tx.go +++ b/core/types/deposit_tx.go @@ -22,6 +22,10 @@ import ( "github.com/ethereum/go-ethereum/common" ) +const ( + DepositTxVersionZeroType = iota +) + const DepositTxType = 0x7E type DepositTx struct { diff --git a/core/types/transaction.go b/core/types/transaction.go index 98648ca75..a8affd888 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -38,6 +38,10 @@ var ( ErrTxTypeNotSupported = errors.New("transaction type not supported") ErrGasFeeCapTooLow = errors.New("fee cap less than base fee") errShortTypedTx = errors.New("typed transaction too short") + + // Custom Errors for deposits + ErrDepositTxTypeNotSupported = errors.New("deposit transaction type not supported") + errUnversionedDeposit = errors.New("deposit transaction does not have version byte") ) // Transaction types. @@ -105,6 +109,10 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error { // encodeTyped writes the canonical encoding of a typed transaction to w. func (tx *Transaction) encodeTyped(w *bytes.Buffer) error { w.WriteByte(tx.Type()) + // Only support v0 right now. + if tx.Type() == DepositTxType { + w.WriteByte(DepositTxVersionZeroType) + } return rlp.Encode(w, tx.inner) } @@ -186,7 +194,13 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) { return &inner, err case DepositTxType: var inner DepositTx - err := rlp.DecodeBytes(b[1:], &inner) + if len(b) < 2 { + return nil, errUnversionedDeposit + } + if b[1] != DepositTxVersionZeroType { + return nil, ErrDepositTxTypeNotSupported + } + err := rlp.DecodeBytes(b[2:], &inner) return &inner, err default: return nil, ErrTxTypeNotSupported