Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add suppressed errors and warnings #1375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/hardhat-zksync-solc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. |

Expand Down
20 changes: 19 additions & 1 deletion packages/hardhat-zksync-solc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion packages/hardhat-zksync-solc/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Artifact } from 'hardhat/types';
import { Artifact, CompilerInput } from 'hardhat/types';

export interface ZkSolcConfig {
version: string; // Currently ignored.
Expand Down Expand Up @@ -46,9 +46,20 @@ 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?: string[];
// Suppress specified errors. Currently supported: txorigin, sendtransfer
suppressedErrors?: string[];
};
}

export interface ZkSyncCompilerInput extends CompilerInput {
// Suppress specified warnings. Currently supported: txorigin, sendtransfer
suppressedWarnings?: string[];
// Suppress specified errors. Currently supported: txorigin, sendtransfer
suppressedErrors?: string[];
}

export interface CompilerOutputSelection {
[file: string]: { [contract: string]: string[] };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
require(a != address(0), "Invalid address");
bool success = a.send(1);
return success;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '../../../src/index';
import { HardhatUserConfig } from 'hardhat/config';

const config: HardhatUserConfig = {
zksolc: {
compilerSource: 'binary',
settings: {
suppressedErrors: ['sendtransfer'],
suppressedWarnings: ['txorigin'],
},
},
networks: {
hardhat: {
zksync: true,
},
},
solidity: {
version: process.env.SOLC_VERSION || '0.8.17',
},
};

export default config;
34 changes: 34 additions & 0 deletions packages/hardhat-zksync-solc/test/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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');

Expand Down
Loading