1
0
Fork 0
forked from lthn/blockchain

Merge branch 'cryptoassets' into cake

This commit is contained in:
cryptozoidberg 2023-10-20 14:15:41 +00:00
commit ccfdb93ae4
9 changed files with 139 additions and 37 deletions

View file

@ -76,6 +76,11 @@ if(TESTNET)
add_definitions(-DTESTNET)
endif()
if(CAKEWALLET)
message("NOTICE: Building libraries for CAKEWALLET")
add_definitions(-DCAKEWALLET)
endif()
set(OPENSSL_USE_STATIC_LIBS TRUE) # link statically
find_package(OpenSSL REQUIRED)
@ -189,6 +194,11 @@ else()
endif()
# If BOOST_ROOT is set, ignore system-wide Boost
if(DEFINED ENV{BOOST_ROOT})
set(Boost_NO_SYSTEM_PATHS ON)
endif()
if(MSVC)
set(Boost_USE_STATIC_LIBS ON)
endif()

View file

@ -13,14 +13,14 @@ Be sure to clone the repository properly:\
### Dependencies
| component / version | minimum <br>(not recommended but may work) | recommended | most recent of what we have ever tested |
|--|--|--|--|
| gcc (Linux) | 7.5.0 | 7.5.0 | 8.3.0 |
| gcc (Linux) | 5.4.0 | 9.4.0 | 12.3.0 |
| llvm/clang (Linux) | UNKNOWN | 7.0.1 | 8.0.0 |
| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2017 (15.9.30) | 2017 (15.9.30) | 2022 (17.6.1) |
| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2017 (15.9.30) | 2017 (15.9.30) | 2022 (17.7.5) |
| [XCode](https://developer.apple.com/downloads/) (macOS) | 12.3 | 14.3 | 14.3 |
| [CMake](https://cmake.org/download/) | 3.1.6 | 3.15.5 | 3.26.3 |
| [CMake](https://cmake.org/download/) | 3.15.5 | 3.22.1 | 3.26.3 |
| [Boost](https://www.boost.org/users/download/) | 1.70 | 1.70 | 1.76 |
| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | - | 1.1.1n | 1.1.1n |
| [Qt](https://download.qt.io/archive/qt/) (*only for GUI*) | 5.8.0 | 5.12.12 | 5.15.2 |
| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | 1.1.1n | 1.1.1w | 1.1.1w |
| [Qt](https://download.qt.io/archive/qt/) (*only for GUI*) | 5.8.0 | 5.11.2 | 5.15.2 |
Note:\
[*server version*] denotes steps required for building command-line tools (daemon, simplewallet, etc.).\
@ -30,25 +30,28 @@ Note:\
### Linux
Recommended OS version: Ubuntu 18.04 LTS.
Recommended OS versions: Ubuntu 20.04, 22.04 LTS.
1. Prerequisites
[*server version*]
sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev
sudo apt-get install -y build-essential g++ curl autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev
[*GUI version*]
sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen checkinstall zlib1g-dev mesa-common-dev libglu1-mesa-dev
2. Download and build Boost
2. Download and build Boost\
(Assuming you have cloned Zano into the 'zano' folder. If you used a different location for Zano, edit line 4 accordingly.)
curl -OL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.bz2
echo "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778 boost_1_70_0.tar.bz2" | shasum -c && tar -xjf boost_1_70_0.tar.bz2
cd boost_1_70_0
rm boost_1_70_0.tar.bz2 && cd boost_1_70_0
patch -p0 < ../zano/utils/boost_1.70_gcc_8.patch || cd ..
./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer,log
./b2
Make sure that you see "The Boost C++ Libraries were successfully built!" message at the end.
3. Install Qt\
(*GUI version only, skip this step if you're building server version*)
@ -63,15 +66,13 @@ Recommended OS version: Ubuntu 18.04 LTS.
4. Install OpenSSL
We recommend installing OpenSSL v1.1.1n locally unless you would like to use the same version system-wide. Adjust the local path `/home/user/openssl` in the commands below according to your needs.
We recommend installing OpenSSL v1.1.1w locally unless you would like to use the same version system-wide. Adjust the local path `/home/user/openssl` in the commands below according to your needs.
curl -OL https://www.openssl.org/source/openssl-1.1.1n.tar.gz
echo "40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a openssl-1.1.1n.tar.gz" | shasum -c && tar xaf openssl-1.1.1n.tar.gz
cd openssl-1.1.1n/
curl -OL https://www.openssl.org/source/openssl-1.1.1w.tar.gz
echo "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8 openssl-1.1.1w.tar.gz" | shasum -c && tar xaf openssl-1.1.1w.tar.gz
cd openssl-1.1.1w/
./config --prefix=/home/user/openssl --openssldir=/home/user/openssl shared zlib
make
make test
make install
make && make test && make install
5. Set environment variables properly\
@ -89,7 +90,7 @@ For instance, by adding the following lines to `~/.bashrc`
export OPENSSL_ROOT_DIR=/home/user/openssl
export QT_PREFIX_PATH=/home/user/Qt5.11.2/5.11.2/gcc_64
Make sure you've restarted your terminal session (by reopening the terminal window or reconnecting the server) to apply these changes.
6. Build the binaries
1. Build daemon and simplewallet:

View file

@ -359,6 +359,8 @@ namespace currency
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key, crypto::key_derivation& derivation);
bool derive_public_key_from_target_address(const account_public_address& destination_addr, const crypto::secret_key& tx_sec_key, size_t index, crypto::public_key& out_eph_public_key);
bool derive_key_pair_from_key_pair(const crypto::public_key& src_pub_key, const crypto::secret_key& src_sec_key, crypto::secret_key& derived_sec_key, crypto::public_key& derived_pub_key, const char(&hs_domain)[32], uint64_t index = 0);
uint16_t get_derivation_hint(const crypto::key_derivation& derivation);
tx_derivation_hint make_tx_derivation_hint_from_uint16(uint16_t hint);
std::string short_hash_str(const crypto::hash& h);
bool is_mixattr_applicable_for_fake_outs_counter(uint8_t mix_attr, uint64_t fake_attr_count);

View file

@ -5427,7 +5427,7 @@ bool wallet2::build_ionic_swap_template(const wallet_public::ionic_swap_proposal
return true;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info)
bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const
{
wallet_public::ionic_swap_proposal proposal = AUTO_VAL_INIT(proposal);
bool r = t_unserializable_object_from_blob(proposal, raw_proposal);
@ -5435,13 +5435,13 @@ bool wallet2::get_ionic_swap_proposal_info(const std::string&raw_proposal, walle
return get_ionic_swap_proposal_info(proposal, proposal_info);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info)
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const
{
wallet_public::ionic_swap_proposal_context ionic_context = AUTO_VAL_INIT(ionic_context);
return get_ionic_swap_proposal_info(proposal, proposal_info, ionic_context);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context)
bool wallet2::get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context) const
{
const transaction& tx = proposal.tx_template;
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);

View file

@ -1026,9 +1026,9 @@ namespace tools
bool build_ionic_swap_template(const wallet_public::ionic_swap_proposal_info& proposal_detais, const currency::account_public_address& destination_addr,
wallet_public::ionic_swap_proposal& proposal,
std::vector<uint64_t>& selected_transfers_for_template);
bool get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info);
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info);
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context);
bool get_ionic_swap_proposal_info(const std::string&raw_proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const;
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info) const;
bool get_ionic_swap_proposal_info(const wallet_public::ionic_swap_proposal& proposal, wallet_public::ionic_swap_proposal_info& proposal_info, wallet_public::ionic_swap_proposal_context& ionic_context) const;
bool accept_ionic_swap_proposal(const std::string& raw_proposal, currency::transaction& result_tx);
bool accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposal& proposal, currency::transaction& result_tx);

View file

@ -1905,10 +1905,10 @@ bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<c
return b_success;
}
void balance_via_wallet(const tools::wallet2& w, uint64_t* p_total, uint64_t* p_unlocked, uint64_t* p_awaiting_in, uint64_t* p_awaiting_out, uint64_t* p_mined)
void balance_via_wallet(const tools::wallet2& w, const crypto::public_key& asset_id, uint64_t* p_total, uint64_t* p_unlocked, uint64_t* p_awaiting_in, uint64_t* p_awaiting_out, uint64_t* p_mined)
{
uint64_t total, unlocked, awaiting_in, awaiting_out, mined;
total = w.balance(unlocked, awaiting_in, awaiting_out, mined);
total = w.balance(unlocked, awaiting_in, awaiting_out, mined, asset_id);
if (p_total)
*p_total = total;
@ -1923,12 +1923,16 @@ void balance_via_wallet(const tools::wallet2& w, uint64_t* p_total, uint64_t* p_
}
bool check_balance_via_wallet(const tools::wallet2& w, const char* account_name,
uint64_t expected_total, uint64_t expected_mined, uint64_t expected_unlocked, uint64_t expected_awaiting_in, uint64_t expected_awaiting_out)
uint64_t expected_total, uint64_t expected_mined, uint64_t expected_unlocked, uint64_t expected_awaiting_in, uint64_t expected_awaiting_out, const crypto::public_key& asset_id /* = currency::native_coin_asset_id */)
{
uint64_t total, unlocked, awaiting_in, awaiting_out, mined;
balance_via_wallet(w, &total, &unlocked, &awaiting_in, &awaiting_out, &mined);
balance_via_wallet(w, asset_id, &total, &unlocked, &awaiting_in, &awaiting_out, &mined);
LOG_PRINT_CYAN("Balance for wallet " << account_name << " @ height " << w.get_top_block_height() << ":" << ENDL <<
std::string asset_id_str;
if (asset_id != currency::native_coin_asset_id)
asset_id_str = std::string(", asset_id: ") + epee::string_tools::pod_to_hex(asset_id).erase(4, 56).insert(4, "...");
LOG_PRINT_CYAN("Balance for wallet " << account_name << " @ height " << w.get_top_block_height() << asset_id_str << ":" << ENDL <<
"unlocked: " << print_money(unlocked) << ENDL <<
"awaiting in: " << print_money(awaiting_in) << ENDL <<
"awaiting out: " << print_money(awaiting_out) << ENDL <<
@ -1939,7 +1943,7 @@ bool check_balance_via_wallet(const tools::wallet2& w, const char* account_name,
bool r = true;
#define _CHECK_BAL(v) if (!(expected_##v == INVALID_BALANCE_VAL || v == expected_##v)) { r = false; LOG_PRINT_RED_L0("invalid " #v " balance, expected: " << print_money_brief(expected_##v)); }
#define _CHECK_BAL(v) if (!(expected_##v == INVALID_BALANCE_VAL || v == expected_##v)) { r = false; LOG_PRINT_RED_L0("invalid " #v " balance, expected: " << print_money_brief(expected_##v) << asset_id_str); }
_CHECK_BAL(unlocked)
_CHECK_BAL(awaiting_in)
_CHECK_BAL(awaiting_out)
@ -2329,6 +2333,7 @@ bool shuffle_source_entries(std::vector<tx_source_entry>& sources)
return true;
}
// creates destinations.size() + 1 outputs if the total sum of amounts is less than the original premine amount (the last one will have amount = old_premine - sum)
bool replace_coinbase_in_genesis_block(const std::vector<currency::tx_destination_entry>& destinations, test_generator& generator, std::vector<test_event_entry>& events, currency::block& genesis_block)
{
bool r = false;
@ -2340,13 +2345,19 @@ bool replace_coinbase_in_genesis_block(const std::vector<currency::tx_destinatio
// replace tx key
keypair tx_key = keypair::generate();
for(auto& el : genesis_block.miner_tx.extra)
for(auto it = genesis_block.miner_tx.extra.begin(); it != genesis_block.miner_tx.extra.end(); /* nothing */)
{
if (el.type() == typeid(crypto::public_key))
if (it->type() == typeid(crypto::public_key))
{
boost::get<crypto::public_key>(el) = tx_key.pub;
break;
boost::get<crypto::public_key>(*it) = tx_key.pub; // rewtire it
}
else if (it->type() == typeid(tx_derivation_hint))
{
it = genesis_block.miner_tx.extra.erase(it);
continue; // remove it
}
++it;
}
uint64_t total_amount = 0;
@ -2357,10 +2368,13 @@ bool replace_coinbase_in_genesis_block(const std::vector<currency::tx_destinatio
{
uint64_t amount = output_index < destinations.size() ? destinations[output_index].amount : premine_amount - total_amount;
const account_public_address& addr = output_index < destinations.size() ? destinations[output_index].addr.back() : destinations.back().addr.back();
if (amount == 0)
break;
crypto::key_derivation derivation{};
bool r = crypto::generate_key_derivation(addr.view_public_key, tx_key.sec, derivation);
CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed");
genesis_block.miner_tx.extra.emplace_back(make_tx_derivation_hint_from_uint16(get_derivation_hint(derivation)));
txout_to_key target{};
r = crypto::derive_public_key(derivation, output_index, addr.spend_public_key, target.key);

View file

@ -703,14 +703,15 @@ bool fill_tx_sources_and_destinations(const std::vector<test_event_entry>& event
bool use_ref_by_id = false);
uint64_t get_balance(const currency::account_keys& addr, const std::vector<currency::block>& blockchain, const map_hash2tx_t& mtx, bool dbg_log = false);
uint64_t get_balance(const currency::account_base& addr, const std::vector<currency::block>& blockchain, const map_hash2tx_t& mtx, bool dbg_log = false);
void balance_via_wallet(const tools::wallet2& w, uint64_t* p_total, uint64_t* p_unlocked = 0, uint64_t* p_awaiting_in = 0, uint64_t* p_awaiting_out = 0, uint64_t* p_mined = 0);
void balance_via_wallet(const tools::wallet2& w, const crypto::public_key& asset_id, uint64_t* p_total, uint64_t* p_unlocked = 0, uint64_t* p_awaiting_in = 0, uint64_t* p_awaiting_out = 0, uint64_t* p_mined = 0);
#define INVALID_BALANCE_VAL std::numeric_limits<uint64_t>::max()
bool check_balance_via_wallet(const tools::wallet2& w, const char* account_name,
uint64_t expected_total,
uint64_t expected_mined = INVALID_BALANCE_VAL,
uint64_t expected_unlocked = INVALID_BALANCE_VAL,
uint64_t expected_awaiting_in = INVALID_BALANCE_VAL,
uint64_t expected_awaiting_out = INVALID_BALANCE_VAL);
uint64_t expected_awaiting_out = INVALID_BALANCE_VAL,
const crypto::public_key& asset_id = currency::native_coin_asset_id);
bool calculate_amounts_many_outs_have_and_no_outs_have(const uint64_t first_blocks_reward, uint64_t& amount_many_outs_have, uint64_t& amount_no_outs_have);
bool find_global_index_for_output(const std::vector<test_event_entry>& events, const crypto::hash& head_block_hash, const currency::transaction& reference_tx, const size_t reference_tx_out_index, uint64_t& global_index);
@ -1112,9 +1113,10 @@ void append_vector_by_another_vector(U& dst, const V& src)
PRINT_EVENT_N_TEXT(VEC_EVENTS, "MAKE_NEXT_POS_BLOCK_TX1(" << #BLK_NAME << ")"); \
currency::block BLK_NAME = AUTO_VAL_INIT(BLK_NAME); \
{ \
std::list<currency::transaction>tx_list; \
std::list<currency::transaction> tx_list; \
tx_list.push_back(TX_1); \
generator.construct_block(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, MINERS_ACC_LIST); \
if (!generator.construct_block(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, MINERS_ACC_LIST)) \
return false; \
} \
VEC_EVENTS.push_back(BLK_NAME)

View file

@ -10,6 +10,64 @@
#include "random_helper.h"
#include "tx_builder.h"
using namespace currency;
// Helpers
bool check_ionic_swap_tx_outs(const std::vector<currency::account_base>& accounts, const currency::transaction& tx, std::shared_ptr<const tools::wallet2> w, const tools::wallet_public::ionic_swap_proposal& proposal)
{
tools::mode_separate_context msc = AUTO_VAL_INIT(msc);
msc.tx_for_mode_separate = proposal.tx_template;
tools::wallet_public::ionic_swap_proposal_context ionic_context = AUTO_VAL_INIT(ionic_context);
bool r = w->get_ionic_swap_proposal_info(proposal, msc.proposal_info, ionic_context);
CHECK_AND_ASSERT_MES(r, false, "get_ionic_swap_proposal_info failed");
// decode all outputs amounts and asset_ids
std::vector<std::pair<uint64_t, crypto::public_key>> outs_amounts_and_asset_ids;
outs_amounts_and_asset_ids.resize(tx.vout.size());
//ionic_context.one_time_skey
const crypto::public_key& tx_pub_key = get_tx_pub_key_from_extra(tx);
for(size_t i = 0; i < tx.vout.size(); ++i)
{
VARIANT_SWITCH_BEGIN(tx.vout[i])
VARIANT_CASE_CONST(currency::tx_out_zarcanum, oz)
for(size_t k = 0; k < accounts.size(); ++k)
{
crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);
bool r = crypto::generate_key_derivation(tx_pub_key, accounts[k].get_keys().view_secret_key, derivation);
CHECK_AND_ASSERT_MES(r, false, "generate_key_derivation failed");
uint64_t decoded_amount = 0;
crypto::public_key decoded_asset_id{};
crypto::scalar_t amount_blinding_mask{};
crypto::scalar_t asset_id_blinding_mask{};
if (decode_output_amount_and_asset_id(oz, derivation, i, decoded_amount, decoded_asset_id, amount_blinding_mask, asset_id_blinding_mask))
{
outs_amounts_and_asset_ids[i] = std::make_pair(decoded_amount, decoded_asset_id);
break;
}
}
VARIANT_SWITCH_END()
}
static_assert(CURRENCY_TX_MIN_ALLOWED_OUTS >= 2);
const size_t expected_number_of_zero_amount_outputs = CURRENCY_TX_MIN_ALLOWED_OUTS - 2;
size_t zero_amount_outputs = 0;
for(auto& oaai : outs_amounts_and_asset_ids)
{
CHECK_AND_ASSERT_MES(oaai.second != null_pkey, false, "Not all outputs were decoded");
if (oaai.first == 0)
++zero_amount_outputs;
}
CHECK_AND_ASSERT_MES(zero_amount_outputs <= expected_number_of_zero_amount_outputs, false, "zero_amount_outputs: " << zero_amount_outputs << ", expected_number_of_zero_amount_outputs: " << expected_number_of_zero_amount_outputs);
return true;
}
//----------------------------------------------------------------------------------------------------
ionic_swap_basic_test::ionic_swap_basic_test()
{

View file

@ -0,0 +1,15 @@
# This patch fixes compilation issue in Boost 1.70-1.71 while it is being compiled by GCC ver >= 8.3
# -- sowle
# see also: https://github.com/boostorg/thread/pull/297
#
--- boost/thread/pthread/thread_data.hpp.orig 2023-10-10 20:22:30.860192033 +0000
+++ boost/thread/pthread/thread_data.hpp 2023-10-10 18:19:22.460764089 +0000
@@ -57,7 +57,7 @@
#else
std::size_t page_size = ::sysconf( _SC_PAGESIZE);
#endif
-#if PTHREAD_STACK_MIN > 0
+#ifdef PTHREAD_STACK_MIN
if (size<PTHREAD_STACK_MIN) size=PTHREAD_STACK_MIN;
#endif
size = ((size+page_size-1)/page_size)*page_size;