An open API service indexing awesome lists of open source software.

https://github.com/masaun/openbanking.nr-integration-examples

OpenBanking.nr integration examples in Noir
https://github.com/masaun/openbanking.nr-integration-examples

noir openbanking-noir recursive-proof-system semaphore-noir zero-knowledge-proof zkpassport

Last synced: 5 months ago
JSON representation

OpenBanking.nr integration examples in Noir

Awesome Lists containing this project

README

          

# OpenBanking.nr Integration Examples

# Overview

- This repo is the experimental repo to test the integrations with the `OpenBanking.nr` library:
- `openbanking.nr-circuit`: https://github.com/attested-frontiers/openbanking.nr-circuit
- `openbanking.nr-server` (API server for `OpenBanking API`): https://github.com/attested-frontiers/openbanking.nr-server


## Run the ZK circuit test

```bash
cd circuits
sh sh circuit_test.sh
```



# Noir + Hardhat Template ๐Ÿš€

A comprehensive boilerplate that seamlessly integrates [Noir](https://noir-lang.org/) zero-knowledge circuits with [Hardhat](https://hardhat.org/) for Ethereum smart contract development. This template provides everything you need to build, test, and deploy ZK applications with enterprise-grade CI/CD pipelines.

## โœจ Features

- **๐Ÿ”’ Zero-Knowledge Circuit Development** - Write and test Noir circuits with full TypeScript integration
- **โšก Hardhat Integration** - Leverage Hardhat's powerful development environment for smart contracts
- **๐Ÿงช Comprehensive Testing** - TypeScript tests for both circuits and smart contracts with dynamic proof generation
- **๐Ÿš€ CI/CD Pipeline** - Automated testing, building, and validation
- **๐Ÿ“ฆ Multiple Proof Formats** - Handle proofs in JSON and binary
- **๐ŸŒ Deployment Ready** - Hardhat Ignition integration for seamless deployment
- **๐Ÿ“‹ Code Quality** - ESLint, Solhint, Prettier, Commitlint + Husky for comprehensive code standards

## ๐Ÿ—๏ธ What You'll Learn

This template demonstrates a complete **SimpleCounter** example that showcases:

- **Circuit Development**: Create a Noir circuit that verifies arithmetic operations
- **Proof Generation**: Generate zero-knowledge proofs using the `bb` proving system
- **Smart Contract Verification**: Verify proofs on-chain using auto-generated Solidity verifiers
- **Full-Stack Integration**: TypeScript tests that create, verify, and submit proofs dynamically
- **Production Deployment**: Deploy and interact with your ZK application on Ethereum testnets

## ๐Ÿ“‹ Prerequisites

Before getting started, ensure you have:

- **Node.js** (v18 or later) and **Yarn**
- **Noir toolchain** - Install via [noirup](https://noir-lang.org/docs/getting_started/quick_start#installation)
- **Barretenberg** (`bb`) - Usually installed with Noir, or install separately
- **Git** for version control

```bash
# Install Noir toolchain
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
noirup

# Verify installations
nargo --version
bb --version
```

## ๐Ÿš€ Quick Start

1. **Clone and Install**

```bash
git clone
cd noir-hardhat-template
yarn install
```

2. **Build the Circuit**

```bash
yarn circuit:build
```

3. **Test Everything**

```bash
# Test the Noir circuit
yarn circuit:test

# Test smart contracts with proof verification
yarn contracts:test
```

4. **Generate and Verify Proofs**

```bash
# Generate witness and verification key
yarn circuit:witness
yarn circuit:vk

# Create and verify a proof
yarn circuit:prove
yarn circuit:verify
```

## ๐Ÿ“ Project Structure

```
noir-hardhat-template/
โ”œโ”€โ”€ circuit/ # Noir circuit source code
โ”‚ โ”œโ”€โ”€ src/main.nr # Main circuit logic (SimpleCounter)
โ”‚ โ”œโ”€โ”€ Nargo.toml # Circuit configuration
โ”‚ โ”œโ”€โ”€ Prover.toml # Proving parameters
โ”‚ โ””โ”€โ”€ target/ # Compiled circuit artifacts
โ”œโ”€โ”€ contracts/ # Solidity smart contracts
โ”‚ โ”œโ”€โ”€ SimpleCounter.sol # Main contract with ZK verification
โ”‚ โ””โ”€โ”€ VerifierKeccak.sol # Auto-generated proof verifier
โ”œโ”€โ”€ test/ # TypeScript test suites
โ”‚ โ””โ”€โ”€ SimpleCounter.ts # Comprehensive integration tests
โ”œโ”€โ”€ ignition/ # Hardhat Ignition deployment modules
โ”‚ โ””โ”€โ”€ modules/
โ”‚ โ””โ”€โ”€ SimpleCounter.ts # Deployment configuration
โ”œโ”€โ”€ .github/workflows/ # CI/CD pipeline configuration
โ””โ”€โ”€ hardhat.config.ts # Hardhat configuration
```

## ๐Ÿ› ๏ธ Available Scripts

### Circuit Operations

```bash
yarn circuit:build # Compile Noir circuit
yarn circuit:test # Run circuit tests
yarn circuit:witness # Generate witness from inputs
yarn circuit:vk # Generate verification key
yarn circuit:prove # Generate zero-knowledge proof
yarn circuit:verify # Verify generated proof
yarn circuit:solidity_verifier # Generate Solidity verifier contract
```

### Smart Contract Operations

```bash
yarn contracts:compile # Compile Solidity contracts
yarn contracts:test # Run smart contract tests
yarn contracts:deploy # Deploy to Sepolia testnet
```

### Development Tools

```bash
yarn commitlint # Validate commit messages
yarn commitlint:last # Check last commit message
yarn lint # Run ESLint on TypeScript files
yarn lint:fix # Auto-fix ESLint issues
yarn format # Format code with Prettier
yarn format:check # Check formatting without changes
yarn lint:all # Run linting and format check
```

## ๐ŸŽจ Code Quality

This template includes comprehensive linting and formatting tools to maintain code quality:

### **TypeScript Linting** (ESLint)

- Configured with TypeScript-specific rules and best practices
- Integrates with Prettier for consistent formatting
- Catches potential bugs and enforces coding standards
- Run with `yarn lint` or auto-fix with `yarn lint:fix`

### **Solidity Linting** (Solhint)

- Enforces Solidity best practices and security patterns
- Configured with recommended rules for modern Solidity development
- Run with `npx hardhat check`
- Auto-generated verifier contracts are excluded from linting

### **Code Formatting** (Prettier)

- Ensures consistent code style across TypeScript, Solidity, JSON, and Markdown
- Configured with sensible defaults for each file type
- Run with `yarn format` or check with `yarn format:check`

### **Pre-commit Hooks**

- Automatically runs linting and formatting on staged files
- Prevents committing code that doesn't meet quality standards
- Powered by Husky and lint-staged

### **CI Integration**

The CI pipeline includes dedicated jobs for:

- TypeScript linting
- Solidity linting
- Formatting verification
- Commit message validation

### **Noir Language Support**

Currently, there are no dedicated linting tools for Noir. However:

- VSCode users can install the `vscode-noir` extension for syntax highlighting and LSP support
- NeoVim users can use the `noir-nvim` plugin
- The Language Server Protocol (LSP) provides basic error checking via `nargo lsp`

## ๐Ÿ”„ CI/CD Pipeline

Our GitHub Actions pipeline ensures code quality and functionality across all components:

### **Automated Workflows**

- **๐Ÿ” Commit Validation** - Enforces conventional commit standards on all PRs and pushes
- **โœจ TypeScript Linting** - ESLint checks for code quality and potential bugs
- **๐Ÿ”’ Solidity Linting** - Solhint enforces best practices and security patterns
- **๐ŸŽจ Format Check** - Prettier ensures consistent code formatting
- **๐Ÿ”ง Circuit Build** - Compiles Noir circuits and caches artifacts
- **๐Ÿงช Circuit Testing** - Runs all circuit tests with Noir toolchain
- **๐Ÿ” Proof Generation & Verification** - Full prove/verify cycle validation
- **๐Ÿ“ Contract Compilation** - Compiles Solidity contracts with optimizations
- **โšก Integration Testing** - End-to-end tests with proof verification on contracts

## ๐Ÿ’ก Understanding the SimpleCounter Example

The **SimpleCounter** demonstrates a complete ZK application workflow:

### **The Circuit** (`circuit/src/main.nr`)

```noir
fn main(x: Field, y: pub Field, z: pub Field) {
assert((x != y) & (y != z));
}

#[test]
fn test_main() {
main(1, 2, 1);
}
```

This circuit implements a **uniqueness constraint verification**:

- **Private Input** (`x`): A secret value known only to the prover
- **Public Inputs** (`y`, `z`): Values that are publicly known and verified
- **Constraint**: Proves that `x` is different from `y` AND `y` is different from `z`
- **Use Case**: Demonstrates how to prove knowledge of a unique value without revealing it

### **The Smart Contract** (`contracts/SimpleCounter.sol`)

- Stores a counter value on-chain
- Accepts zero-knowledge proofs of uniqueness constraints
- Verifies proofs using the auto-generated Solidity verifier
- Increments the counter only when valid proofs are submitted

### **The Tests** (`test/SimpleCounter.ts`)

- Dynamically generates proofs with different combinations of `x`, `y`, `z` values
- Demonstrates proof format conversion (binary โ†” JSON)
- Verifies end-to-end integration between uniqueness circuits and smart contracts
- Shows how private values can remain hidden while proving constraints

## ๐ŸŒ Deployment

### **Environment Setup**

Configure your deployment environment:

```bash
# Set your private key and RPC URL
npx hardhat vars set SEPOLIA_PRIVATE_KEY
npx hardhat vars set SEPOLIA_URL_RPC
npx hardhat vars set ETHERSCAN_API_KEY
```

### **Deploy to Sepolia**

```bash
yarn contracts:deploy
```

The deployment uses **Hardhat Ignition** for:

- โœ… Reproducible deployments
- โœ… Automatic verification on Etherscan

## ๐Ÿงช Development Workflow

1. **Write your circuit** in `circuit/src/main.nr`
2. **Test circuit logic** with `yarn circuit:test`
3. **Generate verifier contract** with `yarn circuit:solidity_verifier`
4. **Write smart contract tests** in TypeScript
5. **Run full test suite** with `yarn contracts:test`
6. **Deploy and verify** on testnet

## ๐Ÿ“š Learn More

- **[Noir Documentation](https://noir-lang.org/docs)** - Learn zero-knowledge circuit development
- **[Hardhat Documentation](https://hardhat.org/docs)** - Master Ethereum development
- **[Barretenberg](https://github.com/AztecProtocol/aztec-packages/tree/master/barretenberg)** - Understanding the proving system

## ๐Ÿค Contributing

Contributions are welcome! Please ensure:

- Follow conventional commit standards (enforced by our CI)
- Add tests for new features
- Update documentation as needed
- All CI checks pass

## ๐Ÿ“„ License

This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.

---

**Built with โค๏ธ for the Noir and Ethereum communities**