-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add parsigex #291
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
varex83
wants to merge
28
commits into
main
Choose a base branch
from
bohdan/dkg-parsigex
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
feat: add parsigex #291
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1430acc
feat: add deadline.rs
varex83 364977e
feat: deadline tests
varex83 368177c
fix: remove comments
varex83 f4b6893
Merge remote-tracking branch 'origin/main' into bohdan/deadline
varex83 de6dba4
wip: add parasig db and some tests
varex83 d71c885
refactor: remove old app/deadline
varex83 13de57a
feat: add rust docs
varex83 fc85e63
feat: add clone box and clone eq
varex83 5767cc1
Merge branch 'bohdan/update-signeddata-trait' into bohdan/parasigdb
varex83 e214d6f
Merge remote-tracking branch 'origin/main' into bohdan/deadline
varex83 7aced94
Merge branch 'bohdan/deadline' into bohdan/parasigdb
varex83 288f63c
feat: finish tests
varex83 8a3780e
feat: add parsigex [wip]
varex83 a4c4bb2
fix: typo
varex83 1b0711f
Merge branch 'bohdan/parasigdb' into bohdan/dkg-parsigex
varex83 6e9d224
fix: parsigex
varex83 52cbe10
Merge remote-tracking branch 'origin/main' into bohdan/dkg-parsigex
varex83 0247655
refactor: parsigex
varex83 eb5615e
fix: linter
varex83 6d3e20b
feat: add subscribe
varex83agent e643bd1
feat: add documentation for parsigex
varex83 e5f1750
fix: review comments
varex83 b0721f8
fix: review comments
varex83 ac01508
fix: review comments
varex83 b07a460
fix: cargo deny
varex83 0de6cdc
fix: linter
varex83 4a95b0b
Merge remote-tracking branch 'origin/main' into bohdan/dkg-parsigex
varex83 d248c45
fix: remove unused deps
varex83 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
Large diffs are not rendered by default.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| //! Partial signature exchange codec helpers used by core types. | ||
|
|
||
| use std::any::Any; | ||
|
|
||
| use crate::{ | ||
| signeddata::{ | ||
| Attestation, BeaconCommitteeSelection, SignedAggregateAndProof, SignedRandao, | ||
| SignedSyncContributionAndProof, SignedSyncMessage, SignedVoluntaryExit, | ||
| SyncCommitteeSelection, VersionedAttestation, VersionedSignedAggregateAndProof, | ||
| VersionedSignedProposal, VersionedSignedValidatorRegistration, | ||
| }, | ||
| types::{DutyType, Signature, SignedData}, | ||
| }; | ||
|
|
||
| /// Error type for partial signature exchange codec operations. | ||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum ParSigExCodecError { | ||
| /// Missing duty or data set fields. | ||
| #[error("invalid parsigex msg fields")] | ||
| InvalidMessageFields, | ||
|
|
||
| /// Invalid partial signed data set proto. | ||
| #[error("invalid partial signed data set proto fields")] | ||
| InvalidParSignedDataSetFields, | ||
|
|
||
| /// Invalid partial signed proto. | ||
| #[error("invalid partial signed proto")] | ||
| InvalidParSignedProto, | ||
|
varex83 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /// Invalid duty type. | ||
| #[error("invalid duty")] | ||
| InvalidDuty, | ||
|
|
||
| /// Unsupported duty type. | ||
| #[error("unsupported duty type")] | ||
| UnsupportedDutyType, | ||
|
|
||
| /// Deprecated builder proposer duty. | ||
| #[error("deprecated duty builder proposer")] | ||
| DeprecatedBuilderProposer, | ||
|
|
||
| /// Failed to parse a public key. | ||
| #[error("invalid public key: {0}")] | ||
| InvalidPubKey(String), | ||
|
|
||
| /// Invalid share index. | ||
| #[error("invalid share index")] | ||
| InvalidShareIndex, | ||
|
|
||
| /// Serialization failed. | ||
| #[error("marshal signed data: {0}")] | ||
| Serialize(#[from] serde_json::Error), | ||
| } | ||
|
|
||
| pub(crate) fn serialize_signed_data(data: &dyn SignedData) -> Result<Vec<u8>, ParSigExCodecError> { | ||
|
varex83agent marked this conversation as resolved.
varex83 marked this conversation as resolved.
|
||
| let any = data as &dyn Any; | ||
|
|
||
| macro_rules! serialize_as { | ||
| ($ty:ty) => { | ||
| if let Some(value) = any.downcast_ref::<$ty>() { | ||
| return Ok(serde_json::to_vec(value)?); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| serialize_as!(Attestation); | ||
| serialize_as!(VersionedAttestation); | ||
| serialize_as!(VersionedSignedProposal); | ||
| serialize_as!(VersionedSignedValidatorRegistration); | ||
| serialize_as!(SignedVoluntaryExit); | ||
| serialize_as!(SignedRandao); | ||
| serialize_as!(Signature); | ||
| serialize_as!(BeaconCommitteeSelection); | ||
| serialize_as!(SignedAggregateAndProof); | ||
| serialize_as!(VersionedSignedAggregateAndProof); | ||
| serialize_as!(SignedSyncMessage); | ||
| serialize_as!(SyncCommitteeSelection); | ||
| serialize_as!(SignedSyncContributionAndProof); | ||
|
|
||
| Err(ParSigExCodecError::UnsupportedDutyType) | ||
| } | ||
|
|
||
| pub(crate) fn deserialize_signed_data( | ||
| duty_type: &DutyType, | ||
| bytes: &[u8], | ||
| ) -> Result<Box<dyn SignedData>, ParSigExCodecError> { | ||
| macro_rules! deserialize_json { | ||
| ($ty:ty) => { | ||
| serde_json::from_slice::<$ty>(bytes) | ||
| .map(|value| Box::new(value) as Box<dyn SignedData>) | ||
| .map_err(ParSigExCodecError::from) | ||
| }; | ||
| } | ||
|
|
||
| match duty_type { | ||
| // Match Go order: old Attestation format first, then VersionedAttestation. | ||
| DutyType::Attester => deserialize_json!(Attestation) | ||
| .or_else(|_| deserialize_json!(VersionedAttestation)) | ||
| .map_err(|_| ParSigExCodecError::UnsupportedDutyType), | ||
| DutyType::Proposer => deserialize_json!(VersionedSignedProposal), | ||
| DutyType::BuilderProposer => Err(ParSigExCodecError::DeprecatedBuilderProposer), | ||
| DutyType::BuilderRegistration => deserialize_json!(VersionedSignedValidatorRegistration), | ||
| DutyType::Exit => deserialize_json!(SignedVoluntaryExit), | ||
| DutyType::Randao => deserialize_json!(SignedRandao), | ||
| DutyType::Signature => deserialize_json!(Signature), | ||
| DutyType::PrepareAggregator => deserialize_json!(BeaconCommitteeSelection), | ||
| // Match Go order: old SignedAggregateAndProof format first, then versioned. | ||
| DutyType::Aggregator => deserialize_json!(SignedAggregateAndProof) | ||
| .or_else(|_| deserialize_json!(VersionedSignedAggregateAndProof)) | ||
| .map_err(|_| ParSigExCodecError::UnsupportedDutyType), | ||
| DutyType::SyncMessage => deserialize_json!(SignedSyncMessage), | ||
| DutyType::PrepareSyncContribution => deserialize_json!(SyncCommitteeSelection), | ||
| DutyType::SyncContribution => deserialize_json!(SignedSyncContributionAndProof), | ||
| DutyType::Unknown | DutyType::InfoSync | DutyType::DutySentinel(_) => { | ||
|
varex83 marked this conversation as resolved.
Outdated
|
||
| Err(ParSigExCodecError::UnsupportedDutyType) | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
Unused dependencies:
unsigned-varintfutures-timer