-
Notifications
You must be signed in to change notification settings - Fork 294
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
14 changed files
with
261 additions
and
4 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
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
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
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
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
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,115 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2022 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "evm_fixture.hpp" | ||
#include <numeric> | ||
|
||
using namespace evmc::literals; | ||
using namespace evmone; | ||
using namespace intx; | ||
using evmone::test::evm; | ||
|
||
|
||
TEST_P(evm, exchange) | ||
{ | ||
// EXCHANGE is not implemented in Advanced. | ||
if (evm::is_advanced()) | ||
return; | ||
|
||
rev = EVMC_PRAGUE; | ||
|
||
auto pushes = bytecode{}; | ||
for (uint64_t i = 1; i <= 20; ++i) | ||
pushes += push(i); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "00" + ret_top(), 21)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(20); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "00" + OP_DUPN + "01" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(18); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "00" + OP_DUPN + "02" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(19); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "01" + ret_top(), 21)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(20); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "01" + OP_DUPN + "01" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(17); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "01" + OP_DUPN + "03" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(19); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "10" + ret_top(), 21)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(20); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "10" + OP_DUPN + "02" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(17); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "10" + OP_DUPN + "03" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(18); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "f2" + ret_top(), 21)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(20); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "f2" + OP_DUPN + "10" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(1); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "f2" + OP_DUPN + "13" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(4); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "0f" + ret_top(), 21)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(20); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "0f" + OP_DUPN + "01" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(3); | ||
|
||
execute(eof_bytecode(pushes + OP_EXCHANGE + "0f" + OP_DUPN + "11" + ret_top(), 22)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(19); | ||
} | ||
|
||
TEST_P(evm, exchange_deep_stack) | ||
{ | ||
// EXCHANGE is not implemented in Advanced. | ||
if (evm::is_advanced()) | ||
return; | ||
|
||
rev = EVMC_PRAGUE; | ||
auto full_stack_code = bytecode{}; | ||
for (uint64_t i = 255; i >= 1; --i) | ||
full_stack_code += push(i); | ||
|
||
execute(eof_bytecode(full_stack_code + OP_EXCHANGE + "ff" + ret_top(), 256)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(1); | ||
execute(eof_bytecode(full_stack_code + OP_EXCHANGE + "ff" + OP_DUPN + "10" + ret_top(), 257)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(33); | ||
execute(eof_bytecode(full_stack_code + OP_EXCHANGE + "ff" + OP_DUPN + "20" + ret_top(), 257)); | ||
EXPECT_STATUS(EVMC_SUCCESS); | ||
EXPECT_OUTPUT_INT(17); | ||
} | ||
|
||
TEST_P(evm, exchange_undefined_in_legacy) | ||
{ | ||
rev = EVMC_PRAGUE; | ||
|
||
execute(push(1) + push(2) + push(3) + OP_EXCHANGE + "00"); | ||
EXPECT_STATUS(EVMC_UNDEFINED_INSTRUCTION); | ||
} |
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,49 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2023 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "../utils/bytecode.hpp" | ||
#include "state_transition.hpp" | ||
|
||
using namespace evmc::literals; | ||
using namespace evmone::test; | ||
|
||
TEST_F(state_transition, dupn) | ||
{ | ||
rev = EVMC_PRAGUE; | ||
tx.to = To; | ||
pre.insert(*tx.to, | ||
{ | ||
.code = eof_bytecode( | ||
push(1) + 255 * push(2) + OP_DUPN + "ff" + sstore(0) + sstore(1) + OP_STOP, 258), | ||
}); | ||
expect.post[*tx.to].storage[0x00_bytes32] = 0x01_bytes32; | ||
expect.post[*tx.to].storage[0x01_bytes32] = 0x02_bytes32; | ||
} | ||
|
||
TEST_F(state_transition, swapn) | ||
{ | ||
rev = EVMC_PRAGUE; | ||
tx.to = To; | ||
pre.insert(*tx.to, | ||
{ | ||
.code = eof_bytecode( | ||
push(1) + 256 * push(2) + OP_SWAPN + "ff" + sstore(0) + sstore(1) + OP_STOP, 258), | ||
}); | ||
expect.post[*tx.to].storage[0x00_bytes32] = 0x01_bytes32; | ||
expect.post[*tx.to].storage[0x01_bytes32] = 0x02_bytes32; | ||
} | ||
|
||
TEST_F(state_transition, exchange) | ||
{ | ||
rev = EVMC_PRAGUE; | ||
tx.to = To; | ||
pre.insert(*tx.to, { | ||
.code = eof_bytecode(push(1) + push(2) + push(3) + OP_EXCHANGE + "00" + | ||
sstore(0) + sstore(1) + sstore(2) + OP_STOP, | ||
4), | ||
}); | ||
expect.post[*tx.to].storage[0x00_bytes32] = 0x03_bytes32; | ||
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32; | ||
expect.post[*tx.to].storage[0x02_bytes32] = 0x02_bytes32; | ||
} |
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