From 6854e2b5d68fc19ac9310075d465f7876f0e5597 Mon Sep 17 00:00:00 2001 From: hrkrshnn Date: Thu, 13 Oct 2022 02:04:48 +0200 Subject: [PATCH] fix: `bytecodeHash` cannot be set to non-none for `appendCBOR=false` Testing: see `test/cmdlineTests/metadata_append_standard_json_error` Closes: https://github.com/ethereum/solidity/issues/13628 --- libsolidity/interface/StandardCompiler.cpp | 7 +++++ .../metadata_append_standard_json_error/args | 1 + .../input.json | 29 +++++++++++++++++++ .../output.json | 12 ++++++++ 4 files changed, 49 insertions(+) create mode 100644 test/cmdlineTests/metadata_append_standard_json_error/args create mode 100644 test/cmdlineTests/metadata_append_standard_json_error/input.json create mode 100644 test/cmdlineTests/metadata_append_standard_json_error/output.json diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 15e713d5b..676f02d62 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -929,6 +929,13 @@ std::variant StandardCompiler: metadataHash == "bzzr1" ? CompilerStack::MetadataHash::Bzzr1 : CompilerStack::MetadataHash::None; + if (ret.metadataFormat == CompilerStack::MetadataFormat::NoMetadata && ret.metadataHash != CompilerStack::MetadataHash::None) + return formatFatalError( + Error::Type::JSONError, + "When the parameter \"appendCBOR\" is set to false, the parameter \"bytecodeHash\" cannot be set to \"" + + metadataHash + + "\". The parameter \"bytecodeHash\" should either be skipped, or set to \"none\"." + ); } Json::Value outputSelection = settings.get("outputSelection", Json::Value()); diff --git a/test/cmdlineTests/metadata_append_standard_json_error/args b/test/cmdlineTests/metadata_append_standard_json_error/args new file mode 100644 index 000000000..a905f1fe6 --- /dev/null +++ b/test/cmdlineTests/metadata_append_standard_json_error/args @@ -0,0 +1 @@ +--pretty-json --json-indent 4 diff --git a/test/cmdlineTests/metadata_append_standard_json_error/input.json b/test/cmdlineTests/metadata_append_standard_json_error/input.json new file mode 100644 index 000000000..f12e45bf2 --- /dev/null +++ b/test/cmdlineTests/metadata_append_standard_json_error/input.json @@ -0,0 +1,29 @@ +{ + "language": "Solidity", + "sources": + { + "A": + { + "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;\n\ncontract test {}" + } + }, + "settings": + { + "viaIR": true, + "optimizer": { + "enabled": true + }, + "metadata": + { + "appendCBOR": false, + "bytecodeHash": "ipfs" + }, + "outputSelection": + { + "A": + { + "test": ["evm.bytecode"] + } + } + } +} diff --git a/test/cmdlineTests/metadata_append_standard_json_error/output.json b/test/cmdlineTests/metadata_append_standard_json_error/output.json new file mode 100644 index 000000000..0c264f898 --- /dev/null +++ b/test/cmdlineTests/metadata_append_standard_json_error/output.json @@ -0,0 +1,12 @@ +{ + "errors": + [ + { + "component": "general", + "formattedMessage": "When the parameter \"appendCBOR\" is set to false, the parameter \"bytecodeHash\" cannot be set to \"ipfs\". The parameter \"bytecodeHash\" should either be skipped, or set to \"none\".", + "message": "When the parameter \"appendCBOR\" is set to false, the parameter \"bytecodeHash\" cannot be set to \"ipfs\". The parameter \"bytecodeHash\" should either be skipped, or set to \"none\".", + "severity": "error", + "type": "JSONError" + } + ] +}