-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CALLF and RETF EOF instructions specified by EIP-4750 EOF Functions (https://eips.ethereum.org/EIPS/eip-4750). Co-authored-by: Andrei Maiboroda <andrei@ethereum.org>
- Loading branch information
Showing
11 changed files
with
99 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2022 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "evm_fixture.hpp" | ||
#include "evmone/eof.hpp" | ||
|
||
using evmone::test::evm; | ||
|
||
TEST_P(evm, eof_function_example1) | ||
{ | ||
// Relative jumps are not implemented in Advanced. | ||
if (is_advanced()) | ||
return; | ||
|
||
rev = EVMC_CANCUN; | ||
const auto code = | ||
"EF00 01 010008 020002 000f 0002 030000 00" | ||
"00000002 02010002" | ||
"6001 6008 b00001 " + | ||
ret_top() + "03b1"; | ||
|
||
ASSERT_EQ((int)evmone::validate_eof(rev, code), (int)evmone::EOFValidationError{}); | ||
|
||
execute(code); | ||
EXPECT_GAS_USED(EVMC_SUCCESS, 32); | ||
EXPECT_OUTPUT_INT(7); | ||
} | ||
|
||
TEST_P(evm, eof_function_example2) | ||
{ | ||
// Relative jumps are not implemented in Advanced. | ||
if (is_advanced()) | ||
return; | ||
|
||
rev = EVMC_CANCUN; | ||
const auto code = | ||
"ef0001 01000c 020003 003b 0017 001d 030000 00 00000004 01010003 01010004" | ||
"60043560003560e01c63c766526781145d001c63c6c2ea1781145d00065050600080fd50b00002600052602060" | ||
"00f350b0000160005260206000f3" | ||
"600181115d0004506001b160018103b0000181029050b1" | ||
"600281115d0004506001b160028103b0000260018203b00002019050b1"_hex; | ||
|
||
ASSERT_EQ((int)evmone::validate_eof(rev, code), (int)evmone::EOFValidationError{}); | ||
|
||
// Call fac(5) | ||
const auto calldata_fac = | ||
"c76652670000000000000000000000000000000000000000000000000000000000000005"_hex; | ||
execute(bytecode{code}, calldata_fac); | ||
EXPECT_GAS_USED(EVMC_SUCCESS, 246); | ||
EXPECT_EQ(output, "0000000000000000000000000000000000000000000000000000000000000078"_hex); | ||
|
||
// Call fib(15) | ||
const auto calldata_fib = | ||
"c6c2ea17000000000000000000000000000000000000000000000000000000000000000f"_hex; | ||
execute(bytecode{code}, calldata_fib); | ||
EXPECT_GAS_USED(EVMC_SUCCESS, 44544); | ||
EXPECT_EQ(output, "0000000000000000000000000000000000000000000000000000000000000262"_hex); | ||
} |
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