|
1 | 1 | use pluto_crypto::types::{PUBLIC_KEY_LENGTH, PublicKey}; |
| 2 | +use pluto_eth2api::{ |
| 3 | + spec::{ |
| 4 | + BuilderVersion, |
| 5 | + phase0::{BLS_PUBKEY_LEN, BLS_SIGNATURE_LEN}, |
| 6 | + }, |
| 7 | + v1, |
| 8 | + versioned::VersionedSignedValidatorRegistration, |
| 9 | +}; |
2 | 10 | use pluto_ssz::serde_utils::Hex0x; |
3 | 11 | use serde::{Deserialize, Serialize}; |
4 | 12 |
|
5 | | -use crate::{deposit::DepositData, registration::BuilderRegistration}; |
| 13 | +use crate::{definition::ADDRESS_LEN, deposit::DepositData, registration::BuilderRegistration}; |
6 | 14 | use serde_with::{ |
7 | 15 | base64::{Base64, Standard}, |
8 | 16 | serde_as, |
@@ -41,6 +49,9 @@ pub enum DistValidatorError { |
41 | 49 | /// Invalid public share index. |
42 | 50 | #[error("invalid public share index: got {0}, want less than {1}")] |
43 | 51 | InvalidPublicShareIndex(usize, usize), |
| 52 | + /// Invalid builder registration. |
| 53 | + #[error("invalid registration")] |
| 54 | + InvalidRegistration, |
44 | 55 | } |
45 | 56 |
|
46 | 57 | impl DistValidator { |
@@ -83,20 +94,41 @@ impl DistValidator { |
83 | 94 | } |
84 | 95 |
|
85 | 96 | /// True if the validator has zero valued registration. |
86 | | - /// registration. |
87 | 97 | pub fn zero_registration(&self) -> bool { |
88 | | - self.builder_registration.signature.is_empty() |
89 | | - && self.builder_registration.message.fee_recipient.is_empty() |
| 98 | + self.builder_registration.signature == [0u8; BLS_SIGNATURE_LEN] |
| 99 | + && self.builder_registration.message.fee_recipient == [0u8; ADDRESS_LEN] |
90 | 100 | && self.builder_registration.message.gas_limit == 0 |
91 | 101 | && self.builder_registration.message.timestamp.timestamp() == 0 |
92 | | - && self.builder_registration.message.pub_key.is_empty() |
| 102 | + && self.builder_registration.message.pub_key == [0u8; BLS_PUBKEY_LEN] |
93 | 103 | } |
94 | 104 |
|
95 | 105 | /// Validator's Eth2 registration. |
96 | | - pub fn eth2_registration(&self) -> Result<(), DistValidatorError> { |
97 | | - unimplemented!( |
98 | | - "Eth2 registration requires to have ethereum types library which is not yet integrated in pluto-cluster" |
99 | | - ) |
| 106 | + pub fn eth2_registration( |
| 107 | + &self, |
| 108 | + ) -> Result<VersionedSignedValidatorRegistration, DistValidatorError> { |
| 109 | + if self.zero_registration() { |
| 110 | + return Err(DistValidatorError::InvalidRegistration); |
| 111 | + } |
| 112 | + |
| 113 | + let reg = &self.builder_registration; |
| 114 | + |
| 115 | + Ok(VersionedSignedValidatorRegistration { |
| 116 | + version: BuilderVersion::V1, |
| 117 | + v1: Some(v1::SignedValidatorRegistration { |
| 118 | + message: v1::ValidatorRegistration { |
| 119 | + fee_recipient: reg.message.fee_recipient, |
| 120 | + gas_limit: reg.message.gas_limit, |
| 121 | + timestamp: reg |
| 122 | + .message |
| 123 | + .timestamp |
| 124 | + .timestamp() |
| 125 | + .try_into() |
| 126 | + .map_err(|_| DistValidatorError::InvalidRegistration)?, |
| 127 | + pubkey: reg.message.pub_key, |
| 128 | + }, |
| 129 | + signature: reg.signature, |
| 130 | + }), |
| 131 | + }) |
100 | 132 | } |
101 | 133 | } |
102 | 134 |
|
|
0 commit comments