-
Notifications
You must be signed in to change notification settings - Fork 1
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
chore: Add code to implement pedersenHash/GetTreeKeyHash in javascript #22
Conversation
f6b4a43
to
e91df9c
Compare
…nd fix class import
This is an optimization and we can remove it and pad on the js side
e91df9c
to
ef6d688
Compare
I'm not sure where this is called in the down stream package, though note that you likely don't want to implement calls like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, two small first comments. 🙂
I will go ahead and merge this in. In a subsequent PR I will clean the API up when possible, and add some documentation. |
// ext_input = inp + b"\0" * (255 * 16 - len(inp)) | ||
// ints = [2 + 256 * len(inp)] + \ | ||
// int.from_bytes(ext_input[16 * i:16 * (i + 1)]) for i in range(255)] | ||
// return compute_commitment_root(ints).serialize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Kev,
some additional comments here: we also need getTreeKeyHash()
for optimization to not have this called over and over again with the same parameters from getTreeKey()
, I will just expose this method in a quick follow-up release (so note is purely informational, nothing to do on your side).
Generally I am not so sure about the relation of Context.getTreeKey()
and this standalone getTreeKey()
coming from this file (and both exposed on the API level), can you clarify?
All the best
Holge
|
||
const subIndex = 0 | ||
|
||
const keyRust = context.getTreeKey(address, treeIndex, subIndex) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Context
thing needs to be "statefull" I assume?
Or could the methods on this also be static
(at least partially)?
It would be a bit more convenient if it would not be necessary to initialize an initial context with new Context()
and manage this object (what does this object do?) and just call Context.getTreeKey()
(so, the captial Context
, and not context
).
In case all
methods from Context could also be made static it would be even better if Context
goes away completely and only the methods would be exposed directly.
If Context
need to stay I would prefer another name, something more expressive and less generic (FFI
?).
const treeIndex = new Uint8Array([ | ||
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, | ||
56, 57, 58, 59, 60, 61, 62, 63, 64, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused, taking this from the EIP https://eips.ethereum.org/EIPS/eip-6800 ...
def get_tree_key(address: Address32, tree_index: int, sub_index: int):
# Asssumes VERKLE_NODE_WIDTH = 256
return (
pedersen_hash(address + tree_index.to_bytes(32, 'little'))[:31] +
bytes([sub_index])
)
def get_tree_key_for_version(address: Address32):
return get_tree_key(address, 0, VERSION_LEAF_KEY)
... tree_index
is simply 0
, while above it is such a complex byte value. 🤔 How is this coming together?
This is a first pass at adding the code needed for pedersenHash/GetTreeKeyHash.
This would supercede #16