ezkl - Infernet ML
Description: Infernet ML Documentation

Skip to content

# Module: `ezkl`

## `EZKLGenerateProofRequest`

Bases: `BaseModel`

A request for an EZKL proof.

Attributes:

Name | Type | Description
--- | --- | ---
`witness_data` | `WitnessInputData` |
`vk_address` | `Optional[HexStr]` | Optional[HexStr]: the address of the verifying key contract

Source code in `src/infernet_ml/services/ezkl.py`

    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    class EZKLGenerateProofRequest(BaseModel):
        """
        A request for an EZKL proof.

        Attributes:
            witness_data: RitualRepo: data necessary to generate a witness
            vk_address: Optional[HexStr]: the address of the verifying key contract
        """

        repo_id: str
        witness_data: WitnessInputData

        # vk_address refers to a separate verifying key contract.
        # See (EZKL documentation)[https://github.com/zkonduit/ezkl/blob/main/src/python.rs#L1493] for more info. # noqa: E501
        vk_address: Optional[HexStr] = None

        def to_keyval(self) -> List[Tuple[str, Optional[str]]]:
            """
            Convert the request to a list of key-value pairs.

            Returns:
                List[Tuple[str, Optional[str]]]: the key-value pairs
            """
            return [
                ("repo_id", self.repo_id),
                ("vk_address", self.vk_address),
            ]

        def to_web3(self) -> bytes:
            """
            Convert the request to a web3 ABI-encoded byte string.

            Returns:
                bytes: the ABI-encoded byte string
            """
            repo_id = RitualRepoId.from_unique_id(self.repo_id)
            return encode(
                [
                    "bytes",
                    "bytes",
                ],
                [
                    repo_id.to_web3(),
                    self.witness_data.to_abi_encoded,
                ],
            )

        @classmethod
        def from_numpy(
            cls, repo_id: str, np_input: np.ndarray[Any, Any]
        ) -> EZKLGenerateProofRequest:
            """
            Create a request from a numpy array.

            Args:
                repo_id (str): the repo ID
                np_input (np.ndarray[Any, Any]): the input data

            Returns:
                EZKLGenerateProofRequest: the request
            """
            witness_data = WitnessInputData.from_numpy(input_vector=np_input)
            return cls(
                repo_id=repo_id,
                witness_data=witness_data,
            )

        @classmethod
        def from_web3(cls, input_hex: Union[str, bytes]) -> EZKLGenerateProofRequest:
            """
            Create a request from a web3 ABI-encoded byte string.

            Args:
                input_hex: Union[str, bytes]: the ABI-encoded byte string

            Returns:
                EZKLGenerateProofRequest: the request
            """
            if isinstance(input_hex, str):
                input_hex = bytes.fromhex(input_hex.removeprefix("0x"))

            repo_id_data, witness_data = decode(["bytes", "bytes"], input_hex)
            return cls(
                repo_id=RitualRepoId.from_web3(repo_id_data).to_unique_id(),
                witness_data=WitnessInputData.from_abi_encoded(witness_data),
            )

### `from_numpy(repo_id, np_input)` `classmethod`

Create a request from a numpy array.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`repo_id` | `str` | the repo ID | required
`np_input` | `ndarray[Any, Any]` | the input data | required

Returns:

Name | Type | Description
--- | --- | ---
`EZKLGenerateProofRequest` | `EZKLGenerateProofRequest` | the request

Source code in `src/infernet_ml/services/ezkl.py`

    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    @classmethod
    def from_numpy(
        cls, repo_id: str, np_input: np.ndarray[Any, Any]
    ) -> EZKLGenerateProofRequest:
        """
        Create a request from a numpy array.

        Args:
            repo_id (str): the repo ID
            np_input (np.ndarray[Any, Any]): the input data

        Returns:
            EZKLGenerateProofRequest: the request
        """
        witness_data = WitnessInputData.from_numpy(input_vector=np_input)
        return cls(
            repo_id=repo_id,
            witness_data=witness_data,
        )

### `from_web3(input_hex)` `classmethod`

Create a request from a web3 ABI-encoded byte string.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`input_hex` | `Union[str, bytes]` | Union[str, bytes]: the ABI-encoded byte string | required

Returns:

Name | Type | Description
--- | --- | ---
`EZKLGenerateProofRequest` | `EZKLGenerateProofRequest` | the request

Source code in `src/infernet_ml/services/ezkl.py`

    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    @classmethod
    def from_web3(cls, input_hex: Union[str, bytes]) -> EZKLGenerateProofRequest:
        """
        Create a request from a web3 ABI-encoded byte string.

        Args:
            input_hex: Union[str, bytes]: the ABI-encoded byte string

        Returns:
            EZKLGenerateProofRequest: the request
        """
        if isinstance(input_hex, str):
            input_hex = bytes.fromhex(input_hex.removeprefix("0x"))

        repo_id_data, witness_data = decode(["bytes", "bytes"], input_hex)
        return cls(
            repo_id=RitualRepoId.from_web3(repo_id_data).to_unique_id(),
            witness_data=WitnessInputData.from_abi_encoded(witness_data),
        )

### `to_keyval()`

Convert the request to a list of key-value pairs.

Returns:

Type | Description
--- | ---
`List[Tuple[str, Optional[str]]]` | List[Tuple[str, Optional[str]]]: the key-value pairs

Source code in `src/infernet_ml/services/ezkl.py`

    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    def to_keyval(self) -> List[Tuple[str, Optional[str]]]:
        """
        Convert the request to a list of key-value pairs.

        Returns:
            List[Tuple[str, Optional[str]]]: the key-value pairs
        """
        return [
            ("repo_id", self.repo_id),
            ("vk_address", self.vk_address),
        ]

### `to_web3()`

Convert the request to a web3 ABI-encoded byte string.

Returns:

Name | Type | Description
--- | --- | ---
`bytes` | `bytes` | the ABI-encoded byte string

Source code in `src/infernet_ml/services/ezkl.py`

    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    def to_web3(self) -> bytes:
        """
        Convert the request to a web3 ABI-encoded byte string.

        Returns:
            bytes: the ABI-encoded byte string
        """
        repo_id = RitualRepoId.from_unique_id(self.repo_id)
        return encode(
            [
                "bytes",
                "bytes",
            ],
            [
                repo_id.to_web3(),
                self.witness_data.to_abi_encoded,
            ],
        )