From 2a41295d038555c521c2fec80e5d94e8ae265440 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 27 Sep 2022 14:26:10 +0200 Subject: [PATCH] Drop implicit alignment argument from FixedHash --- libsolutil/FixedHash.h | 2 +- test/EVMHost.cpp | 4 +-- test/libsolutil/FixedHash.cpp | 27 ++++++++++--------- .../EwasmBuiltinInterpreter.cpp | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/libsolutil/FixedHash.h b/libsolutil/FixedHash.h index 97a80603a..c4c72e9eb 100644 --- a/libsolutil/FixedHash.h +++ b/libsolutil/FixedHash.h @@ -61,7 +61,7 @@ public: explicit FixedHash() { m_data.fill(0); } /// Construct from another hash, filling with zeroes or cropping as necessary. - template explicit FixedHash(FixedHash const& _h, ConstructFromHashType _t = AlignLeft) + template explicit FixedHash(FixedHash const& _h, ConstructFromHashType _t) { m_data.fill(0); unsigned c = std::min(M, N); diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 30b584a90..7dea40b63 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -255,7 +255,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept h160 createAddress(keccak256( bytes(begin(message.sender.bytes), end(message.sender.bytes)) + asBytes(to_string(sender.nonce++)) - )); + ), h160::AlignLeft); message.destination = convertToEVMC(createAddress); code = evmc::bytes(message.input_data, message.input_data + message.input_size); } @@ -266,7 +266,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept bytes(begin(message.sender.bytes), end(message.sender.bytes)) + bytes(begin(message.create2_salt.bytes), end(message.create2_salt.bytes)) + keccak256(bytes(message.input_data, message.input_data + message.input_size)).asBytes() - )); + ), h160::AlignLeft); message.destination = convertToEVMC(createAddress); if (accounts.count(message.destination) && ( accounts[message.destination].nonce > 0 || diff --git a/test/libsolutil/FixedHash.cpp b/test/libsolutil/FixedHash.cpp index 67397e9e1..279f4246a 100644 --- a/test/libsolutil/FixedHash.cpp +++ b/test/libsolutil/FixedHash.cpp @@ -146,29 +146,30 @@ BOOST_AUTO_TEST_CASE(string_constructor_frombytes) BOOST_AUTO_TEST_CASE(converting_constructor) { - // Truncation - FixedHash<8> a = FixedHash<8>(FixedHash<12>("112233445566778899001122")); + // Left-aligned truncation + FixedHash<8> a = FixedHash<8>(FixedHash<12>("112233445566778899001122"), FixedHash<8>::AlignLeft); BOOST_CHECK_EQUAL(a.size, 8); BOOST_CHECK_EQUAL(a.hex(), "1122334455667788"); + // Right-aligned truncation + FixedHash<8> b = FixedHash<8>(FixedHash<12>("112233445566778899001122"), FixedHash<8>::AlignRight); + BOOST_CHECK_EQUAL(b.size, 8); + BOOST_CHECK_EQUAL(b.hex(), "5566778899001122"); + // Left-aligned extension - FixedHash<12> b = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignLeft); - BOOST_CHECK_EQUAL(b.size, 12); - BOOST_CHECK_EQUAL(b.hex(), "112233445566778800000000"); + FixedHash<12> c = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignLeft); + BOOST_CHECK_EQUAL(c.size, 12); + BOOST_CHECK_EQUAL(c.hex(), "112233445566778800000000"); // Right-aligned extension - FixedHash<12> c = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignRight); - BOOST_CHECK_EQUAL(c.size, 12); - BOOST_CHECK_EQUAL(c.hex(), "000000001122334455667788"); - - // Default setting - FixedHash<12> d = FixedHash<12>(FixedHash<8>("1122334455667788")); - BOOST_CHECK_EQUAL(d, b); + FixedHash<12> d = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignRight); + BOOST_CHECK_EQUAL(d.size, 12); + BOOST_CHECK_EQUAL(d.hex(), "000000001122334455667788"); // FailIfDifferent setting // TODO: Shouldn't this throw? FixedHash<12> e = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::FailIfDifferent); - BOOST_CHECK_EQUAL(e, b); + BOOST_CHECK_EQUAL(e, c); } BOOST_AUTO_TEST_CASE(arith_constructor) diff --git a/test/tools/yulInterpreter/EwasmBuiltinInterpreter.cpp b/test/tools/yulInterpreter/EwasmBuiltinInterpreter.cpp index 25349f5d1..36f51b11c 100644 --- a/test/tools/yulInterpreter/EwasmBuiltinInterpreter.cpp +++ b/test/tools/yulInterpreter/EwasmBuiltinInterpreter.cpp @@ -439,7 +439,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector