diff --git a/yarn-project/noir-compiler/src/cli/contract.ts b/yarn-project/noir-compiler/src/cli/contract.ts index 1e0de766a4f..020908f0ab0 100644 --- a/yarn-project/noir-compiler/src/cli/contract.ts +++ b/yarn-project/noir-compiler/src/cli/contract.ts @@ -39,7 +39,7 @@ export function compileContract(program: Command, name = 'contract', log: LogFn const compile = compileUsingNargo; log(`Compiling contracts...`); - const result = await compile(projectPath); + const result = await compile(projectPath, { log }); for (const contract of result) { const artifactPath = resolve(projectPath, outdir, `${contract.name}.json`); diff --git a/yarn-project/noir-compiler/src/compile/nargo.ts b/yarn-project/noir-compiler/src/compile/nargo.ts index 74c8fbf3358..790f4462b84 100644 --- a/yarn-project/noir-compiler/src/compile/nargo.ts +++ b/yarn-project/noir-compiler/src/compile/nargo.ts @@ -1,8 +1,11 @@ +import { LogFn, createDebugLogger } from '@aztec/foundation/log'; + import { execSync } from 'child_process'; import { readFileSync, readdirSync, statSync } from 'fs'; import { emptyDirSync } from 'fs-extra'; import path from 'path'; +import { NoirCommit, NoirTag } from '../index.js'; import { NoirCompilationArtifacts, NoirCompiledContract, NoirDebugMetadata } from '../noir_artifact.js'; /** Compilation options */ @@ -11,13 +14,18 @@ export type CompileOpts = { quiet?: boolean; /** Path to the nargo binary. */ nargoBin?: string; + /** Logging function */ + log?: LogFn; }; /** * A class that compiles noir contracts using nargo via the shell. */ export class NargoContractCompiler { - constructor(private projectPath: string, private opts: CompileOpts = {}) {} + private log: LogFn; + constructor(private projectPath: string, private opts: CompileOpts = {}) { + this.log = opts.log ?? createDebugLogger('aztec:noir-compiler'); + } /** * Compiles the contracts in projectPath and returns the Noir artifact. @@ -26,12 +34,23 @@ export class NargoContractCompiler { public compile(): Promise { const stdio = this.opts.quiet ? 'ignore' : 'inherit'; const nargoBin = this.opts.nargoBin ?? 'nargo'; - execSync(`${nargoBin} --version`, { cwd: this.projectPath, stdio }); + const version = execSync(`${nargoBin} --version`, { cwd: this.projectPath, stdio: 'pipe' }).toString(); + this.checkNargoBinVersion(version.replace('\n', '')); emptyDirSync(this.getTargetFolder()); execSync(`${nargoBin} compile --output-debug `, { cwd: this.projectPath, stdio }); return Promise.resolve(this.collectArtifacts()); } + private checkNargoBinVersion(version: string) { + if (!version.includes(NoirCommit)) { + this.log( + `Warning: the nargo version installed locally does not match the expected one. This may cause issues when compiling or deploying contracts. Consider updating your nargo or aztec-cli installation. \n- Expected: ${NoirTag} (git version hash: ${NoirCommit})\n- Found: ${version}`, + ); + } else if (!this.opts.quiet) { + this.log(`Using ${version}`); + } + } + private collectArtifacts(): NoirCompilationArtifacts[] { const contractArtifacts = new Map(); const debugArtifacts = new Map(); diff --git a/yarn-project/noir-compiler/src/index.ts b/yarn-project/noir-compiler/src/index.ts index bade7654a79..b7054d89577 100644 --- a/yarn-project/noir-compiler/src/index.ts +++ b/yarn-project/noir-compiler/src/index.ts @@ -2,6 +2,10 @@ import { ContractAbi } from '@aztec/foundation/abi'; import { CompileOpts, NargoContractCompiler } from './compile/nargo.js'; import { generateAztecAbi } from './contract-interface-gen/abi.js'; +import NoirVersion from './noir-version.json' assert { type: 'json' }; + +const { commit: NoirCommit, tag: NoirTag } = NoirVersion; +export { NoirCommit, NoirTag }; export { generateNoirContractInterface } from './contract-interface-gen/noir.js'; export { generateTypescriptContractInterface } from './contract-interface-gen/typescript.js'; diff --git a/yarn-project/noir-compiler/src/noir-version.json b/yarn-project/noir-compiler/src/noir-version.json new file mode 100644 index 00000000000..31ee4c22897 --- /dev/null +++ b/yarn-project/noir-compiler/src/noir-version.json @@ -0,0 +1,4 @@ +{ + "tag": "aztec", + "commit": "39e1433a9c4184b72f3c5ab0368cfaa5d4ce537b" +} diff --git a/yarn-project/noir-compiler/tsconfig.json b/yarn-project/noir-compiler/tsconfig.json index 63f8ab3e9f7..a2d81aa678d 100644 --- a/yarn-project/noir-compiler/tsconfig.json +++ b/yarn-project/noir-compiler/tsconfig.json @@ -10,5 +10,5 @@ "path": "../foundation" } ], - "include": ["src"] + "include": ["src", "src/*.json"] } diff --git a/yarn-project/noir-contracts/Dockerfile.build b/yarn-project/noir-contracts/Dockerfile.build index 45a6508f6e2..f5d9ed70ca7 100644 --- a/yarn-project/noir-contracts/Dockerfile.build +++ b/yarn-project/noir-contracts/Dockerfile.build @@ -4,6 +4,7 @@ FROM ubuntu:jammy RUN apt-get update && apt-get install -y \ + jq \ curl \ git \ sed diff --git a/yarn-project/noir-contracts/scripts/compile.sh b/yarn-project/noir-contracts/scripts/compile.sh index c867cc12526..4a9555b0b1e 100755 --- a/yarn-project/noir-contracts/scripts/compile.sh +++ b/yarn-project/noir-contracts/scripts/compile.sh @@ -41,7 +41,15 @@ build() { nargo compile --output-debug; } +# Check nargo version matches the expected one echo "Using $(nargo --version)" +EXPECTED_VERSION=$(jq -r '.commit' ../noir-compiler/src/noir-version.json) +FOUND_VERSION=$(nargo --version | grep -oP 'git version hash: \K[0-9a-f]+') +if [ "$EXPECTED_VERSION" != "$FOUND_VERSION" ]; then + echo "Expected nargo version $EXPECTED_VERSION but found version $FOUND_VERSION. Aborting." + exit 1 +fi + # Build contracts for CONTRACT_NAME in "$@"; do diff --git a/yarn-project/noir-contracts/scripts/install_noir.sh b/yarn-project/noir-contracts/scripts/install_noir.sh index c0c9d70d729..325e9a56620 100755 --- a/yarn-project/noir-contracts/scripts/install_noir.sh +++ b/yarn-project/noir-contracts/scripts/install_noir.sh @@ -2,7 +2,7 @@ # Script to install noirup and the latest aztec nargo set -eu -VERSION="aztec" +VERSION="${VERSION:-$(jq -r '.tag' ../noir-compiler/src/noir-version.json)}" # Install nargo noirup -v $VERSION