Skip to content

Commit

Permalink
Merge branch 'main' into plugin_http_api_test_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 authored Aug 3, 2022
2 parents dd3b6a1 + d2d7996 commit 5c698bb
Show file tree
Hide file tree
Showing 54 changed files with 194 additions and 431 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testnet.template ${CMAKE_CURRENT_BINA
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/eosio.version.in ${CMAKE_CURRENT_BINARY_DIR}/eosio.version.hpp)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eosio.version.hpp DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} COMPONENT dev EXCLUDE_FROM_ALL)

set(EOS_ROOT_DIR ${CMAKE_BINARY_DIR})
set(EOS_ROOT_DIR "${CMAKE_BINARY_DIR}/lib")
configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/eosio-config.cmake.in ${CMAKE_BINARY_DIR}/lib/cmake/eosio/eosio-config.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/eosio-config.cmake.in ${CMAKE_BINARY_DIR}/lib/cmake/eosio/mandel-config.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/EosioTesterBuild.cmake.in ${CMAKE_BINARY_DIR}/lib/cmake/eosio/EosioTester.cmake @ONLY)

set(EOS_ROOT_DIR ${CMAKE_INSTALL_PREFIX})
set(EOS_ROOT_DIR "${CMAKE_INSTALL_FULL_LIBDIR}")
configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/eosio-config.cmake.in ${CMAKE_BINARY_DIR}/modules/eosio-config.cmake @ONLY)
configure_file(${CMAKE_SOURCE_DIR}/CMakeModules/eosio-config.cmake.in ${CMAKE_BINARY_DIR}/modules/mandel-config.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/modules/eosio-config.cmake DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/eosio COMPONENT dev EXCLUDE_FROM_ALL)
Expand Down
30 changes: 15 additions & 15 deletions CMakeModules/EosioTester.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,29 @@ find_package(Boost @Boost_MAJOR_VERSION@.@Boost_MINOR_VERSION@ EXACT REQUIRED CO
iostreams
unit_test_framework)

