From 1b29313e753d5906af74b9989df7e18bc2d6f5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Tue, 19 Dec 2023 17:26:56 +0000 Subject: [PATCH] feat: compile base rollup as a circuit (#3739) This PR adds a variant of the base rollup that is a circuit. This makes sure that PRs don't break compilation as a circuit of the base rollup and tracks its constraint count. After the last noir pull, thanks to @TomAFrench compilation is now much faster, allowing to compile the base rollup as a circuit in a reasonable time (prev. it took 5 minutes, now some seconds) --- yarn-project/noir-protocol-circuits/src/Nargo.toml | 1 + .../src/crates/rollup-base-simulated/Nargo.toml | 9 +++++++++ .../src/crates/rollup-base-simulated/src/main.nr | 5 +++++ .../src/crates/rollup-base/src/main.nr | 5 ++--- yarn-project/noir-protocol-circuits/src/index.ts | 8 ++++---- 5 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/Nargo.toml create mode 100644 yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/src/main.nr diff --git a/yarn-project/noir-protocol-circuits/src/Nargo.toml b/yarn-project/noir-protocol-circuits/src/Nargo.toml index 40096bdb01a..79a55c635e0 100644 --- a/yarn-project/noir-protocol-circuits/src/Nargo.toml +++ b/yarn-project/noir-protocol-circuits/src/Nargo.toml @@ -16,5 +16,6 @@ members = [ "crates/rollup-lib", "crates/rollup-merge", "crates/rollup-base", + "crates/rollup-base-simulated", "crates/rollup-root", ] diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/Nargo.toml b/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/Nargo.toml new file mode 100644 index 00000000000..cda6dfa73c5 --- /dev/null +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/Nargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rollup_base_simulated" +type = "bin" +authors = [""] +compiler_version = ">=0.18.0" + +[dependencies] +rollup_lib = { path = "../rollup-lib" } +types = { path = "../types" } diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/src/main.nr new file mode 100644 index 00000000000..67faaa8ec99 --- /dev/null +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-base-simulated/src/main.nr @@ -0,0 +1,5 @@ +use dep::rollup_lib::base::{BaseRollupInputs,BaseOrMergeRollupPublicInputs}; + +unconstrained fn main(inputs: BaseRollupInputs) -> pub BaseOrMergeRollupPublicInputs { + inputs.base_rollup_circuit() +} diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-base/src/main.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-base/src/main.nr index 7405a961633..a7b7b5cdd10 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-base/src/main.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-base/src/main.nr @@ -1,6 +1,5 @@ use dep::rollup_lib::base::{BaseRollupInputs,BaseOrMergeRollupPublicInputs}; -//TODO add a circuit variant -unconstrained fn main(inputs : BaseRollupInputs) -> pub BaseOrMergeRollupPublicInputs { +fn main(inputs: BaseRollupInputs) -> pub BaseOrMergeRollupPublicInputs { inputs.base_rollup_circuit() -} \ No newline at end of file +} diff --git a/yarn-project/noir-protocol-circuits/src/index.ts b/yarn-project/noir-protocol-circuits/src/index.ts index 97671183a7c..89954211e99 100644 --- a/yarn-project/noir-protocol-circuits/src/index.ts +++ b/yarn-project/noir-protocol-circuits/src/index.ts @@ -26,7 +26,7 @@ import PublicKernelPrivatePreviousJson from './target/public_kernel_private_prev import PublicKernelPrivatePreviousSimulatedJson from './target/public_kernel_private_previous_simulated.json' assert { type: 'json' }; import PublicKernelPublicPreviousJson from './target/public_kernel_public_previous.json' assert { type: 'json' }; import PublicKernelPublicPreviousSimulatedJson from './target/public_kernel_public_previous_simulated.json' assert { type: 'json' }; -import BaseRollupJson from './target/rollup_base.json' assert { type: 'json' }; +import BaseRollupSimulatedJson from './target/rollup_base_simulated.json' assert { type: 'json' }; import MergeRollupJson from './target/rollup_merge.json' assert { type: 'json' }; import RootRollupJson from './target/rollup_root.json' assert { type: 'json' }; import { @@ -416,12 +416,12 @@ async function executeMergeRollupWithACVM(input: MergeRollupInputType): Promise< * Executes the base rollup with the given inputs using the acvm. */ async function executeBaseRollupWithACVM(input: BaseRollupInputType): Promise { - const initialWitnessMap = abiEncode(BaseRollupJson.abi as Abi, input as any); + const initialWitnessMap = abiEncode(BaseRollupSimulatedJson.abi as Abi, input as any); // Execute the circuit on those initial witness values // // Decode the bytecode from base64 since the acvm does not know about base64 encoding - const decodedBytecode = Buffer.from(BaseRollupJson.bytecode, 'base64'); + const decodedBytecode = Buffer.from(BaseRollupSimulatedJson.bytecode, 'base64'); // // Execute the circuit const _witnessMap = await executeCircuitWithBlackBoxSolver( @@ -434,7 +434,7 @@ async function executeBaseRollupWithACVM(input: BaseRollupInputType): Promise