diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-04-27 23:26:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-27 23:26:08 +0800 |
commit | 2c8b77006255b15743efd0b54964227bccc07c57 (patch) | |
tree | 17cb0166bb6290aeb125d07e4247e57d58203b64 /libevmasm/ConstantOptimiser.h | |
parent | 122dc65b3608b368897701dbdebc689bc614933f (diff) | |
parent | 0e91b8fb98ee942aeb668ef5ff1c6e40c52a7a2e (diff) | |
download | dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar.gz dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar.bz2 dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar.lz dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar.xz dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.tar.zst dexon-solidity-2c8b77006255b15743efd0b54964227bccc07c57.zip |
Merge pull request #2187 from ethereum/testOptimizer
Add recomputation check for number representation.
Diffstat (limited to 'libevmasm/ConstantOptimiser.h')
-rw-r--r-- | libevmasm/ConstantOptimiser.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libevmasm/ConstantOptimiser.h b/libevmasm/ConstantOptimiser.h index 4f12c49f..85bdabac 100644 --- a/libevmasm/ConstantOptimiser.h +++ b/libevmasm/ConstantOptimiser.h @@ -21,10 +21,14 @@ #pragma once -#include <vector> +#include <libevmasm/Exceptions.h> + +#include <libdevcore/Assertions.h> #include <libdevcore/CommonData.h> #include <libdevcore/CommonIO.h> +#include <vector> + namespace dev { namespace eth @@ -130,6 +134,11 @@ public: ConstantOptimisationMethod(_params, _value) { m_routine = findRepresentation(m_value); + assertThrow( + checkRepresentation(m_value, m_routine), + OptimizerException, + "Invalid constant expression created." + ); } virtual bigint gasNeeded() override { return gasNeeded(m_routine); } @@ -141,6 +150,8 @@ public: protected: /// Tries to recursively find a way to compute @a _value. AssemblyItems findRepresentation(u256 const& _value); + /// Recomputes the value from the calculated representation and checks for correctness. + bool checkRepresentation(u256 const& _value, AssemblyItems const& _routine); bigint gasNeeded(AssemblyItems const& _routine); /// Counter for the complexity of optimization, will stop when it reaches zero. |