From 3c88d295b3a5086bc5fbca042785713ddd811963 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 14 Dec 2019 13:38:44 +0000 Subject: [PATCH 1/3] Remove FixedHash(unsigned) constructor --- libsolutil/FixedHash.h | 3 --- test/contracts/FixedFeeRegistrar.cpp | 2 +- test/tools/yulInterpreter/Interpreter.cpp | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/libsolutil/FixedHash.h b/libsolutil/FixedHash.h index 90c0ab4dc..2be702180 100644 --- a/libsolutil/FixedHash.h +++ b/libsolutil/FixedHash.h @@ -63,9 +63,6 @@ public: /// Convert from the corresponding arithmetic type. FixedHash(Arith const& _arith) { toBigEndian(_arith, m_data); } - /// Convert from unsigned - explicit FixedHash(unsigned _u) { toBigEndian(_u, m_data); } - /// Explicitly construct, copying from a byte array. explicit FixedHash(bytes const& _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min(_b.size(), N); for (unsigned i = 0; i < c; ++i) m_data[_t == AlignRight ? N - 1 - i : i] = _b[_t == AlignRight ? _b.size() - 1 - i : i]; } } } diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp index a0b1d2a8f..9535c1907 100644 --- a/test/contracts/FixedFeeRegistrar.cpp +++ b/test/contracts/FixedFeeRegistrar.cpp @@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE(reserve) BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee + 1, encodeDyn(name[1])) == encodeArgs()); BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[1])) == encodeArgs(h256(account(0), h256::AlignRight))); BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee - 1, encodeDyn(name[2])) == encodeArgs()); - BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[2])) == encodeArgs(h256(0))); + BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[2])) == encodeArgs(h256{})); } BOOST_AUTO_TEST_CASE(double_reserve) diff --git a/test/tools/yulInterpreter/Interpreter.cpp b/test/tools/yulInterpreter/Interpreter.cpp index 4d28633f6..cbfdbbe52 100644 --- a/test/tools/yulInterpreter/Interpreter.cpp +++ b/test/tools/yulInterpreter/Interpreter.cpp @@ -60,7 +60,7 @@ void InterpreterState::dumpTraceAndState(ostream& _out) const _out << " " << std::uppercase << std::hex << std::setw(4) << offset << ": " << h256(value).hex() << endl; _out << "Storage dump:" << endl; for (auto const& slot: storage) - if (slot.second != h256(0)) + if (slot.second != h256{}) _out << " " << slot.first.hex() << ": " << slot.second.hex() << endl; } From 4d8758fcc338ad01c6f8324419ec57013ebee5ae Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Sat, 14 Dec 2019 13:42:04 +0000 Subject: [PATCH 2/3] Remove operator~ from FixedHash --- libsolutil/FixedHash.h | 2 -- test/contracts/Wallet.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libsolutil/FixedHash.h b/libsolutil/FixedHash.h index 2be702180..d36f61e11 100644 --- a/libsolutil/FixedHash.h +++ b/libsolutil/FixedHash.h @@ -84,8 +84,6 @@ public: /// Required to sort objects of this type or use them as map keys. bool operator<(FixedHash const& _c) const { for (unsigned i = 0; i < N; ++i) if (m_data[i] < _c.m_data[i]) return true; else if (m_data[i] > _c.m_data[i]) return false; return false; } - FixedHash operator~() const { FixedHash ret; for (unsigned i = 0; i < N; ++i) ret[i] = ~m_data[i]; return ret; } - /// @returns a particular byte from the hash. uint8_t& operator[](unsigned _i) { return m_data[_i]; } /// @returns a particular byte from the hash. diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp index 2051c3057..1ec71665a 100644 --- a/test/contracts/Wallet.cpp +++ b/test/contracts/Wallet.cpp @@ -465,7 +465,7 @@ BOOST_AUTO_TEST_CASE(creation) deployWallet(200); BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(m_sender, h256::AlignRight)) == encodeArgs(true)); bool v2 = solidity::test::Options::get().useABIEncoderV2; - BOOST_REQUIRE(callContractFunction("isOwner(address)", ~h256(m_sender, h256::AlignRight)) == (v2 ? encodeArgs() : encodeArgs(false))); + BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(~0)) == (v2 ? encodeArgs() : encodeArgs(false))); } BOOST_AUTO_TEST_CASE(add_owners) From b3d2413a1ff0cb1bac0d6e00a2c9166969dad918 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 13 Dec 2019 00:06:28 +0000 Subject: [PATCH 3/3] Remove unused features of FixedHash --- libsolutil/FixedHash.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/libsolutil/FixedHash.h b/libsolutil/FixedHash.h index d36f61e11..f5a042d4c 100644 --- a/libsolutil/FixedHash.h +++ b/libsolutil/FixedHash.h @@ -75,9 +75,6 @@ public: /// Convert to arithmetic type. operator Arith() const { return fromBigEndian(m_data); } - /// @returns true iff this is the empty hash. - explicit operator bool() const { return std::any_of(m_data.begin(), m_data.end(), [](uint8_t _b) { return _b != 0; }); } - // The obvious comparison operators. bool operator==(FixedHash const& _c) const { return m_data == _c.m_data; } bool operator!=(FixedHash const& _c) const { return m_data != _c.m_data; } @@ -107,12 +104,6 @@ public: /// @returns a copy of the object's data as a byte vector. bytes asBytes() const { return bytes(data(), data() + N); } - /// @returns a mutable reference to the object's data as an STL array. - std::array& asArray() { return m_data; } - - /// @returns a constant reference to the object's data as an STL array. - std::array const& asArray() const { return m_data; } - /// Returns the index of the first bit set to one, or size() * 8 if no bits are set. inline unsigned firstBitSet() const { @@ -129,8 +120,6 @@ public: return ret; } - void clear() { m_data.fill(0); } - private: std::array m_data; ///< The binary data. };