diff --git a/packages/hardhat-zksync-solc/src/compile/index.ts b/packages/hardhat-zksync-solc/src/compile/index.ts index 5cf1dec93..6cc0c68dd 100644 --- a/packages/hardhat-zksync-solc/src/compile/index.ts +++ b/packages/hardhat-zksync-solc/src/compile/index.ts @@ -1,6 +1,7 @@ import { ZkSolcConfig } from '../types'; import { compileWithBinary } from './binary'; import { HardhatDocker, Image } from '@nomiclabs/hardhat-docker'; +import semver from 'semver'; import { validateDockerIsInstalled, createDocker, @@ -12,6 +13,7 @@ import { import { CompilerInput } from 'hardhat/types'; import { ZkSyncSolcPluginError } from '../errors'; import { findMissingLibraries, mapMissingLibraryDependencies, writeLibrariesToFile } from '../utils'; +import { DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION } from '../constants'; export async function compile(zksolcConfig: ZkSolcConfig, input: CompilerInput, solcPath?: string) { let compiler: ICompiler; @@ -38,21 +40,23 @@ export class BinaryCompiler implements ICompiler { public async compile(input: CompilerInput, config: ZkSolcConfig) { // Check for missing libraries - const zkSolcOutput = await compileWithBinary(input, config, this.solcPath, true); + if (semver.gte(config.version, DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION)) { + const zkSolcOutput = await compileWithBinary(input, config, this.solcPath, true); - const missingLibraries = findMissingLibraries(zkSolcOutput); - if (missingLibraries.size > 0) { - if (!config.settings.missingLibrariesPath) { - throw new ZkSyncSolcPluginError('Missing libraries path is not specified'); - } - - const missingLibraryDependencies = mapMissingLibraryDependencies(zkSolcOutput, missingLibraries); - // Write missing libraries to file - const missingLibrariesPath = config.settings.missingLibrariesPath!; - await writeLibrariesToFile(missingLibrariesPath, missingLibraryDependencies); + const missingLibraries = findMissingLibraries(zkSolcOutput); + if (missingLibraries.size > 0) { + if (!config.settings.missingLibrariesPath) { + throw new ZkSyncSolcPluginError('Missing libraries path is not specified'); + } + + const missingLibraryDependencies = mapMissingLibraryDependencies(zkSolcOutput, missingLibraries); + // Write missing libraries to file + const missingLibrariesPath = config.settings.missingLibrariesPath!; + await writeLibrariesToFile(missingLibrariesPath, missingLibraryDependencies); - config.settings.areLibrariesMissing = true; - return zkSolcOutput; + config.settings.areLibrariesMissing = true; + return zkSolcOutput; + } } return await compileWithBinary(input, config, this.solcPath); diff --git a/packages/hardhat-zksync-solc/src/constants.ts b/packages/hardhat-zksync-solc/src/constants.ts index a6940e281..af3590aff 100644 --- a/packages/hardhat-zksync-solc/src/constants.ts +++ b/packages/hardhat-zksync-solc/src/constants.ts @@ -4,6 +4,7 @@ export const PLUGIN_NAME = '@matterlabs/hardhat-zksync-solc'; export const ZK_ARTIFACT_FORMAT_VERSION = 'hh-zksolc-artifact-1'; export const ZKSOLC_BIN_REPOSITORY = 'https://github.com/matter-labs/zksolc-bin'; export const ZKSOLC_BIN_VERSION_INFO = `https://raw.githubusercontent.com/matter-labs/zksolc-bin/main`; +export const DETECT_MISSING_LIBRARY_MODE_COMPILER_VERSION = '1.3.14'; export const defaultZkSolcConfig: ZkSolcConfig = { version: 'latest',