Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into GH-1359-prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 16, 2023
2 parents 5148c87 + 949c7c4 commit cd82cd5
Show file tree
Hide file tree
Showing 49 changed files with 2,634 additions and 275 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
[submodule "libraries/cli11/cli11"]
path = libraries/cli11/cli11
url = https://github.com/AntelopeIO/CLI11.git
[submodule "libraries/libfc/libraries/bls12-381"]
path = libraries/libfc/libraries/bls12-381
url = https://github.com/AntelopeIO/bls12-381
[submodule "libraries/boost"]
path = libraries/boost
url = https://github.com/boostorg/boost.git
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ configure_file(libraries/libfc/include/fc/crypto/webauthn_json/license.txt licen
configure_file(libraries/eos-vm/LICENSE licenses/leap/LICENSE.eos-vm COPYONLY)
configure_file(libraries/prometheus/prometheus-cpp/LICENSE licenses/leap/LICENSE.prom COPYONLY)
configure_file(programs/cleos/LICENSE.CLI11 licenses/leap/LICENSE.CLI11 COPYONLY)
configure_file(libraries/libfc/libraries/bls12-381/LICENSE licenses/leap/LICENSE.bls12-381 COPYONLY)

install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/licenses/leap" DESTINATION "${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/" COMPONENT base)

Expand Down
2 changes: 2 additions & 0 deletions CMakeModules/EosioTester.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ find_library(libchain eosio_chain @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libfc fc @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libsecp256k1 secp256k1 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libbn256 bn256 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libbls12-381 bls12-381 @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)

find_library(libwasm WASM @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libwast WAST @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
Expand Down Expand Up @@ -82,6 +83,7 @@ macro(add_eosio_test_executable test_name)
${libbuiltins}
${libsecp256k1}
${libbn256}
${libbls12-381}
@GMP_LIBRARY@

Boost::date_time
Expand Down
2 changes: 2 additions & 0 deletions CMakeModules/EosioTesterBuild.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ find_library(libchain eosio_chain @CMAKE_BINARY_DIR@/libraries/chain NO_DEFAULT_
find_library(libfc fc @CMAKE_BINARY_DIR@/libraries/libfc NO_DEFAULT_PATH)
find_library(libsecp256k1 secp256k1 @CMAKE_BINARY_DIR@/libraries/libfc/secp256k1 NO_DEFAULT_PATH)
find_library(libbn256 bn256 @CMAKE_BINARY_DIR@/libraries/libfc/libraries/bn256/src NO_DEFAULT_PATH)
find_library(libbls12-381 bls12-381 @CMAKE_BINARY_DIR@/libraries/libfc/libraries/bls12-381 NO_DEFAULT_PATH)

find_library(libwasm WASM @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WASM NO_DEFAULT_PATH)
find_library(libwast WAST @CMAKE_BINARY_DIR@/libraries/wasm-jit/Source/WAST NO_DEFAULT_PATH)
Expand Down Expand Up @@ -79,6 +80,7 @@ macro(add_eosio_test_executable test_name)
${libbuiltins}
${libsecp256k1}
${libbn256}
${libbls12-381}
@GMP_LIBRARY@

Boost::date_time
Expand Down
2 changes: 1 addition & 1 deletion libraries/boost
Submodule boost updated 86 files
+5 −3 .circleci/config.yml
+5 −0 .gitmodules
+1 −1 CMakeLists.txt
+1 −1 Jamroot
+1 −1 boost-build.jam
+9 −6 boostcpp.jam
+2 −2 doc/test/HTML4_symbols.qbk
+1 −1 doc/test/gold/document_to_test_formatting/images.html
+2 −2 doc/test/gold/document_to_test_formatting/remez.html
+1 −1 doc/test/gold/index.html
+2 −2 doc/test/remez.qbk
+2 −2 doc/test/test.qbk
+1 −1 doc/test/test_HTML4_symbols.qbk
+1 −1 libs/accumulators
+1 −1 libs/algorithm
+1 −1 libs/any
+1 −1 libs/asio
+1 −1 libs/assert
+1 −1 libs/atomic
+1 −1 libs/beast
+1 −1 libs/bind
+1 −1 libs/chrono
+1 −0 libs/compat
+1 −1 libs/config
+1 −1 libs/container_hash
+1 −1 libs/context
+1 −1 libs/conversion
+1 −1 libs/core
+1 −1 libs/describe
+1 −1 libs/detail
+1 −1 libs/dll
+1 −1 libs/endian
+1 −1 libs/exception
+1 −1 libs/filesystem
+1 −1 libs/flyweight
+1 −1 libs/function
+1 −1 libs/functional
+1 −1 libs/fusion
+1 −1 libs/geometry
+1 −1 libs/histogram
+1 −1 libs/integer
+1 −1 libs/iterator
+1 −1 libs/json
+1 −1 libs/lambda2
+1 −1 libs/lexical_cast
+1 −1 libs/locale
+1 −1 libs/log
+2 −1 libs/maintainers.txt
+1 −1 libs/math
+1 −1 libs/mp11
+1 −1 libs/mpi
+1 −1 libs/mpl
+1 −1 libs/multi_index
+1 −1 libs/multiprecision
+1 −1 libs/mysql
+1 −1 libs/nowide
+1 −1 libs/optional
+1 −1 libs/outcome
+1 −1 libs/parameter
+1 −1 libs/pool
+1 −1 libs/process
+1 −1 libs/qvm
+1 −1 libs/ratio
+1 −1 libs/signals2
+1 −1 libs/smart_ptr
+1 −1 libs/spirit
+1 −1 libs/stacktrace
+1 −1 libs/stl_interfaces
+1 −1 libs/system
+1 −1 libs/test
+1 −1 libs/throw_exception
+1 −1 libs/timer
+1 −1 libs/type_erasure
+1 −1 libs/type_index
+1 −1 libs/typeof
+1 −1 libs/unordered
+1 −1 libs/url
+1 −1 libs/utility
+1 −1 libs/uuid
+1 −1 libs/variant
+1 −1 libs/variant2
+1 −1 more
+35 −11 status/explicit-failures-markup.xml
+1 −1 tools/boost_install
+1 −1 tools/build
+1 −1 tools/docca
18 changes: 18 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <fc/log/logger_config.hpp>
#include <fc/scoped_exit.hpp>
#include <fc/variant_object.hpp>
#include <bls12-381/bls12-381.hpp>

#include <new>
#include <shared_mutex>
Expand Down Expand Up @@ -338,6 +339,7 @@ struct controller_impl {
set_activation_handler<builtin_protocol_feature_t::get_code_hash>();
set_activation_handler<builtin_protocol_feature_t::get_block_num>();
set_activation_handler<builtin_protocol_feature_t::crypto_primitives>();
set_activation_handler<builtin_protocol_feature_t::bls_primitives>();

self.irreversible_block.connect([this](const block_state_ptr& bsp) {
wasm_if_collect.current_lib(bsp->block_num);
Expand Down Expand Up @@ -3822,6 +3824,22 @@ void controller_impl::on_activation<builtin_protocol_feature_t::crypto_primitive
} );
}

template<>
void controller_impl::on_activation<builtin_protocol_feature_t::bls_primitives>() {
db.modify( db.get<protocol_state_object>(), [&]( auto& ps ) {
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g1_add" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g2_add" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g1_mul" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g2_mul" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g1_exp" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g2_exp" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_pairing" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g1_map" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_g2_map" );
add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "bls_fp_mod" );
} );
}

/// End of protocol feature activation handlers

} } /// eosio::chain
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum class builtin_protocol_feature_t : uint32_t {
configurable_wasm_limits = 18, // configurable_wasm_limits2,
crypto_primitives = 19,
get_block_num = 20,
bls_primitives = 21,
reserved_private_fork_protocol_features = 500000,
};

Expand Down
1 change: 0 additions & 1 deletion libraries/chain/include/eosio/chain/transaction_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ namespace eosio { namespace chain {
>
>;

typedef chainbase::generic_index<transaction_multi_index> transaction_index;
} }

CHAINBASE_SET_INDEX_TYPE(eosio::chain::transaction_object, eosio::chain::transaction_multi_index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class eosvmoc_runtime : public eosio::chain::wasm_runtime_interface {

// Defined in eos-vm-oc.cpp. Used for non-main thread in multi-threaded execution
thread_local static std::unique_ptr<eosvmoc::executor> exec_thread_local;
thread_local static eosvmoc::memory mem_thread_local;
thread_local static std::unique_ptr<eosvmoc::memory> mem_thread_local;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,17 @@ inline constexpr auto get_intrinsic_table() {
"env.sha3",
"env.blake2_f",
"env.k1_recover",
"env.get_block_num"
"env.get_block_num",
"env.bls_g1_add",
"env.bls_g2_add",
"env.bls_g1_mul",
"env.bls_g2_mul",
"env.bls_g1_exp",
"env.bls_g2_exp",
"env.bls_pairing",
"env.bls_g1_map",
"env.bls_g2_map",
"env.bls_fp_mod"
);
}
inline constexpr std::size_t find_intrinsic_index(std::string_view hf) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class memory {
static constexpr uintptr_t first_intrinsic_offset = cb_offset + 8u;
// The maximum amount of data that PIC code can include in the prologue
static constexpr uintptr_t max_prologue_size = mutable_global_size + table_size;
// Number of slices for read-only threads.
// Use a small number to save upfront virtual memory consumption.
// Memory uses beyond this limit will be handled by mprotect.
static constexpr uint32_t sliced_pages_for_ro_thread = 10;

// Changed from -cb_offset == EOS_VM_OC_CONTROL_BLOCK_OFFSET to get around
// of compile warning about comparing integers of different signedness
Expand Down
111 changes: 111 additions & 0 deletions libraries/chain/include/eosio/chain/webassembly/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,117 @@ namespace webassembly {
*/
int32_t k1_recover( span<const char> signature, span<const char> digest, span<char> pub) const;

/**
* Host function for G1 addition on the elliptic curve bls12-381
*
* @ingroup crypto
* @param op1 - a span containing the first operand G1 point.
* @param op2 - a span containing the second operand G1 point.
* @param[out] result - the result op1 + op2.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_add(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G2 addition on the elliptic curve bls12-381
*
* @ingroup crypto
* @param op1 - a span containing the first operand G2 point.
* @param op2 - a span containing the second operand G2 point.
* @param[out] result - the result op1 + op2.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_add(span<const char> op1, span<const char> op2, span<char> result) const;

/**
* Host function for G1 scalar multiplication on the elliptic curve bls12-381
*
* @ingroup crypto
* @param point - a span containing the G1 point operand.
* @param scalar - a span containing the scalar operand.
* @param[out] result - the result: scalar * point.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_mul(span<const char> point, span<const char> scalar, span<char> result) const;

/**
* Host function for G2 scalar multiplication on the elliptic curve bls12-381
*
* @ingroup crypto
* @param point - a span containing the G2 point operand.
* @param scalar - a span containing the scalar operand.
* @param[out] result - the result op1 * op2.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_mul(span<const char> point, span<const char> scalar, span<char> result) const;

/**
* Host function for G1 multi-exponentiation on the elliptic curve bls12-381
*
* @ingroup crypto
* @param points - a span containing a list of G1 points (P0, P1, P2... Pn).
* @param scalars - a span containing a list of scalars (s0, s1, s2... sn).
* @param n - the number of elements in the lists.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_exp(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function for G2 multi-exponentiation on the elliptic curve bls12-381
*
* @ingroup crypto
* @param points - a span containing a list of G2 points (P0, P1, P2... Pn).
* @param scalars - a span containing a list of scalars (s0, s1, s2... sn).
* @param n - the number of elements in the lists.
* @param[out] result - the result s0 * P0 + s1 * P1 + ... + sn * Pn.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_exp(span<const char> points, span<const char> scalars, const uint32_t n, span<char> result) const;

/**
* Host function to calculate the pairing of (G1, G2) pairs on the elliptic curve bls12-381
*
* @ingroup crypto
* @param g1_points - a span containing a list of G1 points (P0, P1, P2... Pn).
* @param g2_points - a span containing a list of G2 points (P0, P1, P2... Pn).
* @param n - the number of elements in the lists.
* @param[out] result - the result e(g1_0, g2_0) * e(g1_1, g2_1) * ... * e(g1_n, g2_n)
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_pairing(span<const char> g1_points, span<const char> g2_points, const uint32_t n, span<char> result) const;

/**
* Host function for mapping fp to G1 on the elliptic curve bls12-381
*
* @ingroup crypto
* @param e - a span containing the field element fp to be mapped.
* @param[out] result - the resulting element in G1.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g1_map(span<const char> e, span<char> result) const;

/**
* Host function for mapping fp2 to G2 on the elliptic curve bls12-381
*
* @ingroup crypto
* @param e - a span containing the field element fp2 to be mapped.
* @param[out] result - the resulting element in G2.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_g2_map(span<const char> e, span<char> result) const;

/**
* Host function for modular reduction of 64 bytes wide scalar to a field element (fp, 48 bytes) of the elliptic curve bls12-381
* Involves Montgomery conversion on the resulting field element.
*
* @ingroup crypto
* @param s - a span containing the 64 bytes wide scalar to be reduced.
* @param[out] result - the resulting field element fp in Montogomery form.
* @return -1 if there was an error 0 otherwise
*/
int32_t bls_fp_mod(span<const char> s, span<char> result) const;

// compiler builtins api
void __ashlti3(legacy_ptr<int128_t>, uint64_t, uint64_t, uint32_t) const;
void __ashrti3(legacy_ptr<int128_t>, uint64_t, uint64_t, uint32_t) const;
Expand Down
11 changes: 11 additions & 0 deletions libraries/chain/protocol_feature_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ Adds new cryptographic host functions
Builtin protocol feature: GET_BLOCK_NUM
Enables new `get_block_num` intrinsic which returns the current block number.
*/
{}
} )
( builtin_protocol_feature_t::bls_primitives, builtin_protocol_feature_spec{
"BLS_PRIMITIVES",
fc::variant("01969c44de35999b924095ae7f50081a7f274409fdbccb9fc54fa7836c76089c").as<digest_type>(),
// SHA256 hash of the raw message below within the comment delimiters (do not modify message below).
/*
Builtin protocol feature: BLS_PRIMITIVES
Adds new cryptographic host functions
- Add, multiply, multi-exponentiation and pairing functions for the bls12-381 elliptic curve.
*/
{}
} )
Expand Down
15 changes: 9 additions & 6 deletions libraries/chain/wasm_interface_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ namespace eosio::chain {

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
struct eosvmoc_tier {
// Called from main thread
eosvmoc_tier(const std::filesystem::path& d, const eosvmoc::config& c, const chainbase::database& db)
: cc(d, c, db) {
// construct exec for the main thread
init_thread_local_data();
// Construct exec and mem for the main thread
exec = std::make_unique<eosvmoc::executor>(cc);
mem = std::make_unique<eosvmoc::memory>(wasm_constraints::maximum_linear_memory/wasm_constraints::wasm_page_size);
}

// Support multi-threaded execution.
// Called from read-only threads
void init_thread_local_data() {
exec = std::make_unique<eosvmoc::executor>(cc);
mem = std::make_unique<eosvmoc::memory>(eosvmoc::memory::sliced_pages_for_ro_thread);
}

eosvmoc::code_cache_async cc;

// Each thread requires its own exec and mem.
thread_local static std::unique_ptr<eosvmoc::executor> exec;
thread_local static eosvmoc::memory mem;
thread_local static std::unique_ptr<eosvmoc::memory> mem;
};

thread_local std::unique_ptr<eosvmoc::executor> eosvmoc_tier::exec{};
thread_local eosvmoc::memory eosvmoc_tier::mem{wasm_constraints::maximum_linear_memory / wasm_constraints::wasm_page_size};
thread_local std::unique_ptr<eosvmoc::memory> eosvmoc_tier::mem{};
#endif

wasm_interface_collection::wasm_interface_collection(wasm_interface::vm_type vm, wasm_interface::vm_oc_enable eosvmoc_tierup,
Expand Down Expand Up @@ -71,7 +74,7 @@ void wasm_interface_collection::apply(const digest_type& code_hash, const uint8_
if (cd) {
if (!context.is_applying_block()) // read_only_trx_test.py looks for this log statement
tlog("${a} speculatively executing ${h} with eos vm oc", ("a", context.get_receiver())("h", code_hash));
eosvmoc->exec->execute(*cd, eosvmoc->mem, context);
eosvmoc->exec->execute(*cd, *eosvmoc->mem, context);
return;
}
}
Expand Down
Loading

0 comments on commit cd82cd5

Please sign in to comment.