# Noir

## 1. Noir란

### Noir 배경

초기 ZK DSL들은 회로에 많이 가까운 형태(R1CS 스타일, low-level DSL)에 머무르는 경우가 많았기 때문에, 일반적인 애플리케이션 개발자가 바로 쓰기에는 진입 장벽이 높다는 문제가 있었다.&#x20;

또한, 특정 프로토콜이나 특정 proving backend에 강하게 묶인 언어가 많아서, "ZK 앱 코드는 그대로 두고, 뒤에 붙는 프루빙 시스템만 바꾼다"는 식의 설계가 쉽지 않았다.

Noir는 이런 문제의식에서 출발한 고수준 ZK 프로그래밍 언어이다.

### Noir 목적

* 일반 개발자가 Rust/TypeScript와 비슷한 감각으로 ZK 로직을 작성할 수 있게 하는 것
* 특정 프로토콜에 종속되지 않고, 여러 proving backend에 붙을 수 있는 범용 DSL을 제공하는 것
* "앱 로직"과 "프루빙 시스템 구현"을 분리해서, 앱 개발자는 Noir 코드에 집중하고 백엔드 팀은 Plonk, UltraPlonk, Halo2 등 다양한 proving 시스템을 선택·교체할 수 있게 하는 것

즉 Noir의 목적은, "ZK 회로 언어"를 넘어 "ZK 애플리케이션 언어"에 가까운 고수준 DSL을 제공하는 것이라고 정리할 수 있다.

### Noir의 회로 표현 방식

Noir는 문법적으로 **일반 프로그래밍 언어에 상당히 가깝다**.

* 정적 타입, 함수, 제어문(`if`, `for`) 등을 사용해 로직을 작성한다.
* 개발자 입장에서는 "일반 함수형/시스템 언어"에 회로 제약이 추가된 느낌이다.
* 내부적으로는 Noir 코드가 **ACIR (Abstract Circuit Intermediate Representation)** 라는 중간 표현으로 변환되고, 이 ACIR이 다시 각 proving backend의 회로 표현(R1CS, Plonkish constraint 등)으로 매핑되는 구조이다.

이 말은 곧:

* Noir 코드는 논리/비즈니스 레벨을 표현하는 데 집중하고, 이게 R1CS에서 어떻게 flatten 되는지, 어떤 gate로 최적화되는지는 컴파일러 + backend가 담당한다는 뜻이다.

Circom이 회로 DSL에 더 가깝다면, Noir는 한 단계 위의 ZK-aware 일반 언어에 더 가까운 포지션이라고 볼 수 있다.

***

## 2. 사용법

### 설치

{% code fullWidth="false" expandable="true" %}

```zsh
curl -L https://raw.githubusercontent.com/noir-lang/noirup/refs/heads/main/install | bash
source ~/.zshrc
noirup
```

{% endcode %}

### 새 프로젝트 생성

noir는 쉽게 프로젝트를 생성하여 template 파일들을 제공한다.

```zsh
nargo new practice1
```

* `src/main.nr` 는 simple boilerplate circuit 을 포함한다.

```rust
fn main(x: Field, out: pub Field) {
    let y = x * x * x + x + 5;

    assert(y == out);
}

#[test]
fn test_main() {
    main(3, 35);

}

```

main 함수에 ACIR 회로가 정의되어 있으며 이를 컴파일하여 증명을 만든다.

* `Nargo.toml` environmental options, dependencies, and others 같은 프로젝트에 대한 정보를 갖는다.

```
[package]
name = "practice1"
type = "bin"
authors = [""]

[dependencies]
```

* type
  * bin: 프로젝트 output이 실행 가능한 바이너리로, main 함수가 entry point이다.
  * lib: 다른 프로젝트에서 활용 가능한 구조로 ACIR로 컴파일 되지 않는다.
  * contract: bin 타입과 비슷하지만 main 함수가 없다. Aztec Network에 올라가는 contract이다.

### 환경 check

```zsh
nargo check
```

프로젝트에 정의된 패키지와 의존성에 오류가 없는지 체크한다. \
결과물로 회로에 대해 input을 받는 Prover.toml이 생긴다.

```toml
// Prover.toml
out = ""
x = ""
```

### Circuit compile

```zsh
nargo compile
```

main 함수에 정의된 코드로 어떤 순서로 실행되고, 제약이 생기는지 **ACIR(Abstract Circuit Intermediate Representation)** 형식으로 컴파일한다.

### Circuit execute

Prover.toml 원하는 out 값과 비밀 값인 x를 작성한다.

```toml
// Prover.toml
out = "35"
x = "3"
```

그리고 컴파일된 ACIR 파일을 바탕으로 input 값을 회로에 넣어 실행한다.

```zsh
nargo execute
```

결과물로 `./target/<project>.gz` 형식으로 witness가 나온다.

Noir는 여기까지 진행되고 나머지는 Proving Backend에서 처리된다.

### Proving Backend

보통 Noir를 통해 만든 witness를 가지고 Barretenberg라는 backend를 사용한다.

#### 설치

```zsh
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/refs/heads/next/barretenberg/bbup/install | bash
source ~/.zshrc
bbup
```

Noir를 통해 만든 witness와 circuit을 통해 bb를 사용하여 증명을 생성한다.

#### Prove & Verify key

circuit과 witness를 인자로 넣어 Proof를 만든다. 또한 verify key 옵션을 넣어 검증할 때 witness 없이 검증할 수 있는 vk를 만든다.

```zsh
bb prove -b ./target/practice1.json -w ./target/practice1.gz --write_vk -o target
```

결과물로 proof, vk, public\_input이 생성된다.&#x20;

#### 검증

```zsh
bb verify -p ./target/proof -k ./target/vk
```

만들어진 vk와 proof를 통해 검증할 수 있다.

***

## 3. References

* [https://noir-lang.org/docs](https://noir-lang.org/docs/)
* [https://barretenberg.aztec.network/docs/getting\_started](https://barretenberg.aztec.network/docs/getting_started/)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://upsidezkp.gitbook.io/upside-zkp-docs/step-4/zkp-dsl-proving-system/noir.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
