-
Notifications
You must be signed in to change notification settings - Fork 293
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
Implement EXCHANGE from EIP-663 #839
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dividing line between this and the
evm_...
test still evades me.My rationale was convenience mostly - this test here only tests basic cases, mostly to ensure different EVMs have the same understanding of the meaning of the arguments. The
evm_...
test is more manageable and as such contains more cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are not needed in this case unless you want to export them to JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, my thinking was exactly - export to JSON