Skip to content

Commit

Permalink
t8n: Include empty requests[Hash] in JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Oct 29, 2024
1 parent 884db23 commit 5a3e47f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ find_package(intx CONFIG REQUIRED)
add_subdirectory(evmmax)
add_subdirectory(evmone)
add_subdirectory(evmone_precompiles)
add_subdirectory(crypto)
13 changes: 13 additions & 0 deletions lib/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# evmone: Fast Ethereum Virtual Machine implementation
# Copyright 2024 The evmone Authors.
# SPDX-License-Identifier: Apache-2.0

add_library(crypto STATIC)
add_library(evmone::crypto ALIAS crypto)
target_compile_features(crypto PRIVATE cxx_std_20)
target_link_libraries(crypto PUBLIC evmc::evmc_cpp)
target_sources(
crypto PRIVATE
sha256.hpp
sha256.cpp
)
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions lib/evmone_precompiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ target_sources(
ripemd160.cpp
secp256k1.hpp
secp256k1.cpp
sha256.hpp
sha256.cpp
kzg.hpp
kzg.cpp
)
2 changes: 1 addition & 1 deletion lib/evmone_precompiles/kzg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#include "sha256.hpp"
#include "../crypto/sha256.hpp"
#include <intx/intx.hpp>

namespace evmone::crypto
Expand Down
2 changes: 1 addition & 1 deletion test/state/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

add_library(evmone-state STATIC)
add_library(evmone::state ALIAS evmone-state)
target_link_libraries(evmone-state PUBLIC evmc::evmc_cpp PRIVATE evmone evmone::precompiles ethash::keccak)
target_link_libraries(evmone-state PUBLIC evmc::evmc_cpp PRIVATE evmone evmone::precompiles ethash::keccak evmone::crypto)
target_include_directories(evmone-state PRIVATE ${evmone_private_include_dir})
target_sources(
evmone-state PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include "precompiles.hpp"
#include "precompiles_internal.hpp"
#include "precompiles_stubs.hpp"
#include <crypto/sha256.hpp>
#include <evmone_precompiles/blake2b.hpp>
#include <evmone_precompiles/bls.hpp>
#include <evmone_precompiles/bn254.hpp>
#include <evmone_precompiles/kzg.hpp>
#include <evmone_precompiles/ripemd160.hpp>
#include <evmone_precompiles/secp256k1.hpp>
#include <evmone_precompiles/sha256.hpp>
#include <intx/intx.hpp>
#include <array>
#include <bit>
Expand Down
34 changes: 33 additions & 1 deletion test/t8n/t8n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "../lib/crypto/sha256.hpp"
#include "../state/errors.hpp"
#include "../state/ethash_difficulty.hpp"
#include "../state/mpt_hash.hpp"
Expand Down Expand Up @@ -241,7 +242,38 @@ 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.
uint8_t withdrawals[1] = {0x00};
uint8_t deposits[1] = {0x01};
uint8_t consolidations[1] = {0x02};
j_result["requests"][0] = hex0x(evmc::bytes{});
j_result["requests"][1] = hex0x(evmc::bytes{});
j_result["requests"][2] = hex0x(evmc::bytes{});

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<std::byte*>(withdrawals), 1);
crypto::sha256(reinterpret_cast<std::byte*>(deposits_hash),
reinterpret_cast<std::byte*>(deposits), 1);
crypto::sha256(reinterpret_cast<std::byte*>(consolidations_hash),
reinterpret_cast<std::byte*>(consolidations), 1);

uint8_t buffer[3 * crypto::SHA256_HASH_SIZE];
{
auto it = std::begin(buffer);
it = std::copy_n(withdrawals_hash, 32, it);
it = std::copy_n(deposits_hash, 32, it);
std::copy_n(consolidations_hash, 32, 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);
}

std::ofstream{output_dir / output_result_file} << std::setw(2) << j_result;
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/precompiles_kzg_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright 2024 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <crypto/sha256.hpp>
#include <evmc/evmc.hpp>
#include <evmone_precompiles/kzg.hpp>
#include <evmone_precompiles/sha256.hpp>
#include <gtest/gtest.h>
#include <intx/intx.hpp>
#include <span>
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/precompiles_sha256_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Copyright 2024 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include <crypto/sha256.hpp>
#include <evmc/hex.hpp>
#include <evmone_precompiles/sha256.hpp>
#include <gtest/gtest.h>

using evmone::crypto::sha256;
Expand Down

0 comments on commit 5a3e47f

Please sign in to comment.