Trait mina_hasher::Hashable

source ·
pub trait Hashable: Clone {
    type D: DomainParameter;

    // Required methods
    fn to_roinput(&self) -> ROInput;
    fn domain_string(domain_param: Self::D) -> Option<String>;
}
Expand description

Interface for hashable objects

Mina uses fixed-length hashing with domain separation for each type of object hashed. The prior means that Hashable only supports types whose size is not variable.

Important: The developer MUST assure that all domain strings used throughout the system are unique and that all structures hashed are of fixed size.

Here is an example of how to implement the Hashable trait for am Example type.

use mina_hasher::{Hashable, ROInput};

#[derive(Clone)]
struct Example;

impl Hashable for Example {
    type D = ();

    fn to_roinput(&self) -> ROInput {
        let roi = ROInput::new();
        // Serialize example members
        // ...
        roi
    }

    fn domain_string(_: Self::D) -> Option<String> {
       format!("Example").into()
   }
}

See example in ROInput documentation

Required Associated Types§

source

type D: DomainParameter

Generic domain string argument type

Required Methods§

source

fn to_roinput(&self) -> ROInput

Serialization to random oracle input

source

fn domain_string(domain_param: Self::D) -> Option<String>

Generate unique domain string of length <= 20.

The length bound is guarded by an assertion, but uniqueness must be enforced by the developer implementing the traits (see Hashable for more details). The domain string may be parameterized by the contents of the generic domain_param argument.

Note: You should always return Some(String). A None return value is only used for testing.

Implementors§