Posting Request to a Subnet Model
When users need to utilize a subnet model within the 2PM Network, they must engage in a multi-step process to request inference from the model. This process involves contract interactions, data submissions, and cryptographic operations to ensure secure and authorized access to the model's capabilities. Here’s a comprehensive overview of posting a request to a subnet model:
Step-by-Step Process for Posting an Inference Request to a Subnet Model
Interacting with the Royalty Vault Contract:
Users begin by interacting with the
request_Inference
method of the Royalty Vault contract associated with the model's corresponding subnet. This smart contract handles the economic transactions and access permissions for the subnet's resources.
Uploading Signed Inference Data and Paying Fees:
As part of the contract interaction, users are required to upload a signature of their inference data. This signature acts as a verification mechanism to ensure the integrity and authenticity of the data being submitted for inference.
Additionally, users must pay the fees as defined in the contract. These fees compensate for the computational resources and used during the inference process and contribute to the ongoing development and maintenance of the subnet.
Submitting the Transaction:
Once the necessary fees are paid and the data is signed and submitted, the transaction is completed on the blockchain. Users receive a transaction hash, which serves as a receipt and a tracking mechanism for the submitted request.
Sending the Request to the 2PM Node:
With the transaction completed, users must then submit several pieces of information to the corresponding subnet's 2PM Node to initiate the inference process:
Transaction Hash: This is used by the 2PM Node to verify that the fees have been paid and the contract interactions are valid.
Inference Input Data: The actual input data on which inference is to be performed.
Inference Data Signature: This confirms the data's authenticity, ensuring it has not been altered since the signature was applied.
One-Time Key Signature: At the beginning of the request process, 2PM sends a one-time key to the user, which the user must sign and submit. This signature is used to ensure that the request is being made by the rightful user and to enhance the security of the data transmission.
Receiving Inference Results:
Once the 2PM Node has verified all the submitted details, it processes the inference request. The results are then securely sent back to the user, completing the interaction.
For users involved in Fully Homomorphic Encryption (FHE) Model Inference, an additional step is required to access the results. FHE users must utilize their private key to decrypt the received data. This decryption step ensures that the privacy of the data is maintained throughout the process, as only the user with the corresponding private key can access the actual inference results.
Tutorial
This tutorial will guide you through the steps to interact with the Royalty Vault Contract using JavaScript (specifically with Web3.js library) and how to call the 2PM Node's API using HTTP RPC to request model predictions.
Prerequisites:
Node.js installed on your system.
Web3.js library installed. If not already installed, you can add it to your project by running
npm install web3
.Access to an Ethereum wallet with Ether for transaction fees and a private key for signing transactions.
The address and ABI (Application Binary Interface) of the Royalty Vault Contract.
The URL for the 2PM Node API.
Step 1: Setup and Initialize Web3
First, set up your JavaScript environment and initialize Web3 to interact with the Ethereum blockchain.
Step 2: Interacting with the Royalty Vault Contract
To interact with the Royalty Vault Contract, we will call the request_Inference
method. Ensure you have the signature of the inference data input.
Step 3: Calling the 2PM Node API
After the blockchain transaction is confirmed, you can make a prediction request to the 2PM Node API. Assume you have obtained a transaction hash and other necessary details for the API call.
Step 4: Decrypting the Results (for FHE ML model users only)
If the data received is encrypted (in the case of FHE), use your private key to decrypt the results (Refer to ZAMA Concrete ML Docs for details).
Last updated