From 38691f743ceb0a571afb0372e40d22d370f3a9a8 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 18 May 2015 19:28:31 +0200 Subject: [PATCH 01/16] add list of second errorannotation instead of single item. From 148fd2638b7c90db826999b1cc404ef199193fc8 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 18 May 2015 22:14:03 +0200 Subject: [PATCH 02/16] use TrieHash for transactions and receipts roots From a052b5305172dc0759856c6b74b63d898370a198 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 19 May 2015 10:39:33 +0200 Subject: [PATCH 03/16] orderedTrieRoot testing From aefd0e9ca5971b1cd307602cc85db3788dcf648d Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Tue, 19 May 2015 16:46:00 +0200 Subject: [PATCH 04/16] handle output larger than 4069 bytes in test --- TestHelper.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/TestHelper.cpp b/TestHelper.cpp index aada83041..476d1ecf9 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -327,7 +327,8 @@ void ImportTest::checkExpectedState(State const& _stateExpect, State const& _sta void ImportTest::exportTest(bytes const& _output, State const& _statePost) { // export output - m_TestObject["out"] = toHex(_output, 2, HexPrefix::Add); + + m_TestObject["out"] = _output.size() > 4096 ? "#" + toString(_output.size()) : toHex(_output, 2, HexPrefix::Add); // export logs m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries()); @@ -489,7 +490,11 @@ LogEntries importLog(json_spirit::mArray& _a) void checkOutput(bytes const& _output, json_spirit::mObject& _o) { int j = 0; - if (_o["out"].type() == json_spirit::array_type) + + if (_o["out"].get_str().find("#") == 0) + BOOST_CHECK((u256)_output.size() == toInt(_o["out"].get_str().substr(1))); + + else if (_o["out"].type() == json_spirit::array_type) for (auto const& d: _o["out"].get_array()) { BOOST_CHECK_MESSAGE(_output[j] == toInt(d), "Output byte [" << j << "] different!"); From bae5779ab27a5d9d0eca7f567453116c16ae0d80 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 19 May 2015 19:38:17 +0200 Subject: [PATCH 05/16] SHA3, RIPEMD160 and SHA256 are now not cryptopp impls. --- libsolidity/SolidityEndToEndTest.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 6713382fa..aa51a674d 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include using namespace std; @@ -1501,9 +1501,7 @@ BOOST_AUTO_TEST_CASE(sha256) compileAndRun(sourceCode); auto f = [&](u256 const& _input) -> u256 { - h256 ret; - dev::sha256(dev::ref(toBigEndian(_input)), bytesRef(&ret[0], 32)); - return ret; + return dev::sha256(dev::ref(toBigEndian(_input))); }; testSolidityAgainstCpp("a(bytes32)", f, u256(4)); testSolidityAgainstCpp("a(bytes32)", f, u256(5)); @@ -1520,9 +1518,7 @@ BOOST_AUTO_TEST_CASE(ripemd) compileAndRun(sourceCode); auto f = [&](u256 const& _input) -> u256 { - h256 ret; - dev::ripemd160(dev::ref(toBigEndian(_input)), bytesRef(&ret[0], 32)); - return u256(ret); + return h256(dev::ripemd160(h256(_input).ref()), h256::AlignLeft); // This should be aligned right. i guess it's fixed elsewhere? }; testSolidityAgainstCpp("a(bytes32)", f, u256(4)); testSolidityAgainstCpp("a(bytes32)", f, u256(5)); From a5005aefff3df5ab10eb594428d9ea93b1a9c8c6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 19 May 2015 19:51:38 +0200 Subject: [PATCH 06/16] Move non-cryptopp dependent stuff into devcore. --- libsolidity/SolidityEndToEndTest.cpp | 2 +- libsolidity/SolidityNameAndTypeResolution.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index aa51a674d..90ce20d26 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include using namespace std; diff --git a/libsolidity/SolidityNameAndTypeResolution.cpp b/libsolidity/SolidityNameAndTypeResolution.cpp index 4ec7b8bda..c52bbf9de 100644 --- a/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/libsolidity/SolidityNameAndTypeResolution.cpp @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include #include From 2a23521564f48bbaed93838b95dfbae753bcd25c Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 19 May 2015 20:04:48 +0200 Subject: [PATCH 07/16] Move OverlayDB (leveldb dependent) back into libdevcrypto. From 79f11974eafee20365c65c02798200353951564a Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 20 May 2015 00:27:07 +0200 Subject: [PATCH 08/16] Gas estimation taking known state into account. --- GasMeter.cpp => libsolidity/GasMeter.cpp | 60 +++++++++++++++++++++++- libsolidity/solidityExecutionFramework.h | 11 +++-- 2 files changed, 66 insertions(+), 5 deletions(-) rename GasMeter.cpp => libsolidity/GasMeter.cpp (66%) diff --git a/GasMeter.cpp b/libsolidity/GasMeter.cpp similarity index 66% rename from GasMeter.cpp rename to libsolidity/GasMeter.cpp index 0ffe41712..43eb3f956 100644 --- a/GasMeter.cpp +++ b/libsolidity/GasMeter.cpp @@ -21,6 +21,8 @@ */ #include +#include +#include #include #include #include @@ -55,8 +57,21 @@ public: ); } + void testCreationTimeGas(string const& _sourceCode, string const& _contractName = "") + { + compileAndRun(_sourceCode); + auto state = make_shared(); + GasMeter meter(state); + GasMeter::GasConsumption gas; + for (AssemblyItem const& item: *m_compiler.getAssemblyItems(_contractName)) + gas += meter.estimateMax(item); + u256 bytecodeSize(m_compiler.getRuntimeBytecode(_contractName).size()); + gas += bytecodeSize * c_createDataGas; + BOOST_REQUIRE(!gas.isInfinite); + BOOST_CHECK(gas.value == m_gasUsed); + } + protected: - dev::solidity::CompilerStack m_compiler; map m_gasCosts; }; @@ -91,6 +106,49 @@ BOOST_AUTO_TEST_CASE(non_overlapping_filtered_costs) } } +BOOST_AUTO_TEST_CASE(simple_contract) +{ + // Tests a simple "deploy contract" code without constructor. The actual contract is not relevant. + char const* sourceCode = R"( + contract test { + bytes32 public shaValue; + function f(uint a) { + shaValue = sha3(a); + } + } + )"; + testCreationTimeGas(sourceCode); +} + +BOOST_AUTO_TEST_CASE(store_sha3) +{ + char const* sourceCode = R"( + contract test { + bytes32 public shaValue; + function test(uint a) { + shaValue = sha3(a); + } + } + )"; + testCreationTimeGas(sourceCode); +} + +BOOST_AUTO_TEST_CASE(updating_store) +{ + char const* sourceCode = R"( + contract test { + uint data; + uint data2; + function test() { + data = 1; + data = 2; + data2 = 0; + } + } + )"; + testCreationTimeGas(sourceCode); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h index f76465f23..fa25fb12c 100644 --- a/libsolidity/solidityExecutionFramework.h +++ b/libsolidity/solidityExecutionFramework.h @@ -44,11 +44,11 @@ public: bytes const& compileAndRun(std::string const& _sourceCode, u256 const& _value = 0, std::string const& _contractName = "") { - dev::solidity::CompilerStack compiler(m_addStandardSources); - compiler.addSource("", _sourceCode); - ETH_TEST_REQUIRE_NO_THROW(compiler.compile(m_optimize), "Compiling contract failed"); + m_compiler.reset(false, m_addStandardSources); + m_compiler.addSource("", _sourceCode); + ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed"); - bytes code = compiler.getBytecode(_contractName); + bytes code = m_compiler.getBytecode(_contractName); sendMessage(code, true, _value); BOOST_REQUIRE(!m_output.empty()); return m_output; @@ -160,12 +160,14 @@ protected: BOOST_REQUIRE(executive.go()); m_state.noteSending(m_sender); executive.finalize(); + m_gasUsed = executive.gasUsed(); m_output = executive.out().toVector(); m_logs = executive.logs(); } bool m_optimize = false; bool m_addStandardSources = false; + dev::solidity::CompilerStack m_compiler; Address m_sender; Address m_contractAddress; eth::State m_state; @@ -173,6 +175,7 @@ protected: u256 const m_gas = 100000000; bytes m_output; eth::LogEntries m_logs; + u256 m_gasUsed; }; } From b0d5cbf6983030c4e4fb48c45e1602880069b063 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 20 May 2015 09:31:38 +0200 Subject: [PATCH 09/16] Pregenerate DAG when mining on AZ/eth/ethminer. Use regeneratable key for decrets by default. From 8971baec8fcf70b1b5eba285e9bfdb05bddddc97 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Wed, 20 May 2015 13:20:34 +0200 Subject: [PATCH 10/16] remove eth_solidity dependency for statetests From d006006c576fc9b08cfc54aeb6ea17b6710b017c Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 17:57:41 +0200 Subject: [PATCH 11/16] added tests to check references to struct type. --- libsolidity/SolidityEndToEndTest.cpp | 87 ++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 90ce20d26..f9870a9ad 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4023,9 +4023,96 @@ BOOST_AUTO_TEST_CASE(overwriting_inheritance) BOOST_CHECK(callContractFunction("checkOk()") == encodeArgs(6)); } +BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + testStruct data1; + testStruct data2; + testStruct data3; + function test() + { + data1.m_value = 2; + } + function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) + { + testStruct x = data1; //x is a reference data1..m_value == 2 as well as x.m_value = 2 + data2 = data1; // should copy data. data2.m_value == 2 + + ret_local = x.m_value; // = 2 + ret_global = data2.m_value; // = 2 + + x.m_value = 3; + data3 = x; //should copy the data. data3.m_value == 3 + ret_global3 = data3.m_value; // = 3 + ret_global1 = data1.m_value; // =3 + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + BOOST_CHECK(callContractFunction("assign()") == encodeArgs(2, 2, 3, 3)); +} + +BOOST_AUTO_TEST_CASE(struct_delete_member) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + testStruct data1; + function test() + { + data1.m_value = 2; + } + function deleteMember() returns (uint ret_value) + { + testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 + x.m_value = 4; + delete x.m_value; + ret_value = x.m_value; + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + auto res = callContractFunction("deleteMember()"); + BOOST_CHECK(callContractFunction("deleteMember()") == encodeArgs(0)); +} + +BOOST_AUTO_TEST_CASE(struct_delete_struct_in_mapping) +{ + char const* sourceCode = R"( + contract test { + struct testStruct + { + uint m_value; + } + mapping (uint => testStruct) campaigns; + + function test() + { + campaigns[0].m_value = 2; + } + function deleteIt() returns (uint) + { + delete campaigns[0]; + return campaigns[0].m_value; + } + } + )"; + compileAndRun(sourceCode, 0, "test"); + auto res = callContractFunction("deleteIt()"); + BOOST_CHECK(callContractFunction("deleteIt()") == encodeArgs(0)); +} BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces + From 007c88216bf20967c685baadd00cd4a0bebf5941 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:05:51 +0200 Subject: [PATCH 12/16] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index f9870a9ad..c900fff4c 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4115,4 +4115,3 @@ BOOST_AUTO_TEST_SUITE_END() } } } // end namespaces - From a92591e5193b42200163b907b3ef4e36b08636ce Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:35:05 +0200 Subject: [PATCH 13/16] style fix --- libsolidity/SolidityEndToEndTest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index c900fff4c..6b7007a29 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4040,7 +4040,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) } function assign() returns (uint ret_local, uint ret_global, uint ret_global3, uint ret_global1) { - testStruct x = data1; //x is a reference data1..m_value == 2 as well as x.m_value = 2 + testStruct x = data1; //x is a reference data1.m_value == 2 as well as x.m_value = 2 data2 = data1; // should copy data. data2.m_value == 2 ret_local = x.m_value; // = 2 @@ -4049,7 +4049,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) x.m_value = 3; data3 = x; //should copy the data. data3.m_value == 3 ret_global3 = data3.m_value; // = 3 - ret_global1 = data1.m_value; // =3 + ret_global1 = data1.m_value; // = 3 } } )"; From 19262c12cf0ed9fe4377410e25706effe5d92716 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:38:52 +0200 Subject: [PATCH 14/16] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 6b7007a29..88a3613ad 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4049,7 +4049,7 @@ BOOST_AUTO_TEST_CASE(struct_assign_reference_to_struct) x.m_value = 3; data3 = x; //should copy the data. data3.m_value == 3 ret_global3 = data3.m_value; // = 3 - ret_global1 = data1.m_value; // = 3 + ret_global1 = data1.m_value; // = 3. Changed due to the assignment to x.m_value } } )"; From e38eefa9f6116fc5e993c78b305e70f7076dda62 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Wed, 20 May 2015 18:40:00 +0200 Subject: [PATCH 15/16] Update SolidityEndToEndTest.cpp --- libsolidity/SolidityEndToEndTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/SolidityEndToEndTest.cpp b/libsolidity/SolidityEndToEndTest.cpp index 88a3613ad..503615a5a 100644 --- a/libsolidity/SolidityEndToEndTest.cpp +++ b/libsolidity/SolidityEndToEndTest.cpp @@ -4075,7 +4075,7 @@ BOOST_AUTO_TEST_CASE(struct_delete_member) testStruct x = data1; //should not copy the data. data1.m_value == 2 but x.m_value = 0 x.m_value = 4; delete x.m_value; - ret_value = x.m_value; + ret_value = data1.m_value; } } )"; From 4ee8b7a75745d6c496026555520413e2e7a049f8 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 25 May 2015 09:28:06 +0100 Subject: [PATCH 16/16] Add secret store test. Remove unneccessary components of scrypt.