Merge remote-tracking branch 'origin/develop' into breaking

This commit is contained in:
chriseth
2020-06-15 17:11:41 +02:00
132 changed files with 1083 additions and 417 deletions
+6 -6
View File
@@ -106,7 +106,7 @@ bytes solidity::util::fromHex(std::string const& _s, WhenError _throw)
{
int h = fromHex(_s[s++], _throw);
if (h != -1)
ret.push_back(h);
ret.push_back(static_cast<uint8_t>(h));
else
return bytes();
}
@@ -115,7 +115,7 @@ bytes solidity::util::fromHex(std::string const& _s, WhenError _throw)
int h = fromHex(_s[i], _throw);
int l = fromHex(_s[i + 1], _throw);
if (h != -1 && l != -1)
ret.push_back((uint8_t)(h * 16 + l));
ret.push_back(static_cast<uint8_t>(h * 16 + l));
else
return bytes();
}
@@ -148,14 +148,14 @@ string solidity::util::getChecksummedAddress(string const& _addr)
h256 hash = keccak256(boost::algorithm::to_lower_copy(s, std::locale::classic()));
string ret = "0x";
for (size_t i = 0; i < 40; ++i)
for (unsigned i = 0; i < 40; ++i)
{
char addressCharacter = s[i];
unsigned nibble = (unsigned(hash[i / 2]) >> (4 * (1 - (i % 2)))) & 0xf;
uint8_t nibble = hash[i / 2u] >> (4u * (1u - (i % 2u))) & 0xf;
if (nibble >= 8)
ret += toupper(addressCharacter);
ret += static_cast<char>(toupper(addressCharacter));
else
ret += tolower(addressCharacter);
ret += static_cast<char>(tolower(addressCharacter));
}
return ret;
}
+36 -2
View File
@@ -64,10 +64,44 @@ public:
FixedHash(Arith const& _arith) { toBigEndian(_arith, 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<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_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]; } } }
explicit FixedHash(bytes const& _array, ConstructFromHashType _sizeMismatchBehavior = FailIfDifferent)
{
if (_array.size() == N)
memcpy(m_data.data(), _array.data(), _array.size());
else
{
m_data.fill(0);
if (_sizeMismatchBehavior != FailIfDifferent)
{
auto bytesToCopy = std::min<size_t>(_array.size(), N);
for (size_t i = 0; i < bytesToCopy; ++i)
if (_sizeMismatchBehavior == AlignRight)
m_data[N - 1 - i] = _array[_array.size() - 1 - i];
else
m_data[i] = _array[i];
}
}
}
/// Explicitly construct, copying from a byte array.
explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent) { if (_b.size() == N) memcpy(m_data.data(), _b.data(), std::min<unsigned>(_b.size(), N)); else { m_data.fill(0); if (_t != FailIfDifferent) { auto c = std::min<unsigned>(_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]; } } }
explicit FixedHash(bytesConstRef _b, ConstructFromHashType _t = FailIfDifferent)
{
if (_b.size() == N)
memcpy(m_data.data(), _b.data(), std::min<size_t>(_b.size(), N));
else
{
m_data.fill(0);
if (_t != FailIfDifferent)
{
auto c = std::min<size_t>(_b.size(), N);
for (size_t i = 0; i < c; ++i)
if (_t == AlignRight)
m_data[N - 1 - i] = _b[_b.size() - 1 - i];
else
m_data[i] = _b[i];
}
}
}
/// Explicitly construct, copying from a string.
explicit FixedHash(std::string const& _s, ConstructFromStringType _t = FromHex, ConstructFromHashType _ht = FailIfDifferent): FixedHash(_t == FromHex ? fromHex(_s, WhenError::Throw) : solidity::util::asBytes(_s), _ht) {}
+11 -10
View File
@@ -69,25 +69,25 @@ static uint64_t const RC[24] = \
#define REPEAT6(e) e e e e e e
#define REPEAT24(e) REPEAT6(e e e e)
#define REPEAT5(e) e e e e e
#define FOR5(v, s, e) \
#define FOR5(type, v, s, e) \
v = 0; \
REPEAT5(e; v += s;)
REPEAT5(e; v = static_cast<type>(v + s);)
/*** Keccak-f[1600] ***/
static inline void keccakf(void* state) {
uint64_t* a = (uint64_t*)state;
auto* a = static_cast<uint64_t*>(state);
uint64_t b[5] = {0};
for (int i = 0; i < 24; i++)
{
uint8_t x, y;
// Theta
FOR5(x, 1,
FOR5(uint8_t, x, 1,
b[x] = 0;
FOR5(y, 5,
FOR5(uint8_t, y, 5,
b[x] ^= a[x + y]; ))
FOR5(x, 1,
FOR5(y, 5,
FOR5(uint8_t, x, 1,
FOR5(uint8_t, y, 5,
a[y + x] ^= b[(x + 4) % 5] ^ rol(b[(x + 1) % 5], 1); ))
// Rho and pi
uint64_t t = a[1];
@@ -97,11 +97,12 @@ static inline void keccakf(void* state) {
t = b[0];
x++; )
// Chi
FOR5(y,
FOR5(uint8_t,
y,
5,
FOR5(x, 1,
FOR5(uint8_t, x, 1,
b[x] = a[y + x];)
FOR5(x, 1,
FOR5(uint8_t, x, 1,
a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); ))
// Iota
a[0] ^= RC[i];