Skip to content

Commit

Permalink
Merge pull request #82 from noir-lang/zpedro/holesky
Browse files Browse the repository at this point in the history
feat: refactor for bun, viem, and other things
  • Loading branch information
signorecello authored Jul 23, 2024
2 parents abc3641 + f8430df commit 6ac86ad
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 10,575 deletions.
8 changes: 3 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM --platform=linux/amd64 node:lts-bookworm-slim
SHELL ["/bin/bash", "-c"]
RUN apt update && apt install -y curl bash git tar gzip libc++-dev
RUN curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
ENV PATH="/root/.nargo/bin:$PATH"
RUN noirup
ENTRYPOINT ["nargo"]
RUN apt update && apt install -y curl bash git tar gzip libc++-dev unzip
RUN curl -fsSL https://bun.sh/install | bash
ENTRYPOINT ["bun"]
27 changes: 13 additions & 14 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
{
"name": "Existing Dockerfile",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {},
"extensions": ["noir-lang.vscode-noir"]
}
},
"postCreateCommand": "nargo"
"name": "Existing Dockerfile",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
},
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {},
"extensions": ["noir-lang.vscode-noir"]
}
}
}
22 changes: 0 additions & 22 deletions .github/actions/setup-yarn/action.yml

This file was deleted.

33 changes: 7 additions & 26 deletions .github/workflows/vite_hardhat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up bun
uses: oven-sh/setup-bun@v1

- name: Get latest version
id: versions_step
run: |
Expand All @@ -23,30 +26,8 @@ jobs:
STABLE=$(echo $output | jq -r '.stable')
echo "::set-output name=stable::$STABLE"
- name: Set up yarn
uses: ./.github/actions/setup-yarn
with:
project: vite-hardhat

- name: Set up nargo
uses: ./.github/actions/setup-nargo
with:
version: ${{ steps.versions_step.outputs.stable }}

- name: Enable Corepack before setting up Node
run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 20.10.0
cache: 'yarn'

- name: Install
run: yarn --immutable
shell: bash

- name: Generate verifier contract
run: yarn prep
- name: Install dependencies
run: bun install

- name: Run test
run: yarn test
- name: Run tests
run: bun test
27 changes: 11 additions & 16 deletions .github/workflows/vite_hardhat_nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule:
# Run a nightly release at 2 AM UTC
- cron: '0 2 * * *'
pull_request:
paths:
- 'vite-hardhat/**'

jobs:
vite-hardhat-setup:
Expand Down Expand Up @@ -48,15 +51,8 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up yarn
uses: ./.github/actions/setup-yarn
with:
project: vite-hardhat

- name: Set up nargo
uses: ./.github/actions/setup-nargo
with:
version: ${{ matrix.version }}
- name: Set up bun
uses: oven-sh/setup-bun@v1

- name: Get stability
id: get-stability
Expand All @@ -75,20 +71,19 @@ jobs:
echo "Is stable: $IS_STABLE"
echo "::set-output name=is_stable::$IS_STABLE"
- name: Install dependencies
run: bun install

- name: Install test version
run: |
yarn add \
bun i \
@noir-lang/noir_js@${{ matrix.version }} \
@noir-lang/backend_barretenberg@${{ matrix.version }} \
@noir-lang/noir_wasm@${{ matrix.version }} \
@noir-lang/types@${{ matrix.version }}
- name: Generate verifier contract
run: yarn prep

- name: Run test
run: yarn test
id: yarn_test
- name: Run tests
run: bun test

- name: Send GitHub Action trigger data to Slack workflow - Stable
uses: slackapi/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/with_foundry_nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule:
# Run a nightly release at 2 AM UTC
- cron: '0 2 * * *'
pull_request:
paths:
- 'with-foundry/**'

jobs:
with-foundry-setup:
Expand Down
3 changes: 0 additions & 3 deletions vite-hardhat/.env.example

This file was deleted.

108 changes: 47 additions & 61 deletions vite-hardhat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,100 +11,86 @@ Want to get started in a pinch? Start your project in a free Github Codespace!

[![Start your project in a free Github Codespace!](https://github.com/codespaces/badge.svg)](https://codespaces.new/noir-lang/noir-starter/tree/main)

In the meantime, follow these simple steps to work on your own machine:
## Locally

1. Install [yarn](https://yarnpkg.com/) (tested on yarn v1.22.19)
2. Install [Node.js >20.10 (latest LTS)](https://nodejs.org/en) (tested on v18.17.0)
3. Install [noirup](https://noir-lang.org/docs/getting_started/installation/#installing-noirup) with
1. Install your favorite package manager. We'll use [bun](https://bun.sh/docs/installation) but feel free to use `yarn` or others:

```bash
curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
curl -fsSL https://bun.sh/install | bash
```

4. Install Nargo with
2. Install dependencies:

```bash
noirup
bun i # "npm i" or "yarn"
```

5. Install dependencies with
3. Run a development Ethereum node

```bash
yarn
bunx hardhat node # "npx hardhat dev node" or "yarn hardhat dev node"
```

6. Generate the verifier contract
4. Run the app

```bash
yarn prep
```

### Test locally
You can run a separate Ethereum node from the dev environment:

1. Start a local development EVM at <http://localhost:8545> with

```bash
npx hardhat node
```

or if foundry is preferred, with

```bash
anvil
```
```bash
bunx hardhat node
```

2. Run the [example test file](./test/index.test.ts) with
and run the dev environment separately:

```bash
yarn test
```
```bash
bunx hardhat dev
```

The test demonstrates basic usage of Noir in a TypeScript Node.js environment.
### Testing

### Deploy locally
You can run the [example test file](./test/index.test.ts) with

1. Start a local development EVM at <http://localhost:8545> with
```bash
bun test
```

```bash
npx hardhat node
```
This test shows the basic usage of Noir in a TypeScript Node.js environment.

or if foundry is preferred, with
> [!NOTE]
> The test is a script, not an executable (we're running `bun test` or `yarn test` instead of `bunx` or `npx`). This is because the test runs its own network and executables.
```bash
anvil
```
### Deploying on other networks

2. Build the project and deploy contracts to the local development chain with
The default scripting targets a local environment. For convenience, we added some configurations for deployment on various other networks. You can see the existing list by running:

```bash
yarn build
```
```bash
bunx hardhat vars setup
```

3. Once your contracts are deployed and the build is finished, you can preview the built website with
If you want to deploy on any of them, just pass in a private key, for example for the holesky network:

```bash
yarn preview
```
```bash
bunx hardhat vars set holesky <your_testnet_private_key>
```

### On-chain verification
You can then run all the commands using that network by passing the `--network` flag. For example:

The app will verify your proof locally. If you have a wallet, it will prompt you to connect to the relevant network and use it for on-chain verification.
```bash
bunx hardhat dev --network holesky # deploys and runs a development server on holesky
bunx hardhat deploy --network holesky # deploys on holesky
bunx hardhat build --network holesky # builds the frontend with the holesky target
```

### Deploy on testnets
Feel free to add more networks, as long as they're supported by `wagmi` ([list here](https://wagmi.sh/react/api/chains#available-chains)). Just make sure you:

For convenience, we added two configurations for deployment on various testnets. You can find them in `hardhat.config.cts`.
- Have funds in these accounts
- Add their configuration in the `networks` property in `hardhat.config.cts`
- Use the name that wagmi expects (for example `ethereum` won't work, as `wagmi` calls it `mainnet`)

To deploy on these testnets, rename `.env.example` to `.env` and add your own [alchemy](https://www.alchemy.com/) keys for these networks.
#### Attaching to an existing contract

Then, prepend your commands with your desired network in a `NETWORK` environment variable. For example, to deploy on sepolia:
You probably don't want to redeploy everytime you build your project. To attach the build to an already deployed contract, pass the `--attach` flag:

```bash
NETWORK=sepolia yarn build`
bunx hardhat deploy --network mainnet # deploys on ethereum mainnet $$$$$!
bunx hardhat dev --network mainnet --attach 0x<yourethereumcontract> # you're now developing using an existing verifier contract
```

Feel free to add more networks, just make sure you:

- Add deployer private keys and alchemy API keys in `.env`
- Have funds in these accounts
- Add a configuration in `hardhat.config.cts`
Binary file added vite-hardhat/bun.lockb
Binary file not shown.
2 changes: 0 additions & 2 deletions vite-hardhat/circuit/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[package]
name = "noirstarter"
type = "bin"
authors = [""]
compiler_version = ">=0.27.0"

[dependencies]
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { CompiledCircuit } from '@noir-lang/types';

export async function getCircuit() {
const fm = createFileManager('/');
const main = (await fetch(new URL(`../circuit/src/main.nr`, import.meta.url)))
const main = (await fetch(new URL(`./src/main.nr`, import.meta.url)))
.body as ReadableStream<Uint8Array>;
const nargoToml = (await fetch(new URL(`../circuit/Nargo.toml`, import.meta.url)))
const nargoToml = (await fetch(new URL(`./Nargo.toml`, import.meta.url)))
.body as ReadableStream<Uint8Array>;

fm.writeFile('./src/main.nr', main);
Expand Down
Loading

0 comments on commit 6ac86ad

Please sign in to comment.