Skip to content

Commit 145cbcd

Browse files
authored
feat: Proving the rollup circuits (#5599)
This PR implements a first stage of proving the rollup circuits. We introduce the bb binary and use it to produce verification keys, generate proofs and later verify those proofs for all of the rollup circuits, currently demonstrated in a unit test.
1 parent 30a2edd commit 145cbcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2595
-1060
lines changed

.circleci/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,18 @@ jobs:
521521
command: cond_spot_run_build yarn-project-test 64
522522
aztec_manifest_key: yarn-project-test
523523

524+
prover-client-test:
525+
docker:
526+
- image: aztecprotocol/alpine-build-image
527+
resource_class: small
528+
steps:
529+
- *checkout
530+
- *setup_env
531+
- run:
532+
name: "Build and test"
533+
command: cond_spot_run_build prover-client-test 128
534+
aztec_manifest_key: prover-client-test
535+
524536
aztec-package:
525537
machine:
526538
image: default
@@ -1429,6 +1441,7 @@ workflows:
14291441
- end-to-end: *defaults_yarn_project
14301442
- aztec-faucet: *defaults_yarn_project_pre_join
14311443
- build-docs: *defaults_yarn_project_pre_join
1444+
- prover-client-test: *defaults_yarn_project
14321445
- yarn-project-test: *defaults_yarn_project
14331446
- yarn-project-x86_64: *defaults_yarn_project_pre_join
14341447
- yarn-project-arm64: *defaults_yarn_project_pre_join
@@ -1581,6 +1594,7 @@ workflows:
15811594
- yellow-paper
15821595
- noir-packages-tests
15831596
- yarn-project-test
1597+
- prover-client-test
15841598
<<: *defaults
15851599

15861600
# Benchmark jobs.

build_manifest.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,23 @@ yarn-project-test:
160160
- l1-contracts
161161
- noir-projects
162162
- barretenberg-x86_64-linux-clang
163+
- noir
164+
165+
# Runs all prover-client checks and tests.
166+
prover-client-test:
167+
buildDir: yarn-project
168+
projectDir: yarn-project/prover-client
169+
dockerfile: Dockerfile.test
170+
rebuildPatterns:
171+
- ^yarn-project/.*\.(ts|tsx|js|cjs|mjs|json|html|md|sh|nr|toml|snap)$
172+
- ^yarn-project/Dockerfile$
173+
dependencies:
174+
- bb.js
175+
- noir-packages
176+
- l1-contracts
177+
- noir-projects
178+
- barretenberg-x86_64-linux-clang
179+
- noir
163180

164181
# Builds all of yarn-project, with all developer dependencies.
165182
# Creates a runnable container used to run tests and formatting checks.

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"bbfree",
1919
"bbmalloc",
2020
"benesjan",
21+
"Bincode",
2122
"bleurgh",
2223
"bodyparser",
2324
"bootnode",

noir/noir-repo/tooling/acvm_cli/src/cli/execute_cmd.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use bn254_blackbox_solver::Bn254BlackBoxSolver;
66
use clap::Args;
77

88
use crate::cli::fs::inputs::{read_bytecode_from_file, read_inputs_from_file};
9-
use crate::cli::fs::witness::save_witness_to_dir;
109
use crate::errors::CliError;
1110
use nargo::ops::{execute_program, DefaultForeignCallExecutor};
1211

13-
use super::fs::witness::create_output_witness_string;
12+
use super::fs::witness::{create_output_witness_string, save_witness_to_dir};
1413

1514
/// Executes a circuit to calculate its return value
1615
#[derive(Debug, Clone, Args)]
@@ -46,9 +45,9 @@ fn run_command(args: ExecuteCommand) -> Result<String, CliError> {
4645
)?;
4746
if args.output_witness.is_some() {
4847
save_witness_to_dir(
49-
&output_witness_string,
50-
&args.working_directory,
48+
output_witness,
5149
&args.output_witness.unwrap(),
50+
&args.working_directory,
5251
)?;
5352
}
5453
Ok(output_witness_string)

noir/noir-repo/tooling/acvm_cli/src/cli/fs/witness.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@ use std::{
55
path::{Path, PathBuf},
66
};
77

8-
use acvm::acir::native_types::WitnessMap;
8+
use acvm::acir::native_types::{WitnessMap, WitnessStack};
99

1010
use crate::errors::{CliError, FilesystemError};
1111

12-
/// Saves the provided output witnesses to a toml file created at the given location
13-
pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
14-
output_witness: &String,
15-
witness_dir: P,
16-
file_name: &String,
17-
) -> Result<PathBuf, FilesystemError> {
18-
let witness_path = witness_dir.as_ref().join(file_name);
12+
fn create_named_dir(named_dir: &Path, name: &str) -> PathBuf {
13+
std::fs::create_dir_all(named_dir)
14+
.unwrap_or_else(|_| panic!("could not create the `{name}` directory"));
15+
16+
PathBuf::from(named_dir)
17+
}
1918

20-
let mut file = File::create(&witness_path)
21-
.map_err(|_| FilesystemError::OutputWitnessCreationFailed(file_name.clone()))?;
22-
write!(file, "{}", output_witness)
23-
.map_err(|_| FilesystemError::OutputWitnessWriteFailed(file_name.clone()))?;
19+
fn write_to_file(bytes: &[u8], path: &Path) -> String {
20+
let display = path.display();
2421

25-
Ok(witness_path)
22+
let mut file = match File::create(path) {
23+
Err(why) => panic!("couldn't create {display}: {why}"),
24+
Ok(file) => file,
25+
};
26+
27+
match file.write_all(bytes) {
28+
Err(why) => panic!("couldn't write to {display}: {why}"),
29+
Ok(_) => display.to_string(),
30+
}
2631
}
2732

2833
/// Creates a toml representation of the provided witness map
@@ -34,3 +39,19 @@ pub(crate) fn create_output_witness_string(witnesses: &WitnessMap) -> Result<Str
3439

3540
toml::to_string(&witness_map).map_err(|_| CliError::OutputWitnessSerializationFailed())
3641
}
42+
43+
pub(crate) fn save_witness_to_dir<P: AsRef<Path>>(
44+
witnesses: WitnessStack,
45+
witness_name: &str,
46+
witness_dir: P,
47+
) -> Result<PathBuf, FilesystemError> {
48+
create_named_dir(witness_dir.as_ref(), "witness");
49+
let witness_path = witness_dir.as_ref().join(witness_name).with_extension("gz");
50+
51+
let buf: Vec<u8> = witnesses
52+
.try_into()
53+
.map_err(|_op| FilesystemError::OutputWitnessCreationFailed(witness_name.to_string()))?;
54+
write_to_file(buf.as_slice(), &witness_path);
55+
56+
Ok(witness_path)
57+
}

