From 2bebe323b81e4956cb6657f3f00001bc2173164d Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 21:22:15 +0000 Subject: [PATCH] fix(wire): reject unsupported output types Co-Authored-By: Charon --- wire/transaction.go | 6 ++++++ wire/transaction_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/wire/transaction.go b/wire/transaction.go index 28cd8ed..d37ea95 100644 --- a/wire/transaction.go +++ b/wire/transaction.go @@ -342,6 +342,9 @@ func encodeOutputsV1(enc *Encoder, vout []types.TxOutput) { if !encodeTxOutTarget(enc, v.Target, "encodeOutputsV1") { return } + default: + enc.err = coreerr.E("encodeOutputsV1", fmt.Sprintf("wire: unsupported output type %T", out), nil) + return } } } @@ -386,6 +389,9 @@ func encodeOutputsV2(enc *Encoder, vout []types.TxOutput) { enc.WriteBlob32((*[32]byte)(&v.BlindedAssetID)) enc.WriteUint64LE(v.EncryptedAmount) enc.WriteUint8(v.MixAttr) + default: + enc.err = coreerr.E("encodeOutputsV2", fmt.Sprintf("wire: unsupported output type %T", out), nil) + return } } } diff --git a/wire/transaction_test.go b/wire/transaction_test.go index 2981675..aa289ae 100644 --- a/wire/transaction_test.go +++ b/wire/transaction_test.go @@ -996,6 +996,10 @@ type unsupportedTxOutTarget struct{} func (unsupportedTxOutTarget) TargetType() uint8 { return 250 } +type unsupportedTxOutput struct{} + +func (unsupportedTxOutput) OutputType() uint8 { return 250 } + func TestEncodeTransaction_UnsupportedInput_Bad(t *testing.T) { tx := types.Transaction{ Version: 1, @@ -1045,3 +1049,31 @@ func TestEncodeTransaction_UnsupportedOutputTarget_Bad(t *testing.T) { }) } } + +func TestEncodeTransaction_UnsupportedOutputType_Bad(t *testing.T) { + tests := []struct { + name string + version uint64 + }{ + {name: "v1", version: types.VersionPreHF4}, + {name: "v2", version: types.VersionPostHF4}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tx := types.Transaction{ + Version: tt.version, + Vin: []types.TxInput{types.TxInputGenesis{Height: 1}}, + Vout: []types.TxOutput{unsupportedTxOutput{}}, + Extra: EncodeVarint(0), + } + + var buf bytes.Buffer + enc := NewEncoder(&buf) + EncodeTransactionPrefix(enc, &tx) + if enc.Err() == nil { + t.Fatal("expected encode error for unsupported output type") + } + }) + } +}