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