[](https://)# Update Recently have taken an interest into Portal network for a couple of reasons: 1. I always cringe on how large running a full node can be and how long it takes for it to fully sync up 2. I feel that portal network is a step towards statelessness I recently have been trying to work on the accumulator which consist of a Master and an epoch accumulator. A draft spec have been written on how to handle for reorgs in an accumulator but needs tweaking As of now, using ddht Alexendria branch as a reference, I am trying to implement a similar accumulator implementation in Rust At this current stage, I am attempting to verify the SSZ which I have implemented in Rust works exactly as it should using the ddht version as a benchmark Included code snippet: ## Sedes Structure `List[ Container[ block_hash : byte32, total_difficulty : int], 2048]` ## Test data The examples are constructed using the data of Block#0 which resembles: ``` Block { block_hash:String = "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", total_difficulty:u64 = 17179869184 } ``` ## Example of code snippet ### Python (py-ssz) ``` from typing import NamedTuple, Optional, Tuple, List from eth_typing import Hash32 import ssz from ssz import sedes as ssz_sedes from eth_utils import to_bytes class AccumulatorLeaf(NamedTuple): block_hash: Hash32 total_difficulty: int AccumulatorLeafSedes = ssz_sedes.Container( field_sedes=(ssz_sedes.bytes32, ssz_sedes.uint256) ) EpochAccumulatorSedes = ssz_sedes.List(AccumulatorLeafSedes, max_length=EPOCH_SIZE) class Block: def __init__(self, block_hash: Hash32, total_difficulty: int): self.block_hash = block_hash self.total_difficulty = total_difficulty def test() : ##block data here block = Block("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",17179869184) leaf = AccumulatorLeaf( block_hash=Hash32(to_bytes(hexstr=block.block_hash)), total_difficulty=int(block.total_difficulty), ) epoch_accumulator = (leaf,) #getting the hash epoch_accumulator_root = ssz.get_hash_tree_root( epoch_accumulator, sedes=EpochAccumulatorSedes, ) #encode to ssz epoch_encoded = ssz.encode(epoch_accumulator, sedes=EpochAccumulatorSedes) ``` ### Rust (eth2-ssz) ``` use ethereum_types::H256; use ssz::{Decode, DecodeError, Encode}; use ssz_derive::{Decode, Encode}; use ssz_types::{typenum, VariableList}; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; use typenum::U2048; #[derive(Clone, Copy, Encode, Decode, Debug, PartialEq, TreeHash, Default)] pub struct EpochSede { block_hash: H256, total_difficulty: U256, } #[derive(Debug, Clone)] pub struct Block { pub block_hash: String, pub total_difficulty: u64, } fn main() { //defined block data let block = Block { block_hash: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".to_string(), total_difficulty: 17179869184 }; let serialized = impl_serde::serialize::from_hex(&block.block_hash).unwrap(); let typed_block_hash = <H256>::from_slice(&serialized[..]); //convert total_diffuculty to U256 let total_difficulty = let epoch_sede = EpochSede::new(typed_block_hash, total_difficulty); let epoch_accumulator: Vec<EpochSede> = vec![epoch_sede]; let epoch_sede_var_list: VariableList<_, U2048> = VariableList::from(epoch_accumulator.clone()); let epoch_hash = epoch_sede_var_list.tree_hash_root(); let epoch_encoded = &epoch_sede_fixed_vec.as_ssz_bytes(); } impl EpochSede { pub fn new(block_hash: H256, total_difficulty: u64) -> EpochSede { EpochSede { block_hash, total_difficulty, } } } ``` ```