Skip to content

Commit

Permalink
fix: change input parametrs name and add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriyaga committed May 14, 2024
1 parent 2a4809c commit e21fa0e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 19 deletions.
15 changes: 10 additions & 5 deletions packages/hardhat-zksync-solc/src/compile/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ export async function compileWithBinary(
solcPath: string,
detectMissingLibrariesMode: boolean = false,
): Promise<any> {
const { compilerPath, isSystem, forceEvmla } = config.settings;
const { compilerPath } = config.settings;

let processCommand = `${compilerPath} --standard-json --solc ${solcPath} ${
detectMissingLibrariesMode ? '--detect-missing-libraries' : ''
}`;
let processCommand = `${compilerPath} --standard-json --solc ${solcPath}`;

if (semver.lt(config.version, ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN)) {
processCommand += `${isSystem ? ' --system-mode' : ''} ${forceEvmla ? ' --force-evmla' : ''}`;
const { isSystem, viaEVMAssembly, viaYul } = config.settings;
processCommand += `${detectMissingLibrariesMode ? ' --detect-missing-libraries' : ''} ${
isSystem ? '--system-mode' : ''
} ${viaEVMAssembly ? '--force-evmla' : ''} ${viaYul ? '--via-ir' : ''}`;
}

if (detectMissingLibrariesMode && semver.gte(config.version, ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN)) {
input.settings.detectMissingLibraries = detectMissingLibrariesMode;
}

const output: string = await new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-zksync-solc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const defaultZkSolcConfig: ZkSolcConfig = {
version: 'latest',
compilerSource: 'binary',
settings: {
forceEvmla: true,
optimizer: {
enabled: true,
mode: '3',
Expand Down Expand Up @@ -62,7 +61,8 @@ export const COMPILER_BINARY_CORRUPTION_ERROR_ZKVM_SOLC = (compilerPath: string)
`The zkvm-solc binary at path ${compilerPath} is corrupted. Please delete it and try again.`;
export const COMPILER_ZKSOLC_VERSION_WITH_ZKVM_SOLC_ERROR = `zkVm (eraVersion) compiler is supported only with usage of zksolc version >= ${ZKSOLC_COMPILER_VERSION_MIN_VERSION_WITH_ZKVM_COMPILER}.`;

export const COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN = `For zksolc versions greater than or equal to ${ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN}, ensure that the forceEvmla flag is set to true.`;
export const COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN = `For zksolc versions greater than or equal to ${ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN}, ensure that the eather viaYul or viaEVMAssembly flag is set to true inside zksolc settings.`;
export const COMPILER_ZKSOLC_NEED_EVM_CODEGEN = `For zksolc versions greater than or equal to ${ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN}, EVM assembly codegen is only supported with the zksolc solidity compiler versions < 0.8. Please disable viaYul flag and set viaEVMAssembly to true in the settings section."`;

export const COMPILERS_CONFLICT_ZKVM_SOLC = (version: string) =>
`Your Hardhat configuration has conflicting Solidity compiler versions for version ${version}. Specify either a compiler version with zkVm support (eraVersion) or one without it.`;
Expand Down
6 changes: 4 additions & 2 deletions packages/hardhat-zksync-solc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export interface ZkSolcConfig {
};
// Whether to support compilation of zkSync-specific simulations
isSystem?: boolean;
// Force evmla
forceEvmla?: boolean;
// Evmla intermediate representation
viaEVMAssembly?: boolean;
// Yul intermediate representation
viaYul?: boolean;
// specific contracts to be compiled
contractsToCompile?: string[];
};
Expand Down
43 changes: 33 additions & 10 deletions packages/hardhat-zksync-solc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ZKSOLC_COMPILER_VERSION_MIN_VERSION_WITH_ZKVM_COMPILER,
COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN,
ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN,
COMPILER_ZKSOLC_NEED_EVM_CODEGEN,
} from './constants';
import { ZkSyncSolcPluginError } from './errors';
import {
Expand Down Expand Up @@ -70,21 +71,39 @@ export function updateCompilerConf(
) {
const compiler = solcConfigData.compiler;
const [major, minor] = getVersionComponents(compiler.version);
if (major === 0 && minor < 8 && zksolc.settings.forceEvmla) {
console.warn('zksolc solidity compiler versions < 0.8 work with forceEvmla enabled by default');
}
const settings = compiler.settings || {};

// Override the default solc optimizer settings with zksolc optimizer settings.
compiler.settings = { ...settings, optimizer: { ...zksolc.settings.optimizer } };
if (needsMandatoryCodegen(zksolc.version)) {
if (!zksolc.settings.viaEVMAssembly && !zksolc.settings.viaYul) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN);
}

if (zksolc.version === 'latest' || semver.gte(zksolc.version, ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN)) {
if (!zksolc.settings.forceEvmla) {
if (zksolc.settings.viaEVMAssembly && zksolc.settings.viaYul) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN);
}
}

if (zksolc.settings.viaYul && major === 0 && minor < 8) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_NEED_EVM_CODEGEN);
}

if (major === 0 && minor < 8) {
if (needsMandatoryCodegen(zksolc.version) && !zksolc.settings.viaEVMAssembly) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_NEED_EVM_CODEGEN);
}

if (needsMandatoryCodegen(zksolc.version) && zksolc.settings.viaEVMAssembly) {
console.warn('zksolc solidity compiler versions < 0.8 work with forceEvmla enabled by default');
}
}

const settings = compiler.settings || {};

compiler.settings.forceEvmla = zksolc.settings.forceEvmla;
compiler.settings.isSystem = zksolc.settings.isSystem;
// Override the default solc optimizer settings with zksolc optimizer settings.
compiler.settings = { ...settings, optimizer: { ...zksolc.settings.optimizer } };
if (needsMandatoryCodegen(zksolc.version)) {
compiler.settings.viaEVMAssembly = zksolc.settings.viaEVMAssembly;
compiler.settings.viaYul = zksolc.settings.viaYul;
compiler.settings.enableEraVMExtensions = zksolc.settings.isSystem;
}

// Remove metadata settings from solidity settings.
Expand Down Expand Up @@ -113,6 +132,10 @@ export function updateCompilerConf(
}
}

function needsMandatoryCodegen(zksolcVersion: string): boolean {
return semver.gte(zksolcVersion, ZKSOLC_COMPILER_MIN_VERSION_WITH_MANDATORY_CODEGEN);
}

export function zeroxlify(hex: string): string {
hex = hex.toLowerCase();
return hex.slice(0, 2) === '0x' ? hex : `0x${hex}`;
Expand Down

0 comments on commit e21fa0e

Please sign in to comment.