Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaRettaroli committed Dec 7, 2024
1 parent d448aa1 commit 1d7fc0d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
83 changes: 43 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,90 @@
# Galxe Identity Protocol x ZKVerify
# Galxe Identity Protocol x zkVerify

This project is developed for the ZKVerify online hackathon. It's a fork of the Galxe Identity Protocol [repository](https://github.com/galxe-identity-protocol/tutorial). You can find the original README [here](README-ORIGINAL.md).
This project is developed for the [zkVerify online hackathon](https://zkverify-zk-application-and-infrastructure-buildin.devfolio.co/overview). It's a fork of the Galxe Identity Protocol [repository](https://github.com/galxe-identity-protocol/tutorial). You can find the original README [here](README-ORIGINAL.md).

The processed files for the hackathon are:

The files modified for the hackathon are:
- [`src/useZkVerify.ts`](apps/tutorial/src/useZkVerify.ts)
- [`package.json`](apps/tutorial/package.json)
- [`start.sh`](start.sh)

The goal of this project is to demonstrate how to integrate zkVerify in Galxe Identity Protocol to significantly reduce verification costs without sacrificing security.

## zkVerify

The goal of this project is to demonstrate how to integrate Galxe Identity Protocol with ZKVerify to significantly reduce verification costs without sacrificing security.
[zkVerify](https://zkverify.io/) is a modular blockchain focused on proof verification. It's specifically enables blockchain networks to offload the computationally heavy and expensive process of zk (zero-knowledge) proof verification, drastically reducing cost. It's support multiple verification schemes, including Groth16, Fflonk, Risc0 and more.

## Galxe
Galxe is a decentralized super app and web3's largest onchain distribution platform, with over 31 million active users and trusted by top partners like Optimism, Polygon, and many more.
Within its infrastructure, Galxe built Identity Protocol, a technology that utilizes privacy-preserving ZK technology to enable safe and seamless integration of digital identities across platforms.
Built on top of Identity Protocol, there is another product by Galxe, the Galxe Passport, chosen by over 1 million users to share their digital identity.

## ZKVerify
zkVerify is a modular blockchain focused on zero-knowledge (ZK) proof verification. It's specifically designed for verifying ZK proofs across different blockchains efficiently, with benefits in terms of cost reduction and fast verification times.
It's support multiple verification schemes, including Groth16, Fflonk, Risc0 and more.
Galxe is a decentralized super app and web3's largest onchain distribution platform, with over 31 million active users and trusted by top partners like Optimism, Polygon, and many more.
Within its infrastructure, Galxe built [Identity Protocol](https://www.galxe.com/identity), a technology that utilizes privacy-preserving ZK technology to enable safe and seamless integration of digital identities across platforms.
Built on top of Identity Protocol, there is another product by Galxe, the [Galxe Passport](https://www.galxe.com/passport), chosen by around 1 million users to share their digital identity.

## What we cooked
We created a new tutorial that follows the original one published by Galxe in this repo, but instead of doing an off-chain or on-chain verification, we use ZKVerify to verify the proof submitted.

> **Note:** Galxe has already integrated Nebra UPA in a tutorial, a protocol that can aggregate multiple proofs for reducing the verification cost. This validates our idea with zkVerify.
We created a new tutorial that follows the original one published by Galxe in this repo, but instead of doing an off-chain or an expensive on-chain verification, we integrated zkVerify technology as verification layer to efficiently verify the proofs.

> **Note:** Galxe has already integrated Nebra UPA in a tutorial, a protocol that aggregates multiple proofs for reducing the verification cost. This validates our idea of introducing zkVerify.
The process is divided in three steps:

1. Issuer issuing a credential to the user
2. User generating a proof to prove some statements about the credential
3. Submitting the proof to ZKVerify to verify it
3. Submitting the proof to zkVerify to verify it

We implemented the last step in two ways:
- Registering the verification key of the issuer onchain and then submitting the proof to ZKVerify
- Submitting the proof directly to ZKVerify with the verification key

We implementing the last step in two way:
- Registering the verification key of the issuer onchain and then submitting the proof to ZKVerify.
- Submitting the proof directly to ZKVerify with the verification key.

+++ add considerations about the size +++
- Registering the verification key of the issuer onchain and then submitting the proof to zkVerify, txHash: [0x11c2ddf64b5ddfcb1b1404d655ac41f23190f579f4bf2d79d612375df7a1fbf6](https://zkverify-explorer.zeeve.net/extrinsics/0x11c2ddf64b5ddfcb1b1404d655ac41f23190f579f4bf2d79d612375df7a1fbf6?tab=events&page=1)
- Submitting the proof directly to zkVerify with the verification key, txHash: [0x7d7a24d8c0c47fcc03f24ec54fa4575f6806bc7f9ef202eff7172496a14c27a2](https://zkverify-explorer.zeeve.net/extrinsics/0x7d7a24d8c0c47fcc03f24ec54fa4575f6806bc7f9ef202eff7172496a14c27a2?tab=events&page=1)

## How to run it

Follow the original tutorial to initialize the repository:

```bash
# Quick start
corepack enable
corepack install
pnpm build
```

This will install the dependencies and build the project.

Then go to the `apps/tutorial` folder and install the dependencies:

```bash
cd apps/tutorial
npm install
pnpm install
```

Add `ZKVERIFY_SIGNER_PK` to the `.env` file with the private key of the account that will register the verification key onchain.

Finally, run the script:

```bash
npm run useZkVerify
```
---
Alternatively you can run the script:
```
chmod +x start.sh
./start.sh
```

## Considerations
Galxe currently serves over 31 million active users and manages more than 350,000 credentials, making it the perfect candidate for testing scalable verification solutions.

Assessed that zkVerify can reduce proof verification costs by >90% compared to native verification on Ethereum, at Galxe's scale, this translates to a significant costs dropping - a transformation that could generate millions in savings annually.

Beyond pure cost reduction, this integration opens new possibilities for Web3 identity management. With over 1 million users actively using Galxe Passport, cheaper verification enables more frequent credential checks, enhanced privacy features, and broader accessibility to trustless credential systems for smaller projects.

On a closing thought, we want to remark how specialized verification layers can solve real problems in large-scale identity systems, with the zkVerify-Galxe integration setting a new standard for efficient, accessible credential verification in Web3.











Before to run make sure you have node latest version:
```bash
# For nvm users:
nvm install --lts
nvm use --lts
```


## Considerations

Galxe currently serves over 31 million active users and manages more than 350k credentials, making it the perfect candidate for testing scalable verification solutions with zkVerify.

Assessed that zkVerify can reduce proof verification costs by >90% compared to native verification on Ethereum, at Galxe's scale, this translates to a significant costs dropping - a transformation that could generate millions in savings annually.

Beyond pure cost reduction, this integration opens new possibilities for Web3 identity management. With around 1 million users actively using Galxe Passport, cheaper verification enables more frequent credential checks, enhanced privacy features, and broader accessibility to trustless credential systems for smaller projects.

On a closing thought, we want to remark how specialized verification layers can solve real problems in large-scale identity systems, with the zkVerify-Galxe integration setting a new standard for efficient, accessible credential verification in Web3.
18 changes: 11 additions & 7 deletions apps/tutorial/src/useZkVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ async function verifyWithZkVerify(proof: babyzkTypes.WholeProof): Promise<boolea
// When using zkVerify on-chain verification, you must first get the verification key.
// You can embed the verification key in your application, or fetch it from a remote server.
// We will fetch the verification key from the chain in this example.
// The first step is to do a static proof verification, making sure that the zk proof is valid.
// The first step is to do a proof verification, making sure that the zk proof is valid.
const tpRegistry = evm.v1.createTypeRegistry({
signerOrProvider: provider,
});
const verifier = await tpRegistry.getVerifier(expectedTypeID, credential.VerificationStackEnum.BabyZK);
const vKey = await verifier.getVerificationKeysRaw();
console.log("on zkVerify-chain static proof verification start, executing verification transaction");
console.log("on zkVerify-chain proof verification start, executing verification transaction");
const verifyResult = await executeVerificationWithZkVerify(proof, vKey);
console.log("on zkVerify-chain static proof verification result: ", verifyResult);
console.log("on zkVerify-chain proof verification result: ", verifyResult);

return true;
}
Expand All @@ -266,7 +266,7 @@ async function verifyWithZkVerifyRegisteredZK(proof: babyzkTypes.WholeProof): Pr
// When using zkVerify on-chain verification, you must first get the verification key.
// You can embed the verification key in your application, or fetch it from a remote server.
// We will fetch the verification key from the chain in this example.
// The first step is to do a static proof verification, making sure that the zk proof is valid.
// The first step is to do a proof verification, making sure that the zk proof is valid.
const tpRegistry = evm.v1.createTypeRegistry({
signerOrProvider: provider,
});
Expand All @@ -275,9 +275,9 @@ async function verifyWithZkVerifyRegisteredZK(proof: babyzkTypes.WholeProof): Pr
// on-chain proof verification
console.log("on zkVerify-chain zk proof, registering verification key");
const transactionHash = await registerVerficationKey(vKey);
console.log("on zkVerify-chain static proof verification start, executing verification transaction");
console.log("on zkVerify-chain proof verification start, executing verification transaction");
const verifyResult = await executeVerificationWithZkVerifyRegisteredZK(proof, transactionHash);
console.log("on zkVerify-chain static proof verification result: ", verifyResult);
console.log("on zkVerify-chain proof verification result: ", verifyResult);

return true;
}
Expand Down Expand Up @@ -308,10 +308,14 @@ async function main() {
console.log("Proof is generated successfully.", proof);

// On zkVeirfy chain verification process: verifying the proof.
console.log("Starting verification with zkVerify");
await verifyWithZkVerify(proof);
console.log("End of verification with zkVerify");

console.log("Starting verification with zkVerify and registered verification key");
await verifyWithZkVerifyRegisteredZK(proof);

console.log("End of verification with zkVerify and registered verification key");

process.exit(0);
}

Expand Down
22 changes: 22 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

echo "Initializing the repository..."
corepack enable
corepack install
pnpm build

echo "Navigating to the apps/tutorial folder and installing dependencies..."
cd apps/tutorial
pnpm install

echo "Ensure the .env file contains the ZKVERIFY_SIGNER_PK variable with the appropriate private key."
echo "You can edit the .env file to add or update this value as needed."
echo

read -p "Press Enter to continue if you have updated the .env file with ZKVERIFY_SIGNER_PK..."

echo "Running the useZkVerify script..."
npm run useZkVerify

0 comments on commit 1d7fc0d

Please sign in to comment.