noir/noir-repo/tooling/acvm_cli/src/errors.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ pub(crate) enum FilesystemError {
2020

2121
#[error(" Error: failed to create output witness file {0}.")]
2222
OutputWitnessCreationFailed(String),
23-
24-
#[error(" Error: failed to write output witness file {0}.")]
25-
OutputWitnessWriteFailed(String),
2623
}
2724

2825
#[derive(Debug, Error)]

noir/noir-repo/tooling/noirc_abi_wasm/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See Cargo.toml for explanation.
66
use getrandom as _;
77

8-
use acvm::acir::native_types::WitnessMap;
8+
use acvm::acir::native_types::{WitnessMap, WitnessStack};
99
use iter_extended::try_btree_map;
1010
use noirc_abi::{
1111
errors::InputParserError,
@@ -113,3 +113,12 @@ pub fn abi_decode(abi: JsAbi, witness_map: JsWitnessMap) -> Result<JsValue, JsAb
113113
<wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&return_struct)
114114
.map_err(|err| err.to_string().into())
115115
}
116+
117+
#[wasm_bindgen(js_name = serializeWitness)]
118+
pub fn serialise_witness(witness_map: JsWitnessMap) -> Result<Vec<u8>, JsAbiError> {
119+
console_error_panic_hook::set_once();
120+
let converted_witness: WitnessMap = witness_map.into();
121+
let witness_stack: WitnessStack = converted_witness.into();
122+
let output = witness_stack.try_into();
123+
output.map_err(|_| JsAbiError::new("Failed to convert to Vec<u8>".to_string()))
124+
}

yarn-project/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ COPY --from=bb.js /usr/src/barretenberg/ts /usr/src/barretenberg/ts
1313
COPY --from=noir-packages /usr/src/noir/packages /usr/src/noir/packages
1414
COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts
1515
COPY --from=noir-projects /usr/src/noir-projects /usr/src/noir-projects
16-
# We want the native ACVM binary
16+
# We want the native ACVM and BB binaries
1717
COPY --from=noir /usr/src/noir/noir-repo/target/release/acvm /usr/src/noir/noir-repo/target/release/acvm
1818
COPY --from=barretenberg /usr/src/barretenberg/cpp/build/bin/bb /usr/src/barretenberg/cpp/build/bin/bb
1919

