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

Fix prove and verifyProof in SecureTrie #79

Merged
merged 1 commit into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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