Skip to content
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

t8n: Include empty requests[Hash] in JSON output #1064

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions test/integration/t8n/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,38 @@ set_tests_properties(
FIXTURES_CLEANUP ${TEST_CASE}
PASS_REGULAR_EXPRESSION ${EXPECTED_OUT_ALLOC}
)

set(TEST_CASE prague_empty_requests)

add_test(
NAME ${PREFIX}/${TEST_CASE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_CASE}
COMMAND
evmone-t8n
--state.fork Prague
--state.reward 0
--state.chainid 1
--input.alloc alloc.json
--input.txs txs.json
--input.env env.json
--output.basedir ${CMAKE_CURRENT_BINARY_DIR}/${TEST_CASE}
--output.result out.json
)
set_tests_properties(${PREFIX}/${TEST_CASE} PROPERTIES FIXTURES_REQUIRED ${TEST_CASE})

add_test(
NAME ${PREFIX}/${TEST_CASE}/out.json
COMMAND ${CMAKE_COMMAND} -E cat ${CMAKE_CURRENT_BINARY_DIR}/${TEST_CASE}/out.json
)
string(
JOIN ".*" EXPECTED_OUT
# empty requests list of exactly 3 elements (withdrawals, deposits, consolidations)
[=["requests": \[[^],]*"0x",[^],]*"0x",[^],]*"0x"[^,]*\]]=]
# requests hash should be present
[=["requestsHash": "0x6036c41849da9c076ed79654d434017387a88fb833c2856b32e18218b3341c5f"]=]
)
set_tests_properties(
${PREFIX}/${TEST_CASE}/out.json PROPERTIES
FIXTURES_CLEANUP ${TEST_CASE}
PASS_REGULAR_EXPRESSION ${EXPECTED_OUT}
)
7 changes: 7 additions & 0 deletions test/integration/t8n/prague_empty_requests/alloc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"code": "",
"nonce": "0x00",
"balance": "0x02540be400"
}
}
6 changes: 6 additions & 0 deletions test/integration/t8n/prague_empty_requests/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"currentCoinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"currentNumber": "0x01",
"currentTimestamp": "0x54c99069",
"currentGasLimit": "0x2fefd8"
}
15 changes: 15 additions & 0 deletions test/integration/t8n/prague_empty_requests/txs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"to": null,
"input": "0x",
"gas": "0x186a0",
"nonce": "0x0",
"value": "0x0",
"gasPrice": "0x32",
"chainId": "0x1",
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"v": "0x1b",
"r": "0x468a915f087692bb9be503831a3dfef2cf9c8dee26deb40ff2ec99e8d22665ae",
"s": "0x5cedae0810c3851ecd1004bfdbfe6ddc7753c2d665993bb01ce75af7857b13dc"
}
]
1 change: 1 addition & 0 deletions test/t8n/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ cable_add_buildinfo_library(PROJECT_NAME evmone)
add_executable(evmone-t8n)
target_link_libraries(evmone-t8n PRIVATE evmone::statetestutils nlohmann_json::nlohmann_json)
target_link_libraries(evmone-t8n PRIVATE evmc::evmc evmone evmone-buildinfo)
target_include_directories(evmone-t8n PRIVATE ${evmone_private_include_dir})
target_sources(evmone-t8n PRIVATE t8n.cpp)
35 changes: 34 additions & 1 deletion test/t8n/t8n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../utils/utils.hpp"
#include <evmone/evmone.h>
#include <evmone/version.h>
#include <evmone_precompiles/sha256.hpp>
#include <nlohmann/json.hpp>
#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -241,7 +242,39 @@ int main(int argc, const char* argv[])
if (rev >= EVMC_PRAGUE)
{
// EIP-7685: General purpose execution layer requests
j_result["requestsRoot"] = hex0x(state::EMPTY_MPT_HASH);
j_result["requests"] = json::json::array();
// TODO: actual requests should be used in the following lines, for now all empty.
const uint8_t withdrawals[1] = {0x00};
pdobacz marked this conversation as resolved.
Show resolved Hide resolved
const uint8_t deposits[1] = {0x01};
const uint8_t consolidations[1] = {0x02};
j_result["requests"][0] = "0x";
j_result["requests"][1] = "0x";
j_result["requests"][2] = "0x";

uint8_t withdrawals_hash[crypto::SHA256_HASH_SIZE];
uint8_t deposits_hash[crypto::SHA256_HASH_SIZE];
uint8_t consolidations_hash[crypto::SHA256_HASH_SIZE];

crypto::sha256(reinterpret_cast<std::byte*>(withdrawals_hash),
reinterpret_cast<const std::byte*>(withdrawals), 1);
crypto::sha256(reinterpret_cast<std::byte*>(deposits_hash),
reinterpret_cast<const std::byte*>(deposits), 1);
crypto::sha256(reinterpret_cast<std::byte*>(consolidations_hash),
reinterpret_cast<const std::byte*>(consolidations), 1);

uint8_t buffer[3 * crypto::SHA256_HASH_SIZE];
{
auto it = std::begin(buffer);
it = std::copy_n(withdrawals_hash, crypto::SHA256_HASH_SIZE, it);
it = std::copy_n(deposits_hash, crypto::SHA256_HASH_SIZE, it);
std::copy_n(consolidations_hash, crypto::SHA256_HASH_SIZE, it);
}

uint8_t requests_hash[crypto::SHA256_HASH_SIZE];
crypto::sha256(reinterpret_cast<std::byte*>(requests_hash),
reinterpret_cast<const std::byte*>(buffer), 3 * crypto::SHA256_HASH_SIZE);

j_result["requestsHash"] = hex0x({requests_hash, 32});
}

std::ofstream{output_dir / output_result_file} << std::setw(2) << j_result;
Expand Down