Skip to content
encrypted-spacesPublic
forked from turbofish-org/merk

About

High-performance Merkle key/value store

Resources

Stars

14 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Note: This is a fork of merk, maintained as part of the encrypted-spaces project. The original README content follows below.


merk

High-performance Merkle key/value store

Merk is a crypto key/value store - more specifically, it's an in-memory Merkle AVL tree with copy-on-write nodes for efficient snapshots and transactions.

Features

  • Copy-on-write snapshots - Cloning a tree root is O(1). Mutations copy only the modified path, so snapshots and writes can coexist cheaply.
  • Transactions - Clone-mutate-publish with O(1) begin and rollback. Single-writer serialization via a writer mutex.
  • Fast proof generation - Since Merk implements an AVL tree rather than a trie, it is very efficient to create and verify proofs for ranges of keys.
  • Web-friendly - Being written in Rust means it is easy to run the proof-verification code in browsers with WebAssembly, allowing for light-clients that can verify data for themselves.

Usage

Install:

cargo add merk

Example:

use merk::avl::Tree;
use merk::Backend;

let mut tree = Tree::new();

// AVL writes preserve operation order.
tree.put(b"key", b"value").unwrap();
tree.put(b"key2", b"value2").unwrap();
tree.put(b"key3", b"value3").unwrap();
tree.delete(b"key3").unwrap();

// Cloning creates an O(1) snapshot.
let snapshot = tree.clone();

// Later writes leave the snapshot alone.
tree.put(b"key5", b"value5").unwrap();

// Reads are fallible: `Ok(None)` is a definite absence, `Err` is a read
// that could not be answered.
assert_eq!(snapshot.get(b"key5").unwrap(), None);
assert_eq!(snapshot.get(b"key").unwrap(), Some(b"value".to_vec()));
assert_eq!(snapshot.get(b"key3").unwrap(), None);
assert_eq!(tree.get(b"key5").unwrap(), Some(b"value5".to_vec()));

Security

Security Audits

Date Auditor Scope Report
October 2024 Trail of Bits orga merk ed abci2 📄

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use the files in this repository except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Copyright © 2024 Turbofish, Inc.

About

High-performance Merkle key/value store

Resources

Stars

14 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages