Skip to content

Comments

Signature verification#215

Merged
dknopik merged 14 commits intosigp:unstablefrom
diegomrsantos:signature-verification
Apr 3, 2025
Merged

Signature verification#215
dknopik merged 14 commits intosigp:unstablefrom
diegomrsantos:signature-verification

Conversation

@diegomrsantos
Copy link
Member

@diegomrsantos diegomrsantos commented Mar 28, 2025

Issue Addressed

#161

Proposed Changes

This pull request adds signature verification and refactors the validation logic by introducing a centralized ValidationContext and updates several message validation functions and tests to use this new context. Key changes include:

  • Replacing multiple function parameters with a single ValidationContext struct in partial signature and consensus message verification.
  • Integrating OpenSSL-based signature verification into the validation flows.
  • Updating tests to reflect the new ValidationContext usage and enhanced signature verification.

@diegomrsantos diegomrsantos force-pushed the signature-verification branch 3 times, most recently from 1a02e0e to 25b3396 Compare March 28, 2025 17:42
@diegomrsantos diegomrsantos force-pushed the signature-verification branch from 25b3396 to 0e59810 Compare March 31, 2025 14:34
@diegomrsantos diegomrsantos self-assigned this Apr 1, 2025
@diegomrsantos diegomrsantos requested a review from Copilot April 1, 2025 08:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the SSV message validation flow by introducing a new ValidationContext and integrating signature verification using OpenSSL. Key changes include:

  • Replacing multiple function parameters with a unified ValidationContext across validation functions.
  • Adding signature verification logic using OpenSSL in the consensus message validation.
  • Updating tests and documentation to align with the new ValidationContext approach.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
anchor/message_validator/src/partial_signature.rs Refactored usage of parameters to use ValidationContext in partial signature validation.
anchor/message_validator/src/lib.rs Introduced the ValidationContext struct and updated operator public key retrieval.
anchor/message_validator/src/consensus_state.rs Enhanced documentation and minor refactoring in operator and signer state handling.
anchor/message_validator/src/consensus_message.rs Integrated ValidationContext into consensus message validation and added signature verification using OpenSSL.
anchor/message_validator/Cargo.toml Added OpenSSL dependency and cleaned up dev-dependencies.
Comments suppressed due to low confidence (2)

anchor/message_validator/src/consensus_state.rs:205

  • Review the use of 'into()' on the slice of OperatorId; ensure that the conversion to the type used in 'seen_signers' is correct and functions as expected.
self.seen_signers.contains(&operators.into())

anchor/message_validator/src/consensus_message.rs:267

  • [nitpick] Consider aligning the naming of the parameter 'operators_pks' with the field 'operators_pk' in ValidationContext for consistency.
if signatures.len() != operators_pks.len() {

@diegomrsantos diegomrsantos force-pushed the signature-verification branch from d7f0caa to ec34b0f Compare April 1, 2025 14:24
diegomrsantos and others added 4 commits April 1, 2025 16:33
# Conflicts:
#	anchor/client/src/config.rs
#	anchor/message_validator/src/consensus_message.rs
#	anchor/message_validator/src/consensus_state.rs
#	anchor/message_validator/src/lib.rs
#	anchor/message_validator/src/partial_signature.rs
#	anchor/network/src/network.rs
#	anchor/validator_store/src/lib.rs
@diegomrsantos diegomrsantos marked this pull request as ready for review April 1, 2025 16:50
@diegomrsantos diegomrsantos requested a review from Copilot April 1, 2025 16:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the signature verification logic by introducing a centralized ValidationContext and updates several message validation functions and tests to use this new context. Key changes include:

  • Replacing multiple function parameters with a single ValidationContext struct in partial signature and consensus message verification.
  • Integrating OpenSSL-based signature verification into the validation flows.
  • Updating tests to reflect the new ValidationContext usage and enhanced signature verification.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
anchor/message_validator/src/partial_signature.rs Refactored validation functions to use the new ValidationContext.
anchor/message_validator/src/lib.rs Introduced helper functions for signature verification using OpenSSL.
anchor/message_validator/src/consensus_state.rs Updated documentation and minor code improvements.
anchor/message_validator/src/consensus_message.rs Updated consensus message validation to use ValidationContext; added signature verification.
anchor/message_validator/Cargo.toml Added OpenSSL dependency and removed unused dev-dependencies.
Comments suppressed due to low confidence (1)

anchor/message_validator/src/lib.rs:363

  • Consider including additional context, such as the operator ID if available, in the 'Signature verification failed' error message to assist in debugging.
        Ok(false) => Err(ValidationFailure::SignatureVerificationFailed {

Copy link
Member

@Zacholme7 Zacholme7 left a comment

Choose a reason for hiding this comment

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

small comments, otherwise looking good!

Processor(#[from] ::processor::Error),
}

struct ValidationContext<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

Are the borrows here just to reduce some clone overheads?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly, wdyt?

}
}

fn get_operator_pks(
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would probably extract this into a function in state.rs instead of keeping it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

why? It's not related to the consensus state

Copy link
Member

Choose a reason for hiding this comment

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

I meant state.rs in the database as this function deals with fetching state. But if this is the only place this is needed then there is not much point in moving it I suppose

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, yeah it's used only here

signed_ssv_message: &SignedSSVMessage,
committee_info: &CommitteeInfo,
role: Role,
validation_context: &ValidationContext,
Copy link
Member

Choose a reason for hiding this comment

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

I like that the ValidationContext borrows its contents, but borrowing again here basically creates a double indirection. Wdyt about passing the context by value?

Copy link
Member

Choose a reason for hiding this comment

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

Or, alternatively, having the Context own the values and passing around a reference, which is maybe even better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! But if it owns the values, we'll have to copy it when creating the struct. Is it necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Moving the values once might have better performance than having one additional level of pointer indirection during the whole of validation. But I don't know. We can also go ahead with my first suggestion if you prefer that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I remember that the reason I passed it as a ref is to avoid it being moved. Doesn't the compiler optimize away the indirections?

Copy link
Member

Choose a reason for hiding this comment

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

How would it?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I move it to a function, it can't be used anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, you mean the indirections. The contents of the struct aren’t mutated anywhere, so there’s no reason to keep loading them from memory many times.

@diegomrsantos diegomrsantos added the ready-for-review This PR is ready to be reviewed label Apr 2, 2025
@diegomrsantos
Copy link
Member Author

@dknopik @Zacholme7 is there anything pending?

@dknopik
Copy link
Member

dknopik commented Apr 2, 2025

Gonna test it on interop tomorrow, after that I think we are good to go imo

Copy link
Member

@dknopik dknopik left a comment

Choose a reason for hiding this comment

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

lgtm

@dknopik dknopik merged commit 1c495f7 into sigp:unstable Apr 3, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review This PR is ready to be reviewed validation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants