-
Notifications
You must be signed in to change notification settings - Fork 116
feat(CCHAIN-740): Implement validator proof protocol per ADR-006 #1450
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
Open
ancazamfir
wants to merge
15
commits into
circlefin:main
Choose a base branch
from
ancazamfir:validator-proof
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
388762e
Implement validator proof protocol per ADR-006
ancazamfir 61ac08c
Refactor metrics
ancazamfir 9e48ac6
Merge branch 'main' into validator-proof
ancazamfir 3ffc58e
Cargo fmt
ancazamfir cce504e
Make validator proof protocol name configurable
ancazamfir a9e388f
Merge remote-tracking branch 'origin/main' into validator-proof
ancazamfir 5e92652
Add upgrade strategy
ancazamfir 3825987
Fix engine builder merge issues, cleanup
ancazamfir 8dd74c6
Build local nodes's validator proof in the app
ancazamfir e619d73
Fix merge mistake, update docs
ancazamfir 1522054
More cleanup after merge
ancazamfir 6f15d32
Send the proof on start and don't wait for first height
ancazamfir 05d60bc
Don't disconnect on codec failures, update docs
ancazamfir 86cbd61
Merge branch 'main' into validator-proof
ancazamfir b1e5552
Cleanup after merge
ancazamfir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //! Validator Proof type for the Proof-of-Validator protocol. | ||
|
|
||
| use alloc::vec::Vec; | ||
| use derive_where::derive_where; | ||
|
|
||
| use crate::{Context, Signature}; | ||
|
|
||
| /// Separator bytes for Proof-of-Validator signatures. | ||
| /// The 3-byte ASCII string "PoV" (0x50 0x6F 0x56). | ||
| const POV_SEPARATOR: &[u8] = b"PoV"; | ||
|
|
||
| /// A proof that a libp2p peer ID is controlled by a validator. | ||
| /// | ||
| /// This allows nodes to cryptographically verify that a peer claiming to be | ||
| /// a validator actually controls the corresponding consensus private key. | ||
| /// | ||
| /// The proof binds a libp2p peer ID to a consensus public key, | ||
| /// signed by the corresponding consensus private key. This allows immediate | ||
| /// signature verification without needing to look up the public key from the | ||
| /// validator set. | ||
| #[derive_where(Clone, Debug, PartialEq, Eq)] | ||
| pub struct ValidatorProof<Ctx: Context> { | ||
| /// The validator's consensus public key (raw bytes) | ||
| pub public_key: Vec<u8>, | ||
| /// The libp2p peer ID bytes | ||
| pub peer_id: Vec<u8>, | ||
| /// Signature over (public_key, peer_id) using the validator's consensus key | ||
| pub signature: Signature<Ctx>, | ||
| } | ||
|
|
||
| impl<Ctx: Context> ValidatorProof<Ctx> { | ||
| /// Creates a new `ValidatorProof`. | ||
| pub fn new(public_key: Vec<u8>, peer_id: Vec<u8>, signature: Signature<Ctx>) -> Self { | ||
| Self { | ||
| public_key, | ||
| peer_id, | ||
| signature, | ||
| } | ||
| } | ||
|
|
||
| /// Returns the bytes to be signed for this proof. | ||
| /// | ||
| /// Format: SEPARATOR || len(public_key) || public_key || len(peer_id) || peer_id | ||
| /// | ||
| /// Where: | ||
| /// - SEPARATOR is "PoV" (0x50 0x6F 0x56) | ||
| /// - len() is encoded as 4 bytes (u32 big-endian) | ||
| pub fn signing_bytes(public_key: &[u8], peer_id: &[u8]) -> Vec<u8> { | ||
| let mut bytes = | ||
| Vec::with_capacity(POV_SEPARATOR.len() + 4 + public_key.len() + 4 + peer_id.len()); | ||
| bytes.extend_from_slice(POV_SEPARATOR); | ||
| bytes.extend_from_slice(&(public_key.len() as u32).to_be_bytes()); | ||
| bytes.extend_from_slice(public_key); | ||
| bytes.extend_from_slice(&(peer_id.len() as u32).to_be_bytes()); | ||
| bytes.extend_from_slice(peer_id); | ||
| bytes | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just familiarizing myself with the ADR and this implementation: Do we need to version this data type? Seems to go through the wire unversioned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently I use the same approach as for sync and consensus, using protocol names that have version in their names. Haven't added it to defaults yet. But if two nodes use different versions, streams will not be established.
Currently hardcoded with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cce504e