Create a Schema Hook
Last updated
Was this helpful?
Last updated
Was this helpful?
In this step, we will extend the verifier contract generated by the ZK library and implement the interface. From the previous step, our generated contract looks something like this:
The generated verifier should now look like this:
To set up your schema hook, create another file that contains the following contents:
Next, we create the SHA256PreimageVerifier
contract which is responsible for setting the contract address for the Sign Protocol instance and adding ownable functionality.
Last, we create ZKHook
to add all of our schema hook logic. Because ZK proofs can be large, we recommend making use of the extraData
field - this data gets passed to Sign Protocol's contract when attestations are created or revoked but does not get stored onchain. extraData
is only forwarded to schema hooks for data processing and verification, so this is a perfect scenario for providing required ZK-proof-related data. This hook decodes the inputted data and passes it to the verifier's verifyProof()
function. The call reverts if verification fails. If verification succeeds, the attestation will be successfully created.
We begin by importing our generated Groth16Verifier
contract, OpenZepplin packages, and the contract.
Once you have completed your ZK schema hook, it is time to deploy the contract to your desired network. After the contract gets deployed, on the same network and set the hook smart contract address to the address of your deployed schema hook contract. Your ZK schema hook is ready to go!