From 3375c7eef8eef6ce42094c20ae12acf07710709a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 23 Apr 2018 23:26:20 +0100 Subject: [PATCH] Ensure that balance/value is checked for as 128 bits and not 64 bits --- src/eei.cpp | 8 ++++---- src/eei.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/eei.cpp b/src/eei.cpp index 092befdbd..8b7eb730c 100644 --- a/src/eei.cpp +++ b/src/eei.cpp @@ -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]; } diff --git a/src/eei.h b/src/eei.h index 6bab4e894..8da68a2a4 100644 --- a/src/eei.h +++ b/src/eei.h @@ -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);