Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Fix prove and verifyProof in SecureTrie (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Feb 8, 2019
1 parent c315566 commit 5ac7288
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ module.exports = class SecureTrie extends CheckpointTrie {
super(...args)
}

static prove (trie, key, cb) {
const hash = ethUtil.keccak256(key)
super.prove(trie, hash, cb)
}

static verifyProof (rootHash, key, proof, cb) {
const hash = ethUtil.keccak256(key)
super.verifyProof(rootHash, hash, proof, cb)
}

copy () {
const db = this.db.copy()
return new SecureTrie(db, this.root)
Expand Down
24 changes: 24 additions & 0 deletions test/secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ tape('SecureTrie', function (t) {
})
})

tape('SecureTrie proof', function (t) {
t.test('create a merkle proof and verify it with a single short key', function (st) {
const trie = new Trie()

async.series([
function (cb) {
trie.put('key1aa', '01234', cb)
},
function (cb) {
Trie.prove(trie, 'key1aa', function (err, prove) {
if (err) return cb(err)
Trie.verifyProof(trie.root, 'key1aa', prove, function (err, val) {
if (err) return cb(err)
st.equal(val.toString('utf8'), '01234')
cb()
})
})
}
], function (err) {
st.end(err)
})
})
})

tape('secure tests', function (it) {
let trie = new Trie()
const jsonTests = require('./fixture/trietest_secureTrie.json').tests
Expand Down

0 comments on commit 5ac7288

Please sign in to comment.