Module o1_utils::hasher

source ·
Expand description

This module provides the CryptoDigest trait, which provides a generic interface for hashing.

To use it, simply implement CryptoDigest for your type:

use o1_utils::hasher::CryptoDigest;
use serde::Serialize;

#[derive(Serialize)]
struct A {
    thing: u8,
}

impl CryptoDigest for A {
    const PREFIX: &'static [u8; 15] = b"kimchi-circuit0";
}

let a = A { thing: 1 };
let expected_result = [164, 8, 215, 27, 25, 36, 6, 167, 42, 86, 200, 203, 99, 74, 178, 134, 66, 168, 85, 7, 224, 189, 73, 63, 117, 23, 18, 193, 168, 176, 123, 80];
assert_eq!(a.digest(), expected_result);

let b = A { thing: 1 };
assert_eq!(a.digest(), b.digest());

Warning: make sure not to reuse the same PREFIX for different types. This prefix is here to semantically distinguish the hash of different types (and thus different use-case).

Traits

  • This trait can be implemented on any type that implements serde::Serialize, in order to provide a digest() function that returns a unique hash.