diff options
author | Gav Wood <g@ethdev.com> | 2014-11-14 19:06:25 +0800 |
---|---|---|
committer | Gav Wood <g@ethdev.com> | 2014-11-14 19:06:25 +0800 |
commit | e4228083ed374e76fbbdfa969148b9e90a2c4c29 (patch) | |
tree | e9e15f09a5fa4d985e1c3cca23e41d1eee17dd2f | |
parent | e4f4eaf7c86481f4ee5f30f24cd1a26c239a4915 (diff) | |
parent | 9d8fe1a091a024eccac861b49bf3f321df11e068 (diff) | |
download | dexon-solidity-e4228083ed374e76fbbdfa969148b9e90a2c4c29.tar.gz dexon-solidity-e4228083ed374e76fbbdfa969148b9e90a2c4c29.tar.zst dexon-solidity-e4228083ed374e76fbbdfa969148b9e90a2c4c29.zip |
Merge pull request #500 from chriseth/sol_jumptable
Replace function selector jump table by more resilient linear time check.
-rw-r--r-- | solidityCompiler.cpp | 14 | ||||
-rw-r--r-- | solidityEndToEndTest.cpp | 16 |
2 files changed, 23 insertions, 7 deletions
diff --git a/solidityCompiler.cpp b/solidityCompiler.cpp index ba2db67e..054ad329 100644 --- a/solidityCompiler.cpp +++ b/solidityCompiler.cpp @@ -80,7 +80,7 @@ BOOST_AUTO_TEST_CASE(smoke_test) "}\n"; bytes code = compileContract(sourceCode); - unsigned boilerplateSize = 51; + unsigned boilerplateSize = 42; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, // initialize local variable x byte(Instruction::PUSH1), 0x2, @@ -100,8 +100,8 @@ BOOST_AUTO_TEST_CASE(different_argument_numbers) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 75; - unsigned boilerplateSize = 88; + unsigned shift = 70; + unsigned boilerplateSize = 83; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, // initialize return variable d byte(Instruction::DUP3), @@ -153,8 +153,8 @@ BOOST_AUTO_TEST_CASE(ifStatement) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 38; - unsigned boilerplateSize = 51; + unsigned shift = 29; + unsigned boilerplateSize = 42; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x0, byte(Instruction::DUP1), @@ -195,8 +195,8 @@ BOOST_AUTO_TEST_CASE(loops) "}\n"; bytes code = compileContract(sourceCode); - unsigned shift = 38; - unsigned boilerplateSize = 51; + unsigned shift = 29; + unsigned boilerplateSize = 42; bytes expectation({byte(Instruction::JUMPDEST), byte(Instruction::JUMPDEST), byte(Instruction::PUSH1), 0x1, diff --git a/solidityEndToEndTest.cpp b/solidityEndToEndTest.cpp index 796adcb1..788c388e 100644 --- a/solidityEndToEndTest.cpp +++ b/solidityEndToEndTest.cpp @@ -148,6 +148,22 @@ BOOST_AUTO_TEST_CASE(recursive_calls) BOOST_CHECK(testSolidityAgainstCpp(0, recursive_calls_cpp, u256(4))); } +BOOST_AUTO_TEST_CASE(multiple_functions) +{ + char const* sourceCode = "contract test {\n" + " function a() returns(uint n) { return 0; }\n" + " function b() returns(uint n) { return 1; }\n" + " function c() returns(uint n) { return 2; }\n" + " function f() returns(uint n) { return 3; }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callFunction(0, bytes()) == toBigEndian(u256(0))); + BOOST_CHECK(callFunction(1, bytes()) == toBigEndian(u256(1))); + BOOST_CHECK(callFunction(2, bytes()) == toBigEndian(u256(2))); + BOOST_CHECK(callFunction(3, bytes()) == toBigEndian(u256(3))); + BOOST_CHECK(callFunction(4, bytes()) == bytes()); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = "contract test {\n" |