I'm trying to verify ZK proofs on solana, but running into compute limits. I was told I can break things into multiple instructions to get around compute limits but I'm not sure how to do that exactly.
3 Answers
That will very much depend on the code you want to run in the instruction, of course. Is it code you wrote yourself, or are you mostly calling function from some library? You would have to find ways to split the work to be done, then do only part of it, and save the intermediate result in a PDA, and pick up form there in the next instruction.
Please post the code (or something that gives us an idea of the nature of the code), so that we can give some further input.
-
1It was a groth16 verification using ark-groth16 verify() function for zk proofs. I found an example of someone breaking it up into smaller chunks here: github.com/zkLinkProtocol/groth16-sol-verifier Commented Jul 24, 2022 at 5:07
To do compute over multiple instructions you can store intermediate calculations in variables on an account. That way when you start up the next transaction you can continue on from where you finished at the end of the last transaction.
This should not be an issue anymore since we have moved to Transaction-wide Compute Budget. This is already enabled in mainnet-beta.
Previously, there was a per-instruction limit but now the compute budget is calculated for the entire transaction. And you can request additional budget for a fee, e.g. here is a web3.js example:
transaction.add(
ComputeBudgetProgram.requestUnits({
units: 100_000,
additionalFee: 100,
})
);
This is the instruction it is calling. I highly recommend reading this part of Solana docs as well.
In short, you should be able to get away with a single instruction and not have to break it up anymore.
-
the additional compute units max out at 1 mil and the code still wasn't complete in that limit, so i think i'll have to still break it up Commented Jul 24, 2022 at 5:06
-
-