Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KS-411] Extra validation for FeedIDs in Streams Codec #14038

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/capabilities/streams/codec.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package streams

import (
"encoding/hex"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -34,6 +35,9 @@ func (c *codec) Unwrap(wrapped values.Value) ([]datastreams.FeedReport, error) {
if err2 != nil {
return nil, fmt.Errorf("failed to decode: %v", err2)
}
if decoded.FeedId != id.Bytes() {
return nil, fmt.Errorf("feed ID mismatch: FeedID: %s, FullReport.FeedId: %s", id, hex.EncodeToString(decoded.FeedId[:]))
}
dest[i].BenchmarkPrice = decoded.BenchmarkPrice.Bytes()
dest[i].ObservationTimestamp = int64(decoded.ObservationsTimestamp)
}
Expand Down
16 changes: 15 additions & 1 deletion core/capabilities/streams/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestCodec_WrapUnwrap(t *testing.T) {
_, err = codec.Unwrap(values.NewBool(true))
require.Error(t, err)

// correct reports byt wrong signatures
// correct reports but wrong signatures
unwrapped, err := codec.Unwrap(wrapped)
require.NoError(t, err)
require.Equal(t, 2, len(unwrapped))
Expand All @@ -85,6 +85,20 @@ func TestCodec_WrapUnwrap(t *testing.T) {
for _, report := range unwrapped {
require.NoError(t, codec.Validate(report, allowedSigners, 2))
}

// invalid FeedID
wrappedInvalid, err := codec.Wrap([]datastreams.FeedReport{
{
FeedID: id2Str, // ID #2 doesn't match what's in report #1
FullReport: report1,
ReportContext: rawCtx,
Signatures: [][]byte{signatureK1R1, signatureK2R1},
},
})
require.NoError(t, err)
_, err = codec.Unwrap(wrappedInvalid)
require.Error(t, err)
require.Contains(t, err.Error(), "feed ID mismatch")
}

func newFeedID(t *testing.T) ([32]byte, string) {
Expand Down
Loading