smartcontractkit / smartcontractkit/chainlink-starknet
Add a fuzz test for Sign+Verify
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 60
- Forks
- 31
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 2
Description
I attempted to do this, but in https://github.com/smartcontractkit/chainlink-starknet/pull/163 but it's hard to filter out invalid reports. We'd need to run SplitFelt on the report and validate that each segment is a valid felt.
//go:build go1.18
// +build go1.18
package keys
import (
cryptorand "crypto/rand"
"encoding/hex"
"testing"
"github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/ocr2/medianreport"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"
"github.com/stretchr/testify/require"
)
// go test -tags=go1.18 -fuzz ./...
func FuzzStarkNetKeyring_Sign_Verify(f *testing.F) {
kr1, err := NewOCR2Key(cryptorand.Reader)
require.NoError(f, err)
kr2, err := NewOCR2Key(cryptorand.Reader)
require.NoError(f, err)
digest := "00044e5d4f35325e464c87374b13c512f60e09d1236dd902f4bef4c9aedd7300"
bytes, err := hex.DecodeString(digest)
require.NoError(f, err)
configDigest, err := ocrtypes.BytesToConfigDigest(bytes)
require.NoError(f, err)
ctx := ocrtypes.ReportContext{
ReportTimestamp: ocrtypes.ReportTimestamp{
ConfigDigest: configDigest,
Epoch: 1,
Round: 1,
},
ExtraHash: [32]byte{
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
},
}
report := ocrtypes.Report{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 91, 43, 83, // observations_timestamp
0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // observers
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, // len
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 150, 2, 210, // observation 1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73, 150, 2, 211, // observation 2
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 224, 182, 179, 167, 100, 0, 0, // juels per fee coin (1 with 18 decimal places)
}
// Seed with valid report
f.Add([]byte(report))
f.Fuzz(func(t *testing.T, report []byte) {
cdc := medianreport.ReportCodec{}
// skip invalid reports
if _, err := cdc.MedianFromReport(report); err != nil {
t.Skip()
}
if _, err := ReportToSigData(ctx, report); err != nil {
t.Skip()
}
sig, err := kr1.Sign(ctx, report)
require.NoError(t, err)
result := kr2.Verify(kr1.PublicKey(), ctx, report, sig)
require.True(t, result)
})
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the keys package with FuzzStarkNetKeyring_Sign_Verify, ReportToSigData, Sign, and Verify, then inspect medianreport.ReportCodec.MedianFromReport and SplitFelt. Run the fuzz command shown in the issue. Done means valid reports are filtered by felt-segment validation and valid inputs consistently sign and verify successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cryptography, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100