diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-11 00:16:55 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-08-11 23:38:43 +0800 |
commit | 2d1bab0de8d6e2637b3827fd3c988ae538b1d9ef (patch) | |
tree | 73603b9de726057dac89486b6e72cf66e89c72e1 | |
parent | 4d82d4f57acf11745bb2e1610c5777128f68bee4 (diff) | |
download | dexon-solidity-2d1bab0de8d6e2637b3827fd3c988ae538b1d9ef.tar.gz dexon-solidity-2d1bab0de8d6e2637b3827fd3c988ae538b1d9ef.tar.zst dexon-solidity-2d1bab0de8d6e2637b3827fd3c988ae538b1d9ef.zip |
Output experimental flag in metadata only for risky features
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 36 | ||||
-rw-r--r-- | test/libsolidity/Metadata.cpp | 1 |
2 files changed, 28 insertions, 9 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index bc52ff7a..70bebfa5 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -632,6 +632,17 @@ string CompilerStack::absolutePath(string const& _path, string const& _reference return result.generic_string(); } +namespace +{ +bool onlySafeExperimentalFeaturesActivated(set<ExperimentalFeature> const& features) +{ + for (auto const feature: features) + if (!ExperimentalFeatureOnlyAnalysis.count(feature)) + return false; + return true; +} +} + void CompilerStack::compileContract( ContractDefinition const& _contract, map<ContractDefinition const*, eth::Assembly const*>& _compiledContracts @@ -649,16 +660,23 @@ void CompilerStack::compileContract( shared_ptr<Compiler> compiler = make_shared<Compiler>(m_optimize, m_optimizeRuns); Contract& compiledContract = m_contracts.at(_contract.fullyQualifiedName()); string metadata = createMetadata(compiledContract); - bytes cborEncodedMetadata = - // 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()) + bytes cborEncodedHash = + // CBOR-encoding of the key "bzzr0" + bytes{0x65, 'b', 'z', 'z', 'r', '0'}+ + // CBOR-encoding of the hash + bytes{0x58, 0x20} + dev::swarmHash(metadata).asBytes(); + bytes cborEncodedMetadata; + if (onlySafeExperimentalFeaturesActivated(_contract.sourceUnit().annotation().experimentalFeatures)) + cborEncodedMetadata = + // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata)} + bytes{0xa1} + + cborEncodedHash; + else 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}; + // CBOR-encoding of {"bzzr0": dev::swarmHash(metadata), "experimental": true} + bytes{0xa2} + + cborEncodedHash + + 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 77679a32..c46e3160 100644 --- a/test/libsolidity/Metadata.cpp +++ b/test/libsolidity/Metadata.cpp @@ -38,6 +38,7 @@ BOOST_AUTO_TEST_CASE(metadata_stamp) // Check that the metadata stamp is at the end of the runtime bytecode. char const* sourceCode = R"( pragma solidity >=0.0; + pragma experimental __testOnlyAnalysis; contract test { function g(function(uint) external returns (uint) x) {} } |