yarn-project/Dockerfile.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM --platform=linux/amd64 aztecprotocol/noir-packages as noir-packages
33
FROM --platform=linux/amd64 aztecprotocol/l1-contracts as contracts
44
FROM --platform=linux/amd64 aztecprotocol/noir-projects as noir-projects
55
FROM --platform=linux/amd64 aztecprotocol/barretenberg-x86_64-linux-clang as barretenberg
6+
FROM aztecprotocol/noir as noir
67

78
FROM node:18.19.0 as builder
89
RUN apt update && apt install -y jq curl perl && rm -rf /var/lib/apt/lists/* && apt-get clean
@@ -12,6 +13,8 @@ COPY --from=bb.js /usr/src/barretenberg/ts /usr/src/barretenberg/ts
1213
COPY --from=noir-packages /usr/src/noir/packages /usr/src/noir/packages
1314
COPY --from=contracts /usr/src/l1-contracts /usr/src/l1-contracts
1415
COPY --from=noir-projects /usr/src/noir-projects /usr/src/noir-projects
16+
# We want the native ACVM and BB binaries
17+
COPY --from=noir /usr/src/noir/noir-repo/target/release/acvm /usr/src/noir/noir-repo/target/release/acvm
1518
COPY --from=barretenberg /usr/src/barretenberg/cpp/build/bin/bb /usr/src/barretenberg/cpp/build/bin/bb
1619

1720
WORKDIR /usr/src/yarn-project

yarn-project/circuit-types/src/tx/processed_tx.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,34 @@ import {
1212
type Header,
1313
KernelCircuitPublicInputs,
1414
type Proof,
15+
type PublicKernelCircuitPrivateInputs,
1516
type PublicKernelCircuitPublicInputs,
17+
type PublicKernelTailCircuitPrivateInputs,
1618
makeEmptyProof,
1719
} from '@aztec/circuits.js';
1820

21+
/**
22+
* Used to communicate to the prover which type of circuit to prove
23+
*/
24+
export enum PublicKernelType {
25+
SETUP,
26+
APP_LOGIC,
27+
TEARDOWN,
28+
TAIL,
29+
}
30+
31+
export type PublicKernelTailRequest = {
32+
type: PublicKernelType.TAIL;
33+
inputs: PublicKernelTailCircuitPrivateInputs;
34+
};
35+
36+
export type PublicKernelNonTailRequest = {
37+
type: PublicKernelType.SETUP | PublicKernelType.APP_LOGIC | PublicKernelType.TEARDOWN;
38+
inputs: PublicKernelCircuitPrivateInputs;
39+
};
40+
41+
export type PublicKernelRequest = PublicKernelTailRequest | PublicKernelNonTailRequest;
42+
1943
/**
2044
* Represents a tx that has been processed by the sequencer public processor,
2145
* so its kernel circuit public inputs are filled in.
@@ -38,6 +62,11 @@ export type ProcessedTx = Pick<Tx, 'proof' | 'encryptedLogs' | 'unencryptedLogs'
3862
* Reason the tx was reverted.
3963
*/
4064
revertReason: SimulationError | undefined;
65+
66+
/**
67+
* The collection of public kernel circuit inputs for simulation/proving
68+
*/
69+
publicKernelRequests: PublicKernelRequest[];
4170
};
4271

4372
export type RevertedTx = ProcessedTx & {
@@ -90,6 +119,7 @@ export function makeProcessedTx(
90119
tx: Tx,
91120
kernelOutput: KernelCircuitPublicInputs,
92121
proof: Proof,
122+
publicKernelRequests: PublicKernelRequest[],
93123
revertReason?: SimulationError,
94124
): ProcessedTx {
95125
return {
@@ -100,6 +130,7 @@ export function makeProcessedTx(
100130
unencryptedLogs: revertReason ? UnencryptedTxL2Logs.empty() : tx.unencryptedLogs,
101131
isEmpty: false,
102132
revertReason,
133+
publicKernelRequests,
103134
};
104135
}
105136

@@ -123,6 +154,7 @@ export function makeEmptyProcessedTx(header: Header, chainId: Fr, version: Fr):
123154
proof: emptyProof,
124155
isEmpty: true,
125156
revertReason: undefined,
157+
publicKernelRequests: [],
126158
};
127159
}
128160

0 commit comments

Comments
 (0)