aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-09 04:32:57 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-11 23:38:43 +0800
commit4d82d4f57acf11745bb2e1610c5777128f68bee4 (patch)
tree629573a49cc463ed2820f4c9ddee09a8cba5aa57
parent53a497b4d85c0748243c899f0a860518eb54bddc (diff)
downloaddexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar.gz
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar.bz2
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar.lz
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar.xz
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.tar.zst
dexon-solidity-4d82d4f57acf11745bb2e1610c5777128f68bee4.zip
Store experimental flag in metadata CBOR
-rw-r--r--Changelog.md2
-rw-r--r--libsolidity/interface/CompilerStack.cpp6
-rw-r--r--test/libsolidity/Metadata.cpp29
3 files changed, 37 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index 0381d434..3f3d2e98 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -2,6 +2,8 @@
Features:
* Parser: Display previous visibility specifier in error if multiple are found.
+ * Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
+ * Metadata: Store experimental flag in metadata CBOR.
Bugfixes:
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp
index 7c66a843..bc52ff7a 100644
--- a/libsolidity/interface/CompilerStack.cpp
+++ b/libsolidity/interface/CompilerStack.cpp
@@ -653,6 +653,12 @@ void CompilerStack::compileContract(
// CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)}
bytes{0xa1, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} +
dev::swarmHash(metadata).asBytes();
+ if (!_contract.sourceUnit().annotation().experimentalFeatures.empty())
+ cborEncodedMetadata =
+ // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true}
+ bytes{0xa2, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} +
+ dev::swarmHash(metadata).asBytes() +
+ bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
solAssert(cborEncodedMetadata.size() <= 0xffff, "Metadata too large");
// 16-bit big endian length
cborEncodedMetadata += toCompactBigEndian(cborEncodedMetadata.size(), 2);
diff --git a/test/libsolidity/Metadata.cpp b/test/libsolidity/Metadata.cpp
index 0d3caddd..77679a32 100644
--- a/test/libsolidity/Metadata.cpp
+++ b/test/libsolidity/Metadata.cpp
@@ -58,6 +58,35 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), bytecode.end() - metadataCBORSize - 2));
}
+BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
+{
+ // Check that the metadata stamp is at the end of the runtime bytecode.
+ char const* sourceCode = R"(
+ pragma solidity >=0.0;
+ pragma experimental __test;
+ contract test {
+ function g(function(uint) external returns (uint) x) {}
+ }
+ )";
+ CompilerStack compilerStack;
+ compilerStack.addSource("", std::string(sourceCode));
+ compilerStack.setOptimiserSettings(dev::test::Options::get().optimize);
+ ETH_TEST_REQUIRE_NO_THROW(compilerStack.compile(), "Compiling contract failed");
+ bytes const& bytecode = compilerStack.runtimeObject("test").bytecode;
+ std::string const& metadata = compilerStack.metadata("test");
+ BOOST_CHECK(dev::test::isValidMetadata(metadata));
+ bytes hash = dev::swarmHash(metadata).asBytes();
+ BOOST_REQUIRE(hash.size() == 32);
+ BOOST_REQUIRE(bytecode.size() >= 2);
+ size_t metadataCBORSize = (size_t(bytecode.end()[-2]) << 8) + size_t(bytecode.end()[-1]);
+ BOOST_REQUIRE(metadataCBORSize < bytecode.size() - 2);
+ bytes expectation =
+ bytes{0xa2, 0x65, 'b', 'z', 'z', 'r', '0', 0x58, 0x20} +
+ hash +
+ bytes{0x6c, 'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l', 0xf5};
+ BOOST_CHECK(std::equal(expectation.begin(), expectation.end(), bytecode.end() - metadataCBORSize - 2));
+}
+
BOOST_AUTO_TEST_CASE(metadata_relevant_sources)
{
CompilerStack compilerStack;