Callback Gas Limit Estimation
When interacting with the AI Oracle, it is crucial to allocate sufficient gas for the execution of the callback function. The gas consumed during the callback depends entirely on the implementation of the aiOracleCallback
method. Its logic directly impacts gas usage - the more complex the logic, the higher the gas consumption. Carefully design your aiOracleCallback
to balance functionality and gas efficiency.
To estimate the gas required for the aiOracleCallback
in a Foundry project:
Run the following command to generate a gas report:
Locate your Prompt contract in the report and check the gas usage for the
aiOracleCallback
method.Use the calculated gas amount to set the gas limit during the initialisation of the Prompt contract (in the constructor).
Alternatively you can use other tools like Hardhat or Tenderly.
Test Script
We provided test script for gas limit estimation in the template repository.
To execute estimation run: forge test test/EstimateGasLimit.t.sol -vvvv . Next to the callback function, you can observe the gas amount needed for execution. eg. [1657555] Prompt::aiOracleCallback -> in this case amount we can set gas limit to 1700000
The above script estimates gas necessary for Stable-Diffusion callback. Note that result will always be constant size (ipfs CID).
Llama3
To estimate gas limit for Llama3, you need to change modelId and result.
💡 The maximum length of Llama3 response is 200 words string, hence we will use this string size to estimate gas limit.
Last updated
Was this helpful?