Guide: Setting up cross-chain replication for ZK Passport
Native state transfer to Ethereum L1 is currently under construction.
This guide walks you through the process of setting up cross-chain replication for ZK Passport Registry state. By the end of this tutorial, you will have:
- Deployed the RegistrationSMTReplicator contract on the target chain.
- Set up your relayer or front-end submission flow.
Step 1: Deploy the RegistrationSMTReplicator
The RegistrationSMTReplicator handles the replication of state from the ZK Registry onto your chain. This ensures your chain is kept up to date with changes to passport registrations.
-
Obtain the contract code for RegistrationSMTReplicator.
-
Deploy the
RegistrationSMTReplicator
to your chain and initialize it:await replicator.__RegistrationSMTReplicator_init(
signer, // public key of the replicator
sourceSMT, // contract address of the original registry on Rarimo L2
chainName // target chain name
);
Step 2: Set up the relayer with front-end submission to replicate the states
To keep the state of the ZK Registry in sync with your chain, you need to set up a relayer with front-end submission.
This will ensure that any changes in the ZK Registry are reflected in the RegistrationSMTReplicator
contract.
You have to set up backend service and make your front-end app update the root:
-
Relayer: Run a relayer service that listens for events from the ZK Registry.
- Follow the instructions in proof-verification-relayer README.
- Make sure you set the right replicator contract address and private key of corresponding
allowedUpdaterAddress
in the config. - Make sure endpoint is available for your frontend app.
-
Front-end: Send the state update transactions on-demand from your front-end:
- After obtaining the proof from verificator-svc you know the required
root
(it is a 11th pub signal). - Now you can get signed state by root
async function getSignedRootState(root: string) {
const API_BASE_URL = 'https://api.example.com'
const requestUrl = new URL(`${API_BASE_URL}/integrations/proof-verification-relayer/v2/state`)
requestUrl.searchParams.set('filter[root]', root)
const res = await fetch(requestUrl.toString())
const { data } = await res.json()
return {
// Signature of root state signed by relayer private key.
signature: data.attributes.signature,
// Time when the event was caught, a.k.a state transition timestamp
timestamp: data.attributes.timestamp,
}
}- You can use the
transitionRoot(root, timestamp, signature)
method on theRegistrationSMTReplicator
contract to submit state updates.
- After obtaining the proof from verificator-svc you know the required