From dd3f7ef177eec49c2705b7721e27383c43e8c0e9 Mon Sep 17 00:00:00 2001 From: ImJeremyHe Date: Tue, 17 Dec 2024 17:58:17 +0800 Subject: [PATCH] Rename --- arbnode/espresso_utils.go | 25 ++++++++++++++----------- arbnode/espresso_utils_test.go | 8 ++------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/arbnode/espresso_utils.go b/arbnode/espresso_utils.go index 94f01886e4..3e0c7c2db3 100644 --- a/arbnode/espresso_utils.go +++ b/arbnode/espresso_utils.go @@ -78,21 +78,21 @@ func validateIfPayloadIsInBlock(p []byte, payloads []espressoTypes.Bytes) bool { return validated } -func ParsePayload(rawPayload []byte) (signature []byte, indices []uint64, messages [][]byte, err error) { - if len(rawPayload) < LEN_SIZE { +func ParseHotShotPayload(payload []byte) (signature []byte, indices []uint64, messages [][]byte, err error) { + if len(payload) < LEN_SIZE { return nil, nil, nil, errors.New("payload too short to parse signature size") } // Extract the signature size - signatureSize := binary.BigEndian.Uint64(rawPayload[:LEN_SIZE]) + signatureSize := binary.BigEndian.Uint64(payload[:LEN_SIZE]) currentPos := LEN_SIZE - if len(rawPayload[currentPos:]) < int(signatureSize) { + if len(payload[currentPos:]) < int(signatureSize) { return nil, nil, nil, errors.New("payload too short for signature") } // Extract the signature - signature = rawPayload[currentPos : currentPos+int(signatureSize)] + signature = payload[currentPos : currentPos+int(signatureSize)] currentPos += int(signatureSize) indices = []uint64{} @@ -100,24 +100,27 @@ func ParsePayload(rawPayload []byte) (signature []byte, indices []uint64, messag // Parse messages for { - if len(rawPayload[currentPos:]) < LEN_SIZE+INDEX_SIZE { - break // No more messages to parse + if currentPos == len(payload)-1 { + break + } + if len(payload[currentPos:]) < LEN_SIZE+INDEX_SIZE { + return nil, nil, nil, errors.New("message size mismatch") } // Extract the index - index := binary.BigEndian.Uint64(rawPayload[currentPos : currentPos+INDEX_SIZE]) + index := binary.BigEndian.Uint64(payload[currentPos : currentPos+INDEX_SIZE]) currentPos += INDEX_SIZE // Extract the message size - messageSize := binary.BigEndian.Uint64(rawPayload[currentPos : currentPos+LEN_SIZE]) + messageSize := binary.BigEndian.Uint64(payload[currentPos : currentPos+LEN_SIZE]) currentPos += LEN_SIZE - if len(rawPayload[currentPos:]) < int(messageSize) { + if len(payload[currentPos:]) < int(messageSize) { return nil, nil, nil, errors.New("message size mismatch") } // Extract the message - message := rawPayload[currentPos : currentPos+int(messageSize)] + message := payload[currentPos : currentPos+int(messageSize)] currentPos += int(messageSize) indices = append(indices, index) diff --git a/arbnode/espresso_utils_test.go b/arbnode/espresso_utils_test.go index 1bd476ab4f..d91ca10e3b 100644 --- a/arbnode/espresso_utils_test.go +++ b/arbnode/espresso_utils_test.go @@ -32,7 +32,7 @@ func TestParsePayload(t *testing.T) { } // Parse the signed payload - signature, indices, messages, err := ParsePayload(signedPayload) + signature, indices, messages, err := ParseHotShotPayload(signedPayload) if err != nil { t.Fatalf("failed to parse payload: %v", err) } @@ -98,10 +98,6 @@ func TestParsePayloadInvalidCases(t *testing.T) { description: "Empty payload", payload: []byte{}, }, - { - description: "Signature size exceeds payload", - payload: append(make([]byte, 8), []byte("short")...), - }, { description: "Message size exceeds remaining payload", payload: func() []byte { @@ -119,7 +115,7 @@ func TestParsePayloadInvalidCases(t *testing.T) { for _, tc := range invalidPayloads { t.Run(tc.description, func(t *testing.T) { - _, _, _, err := ParsePayload(tc.payload) + _, _, _, err := ParseHotShotPayload(tc.payload) if err == nil { t.Errorf("expected error for case '%s', but got none", tc.description) }