Merge pull request #11302 from ethereum/drop-u160

Drop the util::u160 type
This commit is contained in:
chriseth 2021-04-26 15:12:20 +02:00 committed by GitHub
commit 2969bc0f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 31 deletions

View File

@ -65,7 +65,6 @@ using bytesConstRef = util::vector_ref<uint8_t const>;
using bigint = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<>>;
using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
using s256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
using u160 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<160, 160, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
// Map types.
using StringMap = std::map<std::string, std::string>;

View File

@ -373,7 +373,7 @@ inline void toBigEndian(T _val, Out& o_out)
/// Converts a big-endian byte-stream represented on a templated collection to a templated integer value.
/// @a In will typically be either std::string or bytes.
/// @a T will typically by unsigned, u160, u256 or bigint.
/// @a T will typically by unsigned, u256 or bigint.
template <class T, class In>
inline T fromBigEndian(In const& _bytes)
{
@ -383,7 +383,6 @@ inline T fromBigEndian(In const& _bytes)
return ret;
}
inline bytes toBigEndian(u256 _val) { bytes ret(32); toBigEndian(_val, ret); return ret; }
inline bytes toBigEndian(u160 _val) { bytes ret(20); toBigEndian(_val, ret); return ret; }
/// Convenience function for toBigEndian.
/// @returns a byte array just big enough to represent @a _val.

View File

@ -173,12 +173,6 @@ BOOST_AUTO_TEST_CASE(converting_constructor)
BOOST_AUTO_TEST_CASE(arith_constructor)
{
FixedHash<20> a(u160(0x1234));
BOOST_CHECK_EQUAL(
a.hex(),
"0000000000000000000000000000000000001234"
);
FixedHash<32> b(u256(0x12340000));
BOOST_CHECK_EQUAL(
b.hex(),
@ -190,9 +184,6 @@ BOOST_AUTO_TEST_CASE(arith_constructor)
BOOST_AUTO_TEST_CASE(to_arith)
{
FixedHash<20> a{};
BOOST_CHECK_EQUAL(u160(a), 0);
FixedHash<32> b("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
BOOST_CHECK_EQUAL(u256(b), u256("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"));
}

View File

@ -125,12 +125,6 @@ BOOST_AUTO_TEST_CASE(test_format_number_readable)
BOOST_CHECK_EQUAL(formatNumberReadable(u256(0x100000000)), "2**32");
BOOST_CHECK_EQUAL(formatNumberReadable(u256(0xFFFFffff)), "2**32 - 1");
u160 a = 0;
for (int i = 0; i < 20; i++)
{
a <<= 8;
a |= 0x55;
}
u256 b = 0;
for (int i = 0; i < 32; i++)
{
@ -144,7 +138,6 @@ BOOST_AUTO_TEST_CASE(test_format_number_readable)
u256(0xFFFFffffFFFFffff) << 128 |
u256(0xFFFFffffFFFFffff) << 64 |
u256(0xFFFFffffFFFFffff);
BOOST_CHECK_EQUAL(formatNumberReadable(a, true), "0x5555...{+32 more}...5555");
BOOST_CHECK_EQUAL(formatNumberReadable(b, true), "0x5555...{+56 more}...5555");
BOOST_CHECK_EQUAL(formatNumberReadable(c, true), "0xABCD...{+56 more}...6789");
BOOST_CHECK_EQUAL(formatNumberReadable(d, true), "0xAAAAaaaaAAAAaaab * 2**192 - 1");

View File

@ -35,6 +35,7 @@ using namespace solidity;
using namespace solidity::yul;
using namespace solidity::yul::test;
using solidity::util::h160;
using solidity::util::h256;
using solidity::util::keccak256;
@ -181,18 +182,18 @@ u256 EVMInstructionInterpreter::eval(
return u256(keccak256(readMemory(offset, size)));
}
case Instruction::ADDRESS:
return m_state.address;
return h256(m_state.address, h256::AlignRight);
case Instruction::BALANCE:
if (arg[0] == m_state.address)
if (arg[0] == h256(m_state.address, h256::AlignRight))
return m_state.selfbalance;
else
return m_state.balance;
case Instruction::SELFBALANCE:
return m_state.selfbalance;
case Instruction::ORIGIN:
return m_state.origin;
return h256(m_state.origin, h256::AlignRight);
case Instruction::CALLER:
return m_state.caller;
return h256(m_state.caller, h256::AlignRight);
case Instruction::CALLVALUE:
return m_state.callvalue;
case Instruction::CALLDATALOAD:
@ -248,7 +249,7 @@ u256 EVMInstructionInterpreter::eval(
else
return 0xaaaaaaaa + (arg[0] - m_state.blockNumber - 256);
case Instruction::COINBASE:
return m_state.coinbase;
return h256(m_state.coinbase, h256::AlignRight);
case Instruction::TIMESTAMP:
return m_state.timestamp;
case Instruction::NUMBER:
@ -304,11 +305,11 @@ u256 EVMInstructionInterpreter::eval(
case Instruction::CREATE:
accessMemory(arg[1], arg[2]);
logTrace(_instruction, arg);
return u160(0xcccccc + arg[1]);
return (0xcccccc + arg[1]) & u256("0xffffffffffffffffffffffffffffffffffffffff");
case Instruction::CREATE2:
accessMemory(arg[2], arg[3]);
logTrace(_instruction, arg);
return u160(0xdddddd + arg[1]);
return (0xdddddd + arg[1]) & u256("0xffffffffffffffffffffffffffffffffffffffff");
case Instruction::CALL:
case Instruction::CALLCODE:
// TODO assign returndata

View File

@ -410,7 +410,7 @@ u256 EwasmBuiltinInterpreter::evalEthBuiltin(string const& _fun, vector<uint64_t
readU128(arg[0]);
accessMemory(arg[1], arg[2]);
logTrace(evmasm::Instruction::CREATE, {});
writeAddress(arg[3], h160(h256(0xcccccc + arg[1])));
writeAddress(arg[3], h160(0xcccccc + arg[1]));
return 1;
}
else if (_fun == "getBlockDifficulty")

View File

@ -75,16 +75,16 @@ struct InterpreterState
/// This is different than memory.size() because we ignore gas.
u256 msize;
std::map<util::h256, util::h256> storage;
u160 address = 0x11111111;
util::h160 address = util::h160("0x0000000000000000000000000000000011111111");
u256 balance = 0x22222222;
u256 selfbalance = 0x22223333;
u160 origin = 0x33333333;
u160 caller = 0x44444444;
util::h160 origin = util::h160("0x0000000000000000000000000000000033333333");
util::h160 caller = util::h160("0x0000000000000000000000000000000044444444");
u256 callvalue = 0x55555555;
/// Deployed code
bytes code = util::asBytes("codecodecodecodecode");
u256 gasprice = 0x66666666;
u160 coinbase = 0x77777777;
util::h160 coinbase = util::h160("0x0000000000000000000000000000000077777777");
u256 timestamp = 0x88888888;
u256 blockNumber = 1024;
u256 difficulty = 0x9999999;