Skip to content

Commit

Permalink
Merge pull request #1 from vlayer-xyz/leo/profiling-innit
Browse files Browse the repository at this point in the history
Initial profiling commit
  • Loading branch information
LogvinovLeon authored Jan 25, 2024
2 parents 22c4dba + 5dcf325 commit a4ef846
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/circuits_profiling.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: circuits profiling

on: [push]

jobs:
test:
name: circuits profiling
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*


proofs
target
10 changes: 10 additions & 0 deletions .vscode/extensions.json
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.
]
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
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
}
8 changes: 8 additions & 0 deletions Nargo.toml
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"
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
# 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 (nargo, M1 Max)

| 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 |
+-----------+----------------------+--------------+----------------------+
```
3 changes: 3 additions & 0 deletions circuits/keccak/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "keccak"
type = "bin"
1 change: 1 addition & 0 deletions circuits/keccak/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = 0
Empty file added circuits/keccak/Verifier.toml
Empty file.
7 changes: 7 additions & 0 deletions circuits/keccak/src/main.nr
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);
}
3 changes: 3 additions & 0 deletions circuits/keccak_2x/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "keccak_2x"
type = "bin"
1 change: 1 addition & 0 deletions circuits/keccak_2x/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = 0
Empty file.
9 changes: 9 additions & 0 deletions circuits/keccak_2x/src/main.nr
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);
}
3 changes: 3 additions & 0 deletions circuits/poseidon/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[package]
name = "poseidon"
type = "bin"
1 change: 1 addition & 0 deletions circuits/poseidon/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = 42
Empty file added circuits/poseidon/Verifier.toml
Empty file.
6 changes: 6 additions & 0 deletions circuits/poseidon/src/main.nr
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);
}
6 changes: 6 additions & 0 deletions circuits/rlp/Nargo.toml
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" }
3 changes: 3 additions & 0 deletions circuits/rlp/Prover.toml
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 added circuits/rlp/Verifier.toml
Empty file.
10 changes: 10 additions & 0 deletions circuits/rlp/src/main.nr
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);
}
42 changes: 42 additions & 0 deletions prove.sh
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

0 comments on commit a4ef846

Please sign in to comment.