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

Entry point validation / class hash issue #757

@kkovaacs

Description

@kkovaacs

Given this class starknet_in_rust code either fails validation or class hash computation, depending on which way I try to parse the contract class.

Steps to reproduce:

curl -s https://alpha-mainnet.starknet.io/feeder_gateway/get_class_by_hash\?classHash\=0x04479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad > starknet_programs/raw_contract_classes/0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad.json

Two of these three test cases fail:

    #[test]
    fn test_compute_class_hash_0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad_try_from(
    ) {
        let contract_str = fs::read_to_string("starknet_programs/raw_contract_classes/0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad.json").unwrap();

        let contract_class =
            ContractClass::try_from(<String as AsRef<str>>::as_ref(&contract_str)).unwrap();

        assert_eq!(
            compute_deprecated_class_hash(&contract_class).unwrap(),
            felt_str!(
                "4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad",
                16
            )
        );
    }

    #[test]
    fn test_compute_class_hash_0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad_new(
    ) {
        let contract_str = fs::read_to_string("starknet_programs/raw_contract_classes/0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad.json").unwrap();

        let parsed_contract_class = ParsedContractClass::try_from(contract_str.as_str()).unwrap();
        let contract_class = ContractClass::new(
            serde_json::Value::from_str(&contract_str).unwrap(),
            parsed_contract_class.program,
            parsed_contract_class.entry_points_by_type,
            parsed_contract_class.abi,
        )
        .unwrap();

        assert_eq!(
            compute_deprecated_class_hash(&contract_class).unwrap(),
            felt_str!(
                "4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad",
                16
            )
        );
    }
    #[test]
    fn test_compute_class_hash_0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad() {
        let contract_str = fs::read_to_string("starknet_programs/raw_contract_classes/0x4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad.json").unwrap();

        let parsed_contract_class = ParsedContractClass::try_from(contract_str.as_str()).unwrap();
        let contract_class = ContractClass {
            program_json: serde_json::Value::from_str(&contract_str).unwrap(),
            program: parsed_contract_class.program,
            entry_points_by_type: parsed_contract_class.entry_points_by_type,
            abi: parsed_contract_class.abi,
        };

        assert_eq!(
            compute_deprecated_class_hash(&contract_class).unwrap(),
            felt_str!(
                "4479c3b883b34f1eafa5065418225d78a11ee7957c371e1b285e4b77afc6dad",
                16
            )
        );
    }

ContractClass::try_from(&str) does not fail but leads to an invalid class hash.

ContractClass::new() fails because the entry points in this class are not ordered properly.

When constructing ContractClass directly (not possible via the public API) the computed class hash is OK though...

And why are there multiple APIs for parsing a class definition? I'd much prefer something like ContractClass::try_from(&str) that actually works rather than having to use ParsedContractClass (I don't even know what that is and what relation it has with ContractClass).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions