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

fix signature #491

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 13 additions & 1 deletion relayer/pkg/chainlink/ocr2/medianreport/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sort"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/curve"
starknetutils "github.com/NethermindEth/starknet.go/utils"

"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
Expand Down Expand Up @@ -74,13 +75,24 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types

var observers = make([]byte, starknet.FeltLength)
var observations []*felt.Felt

for i, o := range oo {
observers[i] = byte(o.Observer)
// encoding scheme is offset by 1 byte to avoid felt overflow
// [0x0, <1_ID>, <2_ID>, ..., <N_ID>, 0x0, 0x0, ..., 0x0]
// note: this does not alter Starknet's MAX_ORACLES (31)
// to differentiate this encoding scheme from the original encoding scheme, check if, within the first N + 1 bytes, 0 occurs twice
// where N is the number of oracles in the DON
observers[i+1] = byte(o.Observer)

f := starknetutils.BigIntToFelt(o.Value)
observations = append(observations, f)
}

observersBig := starknetutils.BytesToBig(observers)
if observersBig.Cmp(curve.Curve.P) != -1 {
return nil, fmt.Errorf("invalid observers value: %v is larger than size of finite field", observersBig)
}

var report []byte

buf := timestampFelt.Bytes()
Expand Down
3 changes: 2 additions & 1 deletion relayer/pkg/chainlink/ocr2/medianreport/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func TestBuildReport(t *testing.T) {
})

// create expected outputs
observers[i] = uint8(i)
// remember to add 1 byte offset to avoid felt overflow
observers[i+1] = uint8(i)
}

report, err := c.BuildReport(oo)
Expand Down
Loading