From d0f1a3e59f9c2040907275a5a6b5daa420c0c4bf Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Fri, 31 Jul 2020 05:47:11 +0000 Subject: [PATCH] Check deposit signatures when submitting via CLI (#1414) ## Proposed Changes Having been bitten by submitting deposits with invalid signatures (for the wrong testnet), I'm proposing we check the signatures of deposits when submitting them via `lighthouse account validator deposit`. The impact on performance is likely to be minimal because waiting for an Eth1 transaction confirmation takes a lot longer than verifying a single signature. It would be great to have the same protection in the deposit web UI in the Lighthouse Book, but I imagine that will be obsoleted by the validator web UI work. --- account_manager/Cargo.toml | 1 + account_manager/src/validator/deposit.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/account_manager/Cargo.toml b/account_manager/Cargo.toml index 07dc309a5..dceee1368 100644 --- a/account_manager/Cargo.toml +++ b/account_manager/Cargo.toml @@ -11,6 +11,7 @@ slog = "2.5.2" slog-term = "2.5.0" slog-async = "2.5.0" types = { path = "../consensus/types" } +state_processing = { path = "../consensus/state_processing" } dirs = "2.0.2" environment = { path = "../lighthouse/environment" } deposit_contract = { path = "../common/deposit_contract" } diff --git a/account_manager/src/validator/deposit.rs b/account_manager/src/validator/deposit.rs index 6ff002b0f..0e508cfd2 100644 --- a/account_manager/src/validator/deposit.rs +++ b/account_manager/src/validator/deposit.rs @@ -7,6 +7,7 @@ use futures::{ stream::{FuturesUnordered, StreamExt}, }; use slog::{info, Logger}; +use state_processing::per_block_processing::verify_deposit_signature; use std::path::PathBuf; use tokio::time::{delay_until, Duration, Instant}; use types::EthSpec; @@ -135,6 +136,7 @@ where ::Out: std::marker::Send, { let web3 = Web3::new(transport); + let spec = env.eth2_config.spec.clone(); let deposits_fut = async { poll_until_synced(web3.clone(), log.clone()).await?; @@ -143,6 +145,14 @@ where let futures = FuturesUnordered::default(); for (ref mut validator_dir, eth1_deposit_data) in chunk.iter_mut() { + verify_deposit_signature(ð1_deposit_data.deposit_data, &spec).map_err(|e| { + format!( + "Deposit for {:?} fails verification, \ + are you using the correct testnet configuration?\nError: {:?}", + eth1_deposit_data.deposit_data.pubkey, e + ) + })?; + let web3 = web3.clone(); let log = log.clone(); futures.push(async move {