Skip to content

Commit 2a41295

Browse files
committed
Drop implicit alignment argument from FixedHash
1 parent 7252535 commit 2a41295

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

libsolutil/FixedHash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class FixedHash
6161
explicit FixedHash() { m_data.fill(0); }
6262

6363
/// Construct from another hash, filling with zeroes or cropping as necessary.
64-
template <unsigned M> explicit FixedHash(FixedHash<M> const& _h, ConstructFromHashType _t = AlignLeft)
64+
template <unsigned M> explicit FixedHash(FixedHash<M> const& _h, ConstructFromHashType _t)
6565
{
6666
m_data.fill(0);
6767
unsigned c = std::min(M, N);

test/EVMHost.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
255255
h160 createAddress(keccak256(
256256
bytes(begin(message.sender.bytes), end(message.sender.bytes)) +
257257
asBytes(to_string(sender.nonce++))
258-
));
258+
), h160::AlignLeft);
259259
message.destination = convertToEVMC(createAddress);
260260
code = evmc::bytes(message.input_data, message.input_data + message.input_size);
261261
}
@@ -266,7 +266,7 @@ evmc::result EVMHost::call(evmc_message const& _message) noexcept
266266
bytes(begin(message.sender.bytes), end(message.sender.bytes)) +
267267
bytes(begin(message.create2_salt.bytes), end(message.create2_salt.bytes)) +
268268
keccak256(bytes(message.input_data, message.input_data + message.input_size)).asBytes()
269-
));
269+
), h160::AlignLeft);
270270
message.destination = convertToEVMC(createAddress);
271271
if (accounts.count(message.destination) && (
272272
accounts[message.destination].nonce > 0 ||

test/libsolutil/FixedHash.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -146,29 +146,30 @@ BOOST_AUTO_TEST_CASE(string_constructor_frombytes)
146146

147147
BOOST_AUTO_TEST_CASE(converting_constructor)
148148
{
149-
// Truncation
150-
FixedHash<8> a = FixedHash<8>(FixedHash<12>("112233445566778899001122"));
149+
// Left-aligned truncation
150+
FixedHash<8> a = FixedHash<8>(FixedHash<12>("112233445566778899001122"), FixedHash<8>::AlignLeft);
151151
BOOST_CHECK_EQUAL(a.size, 8);
152152
BOOST_CHECK_EQUAL(a.hex(), "1122334455667788");
153153

154-
// Left-aligned extension
155-
FixedHash<12> b = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignLeft);
156-
BOOST_CHECK_EQUAL(b.size, 12);
157-
BOOST_CHECK_EQUAL(b.hex(), "112233445566778800000000");
154+
// Right-aligned truncation
155+
FixedHash<8> b = FixedHash<8>(FixedHash<12>("112233445566778899001122"), FixedHash<8>::AlignRight);
156+
BOOST_CHECK_EQUAL(b.size, 8);
157+
BOOST_CHECK_EQUAL(b.hex(), "5566778899001122");
158158

159-
// Right-aligned extension
160-
FixedHash<12> c = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignRight);
159+
// Left-aligned extension
160+
FixedHash<12> c = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignLeft);
161161
BOOST_CHECK_EQUAL(c.size, 12);
162-
BOOST_CHECK_EQUAL(c.hex(), "000000001122334455667788");
162+
BOOST_CHECK_EQUAL(c.hex(), "112233445566778800000000");
163163

164-
// Default setting
165-
FixedHash<12> d = FixedHash<12>(FixedHash<8>("1122334455667788"));
166-
BOOST_CHECK_EQUAL(d, b);
164+
// Right-aligned extension
165+
FixedHash<12> d = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::AlignRight);
166+
BOOST_CHECK_EQUAL(d.size, 12);
167+
BOOST_CHECK_EQUAL(d.hex(), "000000001122334455667788");
167168

168169
// FailIfDifferent setting
169170
// TODO: Shouldn't this throw?
170171
FixedHash<12> e = FixedHash<12>(FixedHash<8>("1122334455667788"), FixedHash<12>::FailIfDifferent);
171-
BOOST_CHECK_EQUAL(e, b);
172+
BOOST_CHECK_EQUAL(e, c);
172173
}
173174

174175
BOOST_AUTO_TEST_CASE(arith_constructor)

test/tools/yulInterpreter/EwasmBuiltinInterpreter.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
439439
}
440440
else if (_fun == "getExternalCodeSize")
441441
// Generate "random" code length.
442-
return uint32_t(u256(keccak256(h256(readAddress(arg[0])))) & 0xfff);
442+
return uint32_t(u256(keccak256(h256(readAddress(arg[0]), h256::AlignLeft))) & 0xfff);
443443
else if (_fun == "getGasLeft")
444444
return 0x99;
445445
else if (_fun == "getBlockGasLimit")

0 commit comments

Comments
 (0)