types - Infernet ML
Description: Infernet ML Documentation

Skip to content

# Module: `types`

## `EZKLServiceConfig`

Bases: `BaseModel`

Configuration for loading EZKL Proving Artifacts. If a model source & repo_id are provided, those are loaded & used as the default artifact.

Attributes:

Name | Type | Description
--- | --- | ---
`ARTIFACT_DIRECTORY` | `Optional[str]` | Defaults to `/artifacts`. Directory where the artifacts are stored.
`HF_TOKEN` | `Optional[str]` | Defaults to `None`. The token to use for downloading artifacts from the huggingface, for private repositories.

Source code in `src/infernet_ml/zk/ezkl/types.py`

    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    class EZKLServiceConfig(BaseModel):
        """
        Configuration for loading EZKL Proving Artifacts. If a model source & repo_id are
        provided, those are loaded & used as the default artifact.

        Attributes:
            ARTIFACT_DIRECTORY: Defaults to `/artifacts`. Directory where the artifacts are
                stored.
            HF_TOKEN: Defaults to `None`. The token to use for downloading artifacts from
                the huggingface, for private repositories.
        """

        ARTIFACT_DIRECTORY: Optional[str] = f"{HOMEDIR}/.cache/ritual"
        HF_TOKEN: Optional[str] = None

        class Config:
            # to make config hashable
            frozen = True

## `EZKLVerifyProofRequest`

Bases: `BaseModel`

Data representing a request to verify an EZKL proof. Used in the EZKL Proof Service.

Attributes:

Name | Type | Description
--- | --- | ---
`repo_id` | `str` | RitualRepoId id of the repository containing EZKL artifacts
`proof` | `str` | Dict[str, Any] The ezkl proof to verify

Source code in `src/infernet_ml/zk/ezkl/types.py`

     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    class EZKLVerifyProofRequest(BaseModel):
        """
        Data representing a request to verify an EZKL proof. Used in the EZKL Proof Service.

        Attributes:
            repo_id: RitualRepoId id of the repository containing EZKL artifacts
            proof: Dict[str, Any] The ezkl proof to verify
        """

        repo_id: str
        proof: str

        def to_keyval(self) -> List[Tuple[str, Any]]:
            return [
                ("repo_id", self.repo_id),
                ("proof_length", str(len(json.dumps(self.proof)))),
            ]

## `WitnessInputData`

Bases: `BaseModel`

data required to generate a EZKL request witness - specifically, an input vector, and an output vector.

Attributes:

Name | Type | Description
--- | --- | ---
`input_data` | `RitualVector` | the input vector
`output_data` | `Optional[RitualVector]` | the output vector

Source code in `src/infernet_ml/zk/ezkl/types.py`

    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
    class WitnessInputData(BaseModel):
        """
        data required to generate a EZKL request witness - specifically, an input
        vector, and an output vector.

        Attributes:
            input_data: the input vector
            output_data: the output vector
        """

        input_data: RitualVector
        output_data: Optional[RitualVector]

        @classmethod
        def from_numpy(
            cls,
            input_vector: FloatNumpy,
            output_vector: Optional[FloatNumpy] = None,
        ) -> WitnessInputData:
            """
            Create a WitnessInputData object from numpy arrays.

            Args:
                input_vector: the input vector
                output_vector: the output vector

            Returns:
                WitnessInputData: the WitnessInputData object
            """
            return cls(
                input_data=RitualVector.from_numpy(input_vector),
                output_data=(
                    RitualVector.from_numpy(output_vector) if output_vector else None
                ),
            )

        @property
        def to_abi_encoded(self) -> bytes:
            """
            Encode the WitnessInputData object as an ABI-encoded byte string.

            Returns:
                bytes: the ABI-encoded byte string
            """

            return encode(
                ["bytes", "bytes"],
                [
                    self.input_data.to_web3(),
                    self.output_data.to_web3() if self.output_data else b"",
                ],
            )

        @classmethod
        def from_abi_encoded(cls, input_hex: str | bytes) -> WitnessInputData:
            """
            Create a WitnessInputData object from an ABI-encoded byte string.

            Args:
                input_hex: the ABI-encoded byte string

            Returns:
                WitnessInputData: the WitnessInputData object
            """
            input_hex = (
                input_hex
                if isinstance(input_hex, bytes)
                else bytes.fromhex(input_hex.removeprefix("0x"))
            )

            in_bytes, out_bytes = decode(["bytes", "bytes"], input_hex)
            input_data = RitualVector.from_web3(in_bytes)
            output_data = RitualVector.from_web3(out_bytes) if out_bytes else None
            return cls(
                input_data=input_data,
                output_data=output_data,
            )

### `to_abi_encoded: bytes` `property`

Encode the WitnessInputData object as an ABI-encoded byte string.

Returns:

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

### `from_abi_encoded(input_hex)` `classmethod`

Create a WitnessInputData object from an ABI-encoded byte string.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`input_hex` | `str | bytes` | the ABI-encoded byte string | required

Returns:

Name | Type | Description
--- | --- | ---
`WitnessInputData` | `WitnessInputData` | the WitnessInputData object

Source code in `src/infernet_ml/zk/ezkl/types.py`

    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    @classmethod
    def from_abi_encoded(cls, input_hex: str | bytes) -> WitnessInputData:
        """
        Create a WitnessInputData object from an ABI-encoded byte string.

        Args:
            input_hex: the ABI-encoded byte string

        Returns:
            WitnessInputData: the WitnessInputData object
        """
        input_hex = (
            input_hex
            if isinstance(input_hex, bytes)
            else bytes.fromhex(input_hex.removeprefix("0x"))
        )

        in_bytes, out_bytes = decode(["bytes", "bytes"], input_hex)
        input_data = RitualVector.from_web3(in_bytes)
        output_data = RitualVector.from_web3(out_bytes) if out_bytes else None
        return cls(
            input_data=input_data,
            output_data=output_data,
        )

### `from_numpy(input_vector, output_vector=None)` `classmethod`

Create a WitnessInputData object from numpy arrays.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`input_vector` | `FloatNumpy` | the input vector | required
`output_vector` | `Optional[FloatNumpy]` | the output vector | `None`

Returns:

Name | Type | Description
--- | --- | ---
`WitnessInputData` | `WitnessInputData` | the WitnessInputData object

Source code in `src/infernet_ml/zk/ezkl/types.py`

    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    @classmethod
    def from_numpy(
        cls,
        input_vector: FloatNumpy,
        output_vector: Optional[FloatNumpy] = None,
    ) -> WitnessInputData:
        """
        Create a WitnessInputData object from numpy arrays.

        Args:
            input_vector: the input vector
            output_vector: the output vector

        Returns:
            WitnessInputData: the WitnessInputData object
        """
        return cls(
            input_data=RitualVector.from_numpy(input_vector),
            output_data=(
                RitualVector.from_numpy(output_vector) if output_vector else None
            ),
        )