Skip to content

Commit

Permalink
Ensure that balance/value is checked for as 128 bits and not 64 bits
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 23, 2018
1 parent 5ae71b5 commit 3375c7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/eei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,15 +872,15 @@ string toHex(evmc_uint256be const& value) {
{
evmc_uint256be balance;
context->fn_table->get_balance(&balance, context, &msg.destination);
if (safeLoadUint64(balance) < safeLoadUint64(value))
if (safeLoadUint128(balance) < safeLoadUint128(value))
throw OutOfGasException{};
}

uint64_t EthereumInterface::safeLoadUint64(evmc_uint256be const& value)
uint64_t EthereumInterface::safeLoadUint128(evmc_uint256be const& value)
{
heraAssert(!exceedsUint64(value), "Value exceeds 64 bits.");
heraAssert(!exceedsUint128(value), "Value exceeds 128 bits.");
uint64_t ret = 0;
for (unsigned i = 24; i < 32; i++) {
for (unsigned i = 16; i < 32; i++) {
ret <<= 8;
ret |= value.bytes[i];
}
Expand Down
2 changes: 1 addition & 1 deletion src/eei.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct EthereumInterface : ShellExternalInterface {

void ensureSenderBalance(evmc_uint256be const& value);

static uint64_t safeLoadUint64(evmc_uint256be const& value);
static uint64_t safeLoadUint128(evmc_uint256be const& value);

/* Checks if host supplied 256 bit value exceeds UINT64_MAX */
static bool exceedsUint64(evmc_uint256be const& value);
Expand Down

0 comments on commit 3375c7e

Please sign in to comment.