From 173a0abab4cde6f30b6263372884eda77c986423 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 13 Dec 2022 17:03:21 +1100 Subject: [PATCH] Fix `Withdrawal` serialisation and check address change fork (#3789) * Disallow address changes before Capella * Quote u64s in Withdrawal serialisation --- beacon_node/beacon_chain/src/beacon_chain.rs | 7 +++++++ beacon_node/beacon_chain/src/errors.rs | 1 + consensus/types/src/withdrawal.rs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 7841f53e7..0bbbe9235 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -2191,7 +2191,14 @@ impl BeaconChain { ) -> Result, Error> { #[cfg(feature = "withdrawals-processing")] { + let current_fork = self.spec.fork_name_at_slot::(self.slot()?); + if let ForkName::Base | ForkName::Altair | ForkName::Merge = current_fork { + // Disallow BLS to execution changes prior to the Capella fork. + return Err(Error::BlsToExecutionChangeBadFork(current_fork)); + } + let wall_clock_state = self.wall_clock_state()?; + Ok(self .observed_bls_to_execution_changes .lock() diff --git a/beacon_node/beacon_chain/src/errors.rs b/beacon_node/beacon_chain/src/errors.rs index 60282426a..3a2e4a0bc 100644 --- a/beacon_node/beacon_chain/src/errors.rs +++ b/beacon_node/beacon_chain/src/errors.rs @@ -206,6 +206,7 @@ pub enum BeaconChainError { MissingPersistedForkChoice, CommitteePromiseFailed(oneshot_broadcast::Error), MaxCommitteePromises(usize), + BlsToExecutionChangeBadFork(ForkName), } easy_from_to!(SlotProcessingError, BeaconChainError); diff --git a/consensus/types/src/withdrawal.rs b/consensus/types/src/withdrawal.rs index 10530dcb5..6f14cf1c5 100644 --- a/consensus/types/src/withdrawal.rs +++ b/consensus/types/src/withdrawal.rs @@ -12,8 +12,10 @@ use tree_hash_derive::TreeHash; pub struct Withdrawal { #[serde(with = "eth2_serde_utils::quoted_u64")] pub index: u64, + #[serde(with = "eth2_serde_utils::quoted_u64")] pub validator_index: u64, pub address: Address, + #[serde(with = "eth2_serde_utils::quoted_u64")] pub amount: u64, }