From 4d82d4f57acf11745bb2e1610c5777128f68bee4 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 8 Aug 2017 21:32:57 +0100 Subject: Store experimental flag in metadata CBOR --- libsolidity/interface/CompilerStack.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libsolidity/interface/CompilerStack.cpp') 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); -- cgit v1.2.3 From 2d1bab0de8d6e2637b3827fd3c988ae538b1d9ef Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 10 Aug 2017 17:16:55 +0100 Subject: Output experimental flag in metadata only for risky features --- libsolidity/interface/CompilerStack.cpp | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') 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 const& features) +{ + for (auto const feature: features) + if (!ExperimentalFeatureOnlyAnalysis.count(feature)) + return false; + return true; +} +} + void CompilerStack::compileContract( ContractDefinition const& _contract, map& _compiledContracts @@ -649,16 +660,23 @@ void CompilerStack::compileContract( shared_ptr compiler = make_shared(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); -- cgit v1.2.3 From 7222fac45680dd9955fd37c6245760014a19873a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 27 Jul 2017 11:28:04 +0100 Subject: Remove DocumentationType from natspec --- libsolidity/interface/CompilerStack.cpp | 53 +++++++++++++++++---------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 70bebfa5..07596b99 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -406,39 +406,42 @@ Json::Value const& CompilerStack::contractABI(Contract const& _contract) const return *_contract.abi; } -Json::Value const& CompilerStack::natspec(string const& _contractName, DocumentationType _type) const +Json::Value const& CompilerStack::natspecUser(string const& _contractName) const { - return natspec(contract(_contractName), _type); + return natspecUser(contract(_contractName)); } -Json::Value const& CompilerStack::natspec(Contract const& _contract, DocumentationType _type) const +Json::Value const& CompilerStack::natspecUser(Contract const& _contract) const { if (m_stackState < AnalysisSuccessful) BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); solAssert(_contract.contract, ""); - std::unique_ptr* doc; - // checks wheather we already have the documentation - switch (_type) - { - case DocumentationType::NatspecUser: - doc = &_contract.userDocumentation; - // caches the result - if (!*doc) - doc->reset(new Json::Value(Natspec::userDocumentation(*_contract.contract))); - break; - case DocumentationType::NatspecDev: - doc = &_contract.devDocumentation; - // caches the result - if (!*doc) - doc->reset(new Json::Value(Natspec::devDocumentation(*_contract.contract))); - break; - default: - solAssert(false, "Illegal documentation type."); - } + // caches the result + if (!_contract.userDocumentation) + _contract.userDocumentation.reset(new Json::Value(Natspec::userDocumentation(*_contract.contract))); + + return *_contract.userDocumentation; +} + +Json::Value const& CompilerStack::natspecDev(string const& _contractName) const +{ + return natspecDev(contract(_contractName)); +} + +Json::Value const& CompilerStack::natspecDev(Contract const& _contract) const +{ + if (m_stackState < AnalysisSuccessful) + BOOST_THROW_EXCEPTION(CompilerError() << errinfo_comment("Parsing was not successful.")); + + solAssert(_contract.contract, ""); + + // caches the result + if (!_contract.devDocumentation) + _contract.devDocumentation.reset(new Json::Value(Natspec::devDocumentation(*_contract.contract))); - return *(*doc); + return *_contract.devDocumentation; } Json::Value CompilerStack::methodIdentifiers(string const& _contractName) const @@ -819,8 +822,8 @@ string CompilerStack::createMetadata(Contract const& _contract) const meta["settings"]["libraries"][library.first] = "0x" + toHex(library.second.asBytes()); meta["output"]["abi"] = contractABI(_contract); - meta["output"]["userdoc"] = natspec(_contract, DocumentationType::NatspecUser); - meta["output"]["devdoc"] = natspec(_contract, DocumentationType::NatspecDev); + meta["output"]["userdoc"] = natspecUser(_contract); + meta["output"]["devdoc"] = natspecDev(_contract); return jsonCompactPrint(meta); } -- cgit v1.2.3 From b3986f1d079a98b0894c735111880eb23b177f19 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 21 Aug 2017 14:08:58 +0100 Subject: Remove some unused includes --- libsolidity/interface/CompilerStack.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 70bebfa5..19bfbe63 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -49,8 +49,6 @@ #include #include -#include - using namespace std; using namespace dev; -- cgit v1.2.3 From 1ece7bf4433a37feb449b7f3b4f820a1f5740eaf Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 6 Jul 2017 11:05:05 +0200 Subject: z3 conditions --- libsolidity/interface/CompilerStack.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 412d2fd3..4283cd99 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -236,6 +237,13 @@ bool CompilerStack::analyze() noErrors = false; } + if (noErrors) + { + SMTChecker smtChecker(m_errorReporter); + for (Source const* source: m_sourceOrder) + smtChecker.analyze(*source->ast); + } + if (noErrors) { m_stackState = AnalysisSuccessful; -- cgit v1.2.3 From b3f8ed457a10dab36abaef72310a755a95e0753f Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 11 Jul 2017 13:26:43 +0200 Subject: Cleanup. --- libsolidity/interface/CompilerStack.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 4283cd99..50e20b3d 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -239,7 +239,7 @@ bool CompilerStack::analyze() if (noErrors) { - SMTChecker smtChecker(m_errorReporter); + SMTChecker smtChecker(m_errorReporter, m_readFile); for (Source const* source: m_sourceOrder) smtChecker.analyze(*source->ast); } -- cgit v1.2.3 From 9ac2ac14c1819be2341c6947245bf63b02795528 Mon Sep 17 00:00:00 2001 From: chriseth Date: Thu, 13 Jul 2017 21:06:04 +0200 Subject: Rename read file callback. --- libsolidity/interface/CompilerStack.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libsolidity/interface/CompilerStack.cpp') diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 50e20b3d..363f45dd 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -239,7 +239,7 @@ bool CompilerStack::analyze() if (noErrors) { - SMTChecker smtChecker(m_errorReporter, m_readFile); + SMTChecker smtChecker(m_errorReporter, m_smtQuery); for (Source const* source: m_sourceOrder) smtChecker.analyze(*source->ast); } @@ -535,17 +535,17 @@ StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string if (m_sources.count(importPath) || newSources.count(importPath)) continue; - ReadFile::Result result{false, string("File not supplied initially.")}; + ReadCallback::Result result{false, string("File not supplied initially.")}; if (m_readFile) result = m_readFile(importPath); if (result.success) - newSources[importPath] = result.contentsOrErrorMessage; + newSources[importPath] = result.responseOrErrorMessage; else { m_errorReporter.parserError( import->location(), - string("Source \"" + importPath + "\" not found: " + result.contentsOrErrorMessage) + string("Source \"" + importPath + "\" not found: " + result.responseOrErrorMessage) ); continue; } -- cgit v1.2.3