Crypto

The OpenZeppelin Rust Contracts provide a crate for common cryptographic procedures in a blockchain environment. The following documents the available functionality.

Verifying Merkle Proofs

Developers can build a Merkle Tree off-chain, which allows for verifying that an element (leaf) is part of a set by using a Merkle Proof. This technique is widely used for creating whitelists (e.g. for airdrops) and other advanced use cases.

OpenZeppelin Contracts provides a JavaScript library for building trees off-chain and generating proofs.

MerkleProof provides:

pub fn verify(&self, proof: Vec<B256>, root: B256, leaf: B256) -> bool {
    let proof: Vec<[u8; 32]> = proof.into_iter().map(|m| *m).collect();
    Verifier::<KeccakBuilder>::verify(&proof, *root, *leaf)
}

Note that these functions use keccak256 as the hashing algorithm, but our library also provides generic counterparts: verify_with_builer and verify_multi_proof_with_builder.

We also provide an adapter hash module to use your own hashers in conjunction with them that resembles Rust’s standard library’s API.