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

Improve how declare handles an existing class hash #205

Closed
ericglau opened this issue Sep 22, 2022 · 2 comments · Fixed by #207
Closed

Improve how declare handles an existing class hash #205

ericglau opened this issue Sep 22, 2022 · 2 comments · Fixed by #207
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ericglau
Copy link
Member

ericglau commented Sep 22, 2022

When I call declare on an implementation contract to be used with a proxy, if it was previously declared, register_class_hash currently raises an exception containing the hash in the message string.

To improve usability, I want a way to get the existing declaration's class hash (without having to parse the error message) so that it can be used afterwards.

Consider one of the following:
1. Use a custom error that contains the hash in a field, so that the caller of declare can catch the error and retrieve the hash
2. In declare, suppress the error if a class hash already exists, and just proceed to return with the existing class hash
3. In declare, suppress the error if a class hash already exists, and update the entry in the declaration file (e.g. if a different alias is provided)
4. In declare, have an optional flag such as update which allows it to do (3) only if the flag is set.

5. Provide a function similar to get_declaration, but takes a contract (rather than an alias) and returns the corresponding class hash.

@ericglau ericglau added the enhancement New feature or request label Sep 22, 2022
@ericglau ericglau self-assigned this Sep 22, 2022
@ericglau ericglau changed the title Raise custom exception when registering an existing class hash Improve how declare handles an existing class hash Sep 22, 2022
@ericglau
Copy link
Member Author

ericglau commented Sep 22, 2022

I prefer option (4) above, since an update flag would make declare easier to use in this scenario, and still retain the original error if an update is not desired.

@martriay
Copy link
Contributor

the equivalent of (5) would be:

from starkware.crypto.signature.fast_pedersen_hash import pedersen_hash
from starkware.starknet.core.os.class_hash import compute_class_hash

def get_hash(contract_class):
    return compute_class_hash(
        contract_class=contract_class,
        hash_func=pedersen_hash
    )

@martriay martriay added this to the current milestone Sep 22, 2022
@martriay martriay self-assigned this Sep 22, 2022
@ericglau ericglau removed their assignment Sep 22, 2022
@martriay martriay linked a pull request Sep 22, 2022 that will close this issue
@ericnordelo ericnordelo modified the milestones: current, next Oct 4, 2022
@martriay martriay modified the milestones: next, current Oct 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants