Skip to content

Commit

Permalink
fix: set viaEVMAssembly to true by default for solidity compiler vers…
Browse files Browse the repository at this point in the history
…ion < 0.8
  • Loading branch information
kiriyaga committed May 15, 2024
1 parent 3d2df17 commit 8f65e9c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat-zksync-solc/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const COMPILER_BINARY_CORRUPTION_ERROR_ZKVM_SOLC = (compilerPath: string)
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 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 COMPILER_ZKSOLC_NEED_EVM_CODEGEN = `Yul codegen is only supported for solc >= 0.8. Flag viaEVMAssembly will automatically be set to true by default, overriding viaYul for this compiler.`;

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
1 change: 1 addition & 0 deletions packages/hardhat-zksync-solc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ZkSolcConfig {
// Remove metadata hash from bytecode. If the option is ommited, the metadata hash will be appended by default.
metadata?: {
bytecodeHash?: 'none';
useLiteralContent?: boolean;
};
// addresses of external libraries
libraries?: {
Expand Down
36 changes: 13 additions & 23 deletions packages/hardhat-zksync-solc/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,33 @@ export function updateCompilerConf(
userConfigCompilers: SolcUserConfig[] | Map<string, SolcUserConfig>,
) {
const compiler = solcConfigData.compiler;
const [major, minor] = getVersionComponents(compiler.version);

if (needsMandatoryCodegen(zksolc.version)) {
if (!zksolc.settings.viaEVMAssembly && !zksolc.settings.viaYul) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN);
}

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');
}
if (
(needsMandatoryCodegen(zksolc.version) && !zksolc.settings.viaEVMAssembly && !zksolc.settings.viaYul) ||
(zksolc.settings.viaEVMAssembly && zksolc.settings.viaYul)
) {
throw new ZkSyncSolcPluginError(COMPILER_ZKSOLC_VERSION_EXPLICIT_CODEGEN);
}

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)) {
compiler.settings.viaEVMAssembly = zksolc.settings.viaEVMAssembly ?? false;
compiler.settings.viaYul = zksolc.settings.viaYul ?? false;
compiler.settings.enableEraVMExtensions = zksolc.settings.isSystem ?? false;
compiler.settings.detectMissingLibraries = false;
}

const [major, minor] = getVersionComponents(compiler.version);
if (zksolc.settings.viaYul && major === 0 && minor < 8) {
console.warn(COMPILER_ZKSOLC_NEED_EVM_CODEGEN);
compiler.settings.viaEVMAssembly = true;
compiler.settings.viaYul = false;
}

// Remove metadata settings from solidity settings.
delete compiler.settings.metadata;
// Override the solc metadata settings with zksolc metadata settings.
Expand Down

0 comments on commit 8f65e9c

Please sign in to comment.