From 44da70022a80890c04b3939b7a346bd5cc565f45 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 4 Dec 2023 12:43:13 +0000 Subject: [PATCH] throw compile time error if contract has too many fns --- yarn-project/noir-compiler/package.json | 1 + yarn-project/noir-compiler/src/contract-interface-gen/abi.ts | 4 ++++ yarn-project/noir-compiler/tsconfig.json | 3 +++ yarn-project/yarn.lock | 1 + 4 files changed, 9 insertions(+) diff --git a/yarn-project/noir-compiler/package.json b/yarn-project/noir-compiler/package.json index 2232e05b021..e03849b0de2 100644 --- a/yarn-project/noir-compiler/package.json +++ b/yarn-project/noir-compiler/package.json @@ -45,6 +45,7 @@ } }, "dependencies": { + "@aztec/circuits.js": "workspace:^", "@aztec/foundation": "workspace:^", "@ltd/j-toml": "^1.38.0", "@noir-lang/noir_wasm": "portal:../../noir/packages/noir_wasm", diff --git a/yarn-project/noir-compiler/src/contract-interface-gen/abi.ts b/yarn-project/noir-compiler/src/contract-interface-gen/abi.ts index 61b47ea24d6..df819ae6578 100644 --- a/yarn-project/noir-compiler/src/contract-interface-gen/abi.ts +++ b/yarn-project/noir-compiler/src/contract-interface-gen/abi.ts @@ -1,3 +1,4 @@ +import { FUNCTION_TREE_HEIGHT } from '@aztec/circuits.js'; import { ContractArtifact, DebugMetadata, FunctionArtifact, FunctionType } from '@aztec/foundation/abi'; import { deflate } from 'pako'; @@ -88,6 +89,9 @@ export function generateContractArtifact( { contract, debug }: NoirContractCompilationArtifacts, aztecNrVersion?: string, ): ContractArtifact { + if (contract.functions.length > 2 ** FUNCTION_TREE_HEIGHT) { + throw new Error(`Contract can only have a maximum of ${2 ** FUNCTION_TREE_HEIGHT} functions`); + } const originalFunctions = contract.functions; // TODO why sort? we should have idempotent compilation so this should not be needed. const sortedFunctions = [...contract.functions].sort((fnA, fnB) => fnA.name.localeCompare(fnB.name)); diff --git a/yarn-project/noir-compiler/tsconfig.json b/yarn-project/noir-compiler/tsconfig.json index a2d81aa678d..a6b3ad94790 100644 --- a/yarn-project/noir-compiler/tsconfig.json +++ b/yarn-project/noir-compiler/tsconfig.json @@ -6,6 +6,9 @@ "tsBuildInfoFile": ".tsbuildinfo" }, "references": [ + { + "path": "../circuits.js" + }, { "path": "../foundation" } diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 4c4ad8d3a13..b0696b5e8ae 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -572,6 +572,7 @@ __metadata: version: 0.0.0-use.local resolution: "@aztec/noir-compiler@workspace:noir-compiler" dependencies: + "@aztec/circuits.js": "workspace:^" "@aztec/foundation": "workspace:^" "@jest/globals": ^29.5.0 "@ltd/j-toml": ^1.38.0