From 5138f0f10d46c0dcfba894d2a530e6964ebf0013 Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Tue, 10 Sep 2024 01:15:01 +0200 Subject: [PATCH 1/5] fix: add suppressed errors and warnings --- packages/hardhat-zksync-solc/src/index.ts | 20 ++++++++++- .../src/type-extensions.ts | 1 + packages/hardhat-zksync-solc/src/types.ts | 18 +++++++++- .../contracts/Greeter.sol | 19 +++++++++++ .../hardhat.config.ts | 23 +++++++++++++ .../hardhat-zksync-solc/test/tests/tests.ts | 34 +++++++++++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol create mode 100644 packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts diff --git a/packages/hardhat-zksync-solc/src/index.ts b/packages/hardhat-zksync-solc/src/index.ts index e748956e5..018a5bb83 100644 --- a/packages/hardhat-zksync-solc/src/index.ts +++ b/packages/hardhat-zksync-solc/src/index.ts @@ -13,6 +13,7 @@ import { TASK_COMPILE_SOLIDITY_LOG_RUN_COMPILER_END, TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS, TASK_COMPILE, + TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, } from 'hardhat/builtin-tasks/task-names'; import { extendEnvironment, extendConfig, subtask, task } from 'hardhat/internal/core/config/config-env'; import { getCompilersDir } from 'hardhat/internal/util/global-dir'; @@ -65,7 +66,7 @@ import { SolcStringUserConfigExtractor, SolcUserConfigExtractor, } from './config-extractor'; -import { FactoryDeps } from './types'; +import { FactoryDeps, ZkSyncCompilerInput } from './types'; const logDebug = debug('hardhat:core:tasks:compile'); @@ -554,6 +555,23 @@ subtask(TASK_COMPILE_SOLIDITY_EMIT_ARTIFACTS).setAction( }, ); +subtask(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, async (taskArgs, hre, runSuper) => { + const compilerInput: ZkSyncCompilerInput = await runSuper(taskArgs); + if (hre.network.zksync !== true) { + return compilerInput; + } + + if (hre.config.zksolc.settings.suppressedErrors && hre.config.zksolc.settings.suppressedErrors.length > 0) { + compilerInput.suppressedErrors = hre.config.zksolc.settings.suppressedErrors; + } + + if (hre.config.zksolc.settings.suppressedWarnings && hre.config.zksolc.settings.suppressedWarnings.length > 0) { + compilerInput.suppressedWarnings = hre.config.zksolc.settings.suppressedWarnings; + } + + return compilerInput; +}); + subtask(TASK_COMPILE_REMOVE_OBSOLETE_ARTIFACTS, async (taskArgs, hre, runSuper) => { if (hre.network.zksync !== true || !hre.config.zksolc.settings.areLibrariesMissing) { return await runSuper(taskArgs); diff --git a/packages/hardhat-zksync-solc/src/type-extensions.ts b/packages/hardhat-zksync-solc/src/type-extensions.ts index 5b73a6101..751ca8f2d 100644 --- a/packages/hardhat-zksync-solc/src/type-extensions.ts +++ b/packages/hardhat-zksync-solc/src/type-extensions.ts @@ -29,6 +29,7 @@ declare module 'hardhat/types/config' { interface SolcConfig { eraVersion?: string; + suppressedErrors?: string[]; } interface SolcUserConfig { diff --git a/packages/hardhat-zksync-solc/src/types.ts b/packages/hardhat-zksync-solc/src/types.ts index db0ccb406..277914c78 100644 --- a/packages/hardhat-zksync-solc/src/types.ts +++ b/packages/hardhat-zksync-solc/src/types.ts @@ -1,4 +1,4 @@ -import { Artifact } from 'hardhat/types'; +import { Artifact, CompilerInput } from 'hardhat/types'; export interface ZkSolcConfig { version: string; // Currently ignored. @@ -46,9 +46,25 @@ export interface ZkSolcConfig { forceContractsToCompile?: string[]; // Dump all IR (Yul, EVMLA, LLVM IR, assembly) to files in the specified directory. Only for testing and debugging. debugOutputDir?: string; + // Suppress specified warnings. Currently supported: TxOrigin, SendTransfer + suppressedWarnings?: SuppressedMessageType[]; + // Suppress specified errors. Currently supported: TxOrigin, SendTransfer + suppressedErrors?: SuppressedMessageType[]; }; } +export interface ZkSyncCompilerInput extends CompilerInput { + // Suppress specified warnings. Currently supported: TxOrigin, SendTransfer + suppressedWarnings?: SuppressedMessageType[]; + // Suppress specified errors. Currently supported: TxOrigin, SendTransfer + suppressedErrors?: SuppressedMessageType[]; +} + +export enum SuppressedMessageType { + TxOrigin = 'TxOrigin', + SendTransfer = 'SendTransfer', +} + export interface CompilerOutputSelection { [file: string]: { [contract: string]: string[] }; } diff --git a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol new file mode 100644 index 000000000..f620d48ec --- /dev/null +++ b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.4.22 <0.9.0; + +contract Greeter { + + string greeting; + string bad; + constructor(string memory _greeting) { + greeting = _greeting; + } + + function payGreet(address payable a) public payable returns (bool memory) { + require(a != address(0), "Invalid address"); + bool success = a.send(1); + return success; + } + +} diff --git a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts new file mode 100644 index 000000000..275c72b00 --- /dev/null +++ b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts @@ -0,0 +1,23 @@ +import '../../../src/index'; +import { HardhatUserConfig } from 'hardhat/config'; +import { SuppressedMessageType } from '../../../src/types'; + +const config: HardhatUserConfig = { + zksolc: { + compilerSource: 'binary', + settings: { + suppressedErrors: [SuppressedMessageType.SendTransfer], + suppressedWarnings: [SuppressedMessageType.TxOrigin], + }, + }, + networks: { + hardhat: { + zksync: true, + }, + }, + solidity: { + version: process.env.SOLC_VERSION || '0.8.17', + }, +}; + +export default config; diff --git a/packages/hardhat-zksync-solc/test/tests/tests.ts b/packages/hardhat-zksync-solc/test/tests/tests.ts index a12f2916a..eacd447c2 100644 --- a/packages/hardhat-zksync-solc/test/tests/tests.ts +++ b/packages/hardhat-zksync-solc/test/tests/tests.ts @@ -1,6 +1,7 @@ import { TASK_COMPILE, TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS, + TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH, TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, TASK_COMPILE_SOLIDITY_GET_SOURCE_NAMES, @@ -484,6 +485,39 @@ describe('zksolc plugin', async function () { }); }); + describe('Suppresed warnings and errors', async function () { + useEnvironment('suppresed-warnings-errors'); + + it('Should populate proper compiler input suppresed warnings and errors', async function () { + const rootPath = this.env.config.paths.root; + const sourceNames: string[] = ['contracts/Greeter.sol']; + + const solidityFilesCachePath = path.join(this.env.config.paths.cache, SOLIDITY_FILES_CACHE_FILENAME); + + const dependencyGraph: DependencyGraph = await this.env.run( + TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH, + { + rootPath, + sourceNames, + solidityFilesCachePath, + }, + ); + + const { jobs, _ } = await this.env.run(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS, { + dependencyGraph, + solidityFilesCachePath, + }); + + assert.equal(1, jobs.length); + const compilerInput = await this.env.run(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT, { + compilationJob: jobs[0], + }); + + assert.deepEqual(compilerInput.suppressedWarnings, ['TxOrigin']); + assert.deepEqual(compilerInput.suppressedErrors, ['SendTransfer']); + }); + }); + describe('Missing Library', async function () { useEnvironment('missing-libraries'); From e248d59d1e2382d3bd80bfe7058b9a124ebc835e Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Tue, 10 Sep 2024 01:19:00 +0200 Subject: [PATCH 2/5] chore: revert a tested case --- packages/hardhat-zksync-solc/src/type-extensions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/hardhat-zksync-solc/src/type-extensions.ts b/packages/hardhat-zksync-solc/src/type-extensions.ts index 751ca8f2d..5b73a6101 100644 --- a/packages/hardhat-zksync-solc/src/type-extensions.ts +++ b/packages/hardhat-zksync-solc/src/type-extensions.ts @@ -29,7 +29,6 @@ declare module 'hardhat/types/config' { interface SolcConfig { eraVersion?: string; - suppressedErrors?: string[]; } interface SolcUserConfig { From 78775f9522642a73d047c3e5bcd072a0160f09f6 Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Wed, 25 Sep 2024 07:12:48 +0200 Subject: [PATCH 3/5] fix: make warnings and errors as strings --- packages/hardhat-zksync-solc/src/types.ts | 21 +++++++------------ .../contracts/Greeter.sol | 2 +- .../hardhat.config.ts | 5 ++--- .../hardhat-zksync-solc/test/tests/tests.ts | 12 +++++++++-- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/packages/hardhat-zksync-solc/src/types.ts b/packages/hardhat-zksync-solc/src/types.ts index 277914c78..75762ec98 100644 --- a/packages/hardhat-zksync-solc/src/types.ts +++ b/packages/hardhat-zksync-solc/src/types.ts @@ -46,23 +46,18 @@ export interface ZkSolcConfig { forceContractsToCompile?: string[]; // Dump all IR (Yul, EVMLA, LLVM IR, assembly) to files in the specified directory. Only for testing and debugging. debugOutputDir?: string; - // Suppress specified warnings. Currently supported: TxOrigin, SendTransfer - suppressedWarnings?: SuppressedMessageType[]; - // Suppress specified errors. Currently supported: TxOrigin, SendTransfer - suppressedErrors?: SuppressedMessageType[]; + // Suppress specified warnings. Currently supported: txorigin, sendtransfer + suppressedWarnings?: string[]; + // Suppress specified errors. Currently supported: txorigin, sendtransfer + suppressedErrors?: string[]; }; } export interface ZkSyncCompilerInput extends CompilerInput { - // Suppress specified warnings. Currently supported: TxOrigin, SendTransfer - suppressedWarnings?: SuppressedMessageType[]; - // Suppress specified errors. Currently supported: TxOrigin, SendTransfer - suppressedErrors?: SuppressedMessageType[]; -} - -export enum SuppressedMessageType { - TxOrigin = 'TxOrigin', - SendTransfer = 'SendTransfer', + // Suppress specified warnings. Currently supported: txorigin, sendtransfer + suppressedWarnings?: string[]; + // Suppress specified errors. Currently supported: txorigin, sendtransfer + suppressedErrors?: string[]; } export interface CompilerOutputSelection { diff --git a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol index f620d48ec..32e81dcb4 100644 --- a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol +++ b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/contracts/Greeter.sol @@ -10,7 +10,7 @@ contract Greeter { greeting = _greeting; } - function payGreet(address payable a) public payable returns (bool memory) { + function payGreet(address payable a) public payable returns (bool) { require(a != address(0), "Invalid address"); bool success = a.send(1); return success; diff --git a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts index 275c72b00..4ac14b32c 100644 --- a/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts +++ b/packages/hardhat-zksync-solc/test/fixture-projects/suppresed-warnings-errors/hardhat.config.ts @@ -1,13 +1,12 @@ import '../../../src/index'; import { HardhatUserConfig } from 'hardhat/config'; -import { SuppressedMessageType } from '../../../src/types'; const config: HardhatUserConfig = { zksolc: { compilerSource: 'binary', settings: { - suppressedErrors: [SuppressedMessageType.SendTransfer], - suppressedWarnings: [SuppressedMessageType.TxOrigin], + suppressedErrors: ['sendtransfer'], + suppressedWarnings: ['txorigin'], }, }, networks: { diff --git a/packages/hardhat-zksync-solc/test/tests/tests.ts b/packages/hardhat-zksync-solc/test/tests/tests.ts index eacd447c2..4ef8defbd 100644 --- a/packages/hardhat-zksync-solc/test/tests/tests.ts +++ b/packages/hardhat-zksync-solc/test/tests/tests.ts @@ -513,8 +513,16 @@ describe('zksolc plugin', async function () { compilationJob: jobs[0], }); - assert.deepEqual(compilerInput.suppressedWarnings, ['TxOrigin']); - assert.deepEqual(compilerInput.suppressedErrors, ['SendTransfer']); + assert.deepEqual(compilerInput.suppressedWarnings, ['txorigin']); + assert.deepEqual(compilerInput.suppressedErrors, ['sendtransfer']); + }); + + it('Should successfully compile a simple contract with suppresed warnings and errors', async function () { + await this.env.run(TASK_COMPILE); + + const artifact = this.env.artifacts.readArtifactSync('Greeter') as ZkSyncArtifact; + + assert.equal(artifact.contractName, 'Greeter'); }); }); From 84e52d58c3fd09c118b5c26ac0234e45d240d9c8 Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Wed, 25 Sep 2024 07:17:07 +0200 Subject: [PATCH 4/5] chore: update solc readme file --- packages/hardhat-zksync-solc/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/hardhat-zksync-solc/README.md b/packages/hardhat-zksync-solc/README.md index 107e26d53..7e7af51ab 100644 --- a/packages/hardhat-zksync-solc/README.md +++ b/packages/hardhat-zksync-solc/README.md @@ -36,6 +36,8 @@ zksolc: { mode: '3' // optional. 3 by default, z to optimize bytecode size fallback_to_optimizing_for_size: false, // optional. Try to recompile with optimizer mode "z" if the bytecode is too large }, + suppressedWarnings: ['txorigin', 'sendtransfer'], // Suppress specified warnings. Currently supported: txorigin, sendtransfer + suppressedErrors: ['txorigin', 'sendtransfer'], // Suppress specified errors. Currently supported: txorigin, sendtransfer experimental: { dockerImage: '', // deprecated tag: '' // deprecated @@ -59,6 +61,8 @@ Starting from zksolc version 1.5.0, the ZKsync Era Solidity compiler will be use | enableEraVMExtensions | Required if contracts use enables Yul instructions available only for ZKsync system contracts and libraries. In the older versions of the plugin known as 'isSystem' flag | | forceEVMLA | Compile with EVM legacy assembly codegen. If the zksolc version is below 1.5.0, this argument will act as a 'forceEvmla' flag in the older versions of the plugin, attempting to fallback to EVM legacy assembly if there is a bug with Yul. | | optimizer | Compiler optimizations (enabled: true (default) or false), mode: 3 (default), fallback_to_optimizing_for_size: false (default) recommended for most projects. | +| suppressedWarnings | Suppress specified warnings. Currently supported: txorigin, sendtransfer | +| suppressedErrors | Suppress specified errors. Currently supported: txorigin, sendtransfer | | metadata | Metadata settings. If the option is omitted, the metadata hash appends by default: bytecodeHash. Can only be none. | | dockerImage | (deprecated) option used to identify the name of the compiler docker image. | From 45a933a539e16ec0a8e8807f78ce66a402d2bcad Mon Sep 17 00:00:00 2001 From: Marko Arambasic Date: Wed, 25 Sep 2024 07:43:05 +0200 Subject: [PATCH 5/5] chore: ignore test --- packages/hardhat-zksync-solc/test/tests/tests.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/hardhat-zksync-solc/test/tests/tests.ts b/packages/hardhat-zksync-solc/test/tests/tests.ts index 4ef8defbd..cfb43b7cc 100644 --- a/packages/hardhat-zksync-solc/test/tests/tests.ts +++ b/packages/hardhat-zksync-solc/test/tests/tests.ts @@ -516,14 +516,6 @@ describe('zksolc plugin', async function () { assert.deepEqual(compilerInput.suppressedWarnings, ['txorigin']); assert.deepEqual(compilerInput.suppressedErrors, ['sendtransfer']); }); - - it('Should successfully compile a simple contract with suppresed warnings and errors', async function () { - await this.env.run(TASK_COMPILE); - - const artifact = this.env.artifacts.readArtifactSync('Greeter') as ZkSyncArtifact; - - assert.equal(artifact.contractName, 'Greeter'); - }); }); describe('Missing Library', async function () {