aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-04-06 22:32:20 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-04-27 23:37:02 +0800
commit99dd28d63ec05e001f05d1e788541bf6cf16f881 (patch)
tree642674741386fde092f73533fdfd3e4f1254ca8e
parent2c8b77006255b15743efd0b54964227bccc07c57 (diff)
downloaddexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.gz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.bz2
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.lz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.xz
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.tar.zst
dexon-solidity-99dd28d63ec05e001f05d1e788541bf6cf16f881.zip
Add constant optimizer testing to the fuzz tester.
-rw-r--r--libevmasm/ConstantOptimiser.cpp1
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/fuzzer.cpp87
3 files changed, 87 insertions, 3 deletions
diff --git a/libevmasm/ConstantOptimiser.cpp b/libevmasm/ConstantOptimiser.cpp
index d2ed4faf..a4aa72ba 100644
--- a/libevmasm/ConstantOptimiser.cpp
+++ b/libevmasm/ConstantOptimiser.cpp
@@ -182,6 +182,7 @@ AssemblyItems const& CodeCopyMethod::copyRoutine() const
AssemblyItems ComputeMethod::findRepresentation(u256 const& _value)
{
+ cout << "Looking for " << _value << endl;
if (_value < 0x10000)
// Very small value, not worth computing
return AssemblyItems{_value};
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 4d56ec9d..01a9a188 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -21,4 +21,4 @@ include_directories(BEFORE ..)
target_link_libraries(${EXECUTABLE} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES})
add_executable(solfuzzer fuzzer.cpp)
-target_link_libraries(solfuzzer soljson)
+target_link_libraries(solfuzzer soljson ${Boost_PROGRAM_OPTIONS_LIBRARIES})
diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp
index 410313c5..59090271 100644
--- a/test/fuzzer.cpp
+++ b/test/fuzzer.cpp
@@ -16,15 +16,22 @@
*/
/**
* Executable for use with AFL <http://lcamtuf.coredump.cx/afl>.
- * Reads a single source from stdin and signals a failure for internal errors.
*/
+#include <libevmasm/Assembly.h>
+#include <libevmasm/ConstantOptimiser.h>
+
#include <json/json.h>
+#include <boost/program_options.hpp>
+
#include <string>
#include <iostream>
using namespace std;
+using namespace dev;
+using namespace dev::eth;
+namespace po = boost::program_options;
extern "C"
{
@@ -39,8 +46,41 @@ string contains(string const& _haystack, vector<string> const& _needles)
return "";
}
-int main()
+void testConstantOptimizer()
+{
+ cout << "Testing constant optimizer" << endl;
+ vector<u256> numbers;
+ while (!cin.eof())
+ {
+ h256 data;
+ cin.read(reinterpret_cast<char*>(data.data()), 32);
+ numbers.push_back(u256(data));
+ }
+ cout << "Got " << numbers.size() << " inputs:" << endl;
+
+ Assembly assembly;
+ for (u256 const& n: numbers)
+ {
+ cout << n << endl;
+ assembly.append(n);
+ }
+ for (bool isCreation: {false, true})
+ {
+ for (unsigned runs: {1, 2, 3, 20, 40, 100, 200, 400, 1000})
+ {
+ ConstantOptimisationMethod::optimiseConstants(
+ isCreation,
+ runs,
+ assembly,
+ const_cast<AssemblyItems&>(assembly.items())
+ );
+ }
+ }
+}
+
+void testCompiler()
{
+ cout << "Testing compiler." << endl;
string input;
while (!cin.eof())
{
@@ -87,5 +127,48 @@ int main()
cout << "Output JSON has neither \"errors\" nor \"contracts\"." << endl;
abort();
}
+}
+
+int main(int argc, char** argv)
+{
+ po::options_description options(
+ R"(solfuzzer, fuzz-testing binary for use with AFL.
+Usage: solfuzzer [Options] < input
+Reads a single source from stdin, compiles it and signals a failure for internal errors.
+
+Allowed options)",
+ po::options_description::m_default_line_length,
+ po::options_description::m_default_line_length - 23);
+ options.add_options()
+ (
+ "help",
+ "Show this help screen."
+ )
+ (
+ "const-opt",
+ "Only run the constant optimizer. "
+ "Expects a binary string of up to 32 bytes on stdin."
+ );
+
+ po::variables_map arguments;
+ try
+ {
+ po::command_line_parser cmdLineParser(argc, argv);
+ cmdLineParser.options(options);
+ po::store(cmdLineParser.run(), arguments);
+ }
+ catch (po::error const& _exception)
+ {
+ cerr << _exception.what() << endl;
+ return false;
+ }
+
+ if (arguments.count("help"))
+ cout << options;
+ else if (arguments.count("const-opt"))
+ testConstantOptimizer();
+ else
+ testCompiler();
+
return 0;
}