diff options
| -rw-r--r-- | Changelog.md | 1 | ||||
| -rw-r--r-- | docs/frequently-asked-questions.rst | 6 | ||||
| -rw-r--r-- | libdevcore/Common.h | 41 | ||||
| -rw-r--r-- | libdevcore/CommonData.cpp | 7 | ||||
| -rw-r--r-- | libdevcore/SHA3.cpp | 2 | ||||
| -rw-r--r-- | libdevcore/SHA3.h | 1 | ||||
| -rw-r--r-- | libdevcore/debugbreak.h | 11 | ||||
| -rw-r--r-- | libdevcore/picosha2.h | 360 | ||||
| -rw-r--r-- | libdevcore/vector_ref.h | 20 | ||||
| -rw-r--r-- | liblll/CodeFragment.cpp | 17 | ||||
| -rw-r--r-- | liblll/Compiler.cpp | 30 | ||||
| -rw-r--r-- | liblll/CompilerState.cpp | 4 | ||||
| -rw-r--r-- | liblll/Exceptions.h | 1 | ||||
| -rw-r--r-- | liblll/Parser.cpp | 13 | ||||
| -rw-r--r-- | liblll/Parser.h | 1 | ||||
| -rw-r--r-- | libsolidity/ast/Types.h | 1 | ||||
| -rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 9 |
17 files changed, 66 insertions, 459 deletions
diff --git a/Changelog.md b/Changelog.md index bc79b88a..fb3b23c7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Features: Bugfixes: * Disallow unknown options in `solc` + * Code Generator: expect zero stack increase after `super` as an expression * Inline assembly: support the `address` opcode * Inline assembly: fix parsing of assignment after a label. diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index acc0c106..a4315a14 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -709,10 +709,12 @@ How do I initialize a contract with only a specific amount of wei? Currently the approach is a little ugly, but there is little that can be done to improve it. In the case of a ``contract A`` calling a new instance of ``contract B``, parentheses have to be used around ``new B`` because ``B.value`` would refer to a member of ``B`` called ``value``. -You will need to make sure that you have both contracts aware of each other's presence. +You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor. In this example:: - contract B {} + contract B { + function B() payable {} + } contract A { diff --git a/libdevcore/Common.h b/libdevcore/Common.h index 6fbc112d..43ae7162 100644 --- a/libdevcore/Common.h +++ b/libdevcore/Common.h @@ -87,47 +87,6 @@ using bytes = std::vector<byte>; using bytesRef = vector_ref<byte>; using bytesConstRef = vector_ref<byte const>; -template <class T> -class secure_vector -{ -public: - secure_vector() {} - secure_vector(secure_vector<T> const& /*_c*/) = default; // See https://github.com/ethereum/libweb3core/pull/44 - explicit secure_vector(unsigned _size): m_data(_size) {} - explicit secure_vector(unsigned _size, T _item): m_data(_size, _item) {} - explicit secure_vector(std::vector<T> const& _c): m_data(_c) {} - explicit secure_vector(vector_ref<T> _c): m_data(_c.data(), _c.data() + _c.size()) {} - explicit secure_vector(vector_ref<const T> _c): m_data(_c.data(), _c.data() + _c.size()) {} - ~secure_vector() { ref().cleanse(); } - - secure_vector<T>& operator=(secure_vector<T> const& _c) - { - if (&_c == this) - return *this; - - ref().cleanse(); - m_data = _c.m_data; - return *this; - } - std::vector<T>& writable() { clear(); return m_data; } - std::vector<T> const& makeInsecure() const { return m_data; } - - void clear() { ref().cleanse(); } - - vector_ref<T> ref() { return vector_ref<T>(&m_data); } - vector_ref<T const> ref() const { return vector_ref<T const>(&m_data); } - - size_t size() const { return m_data.size(); } - bool empty() const { return m_data.empty(); } - - void swap(secure_vector<T>& io_other) { m_data.swap(io_other.m_data); } - -private: - std::vector<T> m_data; -}; - -using bytesSec = secure_vector<byte>; - // Numeric types. using bigint = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>>; using u64 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<64, 64, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>; diff --git a/libdevcore/CommonData.cpp b/libdevcore/CommonData.cpp index fc438276..b27271cf 100644 --- a/libdevcore/CommonData.cpp +++ b/libdevcore/CommonData.cpp @@ -20,13 +20,6 @@ */ #include "CommonData.h" -#include <random> - -#if defined(_MSC_VER) -#pragma warning(push) -#pragma warning(disable:4724) // potential mod by 0, line 78 of boost/random/uniform_int_distribution.hpp (boost 1.55) -#endif -#include <boost/random/uniform_int_distribution.hpp> #if defined(_MSC_VER) #pragma warning(pop) #endif diff --git a/libdevcore/SHA3.cpp b/libdevcore/SHA3.cpp index d4536a34..3b12f39f 100644 --- a/libdevcore/SHA3.cpp +++ b/libdevcore/SHA3.cpp @@ -24,7 +24,7 @@ #include <cstdio> #include <cstdlib> #include <cstring> -#include "picosha2.h" + using namespace std; using namespace dev; diff --git a/libdevcore/SHA3.h b/libdevcore/SHA3.h index eedcc420..c481bfc9 100644 --- a/libdevcore/SHA3.h +++ b/libdevcore/SHA3.h @@ -25,7 +25,6 @@ #include <string> #include "FixedHash.h" -#include "vector_ref.h" namespace dev { diff --git a/libdevcore/debugbreak.h b/libdevcore/debugbreak.h index 65612a34..f8838a5f 100644 --- a/libdevcore/debugbreak.h +++ b/libdevcore/debugbreak.h @@ -93,6 +93,13 @@ static void __inline__ trap_instruction(void) /* Has same known problem and workaround * as Thumb mode */ } +#elif defined(ETH_EMSCRIPTEN) +enum { HAVE_TRAP_INSTRUCTION = 1, }; +__attribute__((gnu_inline, always_inline)) +static void __inline__ trap_instruction(void) +{ + asm("debugger"); +} #else enum { HAVE_TRAP_INSTRUCTION = 0, }; #endif @@ -101,11 +108,7 @@ __attribute__((gnu_inline, always_inline)) static void __inline__ debug_break(void) { if (HAVE_TRAP_INSTRUCTION) { -#if defined(ETH_EMSCRIPTEN) - asm("debugger"); -#else trap_instruction(); -#endif } else if (DEBUG_BREAK_PREFER_BUILTIN_TRAP_TO_SIGTRAP) { /* raises SIGILL on Linux x86{,-64}, to continue in gdb: * (gdb) handle SIGILL stop nopass diff --git a/libdevcore/picosha2.h b/libdevcore/picosha2.h deleted file mode 100644 index 44b6bee5..00000000 --- a/libdevcore/picosha2.h +++ /dev/null @@ -1,360 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (C) 2014 okdshin - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ -#ifndef PICOSHA2_H -#define PICOSHA2_H -//picosha2:20140213 -#include <cstdint> -#include <iostream> -#include <vector> -#include <iterator> -#include <cassert> -#include <sstream> -#include <algorithm> - -namespace picosha2 -{ - -namespace detail -{ - -inline uint8_t mask_8bit(uint8_t x){ - return x&0xff; -} - -inline uint32_t mask_32bit(uint32_t x){ - return x&0xffffffff; -} - -static const uint32_t add_constant[64] = { - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, - 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, - 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, - 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, - 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, - 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, - 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, - 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, - 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -}; - -static const uint32_t initial_message_digest[8] = { - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 -}; - -inline uint32_t ch(uint32_t x, uint32_t y, uint32_t z){ - return (x&y)^((~x)&z); -} - -inline uint32_t maj(uint32_t x, uint32_t y, uint32_t z){ - return (x&y)^(x&z)^(y&z); -} - -inline uint32_t rotr(uint32_t x, std::size_t n){ - assert(n < 32); - return mask_32bit((x>>n)|(x<<(32-n))); -} - -inline uint32_t bsig0(uint32_t x){ - return rotr(x, 2)^rotr(x, 13)^rotr(x, 22); -} - -inline uint32_t bsig1(uint32_t x){ - return rotr(x, 6)^rotr(x, 11)^rotr(x, 25); -} - -inline uint32_t shr(uint32_t x, std::size_t n){ - assert(n < 32); - return x >> n; -} - -inline uint32_t ssig0(uint32_t x){ - return rotr(x, 7)^rotr(x, 18)^shr(x, 3); -} - -inline uint32_t ssig1(uint32_t x){ - return rotr(x, 17)^rotr(x, 19)^shr(x, 10); -} - -template<typename RaIter1, typename RaIter2> -void hash256_block(RaIter1 message_digest, RaIter2 first, RaIter2 last){ - (void)last; // FIXME: check this is valid - uint32_t w[64]; - std::fill(w, w+64, 0); - for(std::size_t i = 0; i < 16; ++i){ - w[i] = (static_cast<uint32_t>(mask_8bit(*(first+i*4)))<<24) - |(static_cast<uint32_t>(mask_8bit(*(first+i*4+1)))<<16) - |(static_cast<uint32_t>(mask_8bit(*(first+i*4+2)))<<8) - |(static_cast<uint32_t>(mask_8bit(*(first+i*4+3)))); - } - for(std::size_t i = 16; i < 64; ++i){ - w[i] = mask_32bit(ssig1(w[i-2])+w[i-7]+ssig0(w[i-15])+w[i-16]); - } - - uint32_t a = *message_digest; - uint32_t b = *(message_digest+1); - uint32_t c = *(message_digest+2); - uint32_t d = *(message_digest+3); - uint32_t e = *(message_digest+4); - uint32_t f = *(message_digest+5); - uint32_t g = *(message_digest+6); - uint32_t h = *(message_digest+7); - - for(std::size_t i = 0; i < 64; ++i){ - uint32_t temp1 = h+bsig1(e)+ch(e,f,g)+add_constant[i]+w[i]; - uint32_t temp2 = bsig0(a)+maj(a,b,c); - h = g; - g = f; - f = e; - e = mask_32bit(d+temp1); - d = c; - c = b; - b = a; - a = mask_32bit(temp1+temp2); - } - *message_digest += a; - *(message_digest+1) += b; - *(message_digest+2) += c; - *(message_digest+3) += d; - *(message_digest+4) += e; - *(message_digest+5) += f; - *(message_digest+6) += g; - *(message_digest+7) += h; - for(std::size_t i = 0; i < 8; ++i){ - *(message_digest+i) = mask_32bit(*(message_digest+i)); - } -} - -}//namespace detail - -template<typename InIter> -void output_hex(InIter first, InIter last, std::ostream& os){ - os.setf(std::ios::hex, std::ios::basefield); - while(first != last){ - os.width(2); - os.fill('0'); - os << static_cast<unsigned int>(*first); - ++first; - } - os.setf(std::ios::dec, std::ios::basefield); -} - -template<typename InIter> -void bytes_to_hex_string(InIter first, InIter last, std::string& hex_str){ - std::ostringstream oss; - output_hex(first, last, oss); - hex_str.assign(oss.str()); -} - -template<typename InContainer> -void bytes_to_hex_string(const InContainer& bytes, std::string& hex_str){ - bytes_to_hex_string(bytes.begin(), bytes.end(), hex_str); -} - -template<typename InIter> -std::string bytes_to_hex_string(InIter first, InIter last){ - std::string hex_str; - bytes_to_hex_string(first, last, hex_str); - return hex_str; -} - -template<typename InContainer> -std::string bytes_to_hex_string(const InContainer& bytes){ - std::string hex_str; - bytes_to_hex_string(bytes, hex_str); - return hex_str; -} - -class hash256_one_by_one { -public: - hash256_one_by_one(){ - init(); - } - - void init(){ - buffer_.clear(); - std::fill(data_length_digits_, data_length_digits_+4, 0); - std::copy(detail::initial_message_digest, detail::initial_message_digest+8, h_); - } - - template<typename RaIter> - void process(RaIter first, RaIter last){ - add_to_data_length(std::distance(first, last)); - std::copy(first, last, std::back_inserter(buffer_)); - std::size_t i = 0; - for(;i+64 <= buffer_.size(); i+=64){ - detail::hash256_block(h_, buffer_.begin()+i, buffer_.begin()+i+64); - } - buffer_.erase(buffer_.begin(), buffer_.begin()+i); - } - - void finish(){ - uint8_t temp[64]; - std::fill(temp, temp+64, 0); - std::size_t remains = buffer_.size(); - std::copy(buffer_.begin(), buffer_.end(), temp); - temp[remains] = 0x80; - - if(remains > 55){ - std::fill(temp+remains+1, temp+64, 0); - detail::hash256_block(h_, temp, temp+64); - std::fill(temp, temp+64-4, 0); - } - else { - std::fill(temp+remains+1, temp+64-4, 0); - } - - write_data_bit_length(&(temp[56])); - detail::hash256_block(h_, temp, temp+64); - } - - template<typename OutIter> - void get_hash_bytes(OutIter first, OutIter last)const{ - for(const uint32_t* iter = h_; iter != h_+8; ++iter){ - for(std::size_t i = 0; i < 4 && first != last; ++i){ - *(first++) = detail::mask_8bit(static_cast<uint8_t>((*iter >> (24-8*i)))); - } - } - } - -private: - void add_to_data_length(uint32_t n) { - uint32_t carry = 0; - data_length_digits_[0] += n; - for(std::size_t i = 0; i < 4; ++i) { - data_length_digits_[i] += carry; - if(data_length_digits_[i] >= 65536u) { - data_length_digits_[i] -= 65536u; - carry = 1; - } - else { - break; - } - } - } - void write_data_bit_length(uint8_t* begin) { - uint32_t data_bit_length_digits[4]; - std::copy( - data_length_digits_, data_length_digits_+4, - data_bit_length_digits - ); - - // convert byte length to bit length (multiply 8 or shift 3 times left) - uint32_t carry = 0; - for(std::size_t i = 0; i < 4; ++i) { - uint32_t before_val = data_bit_length_digits[i]; - data_bit_length_digits[i] <<= 3; - data_bit_length_digits[i] |= carry; - data_bit_length_digits[i] &= 65535u; - carry = (before_val >> (16-3)) & 65535u; - } - - // write data_bit_length - for(int i = 3; i >= 0; --i) { - (*begin++) = static_cast<uint8_t>(data_bit_length_digits[i] >> 8); - (*begin++) = static_cast<uint8_t>(data_bit_length_digits[i]); - } - } - std::vector<uint8_t> buffer_; - uint32_t data_length_digits_[4]; //as 64bit integer (16bit x 4 integer) - uint32_t h_[8]; -}; - -inline void get_hash_hex_string(const hash256_one_by_one& hasher, std::string& hex_str){ - uint8_t hash[32]; - hasher.get_hash_bytes(hash, hash+32); - return bytes_to_hex_string(hash, hash+32, hex_str); -} - -inline std::string get_hash_hex_string(const hash256_one_by_one& hasher){ - std::string hex_str; - get_hash_hex_string(hasher, hex_str); - return hex_str; -} - -template<typename RaIter, typename OutIter> -void hash256(RaIter first, RaIter last, OutIter first2, OutIter last2){ - hash256_one_by_one hasher; - //hasher.init(); - hasher.process(first, last); - hasher.finish(); - hasher.get_hash_bytes(first2, last2); -} - -template<typename RaIter, typename OutContainer> -void hash256(RaIter first, RaIter last, OutContainer& dst){ - hash256(first, last, dst.begin(), dst.end()); -} - -template<typename RaContainer, typename OutIter> -void hash256(const RaContainer& src, OutIter first, OutIter last){ - hash256(src.begin(), src.end(), first, last); -} - -template<typename RaContainer, typename OutContainer> -void hash256(const RaContainer& src, OutContainer& dst){ - hash256(src.begin(), src.end(), dst.begin(), dst.end()); -} - - -template<typename RaIter> -void hash256_hex_string(RaIter first, RaIter last, std::string& hex_str){ - uint8_t hashed[32]; - hash256(first, last, hashed, hashed+32); - std::ostringstream oss; - output_hex(hashed, hashed+32, oss); - hex_str.assign(oss.str()); -} - -template<typename RaIter> -std::string hash256_hex_string(RaIter first, RaIter last){ - std::string hex_str; - hash256_hex_string(first, last, hex_str); - return hex_str; -} - -inline void hash256_hex_string(const std::string& src, std::string& hex_str){ - hash256_hex_string(src.begin(), src.end(), hex_str); -} - -template<typename RaContainer> -void hash256_hex_string(const RaContainer& src, std::string& hex_str){ - hash256_hex_string(src.begin(), src.end(), hex_str); -} - -template<typename RaContainer> -std::string hash256_hex_string(const RaContainer& src){ - return hash256_hex_string(src.begin(), src.end()); -} - -}//namespace picosha2 - -#endif //PICOSHA2_H diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index 698377c9..0f543181 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -69,26 +69,6 @@ public: void copyTo(vector_ref<typename std::remove_const<_T>::type> _t) const { if (overlapsWith(_t)) memmove(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); else memcpy(_t.data(), m_data, std::min(_t.size(), m_count) * sizeof(_T)); } /// Copies the contents of this vector_ref to the contents of @a _t, and zeros further trailing elements in @a _t. void populate(vector_ref<typename std::remove_const<_T>::type> _t) const { copyTo(_t); memset(_t.data() + m_count, 0, std::max(_t.size(), m_count) - m_count); } - /// Securely overwrite the memory. - /// @note adapted from OpenSSL's implementation. - void cleanse() - { - static unsigned char s_cleanseCounter = 0; - uint8_t* p = (uint8_t*)begin(); - size_t const len = (uint8_t*)end() - p; - size_t loop = len; - size_t count = s_cleanseCounter; - while (loop--) - { - *(p++) = (uint8_t)count; - count += (17 + ((size_t)p & 0xf)); - } - p = (uint8_t*)memchr((uint8_t*)begin(), (uint8_t)count, len); - if (p) - count += (63 + (size_t)p); - s_cleanseCounter = (uint8_t)count; - memset((uint8_t*)begin(), 0, len); - } _T* begin() { return m_data; } _T* end() { return m_data + m_count; } diff --git a/liblll/CodeFragment.cpp b/liblll/CodeFragment.cpp index e9f86ba0..9dcac845 100644 --- a/liblll/CodeFragment.cpp +++ b/liblll/CodeFragment.cpp @@ -52,17 +52,18 @@ void CodeFragment::finalise(CompilerState const& _cs) CodeFragment::CodeFragment(sp::utree const& _t, CompilerState& _s, bool _allowASM) { -/* cdebug << "CodeFragment. Locals:"; +/* + std::cout << "CodeFragment. Locals:"; for (auto const& i: _s.defs) - cdebug << i.first << ":" << toHex(i.second.m_code); - cdebug << "Args:"; + std::cout << i.first << ":" << i.second.m_asm.out(); + std::cout << "Args:"; for (auto const& i: _s.args) - cdebug << i.first << ":" << toHex(i.second.m_code); - cdebug << "Outers:"; + std::cout << i.first << ":" << i.second.m_asm.out(); + std::cout << "Outers:"; for (auto const& i: _s.outers) - cdebug << i.first << ":" << toHex(i.second.m_code); - debugOutAST(cout, _t); - cout << endl << flush; + std::cout << i.first << ":" << i.second.m_asm.out(); + debugOutAST(std::cout, _t); + std::cout << endl << flush; */ switch (_t.which()) { diff --git a/liblll/Compiler.cpp b/liblll/Compiler.cpp index f1538789..68499106 100644 --- a/liblll/Compiler.cpp +++ b/liblll/Compiler.cpp @@ -45,13 +45,21 @@ bytes dev::eth::compileLLL(string const& _src, bool _opt, vector<string>* _error if (_errors) { _errors->push_back("Parse error."); - _errors->push_back(diagnostic_information(_e)); + _errors->push_back(boost::diagnostic_information(_e)); } } - catch (std::exception) + catch (std::exception const& _e) { if (_errors) - _errors->push_back("Parse error."); + { + _errors->push_back("Parse exception."); + _errors->push_back(boost::diagnostic_information(_e)); + } + } + catch (...) + { + if (_errors) + _errors->push_back("Internal parse exception."); } return bytes(); } @@ -70,12 +78,22 @@ std::string dev::eth::compileLLLToAsm(std::string const& _src, bool _opt, std::v catch (Exception const& _e) { if (_errors) - _errors->push_back(diagnostic_information(_e)); + { + _errors->push_back("Parse error."); + _errors->push_back(boost::diagnostic_information(_e)); + } + } + catch (std::exception const& _e) + { + if (_errors) { + _errors->push_back("Parse exception."); + _errors->push_back(boost::diagnostic_information(_e)); + } } - catch (std::exception) + catch (...) { if (_errors) - _errors->push_back("Parse error."); + _errors->push_back("Internal parse exception."); } return string(); } diff --git a/liblll/CompilerState.cpp b/liblll/CompilerState.cpp index 1d83192c..91c2452d 100644 --- a/liblll/CompilerState.cpp +++ b/liblll/CompilerState.cpp @@ -69,6 +69,10 @@ void CompilerState::populateStandard() "(def 'ripemd160 (data datasize) (msg allgas 3 0 data datasize))" "(def 'sha256 (val) { [0]:val (sha256 0 32) })" "(def 'ripemd160 (val) { [0]:val (ripemd160 0 32) })" + "(def 'wei 1)" + "(def 'szabo 1000000000000)" + "(def 'finney 1000000000000000)" + "(def 'ether 1000000000000000000)" "}"; CodeFragment::compile(s, *this); } diff --git a/liblll/Exceptions.h b/liblll/Exceptions.h index 1e9671b3..aa4bf4e8 100644 --- a/liblll/Exceptions.h +++ b/liblll/Exceptions.h @@ -39,6 +39,7 @@ class InvalidName: public CompilerException {}; class InvalidMacroArgs: public CompilerException {}; class InvalidLiteral: public CompilerException {}; class BareSymbol: public CompilerException {}; +class ParserException: public CompilerException {}; } } diff --git a/liblll/Parser.cpp b/liblll/Parser.cpp index aa4a4de2..2754e9f5 100644 --- a/liblll/Parser.cpp +++ b/liblll/Parser.cpp @@ -96,19 +96,13 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) using symbol_type = sp::basic_string<std::string, sp::utree_type::symbol_type>; using it = string::const_iterator; - static const u256 ether = u256(1000000000) * 1000000000; - static const u256 finney = u256(1000000000) * 1000000; - static const u256 szabo = u256(1000000000) * 1000; - qi::rule<it, space_type, sp::utree()> element; qi::rule<it, string()> str = '"' > qi::lexeme[+(~qi::char_(std::string("\"") + '\0'))] > '"'; qi::rule<it, string()> strsh = '\'' > qi::lexeme[+(~qi::char_(std::string(" ;$@()[]{}:\n\t") + '\0'))]; qi::rule<it, symbol_type()> symbol = qi::lexeme[+(~qi::char_(std::string(" $@[]{}:();\"\x01-\x1f\x7f") + '\0'))]; qi::rule<it, string()> intstr = qi::lexeme[ qi::no_case["0x"][qi::_val = "0x"] >> *qi::char_("0-9a-fA-F")[qi::_val += qi::_1]] | qi::lexeme[+qi::char_("0-9")[qi::_val += qi::_1]]; qi::rule<it, bigint()> integer = intstr; - qi::rule<it, bigint()> multiplier = qi::lit("wei")[qi::_val = 1] | qi::lit("szabo")[qi::_val = szabo] | qi::lit("finney")[qi::_val = finney] | qi::lit("ether")[qi::_val = ether]; - qi::rule<it, space_type, bigint()> quantity = integer[qi::_val = qi::_1] >> -multiplier[qi::_val *= qi::_1]; - qi::rule<it, space_type, sp::utree()> atom = quantity[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; + qi::rule<it, space_type, sp::utree()> atom = integer[qi::_val = px::construct<sp::any_ptr>(px::new_<bigint>(qi::_1))] | (str | strsh)[qi::_val = qi::_1] | symbol[qi::_val = qi::_1]; qi::rule<it, space_type, sp::utree::list_type()> seq = '{' > *element > '}'; qi::rule<it, space_type, sp::utree::list_type()> mload = '@' > element; qi::rule<it, space_type, sp::utree::list_type()> sload = qi::lit("@@") > element; @@ -143,7 +137,8 @@ void dev::eth::parseTreeLLL(string const& _s, sp::utree& o_out) auto ret = s.cbegin(); qi::phrase_parse(ret, s.cend(), element, space, qi::skip_flag::dont_postskip, o_out); for (auto i = ret; i != s.cend(); ++i) - if (!isspace(*i)) - BOOST_THROW_EXCEPTION(std::exception()); + if (!isspace(*i)) { + BOOST_THROW_EXCEPTION(ParserException() << errinfo_comment("Non-whitespace left in parser")); + } } diff --git a/liblll/Parser.h b/liblll/Parser.h index b21989f0..e4542888 100644 --- a/liblll/Parser.h +++ b/liblll/Parser.h @@ -24,6 +24,7 @@ #include <string> #include <vector> #include <libdevcore/Common.h> +#include "Exceptions.h" namespace boost { namespace spirit { class utree; } } namespace sp = boost::spirit; diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 9173f39a..f65d25fb 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -623,6 +623,7 @@ public: } virtual unsigned storageBytes() const override { return 20; } virtual bool canLiveOutsideStorage() const override { return true; } + virtual unsigned sizeOnStack() const override { return m_super ? 0 : 1; } virtual bool isValueType() const override { return true; } virtual std::string toString(bool _short) const override; virtual std::string canonicalName(bool _addDataLocation) const override; diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 155f117f..692abe57 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -2513,6 +2513,15 @@ BOOST_AUTO_TEST_CASE(super_in_constructor) BOOST_CHECK(callContractFunction("f()") == encodeArgs(1 | 2 | 4 | 8)); } +BOOST_AUTO_TEST_CASE(super_alone) +{ + char const* sourceCode = R"( + contract A { function f() { super; } } + )"; + compileAndRun(sourceCode, 0, "A"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs()); +} + BOOST_AUTO_TEST_CASE(fallback_function) { char const* sourceCode = R"( |
