Aligned can be integrated into your applications in a few simple steps to provide a way to verify ZK proofs generated inside your system.
You can find an example of the full flow of using Aligned in your app in the ZKQuiz example.
This example shows a sample app that generates an SP1 proof that a user knows the answers to a quiz and then submits the proof to Aligned for verification. Finally, it includes a smart contract that verifies that a proof was verified in Aligned and mints an NFT.
1. Generate your ZK Proof
To submit proofs to Aligned and get them verified, first you need to generate those proofs. Every proving system has its own way of generating proofs.
To check if a proof was verified in Aligned, you need to make a call to the AlignedServiceManager contract inside your smart contract.
Also, you will need a way to check that the proven program is the correct one.
The Aligned CLI provides a way for you to get the verification key commitment without actually generating and submitting a proof.
You can do this by running the following command:
alignedget-commitment--input<path_to_input_file>
The following is an example of how to call the verifyBatchInclusionMethod from the AlignedServiceManager contract in your smart contract.
contract YourContract {// Your contract variables ...addresspublic alignedServiceManager;bytes32public elfCommitment =<elf_commitment>;constructor(address_alignedServiceManager) {//... Your contract constructor ... alignedServiceManager = _alignedServiceManager; }// Your contract code ...functionyourContractMethod(//... Your function variables, ...bytes32 proofCommitment,bytes32 pubInputCommitment,bytes32 provingSystemAuxDataCommitment,bytes20 proofGeneratorAddr,bytes32 batchMerkleRoot,bytesmemory merkleProof,uint256 verificationDataBatchIndex ) {// ... Your function coderequire(elfCommitment == provingSystemAuxDataCommitment,"ELF does not match"); (bool callWasSuccessful,bytesmemory proofIsIncluded) = alignedServiceManager.staticcall( abi.encodeWithSignature("verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)", proofCommitment, pubInputCommitment, provingSystemAuxDataCommitment, proofGeneratorAddr, batchMerkleRoot, merkleProof, verificationDataBatchIndex ) );require(callWasSuccessful,"static_call failed");bool proofIsIncludedBool = abi.decode(proofIsIncluded, (bool));require(proofIsIncludedBool,"proof not included in batch");// Your function code ... }}
You can find an example of the smart contract that checks if the proof was verified in Aligned in the Quiz Verifier Contract.
Note that the contract checks if the verification key commitment is the same as the program ELF commitment.
require(elfCommitment == provingSystemAuxDataCommitment,"ELF does not match");
This contract also includes a static call to the AlignedServiceManager contract to check if the proof was verified in Aligned.
(bool callWasSuccessfull,bytesmemory proofIsIncluded) = alignedServiceManager.staticcall( abi.encodeWithSignature("verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)", proofCommitment, pubInputCommitment, provingSystemAuxDataCommitment, proofGeneratorAddr, batchMerkleRoot, merkleProof, verificationDataBatchIndex ));require(callWasSuccessfull,"static_call failed");bool proofIsIncludedBool = abi.decode(proofIsIncluded, (bool));require(proofIsIncludedBool,"proof not included in batch");
3. Submit and verify the proof to Aligned
The proof submission and verification can be done either with the SDK or by using the Aligned CLI.
Using the SDK
To submit a proof using the SDK, you can use the submit_and_wait_verification function. This function submits the proof to aligned and waits for it to be verified in Aligned. Alternatively you can call submit if you dont want to wait for proof verification. The following code is an example of how to submit a proof using the SDK:
You can find an example of the proof submission and verification in the ZKQuiz Program.
This example generates a proof, instantiates a wallet to submit the proof, and then submits the proof to Aligned for verification. It then waits for the proof to be verified in Aligned.
Using the CLI
You can find examples of how to submit a proof using the CLI in the submitting proofs guide.