Git Product home page Git Product logo

ssz-rs's Introduction

ssz_rs ✂️️

build crates.io docs.rs codecov

An implementation of the SSZ serialization scheme defined in the consensus-specs repo.

This repo aims to remain lightweight and relatively free-standing, rather than coupled to other ethereum consensus code/dependencies.

🚧 WARNING 🚧

This implementation has not been audited for security and is primarily intended for R&D use cases.

If you need a battle-tested implementation (e.g. for consensus-critical work), refer to the Lighthouse implementation.

Features

To conform to the SSZ spec, a given Rust type should implement the SimpleSerialize trait. Types implementing this trait then obtain:

Encoding / decoding

This library provides routines to serialize from and deserialize into a Rust type to/from the corresponding SSZ data via the Serialize and Deserialize traits.

Merkleization

This library provides the hash tree root computation for types implementing Merkleized.

  • NOTE: more sophisticated hashing strategies are possible, users may run into memory or performance issues with the current implementation.

Multiproofs

This library provides the ability to reason about generalized indices for a given SSZ definition, along with the ability to generate and verify proofs of data at those indices.

  • NOTE: still under construction

no-std feature

This library is no-std compatible. To build without the standard library, disable the crate's default features.

For example, in Cargo.toml:

ssz_rs = { version = "...", default-features = false }

Custom types

This library attempts to provide as minimal an interface over the native Rust types as possible when implementing SSZ types. For example, the uint64 type from the SSZ spec is represented by Rust's native u64 type.

The library also provides custom types for List, Vector, Bitlist and Bitvector following the SSZ spec. Each of these custom types should behave approximately like Rust's Vec type. A notable exception is deferring to the underlying type's iteration capabilities; e.g. to iterate a List you must explicitly call .iter().

For safety, there are only a few ways to construct an instance of each of these custom types:

  • Default::default

  • TryFrom::try_from

  • ssz_rs::Deserialize

Moreover, the ssz_rs_derive package provides macros to derive the encoding and decoding routines for SSZ containers and unions (represented as Rust structs and enums, respectively).

Examples

See the examples for example usage of the facilities of this library.

Testing

This repo includes a copy of the ssz_generic consensus spec tests as integration tests for the ssz_rs package, along with hand-written unit tests. The integration tests are generated via a utility under ssz-rs-test-gen package. See the README there for further details.

ssz-rs's People

Contributors

ralexstokes avatar doubledup avatar 0xtylerholmes avatar claravanstaden avatar onbjerg avatar bluele avatar ncitron avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.