|
| 1 | +// evmone: Fast Ethereum Virtual Machine implementation |
| 2 | +// Copyright 2023 The evmone Authors. |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +#include "evm_fixture.hpp" |
| 6 | +#include "evmone/eof.hpp" |
| 7 | + |
| 8 | +using evmone::test::evm; |
| 9 | +using namespace evmc::literals; |
| 10 | + |
| 11 | +TEST_P(evm, eof1_delegatecall_eof1) |
| 12 | +{ |
| 13 | + rev = EVMC_CANCUN; |
| 14 | + constexpr auto callee = 0xca11ee_address; |
| 15 | + host.accounts[callee].code = eof1_bytecode(OP_STOP); |
| 16 | + bytes call_output{0x01, 0x02, 0x03}; |
| 17 | + host.call_result.output_data = std::data(call_output); |
| 18 | + host.call_result.output_size = std::size(call_output); |
| 19 | + host.call_result.gas_left = 100; |
| 20 | + host.call_result.status_code = EVMC_SUCCESS; |
| 21 | + |
| 22 | + const auto code = eof1_bytecode(delegatecall(callee) + OP_RETURNDATASIZE + OP_PUSH0 + OP_PUSH0 + |
| 23 | + OP_RETURNDATACOPY + ret(0, evmone::OP_RETURNDATASIZE)); |
| 24 | + |
| 25 | + execute(code); |
| 26 | + EXPECT_STATUS(EVMC_SUCCESS); |
| 27 | + EXPECT_EQ(hex({result.output_data, result.output_size}), "010203"); |
| 28 | +} |
| 29 | + |
| 30 | +TEST_P(evm, eof1_delegatecall_legacy) |
| 31 | +{ |
| 32 | + rev = EVMC_CANCUN; |
| 33 | + constexpr auto callee = 0xca11ee_address; |
| 34 | + host.access_account(callee); |
| 35 | + |
| 36 | + for (const auto& target_code : {""_hex, "EF"_hex, "EF01"_hex, "000000"_hex}) |
| 37 | + { |
| 38 | + SCOPED_TRACE("target code: " + hex(target_code)); |
| 39 | + host.accounts[callee].code = target_code; |
| 40 | + |
| 41 | + const auto code = eof1_bytecode(delegatecall(callee) + ret_top()); |
| 42 | + |
| 43 | + execute(code); |
| 44 | + EXPECT_GAS_USED(EVMC_SUCCESS, 133); // Low gas usage because DELEGATECALL fails lightly. |
| 45 | + EXPECT_OUTPUT_INT(0); |
| 46 | + } |
| 47 | +} |
0 commit comments