Skip to content

Commit b2bb2f4

Browse files
committed
node: Remove minimum TxID length
1 parent a7500b6 commit b2bb2f4

4 files changed

Lines changed: 6 additions & 46 deletions

File tree

node/pkg/common/chainlock.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
)
1818

1919
const (
20-
// TxIDLenMin is the minimum length of a txID.
21-
TxIDLenMin = 32
2220
// AddressLength is the length of a normalized Wormhole address in bytes.
2321
AddressLength = 32
2422

@@ -37,7 +35,6 @@ const (
3735
// The minimum size of a marshaled message publication. It is the sum of the sizes of each of
3836
// the fields plus length information for fields with variable lengths (TxID and Payload).
3937
marshaledMsgLenMin = 1 + // TxID length (uint8)
40-
TxIDLenMin + // TxID ([]byte), minimum length of 32 bytes (but may be longer)
4138
8 + // Timestamp (int64)
4239
4 + // Nonce (uint32)
4340
8 + // Sequence (uint64)
@@ -103,7 +100,6 @@ var ErrInputTooLarge = errors.New("input data exceeds maximum allowed size")
103100
var (
104101
ErrBinaryWrite = errors.New("failed to write binary data")
105102
ErrTxIDTooLong = errors.New("field TxID too long")
106-
ErrTxIDTooShort = errors.New("field TxID too short")
107103
ErrInvalidPayload = errors.New("field payload too long")
108104
ErrDataTooShort = errors.New("data too short")
109105
ErrTimestampTooShort = errors.New("data too short for timestamp")
@@ -191,6 +187,8 @@ type MessagePublication struct {
191187
// whose buckets reach quorum at different observation subsets can still
192188
// pick different majorities; recovery for that case is the audit /
193189
// missing_observations reobs flow rather than the delegate-quorum path.
190+
//
191+
// TxID identifies the transaction that emitted this message. There is no minimum length.
194192
TxID []byte
195193
Timestamp time.Time
196194

@@ -357,17 +355,12 @@ func (msg *MessagePublication) MarshalBinary() ([]byte, error) {
357355
return nil, ErrInputSize{Msg: "TxID too long", Want: TxIDSizeMax, Got: txIDLen}
358356
}
359357

360-
if txIDLen < TxIDLenMin {
361-
return nil, ErrInputSize{Msg: "TxID too short", Want: TxIDLenMin, Got: txIDLen}
362-
}
363-
364358
payloadLen := len(msg.Payload)
365359
// Set up for serialization
366360
var (
367361
be = binary.BigEndian
368362
// Size of the buffer needed to hold the serialized message.
369-
// TxIDLenMin is already accounted for in the marshaledMsgLenMin calculation.
370-
bufSize = (marshaledMsgLenMin - TxIDLenMin) + txIDLen + payloadLen
363+
bufSize = marshaledMsgLenMin + txIDLen + payloadLen
371364
buf = make([]byte, 0, bufSize)
372365
)
373366

@@ -528,12 +521,8 @@ func (m *MessagePublication) UnmarshalBinary(data []byte) error {
528521
txIDLen := uint8(data[pos])
529522
pos++
530523

531-
// Bounds checks. TxID length should be at least TxIDLenMin, but not larger than the length of the data.
532-
// The second check is to avoid panics.
533-
if int(txIDLen) < TxIDLenMin {
534-
return ErrInputSize{Msg: "TxID length is too short", Got: int(txIDLen), Want: TxIDLenMin}
535-
}
536-
524+
// Bounds check. TxID length should not be larger than the length of the data.
525+
// This check avoids panics.
537526
if int(txIDLen) > len(data) {
538527
return ErrInputSize{Msg: "TxID length is longer than bytes", Got: int(txIDLen)}
539528
}

node/pkg/common/chainlock_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func TestMessagePublicationUnmarshalBinaryErrors(t *testing.T) {
299299
func FuzzMessagePublicationUnmarshalBinary(f *testing.F) {
300300
// Create a valid message publication for seeding
301301
orig := &MessagePublication{
302-
TxID: make([]byte, TxIDLenMin), // Use minimum valid TxID length
302+
TxID: make([]byte, 32), // 32-byte tx hash (typical Ethereum hash)
303303
Timestamp: time.Unix(int64(1654516425), 0),
304304
Nonce: 123456,
305305
Sequence: 789101112131415,
@@ -349,9 +349,6 @@ func FuzzMessagePublicationUnmarshalBinary(f *testing.F) {
349349
if len(mp.TxID) > 255 {
350350
t.Errorf("TxID length %d exceeds maximum of 255", len(mp.TxID))
351351
}
352-
if len(mp.TxID) < TxIDLenMin && len(mp.TxID) > 0 {
353-
t.Errorf("TxID length %d is less than minimum of %d (unless empty)", len(mp.TxID), TxIDLenMin)
354-
}
355352

356353
// Verify that a successful unmarshal can be marshaled back
357354
_, marshalErr := mp.MarshalBinary()

node/pkg/common/pendingmessage_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ func TestPendingMessage_MarshalError(t *testing.T) {
6969
var (
7070
longTxID = bytes.NewBuffer(make([]byte, math.MaxUint8+1))
7171
)
72-
emitter, err := vaa.StringToAddress("0x707f9118e33a9b8998bea41dd0d46f38bb963fc8")
73-
require.NoError(t, err)
74-
75-
require.NoError(t, err)
7672

7773
tests := []test{
7874
{
@@ -82,22 +78,6 @@ func TestPendingMessage_MarshalError(t *testing.T) {
8278
},
8379
errMsg: "wrong size: TxID too long",
8480
},
85-
{
86-
label: "txID too short",
87-
input: common.MessagePublication{
88-
TxID: []byte{},
89-
Timestamp: time.Unix(int64(1654516425), 0),
90-
Nonce: 123456,
91-
Sequence: 789101112131415,
92-
EmitterChain: vaa.ChainIDEthereum,
93-
EmitterAddress: emitter,
94-
Payload: []byte{},
95-
ConsistencyLevel: 32,
96-
Unreliable: true,
97-
IsReobservation: true,
98-
},
99-
errMsg: "wrong size: TxID too short",
100-
},
10181
}
10282

10383
for _, tc := range tests {

node/pkg/processor/delegate_obs.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ func delegateObservationToMessagePublication(d *gossipv1.DelegateObservation) (*
5959
if txIDLen > TxIDSizeMax {
6060
return nil, fmt.Errorf("delegate observation tx_hash too long: got %d; want at most %d", txIDLen, TxIDSizeMax)
6161
}
62-
if txIDLen < node_common.TxIDLenMin {
63-
return nil, fmt.Errorf("delegate observation tx_hash too short: got %d; want at least %d", txIDLen, node_common.TxIDLenMin)
64-
}
6562

6663
if d.ConsistencyLevel > math.MaxUint8 {
6764
return nil, fmt.Errorf("invalid delegate observation consistency : %d", d.ConsistencyLevel)
@@ -117,9 +114,6 @@ func messagePublicationToDelegateObservation(m *node_common.MessagePublication)
117114
if txIDLen > TxIDSizeMax {
118115
return nil, fmt.Errorf("message publication tx_hash too long: got %d; want at most %d", txIDLen, TxIDSizeMax)
119116
}
120-
if txIDLen < node_common.TxIDLenMin {
121-
return nil, fmt.Errorf("message publication tx_hash too short: got %d; want at least %d", txIDLen, node_common.TxIDLenMin)
122-
}
123117

124118
// Check if payload length is within max message size for p2p
125119
if len(m.Payload) > node_common.DelegatedPayloadLenMax {

0 commit comments

Comments
 (0)