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

CCIP-4710: Adding nil and length check on input value to Ed25519 verify call #400

Merged
merged 4 commits into from
Dec 20, 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
16 changes: 10 additions & 6 deletions commit/merkleroot/rmn/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,11 @@ func TestClient_ComputeReportSignatures(t *testing.T) {
const numNodes = 8
rmnNodes := make([]rmntypes.HomeNodeInfo, numNodes)
for i := 0; i < numNodes; i++ {
// deterministically create a public key by seeding with a 32char string.
publicKey, _, err := ed25519.GenerateKey(
strings.NewReader(strconv.Itoa(i) + strings.Repeat("x", 31)))
require.NoError(t, err)
rmnNodes[i] = rmntypes.HomeNodeInfo{
ID: rmntypes.NodeID(i + 1),
PeerID: [32]byte{1, 2, 3},
SupportedSourceChains: mapset.NewSet(chainS1, chainS2),
OffchainPublicKey: &publicKey,
OffchainPublicKey: getDeterministicPubKey(t),
}
}

Expand Down Expand Up @@ -648,7 +644,7 @@ func Test_controller_validateSignedObservationResponse(t *testing.T) {
{
ID: 20,
SupportedSourceChains: mapset.NewSet[cciptypes.ChainSelector](cciptypes.ChainSelector(2)),
OffchainPublicKey: &ed25519.PublicKey{},
OffchainPublicKey: getDeterministicPubKey(t),
},
},
},
Expand Down Expand Up @@ -743,6 +739,14 @@ func Test_newRequestID(t *testing.T) {
}
}

func getDeterministicPubKey(t *testing.T) *ed25519.PublicKey {
// deterministically create a public key by seeding with a 32char string.
publicKey, _, err := ed25519.GenerateKey(
strings.NewReader(strconv.Itoa(1) + strings.Repeat("x", 31)))
require.NoError(t, err)
return &publicKey
}

func (ts *testSetup) waitForObservationRequestsToBeSent(
rmnClient *mockPeerClient,
homeF int,
Expand Down
6 changes: 6 additions & 0 deletions commit/merkleroot/rmn/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func verifyObservationSignature(
msg := append([]byte(signedObservationPrefix), observationBytesSha256[:]...)
msgSha256 := sha256.Sum256(msg)

if rmnNode.OffchainPublicKey == nil {
return fmt.Errorf("node %d has no offchain public key", rmnNode.ID)
}
if len(*rmnNode.OffchainPublicKey) != ed25519.PublicKeySize {
return fmt.Errorf("node %d has an invalid offchain public key", rmnNode.ID)
}
Comment on lines +50 to +55
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the key changes. As OffchainPublicKey is required, test needs to be updated.

isValid := verifier.Verify(*rmnNode.OffchainPublicKey, msgSha256[:], signedObs.Signature)
if !isValid {
return fmt.Errorf("observation signature does not match node %d public key", rmnNode.ID)
Expand Down
Loading