Skip to content

Commit eccb4f8

Browse files
trianglesphereprotolambda
authored andcommitted
core: Add version to DepositTx (ethereum#19)
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.
1 parent 7d723ed commit eccb4f8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

core/types/deposit_tx.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import (
2222
"github.com/ethereum/go-ethereum/common"
2323
)
2424

25+
const (
26+
DepositTxVersionZeroType = iota
27+
)
28+
2529
const DepositTxType = 0x7E
2630

2731
type DepositTx struct {

core/types/transaction.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ var (
3838
ErrTxTypeNotSupported = errors.New("transaction type not supported")
3939
ErrGasFeeCapTooLow = errors.New("fee cap less than base fee")
4040
errShortTypedTx = errors.New("typed transaction too short")
41+
42+
// Custom Errors for deposits
43+
ErrDepositTxTypeNotSupported = errors.New("deposit transaction type not supported")
44+
errUnversionedDeposit = errors.New("deposit transaction does not have version byte")
4145
)
4246

4347
// Transaction types.
@@ -105,6 +109,10 @@ func (tx *Transaction) EncodeRLP(w io.Writer) error {
105109
// encodeTyped writes the canonical encoding of a typed transaction to w.
106110
func (tx *Transaction) encodeTyped(w *bytes.Buffer) error {
107111
w.WriteByte(tx.Type())
112+
// Only support v0 right now.
113+
if tx.Type() == DepositTxType {
114+
w.WriteByte(DepositTxVersionZeroType)
115+
}
108116
return rlp.Encode(w, tx.inner)
109117
}
110118

@@ -186,7 +194,13 @@ func (tx *Transaction) decodeTyped(b []byte) (TxData, error) {
186194
return &inner, err
187195
case DepositTxType:
188196
var inner DepositTx
189-
err := rlp.DecodeBytes(b[1:], &inner)
197+
if len(b) < 2 {
198+
return nil, errUnversionedDeposit
199+
}
200+
if b[1] != DepositTxVersionZeroType {
201+
return nil, ErrDepositTxTypeNotSupported
202+
}
203+
err := rlp.DecodeBytes(b[2:], &inner)
190204
return &inner, err
191205
default:
192206
return nil, ErrTxTypeNotSupported

0 commit comments

Comments
 (0)