From d7f4e02dbda3a6b22ac1d0a1381b86c3b5f38f09 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 6 Nov 2014 22:39:02 +0100 Subject: [PATCH 1/5] Evaluate expressions in convenient order. --- solidityExpressionCompiler.cpp | 75 ++++++++++++++++------------------ 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/solidityExpressionCompiler.cpp b/solidityExpressionCompiler.cpp index 8fc4a1a22..59a9e9336 100644 --- a/solidityExpressionCompiler.cpp +++ b/solidityExpressionCompiler.cpp @@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(comparison) "}\n"; bytes code = compileFirstExpression(sourceCode); - bytes expectation({byte(eth::Instruction::PUSH2), 0x10, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND), + bytes expectation({byte(eth::Instruction::PUSH1), 0x1, byte(eth::Instruction::PUSH2), 0x11, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND), - byte(eth::Instruction::GT), - byte(eth::Instruction::PUSH1), 0x1, + byte(eth::Instruction::PUSH2), 0x10, 0xaa, byte(eth::Instruction::PUSH2), 0xff, 0xff, byte(eth::Instruction::AND), + byte(eth::Instruction::LT), byte(eth::Instruction::EQ), byte(eth::Instruction::ISZERO)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_CASE(comparison) BOOST_AUTO_TEST_CASE(short_circuiting) { char const* sourceCode = "contract test {\n" - " function f() { var x = (10 + 8 >= 4 || 2 != 9) != true; }" + " function f() { var x = true != (4 <= 8 + 10 || 9 != 2); }" "}\n"; bytes code = compileFirstExpression(sourceCode); @@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE(short_circuiting) BOOST_AUTO_TEST_CASE(arithmetics) { char const* sourceCode = "contract test {\n" - " function f() { var x = (1 * (2 / (3 % (4 + (5 - (6 | (7 & (8 ^ 9)))))))); }" + " function f() { var x = ((((((((9 ^ 8) & 7) | 6) - 5) + 4) % 3) / 2) * 1); }" "}\n"; bytes code = compileFirstExpression(sourceCode); bytes expectation({byte(eth::Instruction::PUSH1), 0x1, @@ -211,14 +211,11 @@ BOOST_AUTO_TEST_CASE(arithmetics) byte(eth::Instruction::XOR), byte(eth::Instruction::AND), byte(eth::Instruction::OR), - byte(eth::Instruction::SWAP1), byte(eth::Instruction::SUB), byte(eth::Instruction::ADD), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), - byte(eth::Instruction::SWAP1), byte(eth::Instruction::MOD), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), - byte(eth::Instruction::SWAP1), byte(eth::Instruction::DIV), byte(eth::Instruction::MUL)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); @@ -231,11 +228,11 @@ BOOST_AUTO_TEST_CASE(unary_operators) "}\n"; bytes code = compileFirstExpression(sourceCode); - bytes expectation({byte(eth::Instruction::PUSH1), 0x1, + bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), + byte(eth::Instruction::PUSH1), 0x1, byte(eth::Instruction::PUSH1), 0x0, byte(eth::Instruction::SUB), byte(eth::Instruction::NOT), byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), - byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), byte(eth::Instruction::EQ), byte(eth::Instruction::ISZERO)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); @@ -244,7 +241,7 @@ BOOST_AUTO_TEST_CASE(unary_operators) BOOST_AUTO_TEST_CASE(unary_inc_dec) { char const* sourceCode = "contract test {\n" - " function f(uint a) { var x = ((a++ ^ ++a) ^ a--) ^ --a; }" + " function f(uint a) { var x = --a ^ (a-- ^ (++a ^ a++)); }" "}\n"; bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "x"}}); @@ -299,16 +296,15 @@ BOOST_AUTO_TEST_CASE(assignment) bytes code = compileFirstExpression(sourceCode, {}, {{"test", "f", "a"}, {"test", "f", "b"}}); // Stack: a, b - bytes expectation({byte(eth::Instruction::DUP1), - byte(eth::Instruction::DUP3), - byte(eth::Instruction::SWAP1), - byte(eth::Instruction::ADD), - // Stack here: a b a+b - byte(eth::Instruction::SWAP2), - byte(eth::Instruction::POP), + bytes expectation({byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), byte(eth::Instruction::DUP2), - // Stack here: a+b b a+b - byte(eth::Instruction::PUSH1), 0x2, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), + byte(eth::Instruction::DUP4), + byte(eth::Instruction::ADD), + // Stack here: a b 2 a+b + byte(eth::Instruction::SWAP3), + byte(eth::Instruction::POP), + byte(eth::Instruction::DUP3), + // Stack here: a+b b 2 a+b byte(eth::Instruction::MUL)}); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } @@ -323,21 +319,20 @@ BOOST_AUTO_TEST_CASE(function_call) {{"test", "f", "a"}, {"test", "f", "b"}}); // Stack: a, b - bytes expectation({byte(eth::Instruction::PUSH1), 0x0d, - byte(eth::Instruction::DUP3), + bytes expectation({byte(eth::Instruction::PUSH1), 0x02, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), + byte(eth::Instruction::PUSH1), 0x12, byte(eth::Instruction::PUSH1), 0x01, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), + byte(eth::Instruction::DUP5), byte(eth::Instruction::ADD), - // Stack here: a b (a+1) - byte(eth::Instruction::DUP3), - byte(eth::Instruction::PUSH1), 0x1a, + // Stack here: a b 2 (a+1) + byte(eth::Instruction::DUP4), + byte(eth::Instruction::PUSH1), 0x19, byte(eth::Instruction::JUMP), byte(eth::Instruction::JUMPDEST), - // Stack here: a b g(a+1, b) - byte(eth::Instruction::PUSH1), 0x02, byte(eth::Instruction::PUSH1), 0xff, byte(eth::Instruction::AND), + // Stack here: a b 2 g(a+1, b) byte(eth::Instruction::MUL), // Stack here: a b g(a+1, b)*2 byte(eth::Instruction::DUP3), - byte(eth::Instruction::SWAP1), byte(eth::Instruction::ADD), // Stack here: a b a+g(a+1, b)*2 byte(eth::Instruction::SWAP2), @@ -355,15 +350,15 @@ BOOST_AUTO_TEST_CASE(negative_literals_8bits) "}\n"; bytes code = compileFirstExpression(sourceCode); - bytes expectation(bytes({byte(eth::Instruction::PUSH1), 0x00, - byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + - bytes({byte(eth::Instruction::ADD), - byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + - bytes({byte(eth::Instruction::ADD), - byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x81) + - bytes({byte(eth::Instruction::ADD), - byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80) + - bytes({byte(eth::Instruction::ADD)})); + bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x80) + + bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x81) + + bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + + bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + + bytes({byte(eth::Instruction::PUSH1), 0x00, + byte(eth::Instruction::ADD), + byte(eth::Instruction::ADD), + byte(eth::Instruction::ADD), + byte(eth::Instruction::ADD)})); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); } @@ -376,11 +371,11 @@ BOOST_AUTO_TEST_CASE(negative_literals_16bits) "}\n"; bytes code = compileFirstExpression(sourceCode); - bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + + bytes expectation(bytes({byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x7f) + + bytes({byte(eth::Instruction::PUSH32)}) + bytes(32, 0xff) + bytes({byte(eth::Instruction::PUSH1), 0x00, byte(eth::Instruction::SIGNEXTEND), - byte(eth::Instruction::PUSH32)}) + bytes(31, 0xff) + bytes(1, 0x7f) + - bytes({byte(eth::Instruction::ADD), + byte(eth::Instruction::ADD), byte(eth::Instruction::PUSH1), 0x01, byte(eth::Instruction::SIGNEXTEND)})); BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end()); From 5a0f9a35c107da5ae1c24c98eb20e557bae4a3e7 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Fri, 7 Nov 2014 13:22:45 +0100 Subject: [PATCH 2/5] small fix in solidityCompiler --- solidityCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index 192fd61a4..ba2db67e6 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) byte(Instruction::JUMPDEST), // beginning of g byte(Instruction::PUSH1), 0x0, byte(Instruction::DUP1), // initialized e and h - byte(Instruction::PUSH1), 0x29 + shift, // ret address + byte(Instruction::PUSH1), byte(0x29 + shift), // ret address byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), From dbcce8b7b95a513e0f8b8b3a6433771af3a7bd9e Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 14:10:00 +0100 Subject: [PATCH 3/5] Clean up state tests --- TestHelper.h | 1 - state.cpp | 14 -------------- tmpFiller.json | 44 -------------------------------------------- 3 files changed, 59 deletions(-) delete mode 100644 tmpFiller.json diff --git a/TestHelper.h b/TestHelper.h index 622b83ac4..a4eb64d84 100644 --- a/TestHelper.h +++ b/TestHelper.h @@ -57,7 +57,6 @@ public: eth::State m_statePost; eth::ExtVMFace m_environment; eth::Transaction m_transaction; - bytes code; private: json_spirit::mObject& m_TestObject; diff --git a/state.cpp b/state.cpp index 4034b4b73..935869058 100644 --- a/state.cpp +++ b/state.cpp @@ -55,12 +55,6 @@ void doStateTests(json_spirit::mValue& v, bool _fillin) ImportTest importer(o, _fillin); - if (_fillin) - { - importer.code = importer.m_statePre.code(importer.m_environment.myAddress); - importer.m_environment.code = importer.code; - } - State theState = importer.m_statePre; bytes tx = importer.m_transaction.rlp(); bytes output; @@ -124,12 +118,4 @@ BOOST_AUTO_TEST_CASE(stSystemOperationsTest) dev::test::executeTests("stSystemOperationsTest", "/StateTests", dev::test::doStateTests); } -BOOST_AUTO_TEST_CASE(tmp) -{ - int currentVerbosity = g_logVerbosity; - g_logVerbosity = 12; - dev::test::executeTests("tmp", "/StateTests", dev::test::doStateTests); - g_logVerbosity = currentVerbosity; -} - BOOST_AUTO_TEST_SUITE_END() diff --git a/tmpFiller.json b/tmpFiller.json deleted file mode 100644 index bd27b8907..000000000 --- a/tmpFiller.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "ABAcalls0": { - "env" : { - "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", - "currentNumber" : "0", - "currentGasLimit" : "10000000", - "currentDifficulty" : "256", - "currentTimestamp" : 1, - "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba" - }, - "pre" : { - "095e7baea6a6c7c4c2dfeb977efac326af552d87" : { - "balance" : "1000000000000000000", - "nonce" : 0, - "code" : "{ [[ (PC) ]] (CALL 1000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 24 0 0 0 0) }", - "storage": {} - }, - "945304eb96065b2a98b57a48a06ae28d285a71b5" : { - "balance" : "23", - "code" : " { [[ (PC) ]] (ADD 1 (CALL 500 0x095e7baea6a6c7c4c2dfeb977efac326af552d87 23 0 0 0 0)) } ", - "nonce" : "0", - "storage" : { - } - }, - "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : { - "balance" : "1000000000000000000", - "nonce" : 0, - "code" : "", - "storage": {} - } - - }, - "transaction" : { - "nonce" : "0", - "gasPrice" : "1", - "gasLimit" : "10000", - "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", - "value" : "100000", - "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", - "data" : "" - } - } - -} From 8be49ae2882f836853c824b1f3ff81cdde3cbe56 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 7 Nov 2014 13:50:51 +0000 Subject: [PATCH 4/5] Fixes for warnings. Take note. --- solidityCompiler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index 192fd61a4..ba2db67e6 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) byte(Instruction::JUMPDEST), // beginning of g byte(Instruction::PUSH1), 0x0, byte(Instruction::DUP1), // initialized e and h - byte(Instruction::PUSH1), 0x29 + shift, // ret address + byte(Instruction::PUSH1), byte(0x29 + shift), // ret address byte(Instruction::PUSH1), 0x1, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x2, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), byte(Instruction::PUSH1), 0x3, byte(Instruction::PUSH1), 0xff, byte(Instruction::AND), From a6ba0f7908627b65d3b115e342746819a2186d10 Mon Sep 17 00:00:00 2001 From: Christoph Jentzsch Date: Fri, 7 Nov 2014 15:16:42 +0100 Subject: [PATCH 5/5] style --- createRandomTest.cpp | 2 +- vm.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/createRandomTest.cpp b/createRandomTest.cpp index a9a993776..f74be9304 100644 --- a/createRandomTest.cpp +++ b/createRandomTest.cpp @@ -134,7 +134,7 @@ void doMyTests(json_spirit::mValue& v) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code.size()) + if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode; diff --git a/vm.cpp b/vm.cpp index a093966d4..93cf121de 100644 --- a/vm.cpp +++ b/vm.cpp @@ -289,7 +289,7 @@ void doVMTests(json_spirit::mValue& v, bool _fillin) o["pre"] = mValue(fev.exportState()); fev.importExec(o["exec"].get_obj()); - if (!fev.code.size()) + if (fev.code.empty()) { fev.thisTxCode = get<3>(fev.addresses.at(fev.myAddress)); fev.code = fev.thisTxCode;