-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "evm_fixture.hpp" | ||
#include <evmmax/evmmax.hpp> | ||
#include <gtest/gtest.h> | ||
#include <array> | ||
|
||
using namespace intx; | ||
using namespace evmmax; | ||
using namespace evmc::literals; | ||
using evmone::test::evm; | ||
|
||
TEST_P(evm, evmmax_32bytes_modulus_test) | ||
{ | ||
if (is_advanced()) | ||
return; | ||
|
||
rev = EVMC_PRAGUE; /// TODO: Use EVMC_EVMMAX | ||
// Modulus == 7 | ||
auto code = mstore(0, 0x07); | ||
// 3 values slots | ||
// Modulus size in bytes | ||
// Modulus offset in EVM memory | ||
// Modulus ID | ||
code += setupx(3, 32, 0, 1); | ||
// value 3 | ||
code += mstore(32, 0x03); | ||
// value 6 | ||
code += mstore(64, 0x06); | ||
// num values | ||
// values offset | ||
// store values | ||
code += storex(2, 32, 0); | ||
// ADDMODX for values in slots 0 and 1 save result in slot 2 | ||
code += addmodx(2, 1, 0); | ||
// MULMODX for values in slots 1 and 2 save result in slot 2 | ||
code += mulmodx(2, 2, 1); | ||
// SUBMODX for values in slots 1 and 2 save result in slot 2 | ||
code += submodx(2, 2, 1); | ||
// load values from slot 2 into EVM memory | ||
code += loadx(1, 2, 96); | ||
// return loaded result | ||
code += ret(96, 32); | ||
|
||
execute(1000, code); | ||
EXPECT_EQ(result.status_code, EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(6); | ||
} | ||
|
||
TEST_P(evm, evmmax_1byte_modulus_test) | ||
{ | ||
if (is_advanced()) | ||
return; | ||
|
||
rev = EVMC_PRAGUE; /// TODO: Use EVMC_EVMMAX | ||
// Modulus == 7 | ||
auto code = mstore8(0, 0x07); | ||
// 3 values slots | ||
// Modulus size in bytes | ||
// Modulus offset in EVM memory | ||
// Modulus ID | ||
code += setupx(3, 1, 0, 1); | ||
// value 3 | ||
code += mstore8(8, 0x03); | ||
// value 6 | ||
code += mstore8(16, 0x06); | ||
// num values | ||
// values offset | ||
// store values | ||
code += storex(2, 1, 0); | ||
// ADDMODX for values in slots 0 and 1 save result in slot 2 | ||
code += addmodx(2, 1, 0); | ||
// MULMODX for values in slots 1 and 2 save result in slot 2 | ||
code += mulmodx(2, 2, 1); | ||
// SUBMODX for values in slots 1 and 2 save result in slot 2 | ||
code += submodx(2, 2, 1); | ||
// load values from slot 2 into EVM memory | ||
code += loadx(1, 2, 17); | ||
// return loaded result | ||
code += ret(17, 8); | ||
|
||
execute(1000, code); | ||
EXPECT_EQ(result.status_code, EVMC_SUCCESS); | ||
|
||
ASSERT_EQ(result.output_size, 8); | ||
EXPECT_EQ(hex({result.output_data, result.output_size}), "0000000000000006"); | ||
} | ||
|
||
TEST_P(evm, evmmax_2byte_modulus_test) | ||
{ | ||
if (is_advanced()) | ||
return; | ||
|
||
rev = EVMC_PRAGUE; /// TODO: Use EVMC_EVMMAX | ||
// Modulus == 263 (0x0107) | ||
auto code = mstore8(0, 0x01); | ||
code += mstore8(1, 0x07); | ||
// 3 values slots | ||
// Modulus size in bytes | ||
// Modulus offset in EVM memory | ||
// Modulus ID | ||
code += setupx(3, 2, 0, 1); | ||
// value 258 | ||
code += mstore8(8, 0x01); | ||
code += mstore8(9, 0x02); | ||
// value 254 | ||
code += mstore8(16, 0x00); | ||
code += mstore8(17, 0xfe); | ||
// num values | ||
// values offset | ||
// store values | ||
code += storex(2, 2, 0); | ||
// ADDMODX for values in slots 0 and 1 save result in slot 2 | ||
code += addmodx(2, 1, 0); // 258 + 254 = 249 mod 263 | ||
// MULMODX for values in slots 1 and 2 save result in slot 2 | ||
code += mulmodx(2, 2, 1); // 249 * 254 = 126 mod 263 | ||
// SUBMODX for values in slots 1 and 2 save result in slot 2 | ||
code += submodx(2, 2, 1); // 126 - 254 = 135 mod 263 | ||
// load values from slot 2 into EVM memory | ||
code += loadx(1, 2, 18); | ||
// return loaded result | ||
code += ret(18, 8); | ||
|
||
execute(1000, code); | ||
EXPECT_EQ(result.status_code, EVMC_SUCCESS); | ||
|
||
ASSERT_EQ(result.output_size, 8); | ||
EXPECT_EQ(hex({result.output_data, result.output_size}), "0000000000000087"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters