From e917b5a12468fb60e1b0bf811655e17f147860a8 Mon Sep 17 00:00:00 2001 From: axaysagathiya Date: Sun, 15 Sep 2024 11:47:37 +0530 Subject: [PATCH] reviews address --- dot/parachain/backing/integration_test.go | 6 ++--- dot/parachain/types/statement.go | 33 ++++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/dot/parachain/backing/integration_test.go b/dot/parachain/backing/integration_test.go index a0192e4e20..2066acef9c 100644 --- a/dot/parachain/backing/integration_test.go +++ b/dot/parachain/backing/integration_test.go @@ -1181,11 +1181,11 @@ func TestConflictingStatementIsMisbehavior(t *testing.T) { } require.Equal(t, relayParent, provisionerMessage.RelayParent) - misbehvaiorReport, ok := provisionerMessage.ProvisionableData.(parachaintypes.ProvisionableDataMisbehaviorReport) + misbehaviorReport, ok := provisionerMessage.ProvisionableData.(parachaintypes.ProvisionableDataMisbehaviorReport) require.True(t, ok) - require.Equal(t, parachaintypes.ValidatorIndex(2), misbehvaiorReport.ValidatorIndex) - doubleVote, ok := misbehvaiorReport.Misbehaviour.(parachaintypes.ValidityDoubleVoteIssuedAndValidity) + require.Equal(t, parachaintypes.ValidatorIndex(2), misbehaviorReport.ValidatorIndex) + doubleVote, ok := misbehaviorReport.Misbehaviour.(parachaintypes.ValidityDoubleVoteIssuedAndValidity) require.True(t, ok) signForSeconded := doubleVote.CommittedCandidateReceiptAndSign.Signature diff --git a/dot/parachain/types/statement.go b/dot/parachain/types/statement.go index 1627393a8b..aade035f4b 100644 --- a/dot/parachain/types/statement.go +++ b/dot/parachain/types/statement.go @@ -80,23 +80,27 @@ type Seconded CommittedCandidateReceipt // Valid represents a statement that a validator has deemed a candidate valid. type Valid CandidateHash +// statementVDTAndSigningContext is just a wrapper struct to hold both the statement and the signing context. +type statementVDTAndSigningContext struct { + Statement StatementVDT + Context SigningContext +} + func (s *StatementVDT) Sign( keystore keystore.Keystore, signingContext SigningContext, key ValidatorID, ) (*ValidatorSignature, error) { - encodedData, err := scale.Marshal(*s) - if err != nil { - return nil, fmt.Errorf("marshalling payload: %w", err) + statementVDTAndSigningContext := statementVDTAndSigningContext{ + Statement: *s, + Context: signingContext, } - encodedSigningContext, err := scale.Marshal(signingContext) + encodedData, err := scale.Marshal(statementVDTAndSigningContext) if err != nil { - return nil, fmt.Errorf("marshalling signing context: %w", err) + return nil, fmt.Errorf("marshalling statement and signing-context: %w", err) } - encodedData = append(encodedData, encodedSigningContext...) - validatorPublicKey, err := sr25519.NewPublicKey(key[:]) if err != nil { return nil, fmt.Errorf("getting public key: %w", err) @@ -119,25 +123,22 @@ func (s *StatementVDT) VerifySignature( signingContext SigningContext, validatorSignature ValidatorSignature, ) (bool, error) { - encodedMsg, err := scale.Marshal(s) - if err != nil { - return false, fmt.Errorf("marshalling statementVDT: %w", err) + statementVDTAndSigningContext := statementVDTAndSigningContext{ + Statement: *s, + Context: signingContext, } - signingContextBytes, err := scale.Marshal(signingContext) + encodedMsg, err := scale.Marshal(statementVDTAndSigningContext) if err != nil { - return false, fmt.Errorf("marshalling signing context: %w", err) + return false, fmt.Errorf("marshalling statement and signing-context: %w", err) } - encodedMsg = append(encodedMsg, signingContextBytes...) - publicKey, err := sr25519.NewPublicKey(validator[:]) if err != nil { return false, fmt.Errorf("getting public key: %w", err) } - ok, err := publicKey.Verify(encodedMsg, validatorSignature[:]) - return ok, err + return publicKey.Verify(encodedMsg, validatorSignature[:]) } // UncheckedSignedFullStatement is a Variant of `SignedFullStatement` where the signature has not yet been verified.