Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Compute hinted class hash #685

Closed
marioiordanov opened this issue Jun 26, 2023 · 9 comments · Fixed by #681
Closed

Compute hinted class hash #685

marioiordanov opened this issue Jun 26, 2023 · 9 comments · Fixed by #681

Comments

@marioiordanov
Copy link
Contributor

I see in the code that compute_hinted_class_hash is being calculated as the keccak of this string r#"{"abi": contract_class.abi, "program": contract_class.program}"#.
Should it be changed to reflect the actual information of abi and program of the json artifact

@SantiagoPittella SantiagoPittella linked a pull request Jun 26, 2023 that will close this issue
2 tasks
@SantiagoPittella
Copy link
Collaborator

Hi! We just fixed it in: #681

@marioiordanov
Copy link
Contributor Author

Yes, it is changed but I think in the abi section the struct is missing state_mutability property

@SantiagoPittella
Copy link
Collaborator

Yes, it is changed but I think in the abi section the struct is missing state_mutability property

Along with the cairo-vm program, we are also storing the compiled program in a serde_json::Value, which has the stateMutability field in each object of the ABI, so it should be there on the deserialization. But let us know if you realize that is not right. Thanks!

@marioiordanov

@marioiordanov
Copy link
Contributor Author

marioiordanov commented Jul 3, 2023

@SantiagoPittella with this (https://gist.github.com/marioiordanov/646683d1fe073e1682fbed5794c168dc) Cairo 0 contract the pythonic Cairo lang produces the following hash 0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f, but compute_deprecated_class_hash gives this one 0x5b5e230e0920e1a18ed8c4360388f042a98b91914f774d7b2cac2633303646d

@marioiordanov
Copy link
Contributor Author

marioiordanov commented Jul 3, 2023

If you need information how its generated you can take a look at this implementation https://github.com/0xSpaceShard/starknet-devnet-rs/blob/2dfcf6c5f5b76338836b5767bc00ed8079796be7/crates/types/src/contract_class.rs#L106

@marioiordanov
Copy link
Contributor Author

@SantiagoPittella @juanbono I saw your changes to the ContractClass compute_deprecated_class_hash. The problem is that you rely on starknet_api and in its ABI they don't take in mind the stateMutability field

@SantiagoPittella
Copy link
Collaborator

Hi! I added a test for the class hash that you mention and looks like it's working. Are you using an specific version of starknet_in_rust or main?

The tests can be found here:
#801

@SantiagoPittella
Copy link
Collaborator

How are you creating the ContractClass? are you using?

        let contract_class = ContractClass::from_path(
            "<my_json.json"
        ).unwrap();

Or are you doing something different?

@SantiagoPittella
Copy link
Collaborator

@SantiagoPittella with this (https://gist.github.com/marioiordanov/646683d1fe073e1682fbed5794c168dc) Cairo 0 contract the pythonic Cairo lang produces the following hash 0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f, but compute_deprecated_class_hash gives this one 0x5b5e230e0920e1a18ed8c4360388f042a98b91914f774d7b2cac2633303646d

Regarding this:
I look in mainnet for the class_hash 0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f and used the json from the mainnet:

curl -s https://alpha-mainnet.starknet.io/feeder_gateway/get_class_by_hash\?classHash\=0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f

And our class_hash calculation worked correctly.
With the one from your link didn't. But it was different from the one from mainnet.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants