Skip to content

Commit ac159a8

Browse files
authored
feat: add legacy locks support (#24)
* feat: setup initial project structure * feat: update CI to use nightly toolchain for rustfmt * feat: update CI to use nightly toolchain for rustfmt * fix: fmt * refactor: reorganize workspace members and remove charon-types crate * feat: add core types and dependencies for Charon * feat: add is_valid method and tests for DutyType * feat: enhance Charon core types with new methods and error handling for PubKey * chore: remove unused proptest dependency from workspace * feat: implement Default trait for UnsignedDataSet, ParSignedDataSet, and SignedDataSet * refactor: update PubKey methods for improved error handling and add try_from implementation * docs: clarify slot duration comment and add debug prints for PubKey serialization/deserialization tests * fix: remove unnecessary println * feat: add tbls crypto boilerplate * feat: add initial implementation of tbls * feat: add tests for the bls implementation * feat: init structure of charon-cluster * feat: integrate blsful implementation and refactor tbls module - Added `thiserror` dependency for improved error handling. - Introduced `blsful` module for TBLS implementation. - Refactored `tbls` module to utilize new types and error handling. - Created `tblsconv` module for type conversions between byte slices and cryptographic types. - Removed the old `herumi` implementation and replaced it with the new `blsful` based implementation. - Added utility functions for key and signature conversions. - Updated types and error definitions for better clarity and consistency. * style: improve code formatting and documentation in tblsconv module - Reformatted comments for better readability. - Adjusted spacing and alignment in error messages for consistency. - Ensured clarity in documentation regarding expected byte lengths for key and signature conversions. * chore: clean up Cargo.toml by removing duplicate dependencies and organizing workspace lints * chore: update Cargo.lock with new dependencies and versions * chore: fix clippy warnings * chore: apply fmt * refactor: replace blsful implementation with blst for threshold BLS signatures - Updated dependencies in Cargo.toml and Cargo.lock to use the blst library. - Removed blsful module and its associated code, including type conversions and utility functions. - Introduced a new blst_impl module for the BLST implementation of threshold BLS signatures. - Refactored tbls module to utilize the new blst implementation. - Cleaned up error handling and types to align with the new library. - Added workspace lints and improved documentation throughout the codebase. * fix: add protoc to workflow files * fix: add ignore files to typos config * feat: add support for cluster definition v1.10.0 * feat: add cluster lock v1.10.0 support * feat: add support for legacy cluster definitions * fix: linter errors * feat: add legacy locks support * fix: linter warnings
1 parent 45efaef commit ac159a8

7 files changed

Lines changed: 770 additions & 114 deletions

File tree

crates/charon-cluster/src/definition.rs

Lines changed: 76 additions & 76 deletions
Large diffs are not rendered by default.

crates/charon-cluster/src/deposit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ use serde_with::{DisplayFromStr, serde_as};
55
/// DepositData defines the deposit data to activate a validator.
66
/// https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#depositdata
77
#[serde_as]
8-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
99
pub struct DepositData {
10-
/// PubKey is the validator's public key.
10+
/// Validator's public key.
1111
#[serde_as(as = "EthHex")]
1212
#[serde(rename = "pubkey")]
1313
pub pub_key: Vec<u8>,
1414

15-
/// WithdrawalCredentials included in the deposit.
15+
/// Withdrawal credentials included in the deposit.
1616
#[serde_as(as = "EthHex")]
1717
pub withdrawal_credentials: Vec<u8>,
1818

19-
/// Amount is the amount in Gwei to be deposited [1ETH..2048ETH].
19+
/// Amount in Gwei to be deposited [1ETH..2048ETH].
2020
/// We use DisplayFromStr to allow for easy conversion from string to u64.
2121
#[serde_as(as = "DisplayFromStr")]
2222
pub amount: u64,

crates/charon-cluster/src/distvalidator.rs

Lines changed: 244 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@ use charon_crypto::types::{PUBLIC_KEY_LENGTH, PublicKey};
22
use serde::{Deserialize, Serialize};
33

44
use crate::{deposit::DepositData, helpers::EthHex, registration::BuilderRegistration};
5-
use serde_with::serde_as;
5+
use serde_with::{
6+
base64::{Base64, Standard},
7+
serde_as,
8+
};
69

710
/// DistValidator is a distributed validator managed by the cluster.
811
#[serde_as]
912
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
1013
pub struct DistValidator {
11-
/// PubKey is the distributed validator group public key.
14+
/// Distributed validator group public key.
1215
#[serde(rename = "distributed_public_key")]
1316
#[serde_as(as = "EthHex")]
1417
pub pub_key: Vec<u8>,
1518

16-
/// PubShares are the public keys corresponding to each node's secret key
17-
/// share. It can be used to verify a partial signature created by any
18-
/// node in the cluster.
19+
/// Public shares are the public keys corresponding to each node's secret
20+
/// key share. It can be used to verify a partial signature created by
21+
/// any node in the cluster.
1922
#[serde(rename = "public_shares")]
2023
#[serde_as(as = "Vec<EthHex>")]
2124
pub pub_shares: Vec<Vec<u8>>,
2225

23-
/// PartialDepositData is the list of partial deposit data.
26+
/// Partial deposit data is the list of partial deposit data.
2427
pub partial_deposit_data: Vec<DepositData>,
2528

26-
/// BuilderRegistration is the pre-generated signed validator builder
29+
/// Builder registration is the pre-generated signed validator builder
2730
/// registration.
2831
pub builder_registration: BuilderRegistration,
2932
}
@@ -40,7 +43,7 @@ pub enum DistValidatorError {
4043
}
4144

4245
impl DistValidator {
43-
/// PublicKey returns the distributed validator group public key.
46+
/// Distributed validator group public key.
4447
pub fn public_key(&self) -> Result<PublicKey, DistValidatorError> {
4548
if self.pub_key.len() != PUBLIC_KEY_LENGTH {
4649
return Err(DistValidatorError::InvalidPublicKeyLength(
@@ -53,13 +56,13 @@ impl DistValidator {
5356
Ok(pub_key)
5457
}
5558

56-
/// PublicKeyHex returns the validator hex group public key.
59+
/// Validator hex group public key.
5760
pub fn public_key_hex(&self) -> Result<String, DistValidatorError> {
5861
let pub_key = self.public_key()?;
5962
Ok(format!("0x{}", hex::encode(pub_key)))
6063
}
6164

62-
/// PublicShare returns a peer's threshold BLS public share.
65+
/// Peer's threshold BLS public share.
6366
pub fn public_share(&self, index: usize) -> Result<PublicKey, DistValidatorError> {
6467
if index >= self.pub_shares.len() {
6568
return Err(DistValidatorError::InvalidPublicShareIndex(
@@ -78,7 +81,7 @@ impl DistValidator {
7881
Ok(pub_share)
7982
}
8083

81-
/// ZeroRegistration returns a true if the validator has zero valued
84+
/// True if the validator has zero valued registration.
8285
/// registration.
8386
pub fn zero_registration(&self) -> bool {
8487
self.builder_registration.signature.is_empty()
@@ -88,10 +91,239 @@ impl DistValidator {
8891
&& self.builder_registration.message.pub_key.is_empty()
8992
}
9093

91-
/// Eth2Registration returns the validator's Eth2 registration.
94+
/// Validator's Eth2 registration.
9295
pub fn eth2_registration(&self) -> Result<(), DistValidatorError> {
9396
unimplemented!(
9497
"Eth2 registration requires to have ethereum types library which is not yet integrated in charon-cluster"
9598
)
9699
}
97100
}
101+
102+
/// DistValidatorV1x1 is a distributed validator managed by the cluster for
103+
/// version v1.0.0 or v1.1.0.
104+
#[serde_as]
105+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
106+
pub struct DistValidatorV1x0or1 {
107+
/// Distributed validator group public key.
108+
#[serde(rename = "distributed_public_key")]
109+
#[serde_as(as = "EthHex")]
110+
pub pub_key: Vec<u8>,
111+
112+
/// Public shares are the public keys corresponding to each node's secret
113+
/// key share. It can be used to verify a partial signature created by
114+
/// any node in the cluster.
115+
#[serde(rename = "public_shares")]
116+
#[serde_as(as = "Vec<Base64<Standard>>")]
117+
pub pub_shares: Vec<Vec<u8>>,
118+
119+
/// Fee recipient address for the validator.
120+
#[serde(default)]
121+
#[serde_as(as = "EthHex")]
122+
pub fee_recipient_address: Vec<u8>,
123+
}
124+
125+
impl From<DistValidator> for DistValidatorV1x0or1 {
126+
fn from(dist_validator: DistValidator) -> Self {
127+
Self {
128+
pub_key: dist_validator.pub_key,
129+
pub_shares: dist_validator.pub_shares,
130+
fee_recipient_address: Default::default(),
131+
}
132+
}
133+
}
134+
135+
impl From<DistValidatorV1x0or1> for DistValidator {
136+
fn from(dist_validator: DistValidatorV1x0or1) -> Self {
137+
Self {
138+
pub_key: dist_validator.pub_key,
139+
pub_shares: dist_validator.pub_shares,
140+
partial_deposit_data: Vec::new(),
141+
builder_registration: BuilderRegistration::default(),
142+
}
143+
}
144+
}
145+
/// DistValidatorV1x2to5 is a distributed validator managed by the cluster for
146+
/// version v1.2.0 to v1.5.0.
147+
#[serde_as]
148+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
149+
pub struct DistValidatorV1x2to5 {
150+
/// Distributed validator group public key.
151+
#[serde(rename = "distributed_public_key")]
152+
#[serde_as(as = "EthHex")]
153+
pub pub_key: Vec<u8>,
154+
155+
/// Public shares are the public keys corresponding to each node's secret
156+
/// key share. It can be used to verify a partial signature created by
157+
/// any node in the cluster.
158+
#[serde(rename = "public_shares")]
159+
#[serde_as(as = "Vec<EthHex>")]
160+
pub pub_shares: Vec<Vec<u8>>,
161+
162+
/// Fee recipient address for the validator.
163+
#[serde(default)]
164+
#[serde_as(as = "EthHex")]
165+
pub fee_recipient_address: Vec<u8>,
166+
}
167+
168+
impl From<DistValidator> for DistValidatorV1x2to5 {
169+
fn from(dist_validator: DistValidator) -> Self {
170+
Self {
171+
pub_key: dist_validator.pub_key,
172+
pub_shares: dist_validator.pub_shares,
173+
fee_recipient_address: Default::default(),
174+
}
175+
}
176+
}
177+
178+
impl From<DistValidatorV1x2to5> for DistValidator {
179+
fn from(dist_validator: DistValidatorV1x2to5) -> Self {
180+
Self {
181+
pub_key: dist_validator.pub_key,
182+
pub_shares: dist_validator.pub_shares,
183+
partial_deposit_data: Vec::new(),
184+
builder_registration: BuilderRegistration::default(),
185+
}
186+
}
187+
}
188+
/// DistValidatorV1x6 is a distributed validator managed by the cluster for
189+
/// version v1.6.0.
190+
#[serde_as]
191+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
192+
pub struct DistValidatorV1x6 {
193+
/// Distributed validator group public key.
194+
#[serde(rename = "distributed_public_key")]
195+
#[serde_as(as = "EthHex")]
196+
pub pub_key: Vec<u8>,
197+
198+
/// Public shares are the public keys corresponding to each node's secret
199+
/// key share. It can be used to verify a partial signature created by
200+
/// any node in the cluster.
201+
#[serde(rename = "public_shares")]
202+
#[serde_as(as = "Vec<EthHex>")]
203+
pub pub_shares: Vec<Vec<u8>>,
204+
205+
/// Deposit data defines the deposit data to activate a validator.
206+
pub deposit_data: DepositData,
207+
}
208+
209+
impl From<DistValidator> for DistValidatorV1x6 {
210+
fn from(dist_validator: DistValidator) -> Self {
211+
Self {
212+
pub_key: dist_validator.pub_key,
213+
pub_shares: dist_validator.pub_shares,
214+
deposit_data: dist_validator
215+
.partial_deposit_data
216+
.into_iter()
217+
.next()
218+
.unwrap_or_default(),
219+
}
220+
}
221+
}
222+
223+
impl From<DistValidatorV1x6> for DistValidator {
224+
fn from(dist_validator: DistValidatorV1x6) -> Self {
225+
Self {
226+
pub_key: dist_validator.pub_key,
227+
pub_shares: dist_validator.pub_shares,
228+
partial_deposit_data: vec![dist_validator.deposit_data],
229+
builder_registration: BuilderRegistration::default(),
230+
}
231+
}
232+
}
233+
234+
/// DistValidatorV1x7 is a distributed validator managed by the cluster for
235+
/// version v1.7.0.
236+
#[serde_as]
237+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
238+
pub struct DistValidatorV1x7 {
239+
/// Distributed validator group public key.
240+
#[serde(rename = "distributed_public_key")]
241+
#[serde_as(as = "EthHex")]
242+
pub pub_key: Vec<u8>,
243+
244+
/// Public shares are the public keys corresponding to each node's secret
245+
/// key share. It can be used to verify a partial signature created by
246+
/// any node in the cluster.
247+
#[serde(rename = "public_shares")]
248+
#[serde_as(as = "Vec<EthHex>")]
249+
pub pub_shares: Vec<Vec<u8>>,
250+
251+
/// Deposit data defines the deposit data to activate a validator.
252+
pub deposit_data: DepositData,
253+
254+
/// Builder registration is the pre-generated signed validator builder
255+
/// registration.
256+
pub builder_registration: BuilderRegistration,
257+
}
258+
259+
impl From<DistValidator> for DistValidatorV1x7 {
260+
fn from(dist_validator: DistValidator) -> Self {
261+
Self {
262+
pub_key: dist_validator.pub_key,
263+
pub_shares: dist_validator.pub_shares,
264+
deposit_data: dist_validator
265+
.partial_deposit_data
266+
.into_iter()
267+
.next()
268+
.unwrap_or_default(),
269+
builder_registration: dist_validator.builder_registration,
270+
}
271+
}
272+
}
273+
274+
impl From<DistValidatorV1x7> for DistValidator {
275+
fn from(dist_validator: DistValidatorV1x7) -> Self {
276+
Self {
277+
pub_key: dist_validator.pub_key,
278+
pub_shares: dist_validator.pub_shares,
279+
partial_deposit_data: vec![dist_validator.deposit_data],
280+
builder_registration: dist_validator.builder_registration,
281+
}
282+
}
283+
}
284+
/// DistValidatorV1x8orLater is a distributed validator managed by the cluster
285+
/// for version v1.8.0 or later.
286+
#[serde_as]
287+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
288+
pub struct DistValidatorV1x8orLater {
289+
/// Distributed validator group public key.
290+
#[serde(rename = "distributed_public_key")]
291+
#[serde_as(as = "EthHex")]
292+
pub pub_key: Vec<u8>,
293+
294+
/// Public shares are the public keys corresponding to each node's secret
295+
/// key share. It can be used to verify a partial signature created by
296+
/// any node in the cluster.
297+
#[serde(rename = "public_shares")]
298+
#[serde_as(as = "Vec<EthHex>")]
299+
pub pub_shares: Vec<Vec<u8>>,
300+
301+
/// Deposit data defines the deposit data to activate a validator.
302+
pub partial_deposit_data: Vec<DepositData>,
303+
304+
/// Builder registration is the pre-generated signed validator builder
305+
/// registration.
306+
pub builder_registration: BuilderRegistration,
307+
}
308+
309+
impl From<DistValidator> for DistValidatorV1x8orLater {
310+
fn from(dist_validator: DistValidator) -> Self {
311+
Self {
312+
pub_key: dist_validator.pub_key,
313+
pub_shares: dist_validator.pub_shares,
314+
partial_deposit_data: dist_validator.partial_deposit_data,
315+
builder_registration: dist_validator.builder_registration,
316+
}
317+
}
318+
}
319+
320+
impl From<DistValidatorV1x8orLater> for DistValidator {
321+
fn from(dist_validator: DistValidatorV1x8orLater) -> Self {
322+
Self {
323+
pub_key: dist_validator.pub_key,
324+
pub_shares: dist_validator.pub_shares,
325+
partial_deposit_data: dist_validator.partial_deposit_data,
326+
builder_registration: dist_validator.builder_registration,
327+
}
328+
}
329+
}

crates/charon-cluster/src/examples/cluster-definition-005.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
],
3333
"uuid": "B6AE17B3-78F5-147B-2C37-2572B93437DF",
3434
"version": "v1.8.0",
35-
<<<<<<< HEAD
36-
"timestamp": "2023-05-18T15: 12: 46+02: 00",
37-
=======
3835
"timestamp": "2023-05-18T15:12:46+02:00",
39-
>>>>>>> origin/main
4036
"num_validators": 2,
4137
"threshold": 3,
4238
"validators": [

crates/charon-cluster/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ pub mod definition;
1010
pub mod deposit;
1111
/// Cluster distributed validator management and coordination.
1212
pub mod distvalidator;
13-
/// Cluster documentation management and coordination.
14-
pub mod doc;
1513
/// Cluster EIP-712 signatures management and coordination.
1614
pub mod eip712sigs;
1715
/// Cluster helpers management and coordination.

0 commit comments

Comments
 (0)