From 9e8d7085463e44e9b1355606409991287cc8a412 Mon Sep 17 00:00:00 2001 From: tchataigner Date: Thu, 20 Jun 2024 14:09:19 +0200 Subject: [PATCH] fix: fix #1 (#33) Signed-off-by: Thomas Chataigner --- aptos/core/src/types/trusted_state.rs | 42 +++++++-------------------- aptos/core/src/types/waypoint.rs | 26 +++++++++++++---- aptos/proof-server/src/bin/client.rs | 34 +++++++++++++--------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/aptos/core/src/types/trusted_state.rs b/aptos/core/src/types/trusted_state.rs index 9be40a47..5146b8a3 100644 --- a/aptos/core/src/types/trusted_state.rs +++ b/aptos/core/src/types/trusted_state.rs @@ -189,22 +189,11 @@ impl TrustedState { bail!("Inconsistent epoch change proof and latest ledger info"); }; - cfg_if::cfg_if! { - if #[cfg(feature = "waypoint")] { - let new_state = TrustedState::EpochState { - waypoint: Waypoint::new_any(verified_ledger_info.ledger_info()), - epoch_state: new_epoch_state, - }; - } else { - let new_state = TrustedState::EpochState { - waypoint: Waypoint { - version: verified_ledger_info.ledger_info().version(), - value: HashValue::default(), - }, - epoch_state: new_epoch_state, - }; - } - } + let new_state = TrustedState::EpochState { + waypoint: Waypoint::new_any(verified_ledger_info.ledger_info()), + epoch_state: new_epoch_state, + }; + Ok(TrustedStateChange::Epoch { new_state, latest_epoch_change_li: epoch_change_li, @@ -396,22 +385,11 @@ impl EpochChangeProof { .next_epoch_state() .ok_or_else(|| format_err!("LedgerInfo doesn't carry a ValidatorSet"))?; - cfg_if::cfg_if! { - if #[cfg(feature = "waypoint")] { - let new_trusted_state = TrustedState::EpochState { - waypoint: Waypoint::new_any(new_li), - epoch_state: new_epoch_state.clone(), - }; - } else { - let new_trusted_state = TrustedState::EpochState { - waypoint: Waypoint { - version: new_li.version(), - value: HashValue::default(), - }, - epoch_state: new_epoch_state.clone(), - }; - } - } + let new_trusted_state = TrustedState::EpochState { + waypoint: Waypoint::new_any(new_li), + epoch_state: new_epoch_state.clone(), + }; + trusted_state = new_trusted_state; } diff --git a/aptos/core/src/types/waypoint.rs b/aptos/core/src/types/waypoint.rs index 5cf6db8b..f5768c4f 100644 --- a/aptos/core/src/types/waypoint.rs +++ b/aptos/core/src/types/waypoint.rs @@ -29,9 +29,9 @@ pub const WAYPOINT_SIZE: usize = U64_SIZE + HASH_LENGTH; pub struct Waypoint { /// The version of the reconfiguration transaction that is being approved by this waypoint. #[getset(get_copy = "pub")] - pub(crate) version: Version, + version: Version, /// The hash of the chosen fields of LedgerInfo. - pub(crate) value: HashValue, + value: HashValue, } /// `Waypoint` is a structure representing a waypoint, @@ -46,11 +46,24 @@ impl Waypoint { /// # Returns /// /// A new `Waypoint`. + /// + /// # Note + /// + /// If the `waypoint` feature is not enabled, the `Waypoint` value will be a dummy value. pub fn new_any(ledger_info: &LedgerInfo) -> Self { - let converter = Ledger2WaypointConverter::new(ledger_info); - Self { - version: ledger_info.version(), - value: converter.hash(), + cfg_if::cfg_if! { + if #[cfg(feature = "waypoint")] { + let converter = Ledger2WaypointConverter::new(ledger_info); + Self { + version: ledger_info.version(), + value: converter.hash(), + } + } else { + Self { + version: ledger_info.version(), + value: HashValue::default(), + } + } } } @@ -146,6 +159,7 @@ impl Ledger2WaypointConverter { /// # Returns /// /// A new `Ledger2WaypointConverter`. + #[allow(dead_code)] pub(crate) fn new(ledger_info: &LedgerInfo) -> Self { Self { epoch: ledger_info.epoch(), diff --git a/aptos/proof-server/src/bin/client.rs b/aptos/proof-server/src/bin/client.rs index 1e30ce93..6d11d9c8 100644 --- a/aptos/proof-server/src/bin/client.rs +++ b/aptos/proof-server/src/bin/client.rs @@ -36,7 +36,8 @@ use anyhow::{anyhow, Result}; use aptos_lc_core::crypto::hash::{CryptoHash, HashValue}; -use aptos_lc_core::types::trusted_state::{TrustedState, TrustedStateChange}; +use aptos_lc_core::types::trusted_state::TrustedState; +use aptos_lc_core::types::waypoint::Waypoint; use clap::Parser; use log::{debug, error, info}; use proof_server::error::ClientError; @@ -491,8 +492,6 @@ async fn epoch_change_proving_task( fetch_epoch_change_proof_data(&aptos_node_url, Some(epoch)).await?; // Retrieve the validator verifier hash for penultimate epoch. - let trusted_state = epoch_change_proof_data.trusted_state().clone(); - let validator_verifier_hash = match epoch_change_proof_data.trusted_state() { TrustedState::EpochState { epoch_state, .. } => epoch_state.verifier().hash(), _ => { @@ -523,16 +522,25 @@ async fn epoch_change_proving_task( debug!("Epoch change proof for latest epoch received from prover"); // Proving is done, ratchet the client state to the new trusted state. - let ratcheted_state = match trusted_state - .verify_and_ratchet_inner(epoch_change_proof_data.epoch_change_proof()) - .map_err(|err| ClientError::Ratchet { source: err.into() })? - { - TrustedStateChange::Epoch { new_state, .. } => new_state, - _ => { - return Err(ClientError::Ratchet { - source: "Expected epoch change".into(), - }) - } + let ledger_info = epoch_change_proof_data + .epoch_change_proof() + .ledger_info_with_sigs + .first() + .ok_or_else(|| ClientError::Internal { + source: "Epoch Change Proof has more than one LedgerInfoWithSignatures".into(), + })? + .ledger_info() + .clone(); + + let ratcheted_state = TrustedState::EpochState { + waypoint: Waypoint::new_any(&ledger_info), + epoch_state: ledger_info + .next_epoch_state() + .ok_or_else(|| ClientError::Internal { + source: "LedgerInfoWithSignatures in EpochChangeProof has no next EpochState" + .into(), + })? + .clone(), }; Ok((ratcheted_state, validator_verifier_hash, epoch_change_proof))