Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

make get_hash return hex #257

Merged
merged 7 commits into from
Nov 7, 2022
Merged

make get_hash return hex #257

merged 7 commits into from
Nov 7, 2022

Conversation

martriay
Copy link
Contributor

@martriay martriay commented Oct 25, 2022

fixes #258

@martriay martriay added this to the current milestone Oct 25, 2022
@martriay martriay removed this from the current milestone Oct 25, 2022
@@ -197,4 +197,6 @@ def get_contract_class(contract_name, overriding_path=None):
def get_hash(contract_name, overriding_path=None):
"""Return the class_hash for a given contract name."""
contract_class = get_contract_class(contract_name, overriding_path)
return compute_class_hash(contract_class=contract_class, hash_func=pedersen_hash)
return hex(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we must pad the class_hash, similar to what we do with addresses. We have an hex_address method in utils, we can add another one like hex_class_hash. (If we don't pad, short class hashes because of leading 0s, could be as confusing as short addresses because of leading 0s).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, i considered it but wasn't sure

Copy link
Contributor

@andrew-fleming andrew-fleming Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pad get_hash, we should update declare's class hash registration for consistency because it's storing the unpadded hex. Also, @ericglau will probably need to adjust one of the hash values in declare_impl: https://github.com/OpenZeppelin/openzeppelin-nile-upgrades/blob/main/src/nile_upgrades/declare_impl.py#L18

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i insist in killing the declarations file. it serves no purpose and it's actually annoying when your declare tx fails.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also resolves the inconsistency :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericnordelo how long class hashes should be? 67?

Copy link
Member

@ericnordelo ericnordelo Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

65 ("0x" + 63 hex) is enough because the length is 250 bits (to fit in a felt). But maybe we should pad to 66 ("0x" + 64), even if we always add a 0 at the beginning (after the 0x) because 32 bytes is a standard in Ethereum? (just thinking out loud, I don't have a strong case for any option).

Starkscan uses 66 (pad with extra 0), while voyager uses 65 (without the leading 0).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder why they pad to 64. how are addresses 64 then? that shouldn't fit a felt

Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I left just a small suggestion regarding a comment.



def hex_class_hash(number):
"""Return the 65 hexadecimal characters length class hash."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either change the number here to 63 or change the comment in hex_address's number to 66 to keep consistency (I didn't consider the "0x" prefix as part of the length of the hexadecimal characters when I added the comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to the former

Copy link
Contributor Author

@martriay martriay Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the comment is misleading, it should say the full length, including the 0x. therefore this comment should say 65, and hex_address's 66

Copy link
Contributor

@andrew-fleming andrew-fleming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@ericnordelo ericnordelo self-requested a review November 7, 2022 17:34
Copy link
Member

@ericnordelo ericnordelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@martriay martriay merged commit 1a3da15 into main Nov 7, 2022
@martriay martriay deleted the return-hex-hash branch November 7, 2022 18:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make get_hash return hex
3 participants