find_library(libtester eosio_testing @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libchain eosio_chain @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libtester eosio_testing @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libchain eosio_chain @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
find_library(libfc fc_debug @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libsecp256k1 secp256k1_debug @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libfc fc_debug @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libsecp256k1 secp256k1_debug @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
else()
find_library(libfc fc @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libsecp256k1 secp256k1 @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib 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)
endif()

find_library(libff ff @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libwasm WASM @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libwast WAST @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libir IR @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(liblogging Logging @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libruntime Runtime @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libsoftfloat softfloat @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libff ff @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)
find_library(libir IR @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(liblogging Logging @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libruntime Runtime @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libsoftfloat softfloat @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
get_filename_component(cryptodir @OPENSSL_CRYPTO_LIBRARY@ DIRECTORY)
find_library(liboscrypto crypto "${cryptodir}" NO_DEFAULT_PATH)
get_filename_component(ssldir @OPENSSL_SSL_LIBRARY@ DIRECTORY)
find_library(libosssl ssl "${ssldir}" NO_DEFAULT_PATH)
find_library(libchainbase chainbase @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libbuiltins builtins @CMAKE_INSTALL_PREFIX@/lib64 @CMAKE_INSTALL_PREFIX@/lib NO_DEFAULT_PATH)
find_library(libchainbase chainbase @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)
find_library(libbuiltins builtins @CMAKE_INSTALL_FULL_LIBDIR@ NO_DEFAULT_PATH)

#Ubuntu build requires rt library to be specified explicitly
if(UNIX AND NOT APPLE)
Expand Down
10 changes: 6 additions & 4 deletions CMakeModules/eosio-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
if(EOSIO_ROOT STREQUAL "" OR NOT EOSIO_ROOT)
set(EOSIO_ROOT "@EOS_ROOT_DIR@")
if(NOT EOSIO_ROOT)
list(APPEND CMAKE_MODULE_PATH @EOS_ROOT_DIR@/cmake/eosio)
else()
# legacy behavior for anyone configuring with -DEOSIO_ROOT=/foo or such
list(APPEND CMAKE_MODULE_PATH ${EOSIO_ROOT}/lib/cmake/eosio)
list(APPEND CMAKE_MODULE_PATH ${EOSIO_ROOT}/lib64/cmake/eosio)
endif()
list(APPEND CMAKE_MODULE_PATH ${EOSIO_ROOT}/lib/cmake/eosio)
list(APPEND CMAKE_MODULE_PATH ${EOSIO_ROOT}/lib64/cmake/eosio)
include(EosioTester)

function(EXTRACT_MAJOR_MINOR_FROM_VERSION version success major minor)
Expand Down
6 changes: 3 additions & 3 deletions libraries/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ target_include_directories( builtins PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}"
install ( TARGETS
builtins

RUNTIME DESTINATION bin COMPONENT dev EXCLUDE_FROM_ALL
LIBRARY DESTINATION lib COMPONENT dev EXCLUDE_FROM_ALL
ARCHIVE DESTINATION lib COMPONENT dev EXCLUDE_FROM_ALL
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT dev EXCLUDE_FROM_ALL
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR} COMPONENT dev EXCLUDE_FROM_ALL
)
4 changes: 1 addition & 3 deletions libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
#include <boost/algorithm/string/predicate.hpp>
#include <fc/io/varint.hpp>

using namespace boost;


namespace eosio { namespace chain {

const size_t abi_serializer::max_recursion_depth;

using boost::algorithm::starts_with;
using boost::algorithm::ends_with;
using std::string;
using std::string_view;
Expand Down
10 changes: 5 additions & 5 deletions libraries/chain/include/eosio/chain/webassembly/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ namespace webassembly {

/**
* Find the table row in a secondary 64-bit integer index table that matches the lowerbound condition for a given secondary key.
* Lowerbound secondary index is the first secondary index which key is <= the given secondary index key.
* Lowerbound secondary index is the first secondary index which key is >= the given secondary index key.
*
* @ingroup database uint64_t-secondary-index
* @param code - the name of the owner of the table.
Expand Down Expand Up @@ -1095,7 +1095,7 @@ namespace webassembly {

/**
* Find the table row in a secondary 128-bit integer index table that matches the lowerbound condition for a given secondary key.
* Lowerbound secondary index is the first secondary index which key is <= the given secondary index key.
* Lowerbound secondary index is the first secondary index which key is >= the given secondary index key.
*
* @ingroup database uint128_t-secondary-index
* @param code - the name of the owner of the table.
Expand Down Expand Up @@ -1236,7 +1236,7 @@ namespace webassembly {

/**
* Find the table row in a secondary 256-bit integer index table that matches the lowerbound condition for a given secondary key.
* Lowerbound secondary index is the first secondary index which key is <= the given secondary index key.
* Lowerbound secondary index is the first secondary index which key is >= the given secondary index key.
*
* @ingroup database 256-bit-secondary-index
* @param code - the name of the owner of the table.
Expand Down Expand Up @@ -1380,7 +1380,7 @@ namespace webassembly {

/**
* Find the table row in a secondary double-precision floating-point index table that matches the lowerbound condition for a given secondary key.
* Lowerbound secondary index is the first secondary index which key is <= the given secondary index key.
* Lowerbound secondary index is the first secondary index which key is >= the given secondary index key.
*
* @ingroup database double-secondary-index
* @param code - the name of the owner of the table.
Expand Down Expand Up @@ -1524,7 +1524,7 @@ namespace webassembly {

/**
* Find the table row in a secondary quadruple-precision floating-point index table that matches the lowerbound condition for a given secondary key.
* Lowerbound secondary index is the first secondary index which key is <= the given secondary index key.
* Lowerbound secondary index is the first secondary index which key is >= the given secondary index key.
*
* @ingroup database long-double-secondary-index
* @param code - the name of the owner of the table.
Expand Down
8 changes: 8 additions & 0 deletions libraries/chain/webassembly/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ namespace eosio { namespace chain { namespace webassembly {
span<const char> exp,
span<const char> modulus,
span<char> out) const {
if (context.control.is_producing_block()) {
static constexpr int byte_size_limit = 256; // Allow up to 2048-bit values for base, exp, and modulus.

if (std::max(std::max(base.size(), exp.size()), modulus.size()) > byte_size_limit) {
EOS_THROW(subjective_block_production_exception, "Bit size too large for values passed into mod_exp");
}
}

bytes bbase(base.data(), base.data() + base.size());
bytes bexp(exp.data(), exp.data() + exp.size());
bytes bmod(modulus.data(), modulus.data() + modulus.size());
Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
3 changes: 3 additions & 0 deletions libraries/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ configure_file(contracts.hpp.in include/testing_contracts/contracts.hpp ESCAPE_Q
add_library(eosio_testing_contracts INTERFACE)
target_include_directories(eosio_testing_contracts INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include/testing_contracts)

configure_file(contracts.cpp.in contracts.cpp ESCAPE_QUOTES)

## SORT .cpp by most likely to change / break compile
add_library( eosio_testing
tester.cpp
tester_network.cpp
${CMAKE_CURRENT_BINARY_DIR}/contracts.cpp
${HEADERS}
)

Expand Down
24 changes: 24 additions & 0 deletions libraries/testing/contracts.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <contracts.hpp>

#include <stdint.h>
#include <vector>

#define INCBIN_STYLE INCBIN_STYLE_SNAKE
#include <fc/io/incbin.h>

#define MAKE_EMBEDDED_WASM_ABI(CN,C, D) \
INCBIN(eosio_testing_contract_ ## CN ## _wasm, "${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".wasm"); \
INCBIN(eosio_testing_contract_ ## CN ## _abi, "${CMAKE_BINARY_DIR}/unittests/" #D "/" #C "/" #C ".abi"); \
\
namespace eosio::testing { \
std::vector<uint8_t> contracts:: CN ## _wasm() { \
return std::vector<uint8_t>(geosio_testing_contract_ ## CN ## _wasm_data, geosio_testing_contract_ ## CN ## _wasm_data + geosio_testing_contract_ ## CN ## _wasm_size); \
} \
std::vector<char> contracts:: CN ## _abi() { \
return std::vector<char>(geosio_testing_contract_ ## CN ## _abi_data, geosio_testing_contract_ ## CN ## _abi_data + geosio_testing_contract_ ## CN ## _abi_size); \
} \
}

MAKE_EMBEDDED_WASM_ABI(eosio_bios, eosio.bios, contracts)
MAKE_EMBEDDED_WASM_ABI(before_producer_authority_eosio_bios, eosio.bios, contracts/old_versions/v1.7.0-develop-preactivate_feature)
MAKE_EMBEDDED_WASM_ABI(before_preactivate_eosio_bios, eosio.bios, contracts/old_versions/v1.6.0-rc3)
12 changes: 9 additions & 3 deletions libraries/testing/contracts.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,24 @@ struct core_sym {
return std::vector<char>(s.begin(), s.end()); \
}

//contracts that need to be available by native contract unit testing's libtester need to be embedded
// in to the library as the build directory may not exist after being 'make install'ed.
#define MAKE_EMBD_WASM_ABI(CN) \
static std::vector<uint8_t> CN ## _wasm(); \
static std::vector<char> CN ## _abi();

namespace eosio {
namespace testing {
struct contracts {
// Contracts in `eos/unittests/contracts' directory
MAKE_READ_WASM_ABI(eosio_bios, eosio.bios, contracts)
MAKE_EMBD_WASM_ABI(eosio_bios)
MAKE_READ_WASM_ABI(eosio_msig, eosio.msig, contracts)
MAKE_READ_WASM_ABI(eosio_system, eosio.system, contracts)
MAKE_READ_WASM_ABI(eosio_token, eosio.token, contracts)
MAKE_READ_WASM_ABI(eosio_wrap, eosio.wrap, contracts)

MAKE_READ_WASM_ABI(before_producer_authority_eosio_bios, eosio.bios, contracts/old_versions/v1.7.0-develop-preactivate_feature)
MAKE_READ_WASM_ABI(before_preactivate_eosio_bios, eosio.bios, contracts/old_versions/v1.6.0-rc3)
MAKE_EMBD_WASM_ABI(before_producer_authority_eosio_bios)
MAKE_EMBD_WASM_ABI(before_preactivate_eosio_bios)

// Contracts in `eos/unittests/unittests/test-contracts' directory
MAKE_READ_WASM_ABI(asserter, asserter, test-contracts)
Expand Down
14 changes: 4 additions & 10 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,8 @@ BOOST_AUTO_TEST_CASE(ram_billing_in_notify_tests) { try {
fc::temp_directory tempdir;
validating_tester chain( tempdir, true );
chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios );
const auto& pfm = chain.control->get_protocol_feature_manager();
const auto& d = pfm.get_builtin_digest(builtin_protocol_feature_t::action_return_value); // testapi requires this
BOOST_REQUIRE(d);
chain.preactivate_protocol_features( {*d} );
chain.preactivate_builtin_protocol_features( {builtin_protocol_feature_t::action_return_value} );
chain.preactivate_builtin_protocol_features( {builtin_protocol_feature_t::crypto_primitives} );

chain.produce_blocks(2);
chain.create_account( "testapi"_n );
Expand Down Expand Up @@ -1850,12 +1848,8 @@ BOOST_AUTO_TEST_CASE(more_deferred_transaction_tests) { try {
fc::temp_directory tempdir;
validating_tester chain( tempdir, true );
chain.execute_setup_policy( setup_policy::preactivate_feature_and_new_bios );

const auto& pfm = chain.control->get_protocol_feature_manager();
auto d = pfm.get_builtin_digest( builtin_protocol_feature_t::replace_deferred );
BOOST_REQUIRE( d );

chain.preactivate_protocol_features( {*d} );
chain.preactivate_builtin_protocol_features( {builtin_protocol_feature_t::replace_deferred} );
chain.preactivate_builtin_protocol_features( {builtin_protocol_feature_t::crypto_primitives} );
chain.produce_block();

const auto& index = chain.control->db().get_index<generated_transaction_multi_index,by_id>();
Expand Down
54 changes: 54 additions & 0 deletions unittests/crypto_primitives_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ BOOST_AUTO_TEST_CASE( modexp_test ) { try {
return_code::failure,
"",
},

};

for(const auto& test : tests) {
Expand All @@ -409,6 +410,59 @@ BOOST_AUTO_TEST_CASE( modexp_test ) { try {
} FC_LOG_AND_RETHROW() }


BOOST_AUTO_TEST_CASE( modexp_subjective_limit_test ) { try {

// Given the need to respect the deadline timer and the current limitation that the deadline timer is not plumbed into the
// inner loops of the implementation of mod_exp (which currently exists in the gmp shared library), only a small enough duration for
// mod_exp can be tolerated to avoid going over the deadline timer by too much. A good threshold for small may be less than 5 ms.
// Then based on benchmarks within the test_modular_arithmetic test within fc, it seems safe to limit the bit size to 2048 bits.

// This test case verifies that the subjective bit size limit for mod_exp is properly enforced within libchain.

// To allow mod_exp to be more useful, the limits on bit size need to be removed and the deadline timer plumbing into the implementation
// needs to occur. When that happens, this test case can be removed.

tester c( setup_policy::preactivate_feature_and_new_bios );

const auto& tester1_account = account_name("tester1");
c.create_accounts( {tester1_account} );
c.produce_block();

const auto& pfm = c.control->get_protocol_feature_manager();
const auto& d = pfm.get_builtin_digest( builtin_protocol_feature_t::crypto_primitives );
BOOST_REQUIRE( d );

c.preactivate_protocol_features( {*d} );
c.produce_block();

c.set_code( tester1_account, contracts::crypto_primitives_test_wasm() );
c.set_abi( tester1_account, contracts::crypto_primitives_test_abi().data() );
c.produce_block();

bytes exponent(256); // 2048 bits of all zeros is fine

c.push_action( tester1_account, "testmodexp"_n, tester1_account, mutable_variant_object()
("base", h2bin("01"))
("exp", exponent)
("modulo", h2bin("0F"))
("expected_error", static_cast<int32_t>(return_code::success))
("expected_result", h2bin("01"))
);

exponent.push_back(0); // But 2056 bits of all zeros crosses the subjective limit (even if the value is still technically only zero).

BOOST_CHECK_EXCEPTION(c.push_action( tester1_account, "testmodexp"_n, tester1_account, mutable_variant_object()
("base", h2bin("01"))
("exp", exponent)
("modulo", h2bin("0F"))
("expected_error", static_cast<int32_t>(return_code::success))
("expected_result", h2bin("01"))),
eosio::chain::subjective_block_production_exception,
fc_exception_message_is("Bit size too large for values passed into mod_exp")
);

} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( blake2f_test ) { try {
tester c( setup_policy::preactivate_feature_and_new_bios );

Expand Down
Loading

0 comments on commit 5c698bb

Please sign in to comment.