Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that balance/value is checked for as 128 bits and not 64 bits #191

Merged
merged 1 commit into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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