Skip to content

Commit d32661c

Browse files
committed
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
1 parent f96e802 commit d32661c

File tree

19 files changed

+119
-5
lines changed

19 files changed

+119
-5
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Language Features:
44

55

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

911

docs/metadata.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ Whereas release builds of solc use a 3 byte encoding of the version as shown
220220
above (one byte each for major, minor and patch version number), prerelease builds
221221
will instead use a complete version string including commit hash and build date.
222222

223+
The commandline flag ``--no-cbor-metadata`` can be used to skip metadata
224+
from getting appended at the end of the deployed bytecode. Equivalently, the
225+
boolean field ``settings.metadata.appendCBOR`` in Standard JSON input can be set to false.
226+
223227
.. note::
224228
The CBOR mapping can also contain other keys, so it is better to fully
225229
decode the data instead of relying on it starting with ``0xa264``.

docs/using-the-compiler.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ Input Description
323323
},
324324
// Metadata settings (optional)
325325
"metadata": {
326+
// The CBOR metadata is appended at the end of the bytecode by default.
327+
// Setting this to false omits the metadata from the runtime and deploy time code.
328+
"appendCBOR": true,
326329
// Use only literal content and not URLs (false by default)
327330
"useLiteralContent": true,
328331
// Use the given hash method for the metadata hash that is appended to the bytecode.

libsolidity/interface/CompilerStack.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ class CompilerStack: public langutil::CharStreamProvider
345345
Json::Value gasEstimates(std::string const& _contractName) const;
346346

347347
/// Changes the format of the metadata appended at the end of the bytecode.
348-
/// This is mostly a workaround to avoid bytecode and gas differences between compiler builds
349-
/// caused by differences in metadata. Should only be used for testing.
350348
void setMetadataFormat(MetadataFormat _metadataFormat) { m_metadataFormat = _metadataFormat; }
351349

352350
static MetadataFormat defaultMetadataFormat()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--pretty-json --json-indent 4
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"language": "Solidity",
3+
"sources":
4+
{
5+
"A":
6+
{
7+
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;\n\ncontract test {}"
8+
}
9+
},
10+
"settings":
11+
{
12+
"viaIR": true,
13+
"optimizer": {
14+
"enabled": true
15+
},
16+
"metadata":
17+
{
18+
"appendCBOR": false
19+
},
20+
"outputSelection":
21+
{
22+
"A":
23+
{
24+
"test": ["evm.bytecode"]
25+
}
26+
}
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"contracts":
3+
{
4+
"A":
5+
{
6+
"test":
7+
{
8+
"evm":
9+
{
10+
"bytecode":
11+
{
12+
"functionDebugData": {},
13+
"generatedSources": [],
14+
"linkReferences": {},
15+
"object": "608080604052346013576004908160198239f35b600080fdfe600080fd",
16+
"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 ",
17+
"sourceMap": "60:16:0:-:0;;;;;;;;;;;;;;;;;"
18+
}
19+
}
20+
}
21+
}
22+
},
23+
"sources":
24+
{
25+
"A":
26+
{
27+
"id": 0
28+
}
29+
}
30+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--no-cbor-metadata --metadata-hash ipfs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cannot specify a metadata hashing method when --no-cbor-metadata is set.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)