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
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
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
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
@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
@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
        ),
    )