Added tests for --no-append-metadata

- Command line tests
- Documented the standard json
- Changelog
- A Change in SolidityExecutionFramework to prevent flaky gas tests
- A boost test for --no-append-metadata
- Removed an outdated comment
This commit is contained in:
hrkrshnn 2022-07-25 00:22:56 +02:00
parent f96e802e74
commit d32661c0af
19 changed files with 119 additions and 5 deletions

View File

@ -4,6 +4,8 @@ Language Features:
Compiler Features:
* Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode.
* Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode.
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string.

View File

@ -220,6 +220,10 @@ Whereas release builds of solc use a 3 byte encoding of the version as shown
above (one byte each for major, minor and patch version number), prerelease builds
will instead use a complete version string including commit hash and build date.
The commandline flag ``--no-cbor-metadata`` can be used to skip metadata
from getting appended at the end of the deployed bytecode. Equivalently, the
boolean field ``settings.metadata.appendCBOR`` in Standard JSON input can be set to false.
.. note::
The CBOR mapping can also contain other keys, so it is better to fully
decode the data instead of relying on it starting with ``0xa264``.

View File

@ -323,6 +323,9 @@ Input Description
},
// Metadata settings (optional)
"metadata": {
// The CBOR metadata is appended at the end of the bytecode by default.
// Setting this to false omits the metadata from the runtime and deploy time code.
"appendCBOR": true,
// Use only literal content and not URLs (false by default)
"useLiteralContent": true,
// Use the given hash method for the metadata hash that is appended to the bytecode.

View File

@ -345,8 +345,6 @@ public:
Json::Value gasEstimates(std::string const& _contractName) const;
/// Changes the format of the metadata appended at the end of the bytecode.
/// This is mostly a workaround to avoid bytecode and gas differences between compiler builds
/// caused by differences in metadata. Should only be used for testing.
void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; }
static MetadataFormat defaultMetadataFormat()

View File

@ -0,0 +1 @@
--pretty-json --json-indent 4

View File

@ -0,0 +1,28 @@
{
"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
},
"outputSelection":
{
"A":
{
"test": ["evm.bytecode"]
}
}
}
}

View File

@ -0,0 +1,30 @@
{
"contracts":
{
"A":
{
"test":
{
"evm":
{
"bytecode":
{
"functionDebugData": {},
"generatedSources": [],
"linkReferences": {},
"object": "608080604052346013576004908160198239f35b600080fdfe600080fd",
"opcodes": "PUSH1 0x80 DUP1 PUSH1 0x40 MSTORE CALLVALUE PUSH1 0x13 JUMPI PUSH1 0x4 SWAP1 DUP2 PUSH1 0x19 DUP3 CODECOPY RETURN JUMPDEST PUSH1 0x0 DUP1 REVERT INVALID PUSH1 0x0 DUP1 REVERT ",
"sourceMap": "60:16:0:-:0;;;;;;;;;;;;;;;;;"
}
}
}
}
},
"sources":
{
"A":
{
"id": 0
}
}
}

View File

@ -0,0 +1 @@
--no-cbor-metadata --metadata-hash ipfs

View File

@ -0,0 +1 @@
Cannot specify a metadata hashing method when --no-cbor-metadata is set.

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.0.0;
contract Empty {}
contract C {
function f() external returns (bytes memory, bytes memory){
return (type(Empty).creationCode, type(Empty).runtimeCode);
}
}

View File

@ -0,0 +1 @@
--no-cbor-metadata --bin --via-ir --optimize

View File

@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >= 0.0.0;
// NOTE: The expected output would be the binary with no metadata.
// The commandline tests would replace bytecode with metadata in it with
// <BYTECODE REMOVED>
// Therefore, not having that means success!
contract C {
}

View File

@ -0,0 +1,4 @@
======= no_append_metadata/input.sol:C =======
Binary:
608080604052346013576004908160198239f35b600080fdfe600080fd

View File

@ -92,6 +92,7 @@ BOOST_AUTO_TEST_CASE(string_storage)
}
)";
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
m_appendCBORMetadata = false;
compileAndRun(sourceCode);
auto evmVersion = solidity::test::CommonOptions::get().evmVersion();

View File

@ -53,7 +53,7 @@ SemanticTest::SemanticTest(
bool _enforceGasCost,
u256 _enforceGasCostMinValue
):
SolidityExecutionFramework(_evmVersion, _vmPaths),
SolidityExecutionFramework(_evmVersion, _vmPaths, false),
EVMVersionRestrictedTestCase(_filename),
m_sources(m_reader.sources()),
m_lineOffset(m_reader.lineNumber()),

View File

@ -62,6 +62,9 @@ bytes SolidityExecutionFramework::multiSourceCompileContract(
m_compiler.enableEvmBytecodeGeneration(!m_compileViaYul);
m_compiler.enableIRGeneration(m_compileViaYul);
m_compiler.setRevertStringBehaviour(m_revertStrings);
if (!m_appendCBORMetadata) {
m_compiler.setMetadataFormat(CompilerStack::MetadataFormat::NoMetadata);
}
m_compiler.setMetadataHash(m_metadataHash);
if (!m_compiler.compile())
{

View File

@ -40,8 +40,14 @@ class SolidityExecutionFramework: public solidity::test::ExecutionFramework
public:
SolidityExecutionFramework(): m_showMetadata(solidity::test::CommonOptions::get().showMetadata) {}
explicit SolidityExecutionFramework(langutil::EVMVersion _evmVersion, std::vector<boost::filesystem::path> const& _vmPaths):
ExecutionFramework(_evmVersion, _vmPaths), m_showMetadata(solidity::test::CommonOptions::get().showMetadata)
explicit SolidityExecutionFramework(
langutil::EVMVersion _evmVersion,
std::vector<boost::filesystem::path> const& _vmPaths,
bool _appendCBORMetadata = true
):
ExecutionFramework(_evmVersion, _vmPaths),
m_showMetadata(solidity::test::CommonOptions::get().showMetadata),
m_appendCBORMetadata(_appendCBORMetadata)
{}
bytes const& compileAndRunWithoutCheck(
@ -80,6 +86,7 @@ protected:
bool m_compileViaYul = false;
bool m_compileToEwasm = false;
bool m_showMetadata = false;
bool m_appendCBORMetadata = true;
CompilerStack::MetadataHash m_metadataHash = CompilerStack::MetadataHash::IPFS;
RevertStrings m_revertStrings = RevertStrings::Default;
};

View File

@ -224,6 +224,15 @@ BOOST_AUTO_TEST_CASE(cli_mode_options)
}
}
BOOST_AUTO_TEST_CASE(no_cbor_metadata)
{
vector<string> commandLine = {"solc", "--no-cbor-metadata", "contract.sol"};
CommandLineOptions parsedOptions = parseCommandLine(commandLine);
bool assert = parsedOptions.metadata.format == CompilerStack::MetadataFormat::NoMetadata;
BOOST_TEST(assert);
}
BOOST_AUTO_TEST_CASE(via_ir_options)
{
BOOST_TEST(!parseCommandLine({"solc", "contract.sol"}).output.viaIR);