{"id":19460124,"url":"https://github.com/offchainlabs/sszpp","last_synced_at":"2026-04-02T01:57:16.586Z","repository":{"id":180856836,"uuid":"656167594","full_name":"OffchainLabs/sszpp","owner":"OffchainLabs","description":"C++ SSZ library","archived":false,"fork":false,"pushed_at":"2024-07-11T12:10:07.000Z","size":175,"stargazers_count":24,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-07-11T13:44:18.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OffchainLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-20T11:42:16.000Z","updated_at":"2024-07-11T12:10:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1604acc-c49c-4009-8aa2-62abed56dd9b","html_url":"https://github.com/OffchainLabs/sszpp","commit_stats":null,"previous_names":["potuz/sszpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fsszpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fsszpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fsszpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OffchainLabs%2Fsszpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OffchainLabs","download_url":"https://codeload.github.com/OffchainLabs/sszpp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223989484,"owners_count":17237089,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T17:35:40.101Z","updated_at":"2026-04-02T01:57:16.546Z","avatar_url":"https://github.com/OffchainLabs.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SSZ++\nA fast SSZ library focused on minimal memory allocations and fast hashing. \n\nIt is focused on templated polymorphism, with no dynamic dispatching and performing the minimal number of memory copies. \n\n**WARNING** This project is in very early implementation status, it is surely filled with bugs and security issues, it should not be used in production code.\n## Requirements\n- A compiler supporting C++23, tested only with GCC 13.1 (clang will fail due to lack of C++20 concepts)\n- [Hashtree](https://github.com/prysmaticlabs/hashtree) is used for hashing.\n- Cmake for building.\n- [intx](https://github.com/chfast/intx) for extended precision integers.\n- Optional for the spectest suite\n    - [Yaml-cpp](https://github.com/jbeder/yaml-cpp)\n    - [Snappy](https://github.com/google/snappy)\n\n## Tests\n\n1. Install all requirements. \n2. Clone the repo: `git clone https://github.com/potuz/sszpp.git`\n3. Build the project. This will download the spectests tarball, will take a while.\n```bash\n$ cd sszpp\n$ mkdir build\n$ cd build\n$ cmake ../\n$ make\n```\n4. Run spectests `./spectests` \n5. Run some simple benchmarks. In the same directory `build` place a file named `state.ssz` with the ssz binary representation of a Capella Beacon State. Then run the benchmark with `./bench_beacon_state`.\n\n## Benchmarks\n\nThese are results on a Dell XPS 9320\n```\n$ ./bench_beacon_state\nDeserialization: 28ms\nHashing: 62ms\nRoot: 0x5422c2fe46f4fa5719f91b353371428125f04ba684264c4bd2b25967258e66d9\n```\nCompared with Prysm using ADX on BLST and fully parallelized GoHashtree for hashing\n```\nDeserialize Duration: 100.248102ms, Hashing Duration: 139.618937ms HTR: 0x5422c2fe46f4fa5719f91b353371428125f04ba684264c4bd2b25967258e66d9\n```\nThese are on a Ryzen 9 7950X\n```\nDeserialization: 27ms\nHashing: 23ms\nRoot: 0x5422c2fe46f4fa5719f91b353371428125f04ba684264c4bd2b25967258e66d9\n```\n\nThese on a Ryzen 9 5900HX without any paralellization (courtesy of E. Del Fante)\n```\nDeserialization: 35ms\nHashing: 349ms\n```\nCompared to native Teku on the same computer deserializing at `130ms` and cold hashing at `1 500ms`. \n\n## Usage\n\nYou can use basic types like `bool`, `std::byte`, `std::uintX_t` with `X=8,16,32,64,128` and `256`. \n\nTo model bitvectors use `std::bitset`, to model arbitrary vectors use `std::array` or `std::vector`. The library provides a wrapper `ssz::list\u003cT, N\u003e` to model the SSZ type `List[T,N]`. That list uses internally a `std::vector\u003cT\u003e` as container. \n\nTo define a custom container unfortunately until `C++26` with static introspection we need to use a macro. You can define them as follows\n```c++\nstruct indexed_attestation_t : ssz::ssz_variable_size_container {\n    ssz::list\u003cstd::uint64_t, MAX_VALIDATORS_PER_COMMITEE\u003e attesting_indices;\n    attestation_data_t data;\n    signature_t signature;\n\n    constexpr auto operator\u003c=\u003e(const indexed_attestation_t\u0026 rhs) const noexcept = default;\n    constexpr bool operator==(const indexed_attestation_t\u0026 rhs) const noexcept = default;\n\n    SSZ_CONT(attesting_indices, data, signature);\n};\n```\nYou only need to inherit from `ssz::ssz_container` or `ssz::ssz_variable_size_container` depending on whether this is a container where all members are fixed sizes or not. These bases classes are empty classes just there for the type traits until reflection comes to C++. \n\nTo deserialize an object of type `T` you would use\n```c++\nstd::vector\u003cstd::byte\u003e vec{bytes};\nauto object = ssz::deserialize\u003cT\u003e(vec);\n```\n\nTo deserialize in place you can use\n```c++\nT object{};\nssz::deserialize(vec, object);\n```\n\nTo deserialize an object allocated in the heap you can use\n```c++\nstd::unique_ptr object_ptr = ssz::deserialize\u003cT*\u003e(vec);\n```\n\nTo serialize your object is simply\n```c++\nstd::vector\u003cstd::byte\u003e vec = ssz::serialize(object);\n```\n\nTo get the hash tree root you would try\n```c++\nstd::array\u003cstd::byte, 32\u003e htr = ssz::hash_tree_root(object, cpu_count);\n```\nwhere `cpu_count` is the number of threads that you want to use. Using `0` (the default) will use all available cores. \n\nThe library comes with all the consensus layer structures used in the `Capella`  fork, you can copy those as templates, or simply wrap your structures around them.\n\n## License\nLicenced under the [Apache License version 2.0](https://apache.org/licenses/LICENSE-2.0.txt) except for [acutest](https://github.com/mity/acutest) (included) that is licenced MIT. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fsszpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffchainlabs%2Fsszpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchainlabs%2Fsszpp/lists"}