Unimplement TreeHash for BeaconState (#6083)

* Unimplement `TreeHash` for `BeaconState`
This commit is contained in:
Michael Sproul
2024-07-12 23:06:08 +10:00
committed by GitHub
parent 0c0b56d9e8
commit 2f0af2be89
16 changed files with 117 additions and 70 deletions

View File

@@ -2,7 +2,6 @@ use serde::Deserialize;
use ssz::Encode;
use ssz_derive::{Decode, Encode};
use std::fmt::Debug;
use tree_hash::TreeHash;
use types::ForkName;
/// Macro to wrap U128 and U256 so they deserialize correctly.
@@ -49,12 +48,12 @@ uint_wrapper!(TestU256, ethereum_types::U256);
/// Trait for types that can be used in SSZ static tests.
pub trait SszStaticType:
serde::de::DeserializeOwned + Encode + TreeHash + Clone + PartialEq + Debug + Sync
serde::de::DeserializeOwned + Encode + Clone + PartialEq + Debug + Sync
{
}
impl<T> SszStaticType for T where
T: serde::de::DeserializeOwned + Encode + TreeHash + Clone + PartialEq + Debug + Sync
T: serde::de::DeserializeOwned + Encode + Clone + PartialEq + Debug + Sync
{
}

View File

@@ -6,6 +6,7 @@ use crate::cases::ssz_static::{check_serialization, check_tree_hash};
use crate::decode::{log_file_access, snappy_decode_file, yaml_decode_file};
use serde::{de::Error as SerdeError, Deserialize, Deserializer};
use ssz_derive::{Decode, Encode};
use tree_hash::TreeHash;
use tree_hash_derive::TreeHash;
use types::typenum::*;
use types::{BitList, BitVector, FixedVector, ForkName, VariableList, Vector};
@@ -206,7 +207,7 @@ impl Case for SszGeneric {
}
}
fn ssz_generic_test<T: SszStaticType + ssz::Decode>(path: &Path) -> Result<(), Error> {
fn ssz_generic_test<T: SszStaticType + TreeHash + ssz::Decode>(path: &Path) -> Result<(), Error> {
let meta_path = path.join("meta.yaml");
let meta: Option<Metadata> = if meta_path.is_file() {
Some(yaml_decode_file(&meta_path)?)

View File

@@ -101,7 +101,7 @@ pub fn check_tree_hash(expected_str: &str, actual_root: &[u8]) -> Result<(), Err
compare_result::<Hash256, Error>(&Ok(tree_hash_root), &Some(expected_root))
}
impl<T: SszStaticType + Decode> Case for SszStatic<T> {
impl<T: SszStaticType + TreeHash + Decode> Case for SszStatic<T> {
fn result(&self, _case_index: usize, _fork_name: ForkName) -> Result<(), Error> {
check_serialization(&self.value, &self.serialized, T::from_ssz_bytes)?;
check_tree_hash(&self.roots.root, self.value.tree_hash_root().as_bytes())?;
@@ -115,7 +115,6 @@ impl<E: EthSpec> Case for SszStaticTHC<BeaconState<E>> {
check_serialization(&self.value, &self.serialized, |bytes| {
BeaconState::from_ssz_bytes(bytes, spec)
})?;
check_tree_hash(&self.roots.root, self.value.tree_hash_root().as_bytes())?;
let mut state = self.value.clone();
let cached_tree_hash_root = state.update_tree_hash_cache().unwrap();

View File

@@ -262,7 +262,7 @@ pub struct SszStaticWithSpecHandler<T, E>(PhantomData<(T, E)>);
impl<T, E> Handler for SszStaticHandler<T, E>
where
T: cases::SszStaticType + ssz::Decode + TypeName,
T: cases::SszStaticType + tree_hash::TreeHash + ssz::Decode + TypeName,
E: TypeName,
{
type Case = cases::SszStatic<T>;