Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PLONK/noir/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hash/sha256/target
hello_world/target
matmult/target
24 changes: 9 additions & 15 deletions PLONK/noir/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
FROM ubuntu:22.04 as base
FROM ubuntu:24.04 AS base

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install \
-y build-essential cmake git libgmp3-dev libprocps-dev libboost-all-dev libssl-dev libsodium-dev nano wget clang lld libomp-dev curl bash xxd
-y build-essential cmake git nano wget curl bash xxd jq python3

RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

RUN git clone https://github.com/noir-lang/noir.git
RUN curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash

WORKDIR noir
ENV PATH="$PATH:/root/.nargo/bin"

RUN git checkout tags/v0.3.2
RUN noirup -v 1.0.0-beta.6

RUN cargo install --locked --path=crates/nargo --no-default-features --features plonk_bn254

# RUN curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash

# RUN cd /root/.nargo/bin/ && rm noirup && wget https://raw.githubusercontent.com/noir-lang/noirup/main/noirup && chmod +x noirup
RUN nargo --version

# ENV PATH="${PATH}:/root/.nargo/bin"
RUN curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/refs/heads/master/barretenberg/bbup/install | bash

# RUN noirup
ENV PATH="$PATH:/root/.bb"

RUN nargo --version
RUN bbup -v 0.87.0

# If you want to avoid downloading fresh Ignite SRS everytime, download it from http://aztec-ignition.s3.amazonaws.com/MAIN%20IGNITION/sealed/transcript00.dat and inject into container.
# COPY transcript00.dat /root/noir_cache/ignition/transcript00.dat
Expand Down
7 changes: 5 additions & 2 deletions PLONK/noir/hash/sha256/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[package]
name = "sha256"
type = "bin"
authors = [""]
compiler_version = "0.1"
compiler_version = ">=1.0.0"

[dependencies]
[dependencies]
sha256 = { tag = "v0.1.4", git = "https://github.com/noir-lang/sha256" }
37 changes: 30 additions & 7 deletions PLONK/noir/hash/sha256/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ def echo(*string):
def main():
print('Running benchmarks for sha256')

setup_time = 0
proof_time = 0
proof_size = 0
verify_time = 0

echo("Running preliminary checks...")
subprocess.check_call(["nargo", "check"])
echo("Done")

echo("Compiling circuit...")
subprocess.check_call(["nargo", "compile"])
echo("Done")

for _ in range(BENCHMARK_ROUNDS):
echo("Running preliminary checks...")
subprocess.check_call(["nargo", "check"])
echo("Generating vk...")
time_start = time.time()
subprocess.check_call(["bb", "write_vk", "-b", "./target/sha256.json", "-o", "./target"])
time_duration = time.time() - time_start
echo("Done")
setup_time += time_duration

