import stew/ranges/[ptr_arith, typedranges, bitranges], eth/rlp/types, trie_defs, trie_utils, db, sparse_proofs export types, trie_utils, bitranges, sparse_proofs.verifyProof type DB = TrieDatabaseRef SparseBinaryTrie* = object db: DB rootHash: ByteRange proc `==`(a: ByteRange, b: KeccakHash): bool = if a.len != b.data.len: return false equalMem(a.baseAddr, b.data[0].unsafeAddr, a.len) type # 256 * 2 div 8 DoubleHash = array[64, byte] proc initDoubleHash(a, b: openArray[byte]): DoubleHash = doAssert(a.len == 32, $a.len) doAssert(b.len == 32, $b.len) copyMem(result[ 0].addr, a[0].unsafeAddr, 32) copyMem(result[32].addr, b[0].unsafeAddr, 32) proc initDoubleHash(x: ByteRange): DoubleHash = initDoubleHash(x.toOpenArray, x.toOpenArray) proc init*(x: typedesc[SparseBinaryTrie], db: DB): SparseBinaryTrie = result.db = db # Initialize an empty tree with one branch var value = initDoubleHash(emptyNodeHashes[0]) result.rootHash = keccakHash(value) result.db.put(result.rootHash.toOpenArray, value) for i in 0..