Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zkVerify integration example for on-chain zk proof verification #11

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions README-ORIGINAL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Galxe Identity Protocol

## What's inside?

This is the monorepo for Galxe Identity protocol, powered by Turborepo. It includes the following packages/apps:

### Packages

- `@galxe-identity-protocol/evm-contracts`: a hardhat project of all the evm contracts, including typechain generated TypeScript bindings.
- `@galxe-identity-protocol/sdk`: a TypeScript SDK for everything related to the protocol.
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo

### Apps

- `cli`: a cli tool for managing the protocol, including interacting with the on-chain contracts and type generation.
- `issuer`: a microservice that issues credentials by GRPC request.
- `sstyper`: a fully self-sovereign credential type setup tool.

## Development setup

### Node version

Developers should use the current LTS version of node. Currently, node v20.11.1. For package users, the SDK is compatible with node v18 and above.

```bash
# For nvm users:
nvm install --lts
nvm use --lts
```

### Setup

We use corepack for managing package managers.

```bash
corepack enable
corepack install # this will install pnpm version specified in package.json
```

## Build, Test, and Lint

```
pnpm lint
pnpm build
pnpm test
```

## How to create a new credential type

1. Using type DSL to design the credential type.
2. Use `app/sstyper` to run the setup process, which will generate type artifacts, including
+ zkey, vkey, proofgen wasm...
+ solidity verifier contract
3. Upload the artifacts to IPFS and create a metadata json file containing URI to the artifacts. See artifacts in `artifacts/**/metadata.json` for reference.
4. Deploy the verifier contract to supported chains. See `evm-contracts/deploy`.
5. Register the type on supported chains, using the `metadata.json` URI. If primitive type, see `evm-contracts/scripts` for reference.

### NOTICE

If you saw build error when building a package that is depending on local packages, try `pnpm build` in the root directory first. It is because that dependencies were not built.
101 changes: 65 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,90 @@
# Galxe Identity Protocol
# Galxe Identity Protocol x zkVerify

## What's inside?
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).

This is the monorepo for Galxe Identity protocol, powered by Turborepo. It includes the following packages/apps:
The processed files for the hackathon are:

### Packages
- [`src/useZkVerify.ts`](apps/tutorial/src/useZkVerify.ts)
- [`package.json`](apps/tutorial/package.json)
- [`start.sh`](start.sh)

- `@galxe-identity-protocol/evm-contracts`: a hardhat project of all the evm contracts, including typechain generated TypeScript bindings.
- `@galxe-identity-protocol/sdk`: a TypeScript SDK for everything related to the protocol.
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo
The goal of this project is to demonstrate how to integrate zkVerify in Galxe Identity Protocol to significantly reduce verification costs without sacrificing security.

### Apps
## zkVerify

- `cli`: a cli tool for managing the protocol, including interacting with the on-chain contracts and type generation.
- `issuer`: a microservice that issues credentials by GRPC request.
- `sstyper`: a fully self-sovereign credential type setup tool.
[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.

## Development setup
## Galxe

### Node version
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.

Developers should use the current LTS version of node. Currently, node v20.11.1. For package users, the SDK is compatible with node v18 and above.
## 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 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

We implemented the last step in two ways:

- Registering the verification key of the issuer onchain and then submitting the proof to zkVerify, txHash: [0x11c2ddf64b5ddfcb1b1404d655ac41f23190f579f4bf2d79d612375df7a1fbf6](https://zkverify-explorer.zeeve.net/extrinsics/0x11c2ddf64b5ddfcb1b1404d655ac41f23190f579f4bf2d79d612375df7a1fbf6)
- Submitting the proof directly to zkVerify with the verification key, txHash: [0x7d7a24d8c0c47fcc03f24ec54fa4575f6806bc7f9ef202eff7172496a14c27a2](https://zkverify-explorer.zeeve.net/extrinsics/0x7d7a24d8c0c47fcc03f24ec54fa4575f6806bc7f9ef202eff7172496a14c27a2)

## How to run it

Follow the original tutorial to initialize the repository:

```bash
# For nvm users:
nvm install --lts
nvm use --lts
# Quick start
corepack enable
corepack install
pnpm build
```

### Setup
This will install the dependencies and build the project.

We use corepack for managing package managers.
Then go to the `apps/tutorial` folder and install the dependencies:

```bash
corepack enable
corepack install # this will install pnpm version specified in package.json
cd apps/tutorial
pnpm install
```

## Build, Test, and Lint
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
```
pnpm lint
pnpm build
pnpm test
---
Alternatively you can run the script:
```
chmod +x start.sh
./start.sh
```

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


## Considerations

## How to create a new credential type
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.

1. Using type DSL to design the credential type.
2. Use `app/sstyper` to run the setup process, which will generate type artifacts, including
+ zkey, vkey, proofgen wasm...
+ solidity verifier contract
3. Upload the artifacts to IPFS and create a metadata json file containing URI to the artifacts. See artifacts in `artifacts/**/metadata.json` for reference.
4. Deploy the verifier contract to supported chains. See `evm-contracts/deploy`.
5. Register the type on supported chains, using the `metadata.json` URI. If primitive type, see `evm-contracts/scripts` for reference.
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.

### NOTICE
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.

If you saw build error when building a package that is depending on local packages, try `pnpm build` in the root directory first. It is because that dependencies were not built.
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.
1 change: 1 addition & 0 deletions apps/tutorial/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEBRA_SIGNER_PK=""
ZKVERIFY_SIGNER_PK=""
4 changes: 3 additions & 1 deletion apps/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "echo NOTHING",
"test": "echo TODO",
"tutorial1": "ts-node -T src/tutorial1.ts",
"useZkVerify": "ts-node -T src/useZkVerify.ts",
"useNebraUpa": "ts-node -T src/useNebraUpa.ts",
"prettier:write": "prettier --write ./src",
"lint": "eslint --ignore-path ./.eslintignore --ext .js,.ts ."
Expand All @@ -27,7 +28,8 @@
"node-fetch": "^3.3.2",
"tslog": "^4.9.2",
"typescript": "^5.4.5",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zkverifyjs": "^0.3.1"
},
"devDependencies": {
"rimraf": "^5.0.6",
Expand Down
Loading