echo("Generating Prover.toml file with random circuit inputs...")
msg = gen_random_bytes(HASH_INPUT_LEN // 8)
Expand All @@ -48,26 +61,36 @@ def main():
open(prover_toml_path, "w").write(prover_toml)
echo("Done")

echo("Performing witness generation...")
time_start = time.time()
subprocess.check_call(["nargo", "execute"])
time_duration = time.time() - time_start
echo("Done")
proof_time += time_duration

echo("Generating proof...")
time_start = time.time()
subprocess.check_call(["nargo", "prove", "p"])
subprocess.check_call(["bb", "prove", "-b", "./target/sha256.json", "-w", "./target/sha256.gz", "-o", "./target"])
time_duration = time.time() - time_start
echo("Done")
proof_time += time_duration

proof_path = get_project_dir() / "proofs" / "p.proof"
proof_size = proof_path.stat().st_size
proof_path = get_project_dir() / "target" / "proof"
public_inputs_path = get_project_dir() / "target" / "public_inputs"
proof_size = proof_path.stat().st_size + public_inputs_path.stat().st_size

echo("Verifying proof...")
time_start = time.time()
subprocess.check_call(["nargo", "verify", "p"])
subprocess.check_call(["bb", "verify", "-k", "./target/vk", "-p", "./target/proof", "-i", "./target/public_inputs"])
time_duration = time.time() - time_start
echo("Done")
verify_time += time_duration

avg_setup_time = (setup_time * 10**6) / BENCHMARK_ROUNDS
avg_proof_time = (proof_time * 10**6) / BENCHMARK_ROUNDS
avg_verify_time = (verify_time * 10**6) / BENCHMARK_ROUNDS
echo(f"(Setup +) Proof time: {avg_proof_time:.0f} us")
echo(f"Setup time: {avg_setup_time:.0f} us")
echo(f"Proof time: {avg_proof_time:.0f} us")
echo(f"Proof size: {proof_size} B")
echo(f"Verify time: {avg_verify_time:.0f} us")

Expand Down
6 changes: 2 additions & 4 deletions PLONK/noir/hash/sha256/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use dep::std;

fn main(msg: [u8; 64], known_hash: pub [u8; 32]) {
let calc_hash = std::hash::sha256(msg);
constrain calc_hash == known_hash;
let calc_hash = sha256::digest(msg);
assert_eq(calc_hash, known_hash);
}
6 changes: 4 additions & 2 deletions PLONK/noir/matmult/Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[package]
name = "matmult"
type = "bin"
authors = [""]
compiler_version = "0.1"
compiler_version = ">=1.0.0"

[dependencies]
[dependencies]
Binary file added PLONK/noir/matmult/out/vk
Binary file not shown.
41 changes: 32 additions & 9 deletions PLONK/noir/matmult/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,63 @@ def echo(*string):
def main():
print('Running benchmarks for matmult')

setup_time = 0
proof_time = 0
proof_size = 0
verify_time = 0
for _ in range(BENCHMARK_ROUNDS):
echo("Running preliminary checks...")
subprocess.check_call(["nargo", "check"])
echo("Done")

echo("Running preliminary checks...")
subprocess.check_call(["nargo", "check"])
echo("Done")

echo("Compiling circuit...")
subprocess.check_call(["nargo", "compile"])
echo("Done")

for _ in range(BENCHMARK_ROUNDS):
# echo("Generating Prover.toml file with random circuit inputs...")
# prover_toml = f"a = {array_a}\nb = {array_b}\nc = {array_c}\n"
# prover_toml_path = get_project_dir() / "Prover.toml"
# open(prover_toml_path, "w").write(prover_toml)
# echo("Done")

echo("Generating vk...")
time_start = time.time()
subprocess.check_call(["bb", "write_vk", "-b", "./target/matmult.json", "-o", "./target"])
time_duration = time.time() - time_start
echo("Done")
setup_time += time_duration

echo("Performing witness generation...")
time_start = time.time()
subprocess.check_call(["nargo", "execute"])
time_duration = time.time() - time_start
echo("Done")
proof_time += time_duration

echo("Generating proof...")
time_start = time.time()
subprocess.check_call(["nargo", "prove", "p"])
subprocess.check_call(["bb", "prove", "-b", "./target/matmult.json", "-w", "./target/matmult.gz", "-o", "./target"])
time_duration = time.time() - time_start
echo("Done")
proof_time += time_duration

proof_path = get_project_dir() / "proofs" / "p.proof"
proof_size = proof_path.stat().st_size
proof_path = get_project_dir() / "target" / "proof"
public_inputs_path = get_project_dir() / "target" / "public_inputs"
proof_size = proof_path.stat().st_size + public_inputs_path.stat().st_size

echo("Verifying proof...")
time_start = time.time()
subprocess.check_call(["nargo", "verify", "p"])
subprocess.check_call(["bb", "verify", "-k", "./target/vk", "-p", "./target/proof", "-i", "./target/public_inputs"])
time_duration = time.time() - time_start
echo("Done")
verify_time += time_duration

avg_setup_time = (setup_time * 10**6) / BENCHMARK_ROUNDS
avg_proof_time = (proof_time * 10**6) / BENCHMARK_ROUNDS
avg_verify_time = (verify_time * 10**6) / BENCHMARK_ROUNDS
echo(f"(Setup +) Proof time: {avg_proof_time:.0f} us")
echo(f"Setup time: {avg_setup_time:.0f} us")
echo(f"Proof time: {avg_proof_time:.0f} us")
echo(f"Proof size: {proof_size} B")
echo(f"Verify time: {avg_verify_time:.0f} us")

Expand Down
8 changes: 4 additions & 4 deletions PLONK/noir/matmult/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
fn main(a : [Field; 1024], b : [Field; 1024], c : pub [Field; 1024]) {
fn main(a: [Field; 1024], b: [Field; 1024], c: pub [Field; 1024]) {
let mut temp_field = [0; 1024];
for i in 0..32 {
for j in 0..32 {
for k in 0..32 {
temp_field[i*32 + j] += temp_field[i*32 + j] + a[i * 32 + k] * b[k * 32 + j];
temp_field[i * 32 + j] += temp_field[i * 32 + j] + a[i * 32 + k] * b[k * 32 + j];
}
}
}

for i in 0..1024 {
constrain c[i] == temp_field[i];
assert_eq(c[i], temp_field[i]);
}
}
}