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

Upgrade intx to 0.6.0 #345

Merged
merged 3 commits into from
Jun 28, 2021
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
6 changes: 3 additions & 3 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

hunter_config(
intx
VERSION 0.5.1
URL https://github.com/chfast/intx/archive/v0.5.1.tar.gz
SHA1 743c46a82750143bd302a4394b7008a2112fc97b
VERSION 0.6.0
URL https://github.com/chfast/intx/archive/v0.6.0.tar.gz
SHA1 507827495de07412863349bc8c2a8704c7b0e5d4
)

hunter_config(
Expand Down
15 changes: 4 additions & 11 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ inline evmc_status_code exp(ExecutionState& state) noexcept
auto& exponent = state.stack.top();

const auto exponent_significant_bytes =
static_cast<int>(intx::count_significant_words<uint8_t>(exponent));
static_cast<int>(intx::count_significant_bytes(exponent));
const auto exponent_cost = state.rev >= EVMC_SPURIOUS_DRAGON ? 50 : 10;
const auto additional_cost = exponent_significant_bytes * exponent_cost;
if ((state.gas_left -= additional_cost) < 0)
Expand Down Expand Up @@ -156,26 +156,19 @@ inline void lt(Stack& stack) noexcept
inline void gt(Stack& stack) noexcept
{
const auto x = stack.pop();
stack[0] = stack[0] < x; // TODO: Using < is faster than >.
stack[0] = stack[0] < x; // Arguments are swapped and < is used.
}

inline void slt(Stack& stack) noexcept
{
// TODO: Move this to intx.
const auto x = stack.pop();
auto& y = stack[0];
const auto x_neg = x.hi.hi >> 63;
const auto y_neg = y.hi.hi >> 63;
y = ((x_neg ^ y_neg) != 0) ? x_neg : x < y;
stack[0] = slt(x, stack[0]);
}

inline void sgt(Stack& stack) noexcept
{
const auto x = stack.pop();
auto& y = stack[0];
const auto x_neg = x.hi.hi >> 63;
const auto y_neg = y.hi.hi >> 63;
y = ((x_neg ^ y_neg) != 0) ? y_neg : y < x;
stack[0] = slt(stack[0], x); // Arguments are swapped and SLT is used.
}

inline void eq(Stack& stack) noexcept
Expand Down
16 changes: 16 additions & 0 deletions test/unittests/evm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,22 @@ TEST_P(evm, exp)
EXPECT_EQ(bytes(&result.output_data[0], 32), a);
}

TEST_P(evm, exp_1_0)
{
const auto code = push(0) + push(1) + OP_EXP + ret_top();
execute(31, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 31);
EXPECT_OUTPUT_INT(1);
}

TEST_P(evm, exp_0_0)
{
const auto code = push(0) + push(0) + OP_EXP + ret_top();
execute(31, code);
EXPECT_GAS_USED(EVMC_SUCCESS, 31);
EXPECT_OUTPUT_INT(1);
}

TEST_P(evm, exp_oog)
{
auto code = "6001600003800a";
Expand Down