Skip to content
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

smt.exists(item) doesn't work if default node value is set #129

Open
fubuloubu opened this issue Mar 10, 2022 · 4 comments · May be fixed by #128
Open

smt.exists(item) doesn't work if default node value is set #129

fubuloubu opened this issue Mar 10, 2022 · 4 comments · May be fixed by #128

Comments

@fubuloubu
Copy link
Contributor

fubuloubu commented Mar 10, 2022

py-trie/trie/smt.py

Lines 340 to 341 in e5bf55c

self.get(key)
return True

should be this instead:

 return self.get(key) == self._default
@sabotagebeats sabotagebeats linked a pull request Mar 11, 2022 that will close this issue
@antazoey
Copy link
Contributor

haha I just got this problem, messaged you, searched, found you created this issue already

@antazoey
Copy link
Contributor

Wouldn't it get fixed by changing get() to check self._default before raising KeyError instead of BLANK_NODE? That way, you still get the KeyError when expected. Same with branch. My attached PR does that, and thus it fixes this issue as well.

@antazoey
Copy link
Contributor

Looking at the doc of the class:

If this default is anything other than a blank
node, then all keys "exist" in the database, which mimics the behavior of
Ethereum on-chain datastores.

So we do want exists return True in this case?

@fubuloubu
Copy link
Contributor Author

Looking at the doc of the class:

If this default is anything other than a blank
node, then all keys "exist" in the database, which mimics the behavior of
Ethereum on-chain datastores.

So we do want exists return True in this case?

I think per the comment that it would augment .exists(key) to a non-default check (which would be useful independently of a KeyError from .get(key)), and leave .get(key) and .branch(key) to allows provide you with a value, even if the key is set default (but non-empty) because I might want to "prove" that my proof leads to an empty value

pacrob pushed a commit to pacrob/py-trie that referenced this issue Apr 18, 2024
* `sphinx-autobuild` for live docs updates.

* Use Python 3.9 and `sphinx-autobuild` `2024.2.4`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants