Skip to content

Commit

Permalink
fix signature
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds committed Jul 16, 2024
1 parent 0361209 commit 0a44a08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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 is to 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
12 changes: 11 additions & 1 deletion relayer/pkg/chainlink/ocr2/medianreport/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ import (
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
)

func TestTrial(t *testing.T) {
val := "4077890116503514227502940569025930714369419670386493876774642852321317355520"
x, err := big.NewInt(0).SetString(val, 10)
assert.False(t, err)

res1 := x.Cmp(big.NewInt(0))
assert.Equal(t, -1, res1)
}

func TestBuildReportWithNegativeValues(t *testing.T) {
c := ReportCodec{}
oo := []median.ParsedAttributedObservation{}
Expand Down Expand Up @@ -73,7 +82,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

0 comments on commit 0a44a08

Please sign in to comment.