Skip to content

Commit

Permalink
Circuits monorepo (#67)
Browse files Browse the repository at this point in the history
* Make circuits a nargo monorepo and add profiling packages

* Use all cores

* Use new monorepo paths in tests

* Adjust github actions to monorepo circuits structure

* Instantiate noir only once

* Add profiling github action

* Move profiling circuits to a separate repo
  • Loading branch information
LogvinovLeon authored Jan 31, 2024
1 parent 15341af commit 584cd54
Show file tree
Hide file tree
Showing 20 changed files with 50 additions and 21 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/circuits_profile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: circuit profiling

on: [push]

jobs:
test:
name: nargo info
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Nargo
uses: noir-lang/[email protected]
with:
toolchain: nightly-2024-01-11 # Pin at 0.23.0 when it's released. We need nightly now as 0.22.0 doesn't have the oracles

- name: Run nargo info
run: nargo info --workspace --silence-warnings | tee profiling_info.txt

- name: Archive profiling artifacts
uses: actions/upload-artifact@v4
with:
name: profiling_info
path: |
profiling_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
uses: noir-lang/[email protected]
with:
toolchain: nightly-2024-01-11 # Pin at 0.23.0 when it's released. We need nightly now as 0.22.0 doesn't have the oracles

- name: Run nargo test
run: |
cd circuit
nargo test
run: nargo test --workspace
4 changes: 1 addition & 3 deletions .github/workflows/contract_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ jobs:
toolchain: nightly-2024-01-11 # Pin at 0.23.0 when it's released. We need nightly now as 0.22.0 doesn't have the oracles

- name: Run nargo codegen-verifier
run: |
cd circuit
nargo codegen-verifier
run: nargo codegen-verifier --package main

- name: Run Forge build
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ts_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
# We don't store circuit compilation artefacts in the repo,
# but typecheck fails on import without them so we just create a fake file here
- name: Create fake circuit compilation artefacts
working-directory: circuit
working-directory: .
run: |
mkdir target
touch target/noir_ethereum_history_api.json
touch target/main.json
- name: Run TypeScript Typecheck
run: yarn typecheck
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ts_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ jobs:
toolchain: nightly-2024-01-11 # Pin at 0.23.0 when it's released. We need nightly now as 0.22.0 doesn't have the oracles

- name: Compile Circuit
run: nargo compile
working-directory: circuit
run: nargo compile --package main

- name: Start Oracle Server
run: |
yarn oracle-server &
- name: Generate Proof
run: nargo prove --oracle-resolver=http://localhost:5555
working-directory: circuit
run: nargo prove --package main --oracle-resolver=http://localhost:5555

- name: Run e2e Tests
run: yarn test:e2e
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
target
proofs
contract
Binary file modified .yarn/install-state.gz
Binary file not shown.
5 changes: 5 additions & 0 deletions Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"circuits/main"
]
default-member = "circuits/main"
File renamed without changes.
2 changes: 1 addition & 1 deletion circuit/Nargo.toml → circuits/main/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "noir_ethereum_history_api"
name = "main"
type = "bin"
authors = ["Arkadiusz Konior, Marek Kirejczyk"]
compiler_version = "0.22.0"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/src/generated-verifier/UltraVerifier.sol
9 changes: 4 additions & 5 deletions packages/noir-ethereum-api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { BarretenbergBackend, ProofData, type CompiledCircuit } from '@noir-lang
import { Noir, WitnessMap } from '@noir-lang/noir_js';
import { promises as fs } from 'fs';
import toml from 'toml';
import noir_ethereum_history_api from '../../../circuit/target/noir_ethereum_history_api.json';
import os from 'os';
import noir_ethereum_history_api from '../../../target/main.json';
import { type Oracles, defaultOracles } from './noir/oracles/oracles.js';
import { decodeHexString, encodeHexString } from './noir/noir_js/encode.js';
import { abiEncode, type InputMap } from '@noir-lang/noirc_abi';

export const circuit = noir_ethereum_history_api as unknown as CompiledCircuit;
const backend = new BarretenbergBackend(circuit, { threads: os.cpus().length });
const noir = new Noir(circuit, backend);

export interface MainInputs extends InputMap {
block_no: number;
Expand All @@ -21,8 +24,6 @@ export async function recordStorageProof(
oracles: Oracles = defaultOracles,
name: string
): Promise<boolean> {
const backend = new BarretenbergBackend(circuit);
const noir = new Noir(circuit, backend);
const proof = await noir.generateFinalProof(input, oracles);

const proofHex = decodeHexString(proof.proof);
Expand All @@ -36,8 +37,6 @@ export async function recordStorageProof(
}

export async function verifyStorageProof(proof: ProofData): Promise<boolean> {
const backend = new BarretenbergBackend(circuit);
const noir = new Noir(circuit, backend);
return await noir.verifyFinalProof(proof);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/noir-ethereum-api/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { verifyStorageProof, readProof, readWitnessMap, readInputMap, circuit }
import { updateNestedField } from '../src/util/object.js';
import { InputMap, WitnessMap, abiEncode } from '@noir-lang/noirc_abi';

const PROOF_PATH = '../../circuit/proofs/noir_ethereum_history_api.proof';
const INPUT_MAP_PATH = '../../circuit/Verifier.toml';
const PROOF_PATH = '../../proofs/main.proof';
const INPUT_MAP_PATH = '../../circuits/main/Verifier.toml';

describe.concurrent(
'e2e',
Expand Down

0 comments on commit 584cd54

Please sign in to comment.