Skip to content

Commit

Permalink
feat: compile base rollup as a circuit (#3739)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
sirasistant authored Dec 19, 2023
1 parent 143271c commit 5118d44
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions yarn-project/noir-protocol-circuits/src/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ members = [
"crates/rollup-lib",
"crates/rollup-merge",
"crates/rollup-base",
"crates/rollup-base-simulated",
"crates/rollup-root",
]
Original file line number Diff line number Diff line change
@@ -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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::rollup_lib::base::{BaseRollupInputs,BaseOrMergeRollupPublicInputs};

unconstrained fn main(inputs: BaseRollupInputs) -> pub BaseOrMergeRollupPublicInputs {
inputs.base_rollup_circuit()
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
8 changes: 4 additions & 4 deletions yarn-project/noir-protocol-circuits/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<BaseRollupReturnType> {
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(
Expand All @@ -434,7 +434,7 @@ async function executeBaseRollupWithACVM(input: BaseRollupInputType): Promise<Ba
);

// Decode the witness map into two fields, the return values and the inputs
const decodedInputs: DecodedInputs = abiDecode(BaseRollupJson.abi as Abi, _witnessMap);
const decodedInputs: DecodedInputs = abiDecode(BaseRollupSimulatedJson.abi as Abi, _witnessMap);

// Cast the inputs as the return type
return decodedInputs.return_value as BaseRollupReturnType;
Expand Down

0 comments on commit 5118d44

Please sign in to comment.