-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trie: verifyProof() error on nested embeded nodes / batch() function UX issues #1055
Comments
Same here, PR would be great together with a test case. 😄 |
Tried to make this example run by updating the code from above to the latest MPT v4 version, came up with to be run in import { BaseTrie as Trie } from 'merkle-patricia-tree'
import { BatchDBOp } from 'merkle-patricia-tree/db'
const trie = new Trie()
async function run() {
const ops = [
{ type: 'put', key: Buffer.from('dog'), value: Buffer.from('puppy') },
{ type: 'put', key: Buffer.from('doge'), value: Buffer.from('coin') }
] as BatchDBOp[]
await trie.batch(ops)
const proof = await Trie.prove(trie, Buffer.from('doge'))
const value = await Trie.verifyProof(trie.root, Buffer.from('doge'), proof)
return value
}
run()
.then((value) => {
console.log(value)
})
.catch((error) => {
console.log(error)
}) This is still not running and we should give this use case another look (and also have a look at the bug here).
|
Original error should have been taken care of when proof.js was eliminated in favor of basetrie.js proof implementation. Is the issue you're seeing now (1) an error in the way the trie is getting build, or |
@zmitton thanks for the answer, can't remember TBH. Will just leave open here for someone to re-evaluate at some point. |
@ryanio do you have got some insight if this might still be an issue? 🤔 |
I am not familiar with this issue yet but I will give the example scripts a try to see what could be going on and will report back. I'll also take a look at the |
The written error reported is "unexpected end of proof", and its coming from the proof.js file. Both that error meseage and the file have been eliminated. I believe I wrote a similar situation to return "missing node error". But now that I look through the code, I cant find that error anymore. I think it should be somewhere around here:
Note: Although the behavior of the tree may be to return something like if (value) {
foundNode = decodeNode(value)
} else{
return new Error("missing trie node")
} I could be wrong. I dont have time to work on this but I hope the information is helpful |
I don't know that I fully understand the logic of why the db not finding a node should generate an error versus a null value but as here our code does check for the key not found error condition in the db and then just returns null to the trie module in such cases. It throws on other errors. |
Is this still an issue or can we close after 3 years? 😅 Lol. 😛 |
I think this is okay now, we might have solved it as part of #1368, I ran the example script in #1055 (comment) and got back a valid value: If someone would like to follow up please open a new issue with a reproducible script so we can help. |
When you try to call the verifyProof function for a node that is embedded in another node, which in turn is also embedded, an error occurs.
To reproduce:
Output:
The reason is that only the variant with one level of embedded nodes is considered. This can be seen in file proof.js:82, where the key length is compared with 1, while with multiple nesting of nodes the key will be longer. In our case, it is equal to 2.
The text was updated successfully, but these errors were encountered: