-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22c4dba
commit 075d40c
Showing
27 changed files
with
364 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: circuit tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: nargo test | ||
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 test | ||
run: nargo test --workspace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: contract tests | ||
|
||
on: [push] | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- 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 codegen-verifier | ||
run: nargo codegen-verifier --package main | ||
|
||
- name: Run Forge build | ||
run: | | ||
cd contracts | ||
forge --version | ||
forge build --sizes | ||
id: build | ||
|
||
- name: Run Forge tests | ||
run: | | ||
cd contracts | ||
forge test -vvv | ||
id: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: TS Lint and Typecheck | ||
|
||
on: [push] | ||
|
||
jobs: | ||
lint-and-typecheck: | ||
name: Lint and Typecheck | ||
runs-on: ubuntu-latest | ||
environment: CI | ||
defaults: | ||
run: | ||
working-directory: packages/noir-ethereum-api | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Enable Corepack and Install Yarn 4 | ||
run: | | ||
corepack enable | ||
yarn set version latest | ||
- name: Install Dependencies | ||
run: yarn install | ||
|
||
- name: Run TypeScript Linter | ||
run: yarn lint | ||
|
||
# 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: . | ||
run: | | ||
mkdir target | ||
touch target/main.json | ||
- name: Run TypeScript Typecheck | ||
run: yarn typecheck | ||
|
||
- name: Run TypeScript format check | ||
run: yarn format:ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: TS tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: yarn test | ||
runs-on: ubuntu-latest | ||
environment: CI | ||
env: | ||
ETHEREUM_JSON_RPC_API_URL: ${{ secrets.ETHEREUM_JSON_RPC_API_URL }} | ||
defaults: | ||
run: | ||
working-directory: packages/noir-ethereum-api | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20.x' | ||
|
||
- name: Enable Corepack and Install Yarn 4 | ||
run: | | ||
corepack enable | ||
yarn set version latest | ||
- name: Install Dependencies | ||
run: yarn install | ||
|
||
- name: Run Unit Tests | ||
run: yarn test:unit | ||
|
||
- 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: Compile Circuit | ||
run: nargo compile --package main | ||
|
||
- name: Start Oracle Server | ||
run: | | ||
yarn oracle-server & | ||
- name: Generate Proof | ||
run: nargo prove --package main --oracle-resolver=http://localhost:5555 | ||
|
||
- name: Run e2e Tests | ||
run: yarn test:e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,3 +128,7 @@ dist | |
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
|
||
proofs | ||
target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"recommendations": [ | ||
"arcanis.vscode-zipfs", // This extension allows VS Code to read from and write to zip archives as if they were regular directories. It's particularly useful in Yarn 2 projects that make use of Zip archives for package management. | ||
"noir-lang.vscode-noir", // This extension provides support for the Noir language, a domain-specific language for zero-knowledge proofs. It likely offers features like syntax highlighting, code formatting, and possibly IntelliSense features for Noir. | ||
"JuanBlanco.solidity", // A Solidity language support extension for VS Code. It offers features like syntax highlighting, code snippets, and compilation for Solidity, the language used for writing smart contracts on Ethereum and other blockchain platforms. | ||
"dbaeumer.vscode-eslint", // Integrates ESLint into VS Code. ESLint is a popular linter for JavaScript and TypeScript, helping to catch errors and enforce coding style guidelines. This extension provides inline linting feedback and can automatically fix certain issues. | ||
"esbenp.prettier-vscode", // Integrates Prettier, an opinionated code formatter, into VS Code. It automatically formats code on save or can be run manually, ensuring consistent code formatting according to predefined style rules. | ||
"github.vscode-github-actions" // Provides syntax highlighting and IntelliSense for GitHub Actions workflows. It also offers features like linting and validation, as well as the ability to run workflows locally. | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.codeActionsOnSave": { | ||
"quickFix": "always" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"search.exclude": { | ||
"**/.yarn": true, | ||
"**/.pnp.*": true | ||
}, | ||
"eslint.nodePath": ".yarn/sdks", | ||
"typescript.tsdk": ".yarn/sdks/typescript/lib", | ||
"prettier.prettierPath": ".yarn/sdks/prettier/index.cjs", | ||
"typescript.enablePromptUseWorkspaceTsdk": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[workspace] | ||
members = [ | ||
"circuits/poseidon", | ||
"circuits/keccak", | ||
"circuits/keccak_2x", | ||
"circuits/rlp" | ||
] | ||
default-member = "circuits/keccak" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
# noir-profiling | ||
# noir-profiling | ||
|
||
## Working on this project | ||
You can print the number of opcodes in all circuits: | ||
``` | ||
nargo info --workspace | ||
``` | ||
|
||
Or regenerate profiling info: | ||
``` | ||
./prove.sh | ||
``` | ||
|
||
## Results | ||
|
||
### Proving times | ||
|
||
| Package | Elapsed Time | User Time | System Time | CPU Usage | Max Memory | | ||
|---------|--------------|-----------|-------------|-----------|------------| | ||
| poseidon | 0:00.64 | 1.17s | 0.19s | 211% | 148.99MB | | ||
| rlp | 0:01.20 | 0.92s | 0.03s | 79% | 96.17MB | | ||
| keccak | 0:07.57 | 40.40s | 0.94s | 545% | 2.30GB | | ||
| keccak_2x | 0:15.00 | 79.91s | 1.75s | 544% | 4.32GB | | ||
|
||
### Circuit sizes | ||
|
||
``` | ||
+-----------+----------------------+--------------+----------------------+ | ||
| Package | Expression Width | ACIR Opcodes | Backend Circuit Size | | ||
+-----------+----------------------+--------------+----------------------+ | ||
| poseidon | Bounded { width: 3 } | 573 | 578 | | ||
+-----------+----------------------+--------------+----------------------+ | ||
| keccak | Bounded { width: 3 } | 4 | 155014 | | ||
+-----------+----------------------+--------------+----------------------+ | ||
| keccak_2x | Bounded { width: 3 } | 7 | 300405 | | ||
+-----------+----------------------+--------------+----------------------+ | ||
| rlp | Bounded { width: 3 } | 4188 | 11172 | | ||
+-----------+----------------------+--------------+----------------------+ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "keccak" | ||
type = "bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = 0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use dep::std; | ||
|
||
fn main(x: u8) { | ||
let array: [u8; 1000] = [x; 1000]; | ||
let hash = std::hash::keccak256(array, 1000); | ||
assert(hash[0] == 174); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "keccak_2x" | ||
type = "bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = 0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use dep::std; | ||
|
||
fn main(x: u8) { | ||
let array: [u8; 1000] = [x; 1000]; | ||
let hash = std::hash::keccak256(array, 1000); | ||
let hash2 = std::hash::keccak256(array, 999); | ||
assert(hash[0] == 174); | ||
assert(hash2[0] == 10); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[package] | ||
name = "poseidon" | ||
type = "bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
x = 42 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use dep::std; | ||
|
||
fn main(x: Field) { | ||
let hash = std::hash::poseidon::bn254::hash_1([x]); | ||
assert(hash == 0x1b408dafebeddf0871388399b1e53bd065fd70f18580be5cdde15d7eb2c52743); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "rlp" | ||
type = "bin" | ||
|
||
[dependencies] | ||
proof = { tag = "v0.1.0", git = "https://github.com/aragonzkresearch/noir-trie-proofs", directory = "lib" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
block_header = [ | ||
249, 2, 17, 160, 10, 210, 58, 71, 229, 91, 254, 185, 245, 139, 35, 127, 191, 50, 125, 165, 19, 165, 59, 86, 127, 77, 226, 197, 94, 143, 9, 69, 104, 149, 113, 39, 160, 164, 115, 165, 166, 228, 180, 44, 203, 222, 52, 48, 157, 214, 190, 69, 130, 116, 84, 133, 170, 215, 193, 212, 152, 106, 149, 100, 253, 145, 220, 246, 94, 160, 69, 11, 1, 238, 164, 195, 225, 91, 51, 198, 134, 50, 21, 34, 253, 120, 157, 26, 173, 81, 148, 24, 94, 179, 165, 5, 99, 85, 90, 78, 104, 180, 160, 82, 128, 145, 254, 48, 73, 106, 165, 234, 223, 46, 5, 168, 79, 141, 218, 64, 98, 200, 87, 199, 28, 213, 222, 164, 182, 145, 219, 253, 186, 121, 39, 160, 167, 139, 46, 219, 193, 195, 174, 240, 47, 40, 188, 121, 97, 50, 227, 220, 35, 99, 122, 36, 94, 78, 156, 78, 197, 54, 232, 163, 249, 213, 16, 58, 160, 111, 180, 73, 26, 200, 238, 6, 49, 66, 159, 230, 23, 226, 13, 10, 230, 7, 51, 103, 45, 139, 187, 57, 125, 86, 1, 146, 77, 200, 196, 223, 158, 160, 55, 41, 196, 37, 89, 112, 4, 6, 183, 246, 239, 121, 175, 146, 171, 71, 19, 99, 239, 56, 75, 116, 235, 20, 239, 208, 243, 25, 211, 222, 248, 120, 160, 203, 87, 65, 73, 168, 197, 46, 86, 209, 173, 204, 46, 232, 157, 204, 145, 75, 151, 105, 166, 72, 142, 173, 255, 186, 120, 43, 121, 104, 228, 130, 134, 160, 150, 115, 130, 186, 247, 99, 108, 21, 244, 243, 60, 208, 96, 34, 93, 32, 175, 77, 181, 18, 59, 49, 192, 153, 255, 123, 231, 108, 251, 75, 134, 92, 160, 78, 107, 27, 31, 43, 92, 213, 101, 63, 87, 83, 248, 163, 19, 104, 103, 84, 248, 119, 180, 32, 209, 82, 52, 250, 148, 101, 219, 76, 194, 160, 125, 160, 83, 37, 183, 243, 189, 9, 79, 122, 28, 120, 150, 139, 190, 225, 222, 184, 206, 225, 117, 233, 244, 162, 244, 212, 38, 220, 37, 129, 215, 25, 93, 53, 160, 229, 6, 255, 207, 78, 120, 107, 238, 212, 128, 106, 189, 84, 39, 136, 172, 149, 67, 89, 238, 163, 122, 88, 90, 149, 80, 59, 121, 249, 7, 238, 1, 160, 81, 214, 156, 64, 149, 165, 65, 36, 216, 223, 167, 73, 213, 180, 230, 230, 32, 106, 193, 147, 176, 40, 93, 119, 210, 13, 1, 159, 16, 112, 114, 103, 160, 211, 15, 4, 49, 74, 86, 24, 146, 109, 246, 80, 207, 194, 97, 226, 153, 241, 94, 43, 233, 192, 2, 152, 171, 150, 86, 26, 250, 234, 179, 74, 156, 160, 175, 157, 156, 73, 109, 26, 48, 12, 182, 175, 211, 173, 181, 241, 131, 247, 105, 98, 255, 101, 7, 227, 21, 63, 78, 41, 155, 58, 231, 222, 15, 141, 160, 219, 213, 163, 116, 191, 119, 232, 215, 182, 77, 130, 102, 90, 48, 66, 197, 228, 202, 43, 169, 232, 246, 11, 23, 100, 50, 211, 205, 202, 115, 60, 49, 128 | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use dep::std; | ||
use dep::proof::rlp; | ||
|
||
global MAX_HEADER_RLP_SIZE = 532; | ||
global HEADER_FIELDS_COUNT = 17; | ||
|
||
fn main(block_header: [u8; MAX_HEADER_RLP_SIZE]) { | ||
let decoded: rlp::RLP_List<HEADER_FIELDS_COUNT> = rlp::decode1(block_header); | ||
assert(decoded.num_fields == HEADER_FIELDS_COUNT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/bash | ||
|
||
packages=("poseidon" "rlp" "keccak" "keccak_2x") | ||
|
||
TIME_FORMAT=' | ||
Elapsed Time: %E | ||
User Time: %U | ||
System Time: %S | ||
CPU Usage: %P | ||
Max Memory: %M' | ||
|
||
convert_memory() { | ||
local kilobytes=$1 | ||
local megabytes=$(echo "scale=2; $kilobytes / 1024" | bc) | ||
if (( $(echo "$megabytes < 1024" | bc -l) )); then | ||
echo "${megabytes}MB" | ||
else | ||
local gigabytes=$(echo "scale=2; $megabytes / 1024" | bc) | ||
echo "${gigabytes}GB" | ||
fi | ||
} | ||
|
||
echo "| Package | Elapsed Time | User Time | System Time | CPU Usage | Max Memory |" | ||
echo "|---------|--------------|-----------|-------------|-----------|------------|" | ||
|
||
for package in "${packages[@]}"; do | ||
temp_file=$(mktemp) | ||
gtime -f "$TIME_FORMAT" nargo prove --package="${package}" > "$temp_file" 2>&1 | ||
output=$(<"$temp_file") | ||
|
||
elapsed_time=$(echo "$output" | grep 'Elapsed Time' | awk '{print $3}') | ||
|
||
user_time=$(echo "$output" | grep 'User Time' | awk '{print $3 " " $4}') | ||
system_time=$(echo "$output" | grep 'System Time' | awk '{print $3 " " $4}') | ||
cpu_usage=$(echo "$output" | grep 'CPU Usage' | awk '{print $3}') | ||
max_memory_kb=$(echo "$output" | grep 'Max Memory' | awk '{print $3}') | ||
max_memory=$(convert_memory "$max_memory_kb") | ||
|
||
echo "| $package | $elapsed_time | $user_time | $system_time | $cpu_usage | $max_memory |" | ||
|
||
rm "$temp_file" | ||
done |