Skip to content
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
[submodule "third_party/glaze"]
path = third_party/glaze
url = https://github.com/stephenberry/glaze
[submodule "third_party/blst"]
path = third_party/blst
url = https://github.com/supranational/blst.git
[submodule "third_party/intx"]
path = third_party/intx
url = https://github.com/chfast/intx.git
Expand Down
13 changes: 7 additions & 6 deletions cmake/copyright.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ file(
LIST_DIRECTORIES false
"cmd/*.?pp" "silkworm/*.?pp"
)
list(FILTER SRC EXCLUDE REGEX "silkworm/core/chain/genesis_[a-z]+\\.cpp\$")
list(FILTER SRC EXCLUDE REGEX "silkworm/core/common/lru_cache(_test)?\\..pp\$")
list(FILTER SRC EXCLUDE REGEX "silkworm/infra/concurrency/thread_pool\\.hpp\$")
list(FILTER SRC EXCLUDE REGEX "silkworm/interfaces/")
list(FILTER SRC EXCLUDE REGEX "silkworm/node/common/preverified_hashes_[a-z]+\\.cpp\$")
list(FILTER SRC EXCLUDE REGEX "silkworm/node/snapshot/config/[a-z_]+.cpp\$")
list(FILTER SRC EXCLUDE REGEX [[silkworm/core/chain/genesis_[a-z]+\.cpp$]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/core/common/lru_cache(_test)?\..pp$]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/core/crypto/kzg\.cpp$]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/infra/concurrency/thread_pool\.hpp$]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/interfaces/]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/node/common/preverified_hashes_[a-z]+\.cpp$]])
list(FILTER SRC EXCLUDE REGEX [[silkworm/node/snapshot/config/[a-z_]+\.cpp$]])

foreach(F IN LISTS SRC)
check("${F}")
Expand Down
2 changes: 2 additions & 0 deletions cmd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ if(NOT SILKWORM_CORE_ONLY)
add_library(cmd_common "${COMMON_SRC}")
target_link_libraries(cmd_common silkworm-buildinfo CLI11::CLI11 silkworm_infra)

add_subdirectory(dev)

# Silkworm components
add_subdirectory(rpcdaemon)

Expand Down
18 changes: 18 additions & 0 deletions cmd/dev/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[[
Copyright 2023 The Silkworm Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]

add_executable(kzg_g2_uncompress kzg_g2_uncompress.cpp)
target_link_libraries(kzg_g2_uncompress silkworm_core blst)
66 changes: 66 additions & 0 deletions cmd/dev/kzg_g2_uncompress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2023 The Silkworm Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <blst.h>

#include <iomanip>
#include <iostream>

#include <silkworm/core/common/assert.hpp>
#include <silkworm/core/common/util.hpp>

// TODO(yperbasis) Switch to std::format when Apple Clang has it
void print_blst_fp(const blst_fp& fp) {
std::cout << "{";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[0] << ", ";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[1] << ", ";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[2] << ", ";
std::cout << "\n ";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[3] << ", ";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[4] << ", ";
std::cout << "0x" << std::setfill('0') << std::setw(16) << std::hex << fp.l[5] << "}";
}

int main() {
using namespace silkworm;

// KZG_SETUP_G2[1], see
// https://github.com/ethereum/consensus-specs/blob/dev/specs/deneb/polynomial-commitments.md#trusted-setup
static const Bytes kKzgSetupG2_1{*from_hex(
"99aca9fb2f7760cecb892bf7262c176b334824f5727f680bba701a33e322cb6667531410dfc7c8e4321a3f0ea8af48cb1436638a2093123f046f0f504cc2a864825542873edbbc5d7ed17af125a4f2cf6433c6f4f61b81173726981dd989761d")};

SILKWORM_ASSERT(kKzgSetupG2_1.length() == 96);

blst_p2_affine g2_affine;
SILKWORM_ASSERT(blst_p2_uncompress(&g2_affine, kKzgSetupG2_1.data()) == BLST_SUCCESS);
blst_p2 out;
blst_p2_from_affine(&out, &g2_affine);

// TODO(C++23) std::print
std::cout << "{{";
print_blst_fp(out.x.fp[0]);
std::cout << ",\n ";
print_blst_fp(out.x.fp[1]);
std::cout << "}},\n{{";
print_blst_fp(out.y.fp[0]);
std::cout << ",\n ";
print_blst_fp(out.y.fp[1]);
std::cout << "}},\n{{";
print_blst_fp(out.z.fp[0]);
std::cout << ",\n ";
print_blst_fp(out.z.fp[1]);
std::cout << "}}" << std::endl;
}
2 changes: 1 addition & 1 deletion cmd/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if(NOT SILKWORM_CORE_ONLY)
endif()
find_package(CLI11 REQUIRED)
add_executable(consensus consensus.cpp)
target_compile_definitions(consensus PRIVATE SILKWORM_CONSENSUS_TEST_DIR="${CMAKE_SOURCE_DIR}/third_party/tests")
target_compile_definitions(consensus PRIVATE SILKWORM_CONSENSUS_TEST_DIR="${SILKWORM_MAIN_DIR}/third_party/tests")
target_link_libraries(consensus PRIVATE silkworm_node evmc::loader CLI11::CLI11)

# BE&KV Tests
Expand Down
2 changes: 1 addition & 1 deletion silkworm/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ set(SILKWORM_CORE_PUBLIC_LIBS
nlohmann_json::nlohmann_json
secp256k1
)
set(SILKWORM_CORE_PRIVATE_LIBS ff)
set(SILKWORM_CORE_PRIVATE_LIBS ff blst)

if(NOT SILKWORM_WASM_API)
if(NOT CONAN_PACKAGE_MANAGER)
Expand Down
5 changes: 5 additions & 0 deletions silkworm/core/common/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>
#include <tuple>
Expand Down Expand Up @@ -67,6 +68,10 @@ class ByteView : public std::basic_string_view<uint8_t> {

constexpr ByteView(const evmc::bytes32& hash) noexcept : ByteView{hash.bytes} {}

template <std::size_t Extent>
constexpr ByteView(std::span<const uint8_t, Extent> span) noexcept
: std::basic_string_view<uint8_t>{span.data(), span.size()} {}

[[nodiscard]] bool is_null() const noexcept { return data() == nullptr; }
};

Expand Down
Loading