From 181b51da27d0ffdb4e1bad036ae196a04b0e55e2 Mon Sep 17 00:00:00 2001 From: Tay8NWWFKpz9JT4NXU0w Date: Mon, 19 Aug 2024 12:18:44 +0000 Subject: [PATCH 1/4] Haven 4.1 (#72) * fix floating point arithmetics differences causing difficulty drift There is a difference in the precision of difficulty calculation between Linux x86_64 and Windows / Linux ARM8. It seems to relate to floating point arithmetic deviations, most likely coming from the additional -m64 flag (rounding to 53 bits) passed in linux.mk in the make depend configuration. Changing the type to long double seems to fix the issue and produce consistent results between Linux x86_64 and other Windows / Linux ARM8. * add a parameter for how long a conversion should remain in the pool * remove conversions faster from the pool * create new hardfork, minting of burnt fees in XHV * add Proof of value rules for transfers with burn * take into account burn transactions in supply calc * add new hard fork * new slippage + mint of XHV validation * support for burn transactions * revert changes for CLI-triggered burn transaction * fix mcap ratio addon was not calculated,formatting * check that slippage is below converted amount * formatting and readability changes * additional security checks * adjust slippage calculation * 20% of on/offshore fees to miners * add mising conf HF_VERSION_OFFSHORE_FEES_V3 --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w --- src/blockchain_db/lmdb/db_lmdb.cpp | 10 +- src/cryptonote_basic/difficulty.cpp | 6 +- src/cryptonote_config.h | 11 +++ src/cryptonote_core/blockchain.cpp | 38 ++++++-- src/cryptonote_core/cryptonote_tx_utils.cpp | 100 +++++++++++++++++--- src/cryptonote_core/tx_pool.cpp | 16 +++- src/hardforks/hardforks.cpp | 6 +- src/ringct/rctSigs.cpp | 31 ++++++ 8 files changed, 190 insertions(+), 28 deletions(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 957ac306c..1ea61d024 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1105,8 +1105,11 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons throw0(DB_ERROR("Failed to add tx circulating supply to db transaction: get_tx_asset_types fails.")); } + bool is_mint_and_burn_tx = (strSource != strDest); + bool is_burn_tx = (strSource == strDest) && tx.amount_burnt > 0; // NEAC : check for presence of offshore TX to see if we need to update circulating supply information - if ((tx.version >= OFFSHORE_TRANSACTION_VERSION) && (strSource != strDest)) { + // Tay8NWWFKpz9JT4NXU0w: Also burn transactions affect the supply + if ((tx.version >= OFFSHORE_TRANSACTION_VERSION) && (is_mint_and_burn_tx || is_burn_tx)) { // Offshore TX - update our records circ_supply cs; cs.tx_hash = tx_hash; @@ -1216,7 +1219,10 @@ void BlockchainLMDB::remove_transaction_data(const crypto::hash& tx_hash, const throw0(DB_ERROR("Failed to add tx circulating supply to db transaction: get_tx_asset_types fails.")); } - if ((tx.version >= OFFSHORE_TRANSACTION_VERSION) && (strSource != strDest)) + bool is_mint_and_burn_tx = (strSource != strDest); + bool is_burn_tx = (strSource == strDest) && tx.amount_burnt > 0; + + if ((tx.version >= OFFSHORE_TRANSACTION_VERSION) && (is_mint_and_burn_tx || is_burn_tx)) { // Update the tally table // Get the current tally value for the source currency type diff --git a/src/cryptonote_basic/difficulty.cpp b/src/cryptonote_basic/difficulty.cpp index 1e55e7c4b..40ffcca59 100644 --- a/src/cryptonote_basic/difficulty.cpp +++ b/src/cryptonote_basic/difficulty.cpp @@ -300,11 +300,11 @@ namespace cryptonote { // To get an average solvetime to within +/- ~0.1%, use an adjustment factor. // adjust=0.99 for 90 < N < 130 - const double adjust = 0.998; + const long double adjust = 0.998; // The divisor k normalizes LWMA. - const double k = N * (N + 1) / 2; + const long double k = N * (N + 1) / 2; - double LWMA(0), sum_inverse_D(0), harmonic_mean_D(0), nextDifficulty(0); + long double LWMA(0), sum_inverse_D(0), harmonic_mean_D(0), nextDifficulty(0); int64_t solveTime(0); uint64_t difficulty(0), next_difficulty(0); diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 4b6a63eac..30bc047b9 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -139,6 +139,7 @@ #define BLOCKS_SYNCHRONIZING_MAX_COUNT 2048 //must be a power of 2, greater than 128, equal to SEEDHASH_EPOCH_BLOCKS #define CRYPTONOTE_MEMPOOL_TX_LIVETIME 86400 //seconds, one day +#define CRYPTONOTE_MEMPOOL_TX_CONVERSION_LIVETIME 3600 //seconds, one hour #define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME 604800 //seconds, one week @@ -255,6 +256,13 @@ #define HF_VERSION_YIELD 23 #define HF_VERSION_CONVERSION_FEES_NOT_BURNT 23 +// Haven v4.1 definitions +#define HF_VERSION_SLIPPAGE_V2 24 +#define HF_VERSION_BURN 24 +#define HF_VERSION_CONVERSION_FEES_NOT_BURNT_FINAL 24 +#define HF_VERSION_OFFSHORE_FEES_V3 24 + + #define STAGENET_VERSION 0x0e #define TESTNET_VERSION 0x1b @@ -263,6 +271,9 @@ #define BURNT_CONVERSION_FEES_MINT_AMOUNT ((uint64_t)2580000000000000000ull) #define BURNT_CONVERSION_FEES_MINT_HEIGHT ((uint64_t)1656720) +#define BURNT_CONVERSION_FEES_MINT_AMOUNT_FINAL ((uint64_t)511812000000000000ull) +#define BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL ((uint64_t)1692002) + #define PER_KB_FEE_QUANTIZATION_DECIMALS 8 #define CRYPTONOTE_SCALING_2021_FEE_ROUNDING_PLACES 2 diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 91d1939fe..20b6e3314 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1601,6 +1601,10 @@ bool Blockchain::validate_miner_transaction( if ((version == HF_VERSION_CONVERSION_FEES_NOT_BURNT) && (m_db->height() == BURNT_CONVERSION_FEES_MINT_HEIGHT)) { governance_reward += BURNT_CONVERSION_FEES_MINT_AMOUNT; } + + if ((version == HF_VERSION_CONVERSION_FEES_NOT_BURNT_FINAL) && (m_db->height() == BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL)) { + governance_reward += BURNT_CONVERSION_FEES_MINT_AMOUNT_FINAL; + } // LAND AHOY!!! if ((b.miner_tx.vout[1].amount != governance_reward) && @@ -1664,7 +1668,20 @@ bool Blockchain::validate_miner_transaction( uint64_t miner_reward_xasset = fee_map[first_output_asset_type]; uint64_t governance_reward_xasset = get_governance_reward(m_db->height(), miner_reward_xasset); miner_reward_xasset -= governance_reward_xasset; - governance_reward_xasset += offshore_fee_map[first_output_asset_type]; + if (version >= HF_VERSION_OFFSHORE_FEES_V3) { + //split onshore/offshore fees 80% governance wallet, 20% miners + boost::multiprecision::uint128_t fee = offshore_fee_map[first_output_asset_type]; + boost::multiprecision::uint128_t fee_miner_xasset = fee / 5; + fee -= fee_miner_xasset; + // 80% + governance_reward_xasset += fee.convert_to(); + // 20% + miner_reward_xasset += fee_miner_xasset.convert_to(); + } else + { + //Full conversion fee goes to the governance wallet before HF_VERSION_OFFSHORE_FEES_V3 + governance_reward_xasset += offshore_fee_map[first_output_asset_type]; + } // xAsset fees change fork if (version >= HF_VERSION_XASSET_FEES_V2) { @@ -1724,10 +1741,14 @@ bool Blockchain::validate_miner_transaction( // from hard fork 2, since a miner can claim less than the full block reward, we update the base_reward // to show the amount of coins that were actually generated, the remainder will be pushed back for later // emission. This modifies the emission curve very slightly. + bool is_burnt_fee_mint_block = ((version == HF_VERSION_CONVERSION_FEES_NOT_BURNT) && (m_db->height() == BURNT_CONVERSION_FEES_MINT_HEIGHT)); + bool is_burnt_fee_mint_block_final = ((version == HF_VERSION_CONVERSION_FEES_NOT_BURNT_FINAL) && (m_db->height() == BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL)); + if (version >= HF_VERSION_CONVERSION_FEES_NOT_BURNT) { - if ((version == HF_VERSION_CONVERSION_FEES_NOT_BURNT) && (m_db->height() == BURNT_CONVERSION_FEES_MINT_HEIGHT)) { - CHECK_AND_ASSERT_MES(money_in_use_map["XHV"] - fee_map["XHV"] - offshore_fee_map["XHV"] - xasset_fee_map["XHV"] - BURNT_CONVERSION_FEES_MINT_AMOUNT == base_reward, false, "base reward calculation bug when minting previously-burnt fees"); - } else { + if (is_burnt_fee_mint_block || is_burnt_fee_mint_block_final ){ + uint64_t minted_due_to_burned_fees_bug = is_burnt_fee_mint_block ? BURNT_CONVERSION_FEES_MINT_AMOUNT : BURNT_CONVERSION_FEES_MINT_AMOUNT_FINAL; + CHECK_AND_ASSERT_MES(money_in_use_map["XHV"] - fee_map["XHV"] - offshore_fee_map["XHV"] - xasset_fee_map["XHV"] - minted_due_to_burned_fees_bug == base_reward, false, "base reward calculation bug when minting previously-burnt fees"); + } else { // Additional logging bool err = (money_in_use_map["XHV"] - fee_map["XHV"] - offshore_fee_map["XHV"] - xasset_fee_map["XHV"] != base_reward); if (err) { @@ -5426,12 +5447,17 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& } } } else { - //make sure those values are 0 for transfers. - if (tx.amount_burnt || tx.amount_minted) { + //make sure those values are 0 for transfers, unless it is a burn transaction + if ((tx.amount_burnt && hf_version 0 for a transfer tx."); bvc.m_verifivation_failed = true; goto leave; } + if ((hf_version >= HF_VERSION_BURN) && tx.amount_minted) { + LOG_PRINT_L2("error: Invalid Tx found. Amount mint > 0 for a transfer tx."); + bvc.m_verifivation_failed = true; + goto leave; + } if (hf_version >= HF_VERSION_OFFSHORE_FEES_V2 && tx.pricing_record_height) { LOG_PRINT_L2("error: Invalid Tx found. Tx pricing_record_height > 0 for a transfer tx."); bvc.m_verifivation_failed = true; diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 6a7a91174..0e0927d78 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -162,8 +162,13 @@ namespace cryptonote // HERE BE DRAGONS!!! // NEAC: mint the previously-burnt XHV conversion fees, and add to the governance wallet - if ((hard_fork_version == HF_VERSION_CONVERSION_FEES_NOT_BURNT) && (height == BURNT_CONVERSION_FEES_MINT_HEIGHT)) { - governance_reward += BURNT_CONVERSION_FEES_MINT_AMOUNT; + + bool is_burnt_fee_mint_block = ((hard_fork_version == HF_VERSION_CONVERSION_FEES_NOT_BURNT) && (height == BURNT_CONVERSION_FEES_MINT_HEIGHT)); + bool is_burnt_fee_mint_block_final = ((hard_fork_version == HF_VERSION_CONVERSION_FEES_NOT_BURNT_FINAL) && (height == BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL)); + + if (is_burnt_fee_mint_block || is_burnt_fee_mint_block_final ){ + uint64_t minted_due_to_burned_fees_bug = is_burnt_fee_mint_block ? BURNT_CONVERSION_FEES_MINT_AMOUNT : BURNT_CONVERSION_FEES_MINT_AMOUNT_FINAL; + governance_reward += minted_due_to_burned_fees_bug; } // LAND AHOY!!! } @@ -306,9 +311,21 @@ namespace cryptonote // Add the conversion fee to the governance payment (if provided) if (offshore_fee_map[fee_map_entry.first] != 0) { - governance_reward_xasset += offshore_fee_map[fee_map_entry.first]; + if (hard_fork_version >= HF_VERSION_OFFSHORE_FEES_V3) { + //split onshore/offshore fees 80% governance wallet, 20% miners + boost::multiprecision::uint128_t fee = offshore_fee_map[fee_map_entry.first]; + boost::multiprecision::uint128_t fee_miner_xasset = fee / 5; + fee -= fee_miner_xasset; + // 80% + governance_reward_xasset += fee.convert_to(); + // 20% + block_reward_xasset += fee_miner_xasset.convert_to(); + } else + { + //Full conversion fee goes to the governance wallet before HF_VERSION_OFFSHORE_FEES_V3 + governance_reward_xasset += offshore_fee_map[fee_map_entry.first]; + } } - // handle xasset converion fees if (hard_fork_version >= HF_VERSION_XASSET_FEES_V2) { if (xasset_fee_map[fee_map_entry.first] != 0) { @@ -796,6 +813,7 @@ namespace cryptonote // Calculate Mcap ratio slippage cpp_bin_float_quad mcap_ratio_slippage = 0.0; + cpp_bin_float_quad mcap_ratio_onshore_addon_slippage = 0.0; if (tx_type == tt::ONSHORE || tx_type == tt::OFFSHORE) { // Calculate Mcap Ratio for XHV spot @@ -808,8 +826,24 @@ namespace cryptonote cpp_bin_float_quad mcr_max = (mcr_sp > mcr_ma) ? mcr_sp : mcr_ma; // Calculate the Mcap ratio slippage - mcap_ratio_slippage = std::sqrt(std::pow(mcr_max.convert_to(), 1.2)) / 6.0; - LOG_PRINT_L2("*** mcap_ratio_slippage = " << mcap_ratio_slippage.convert_to()); + mcap_ratio_slippage = (hf_version < HF_VERSION_SLIPPAGE_V2) ? std::sqrt(std::pow(mcr_max.convert_to(), 1.2)) / 6.0 : std::sqrt(std::pow(mcr_max.convert_to(), 1.7)) / 3.0; + //add-on for onshores, based on XHV price + if ((hf_version >= HF_VERSION_SLIPPAGE_V2) && (tx_type == tt::ONSHORE)) { + + uint128_t mraon_numerator = map_amounts["XHV"]; + uint128_t mraon_denominator = ((map_amounts["XUSD"] * pr.min("XHV"))/COIN)*100; + if ( mraon_denominator == 0 ){ + LOG_ERROR("Invalid denominator (0) in calculation of mcap ratio onshore addon - aborting, XHV price is " << pr.min("XHV") << " XUSD supply is " << map_amounts["XUSD"] ); + return false; + } + mcap_ratio_onshore_addon_slippage = mraon_numerator.convert_to() / mraon_denominator.convert_to(); + } + + LOG_PRINT_L2("*** original mcap_ratio_slippage = " << mcap_ratio_slippage.convert_to()); + LOG_PRINT_L2("*** mcap_ratio_onshore_addon_slippage = " << mcap_ratio_onshore_addon_slippage.convert_to()); + mcap_ratio_slippage+=mcap_ratio_onshore_addon_slippage; + LOG_PRINT_L2("*** final mcap_ratio_slippage (sum of original mcap_ratio_slippage and mcap_ratio_onshore_addon_slippage) = " << mcap_ratio_slippage.convert_to()); + } // Calculate xUSD Peg Slippage @@ -818,7 +852,7 @@ namespace cryptonote xusd_peg_ratio /= COIN; if (xusd_peg_ratio < 1.0) { - xusd_peg_slippage = std::sqrt(std::pow((1.0 - xusd_peg_ratio), 3.0)) / 1.3; + xusd_peg_slippage = (hf_version < HF_VERSION_SLIPPAGE_V2) ? std::sqrt(std::pow((1.0 - xusd_peg_ratio), 3.0)) / 1.3 : std::sqrt(std::pow((1.0 - xusd_peg_ratio), 2.5)) / 0.5; LOG_PRINT_L2("*** xusd_peg_slippage = " << xusd_peg_slippage); } @@ -846,13 +880,48 @@ namespace cryptonote (tx_type == tt::ONSHORE || tx_type == tt::OFFSHORE) ? basic_slippage + std::max(mcap_ratio_slippage, xusd_peg_slippage) : (tx_type == tt::XUSD_TO_XASSET && dest_asset == "XBTC") ? basic_slippage + std::max(xbtc_mcap_ratio_slippage, xusd_peg_slippage) : basic_slippage + xusd_peg_slippage; - LOG_PRINT_L1("total_slippage = " << total_slippage.convert_to()); + LOG_PRINT_L1("total_slippage (before rounding) = " << total_slippage.convert_to()); // Limit total_slippage to 99% so that the code doesn't break - if (total_slippage > 0.99) total_slippage = 0.99; - total_slippage *= convert_amount.convert_to(); - slippage = total_slippage.convert_to(); - slippage -= (slippage % 100000000); + + if (hf_version < HF_VERSION_SLIPPAGE_V2) { + if (total_slippage > 0.99) total_slippage = 0.99; + LOG_PRINT_L1("total_slippage (after rounding) = " << total_slippage.convert_to()); + total_slippage *= convert_amount.convert_to(); + slippage = total_slippage.convert_to(); + slippage -= (slippage % 100000000); + } + else { + if (total_slippage > 1) total_slippage = 1.00; + total_slippage=total_slippage*100.0; + //Make slippage a number in an discrete set of values - integers between 0 and 100 + uint128_t slippage_rounded_numerator=total_slippage.convert_to(); + //Make slippage a number in an discrete set of values - integers multiples of 10 between 0 and 1000 + slippage_rounded_numerator *= 10; + if (slippage_rounded_numerator == 0) + //Minimum slippage is 0.1% + slippage_rounded_numerator = 1; + if (slippage_rounded_numerator > 990) + //Maximum slippage is 99.9% + slippage_rounded_numerator = 999; + uint128_t slippage_rounded_denominator = 1000; + LOG_PRINT_L1("total_slippage (after rounding) = " << slippage_rounded_numerator<< "/1000"); + uint128_t slippage_final_before_dust_rounding_128 = (convert_amount*slippage_rounded_numerator)/slippage_rounded_denominator; + uint64_t slippage_final_before_dust_rounding_64 = slippage_final_before_dust_rounding_128.convert_to(); + uint64_t amount_after_slippage_before_dust_rounding = 0; + if (slippage_final_before_dust_rounding_64 < amount) + amount_after_slippage_before_dust_rounding=amount-slippage_final_before_dust_rounding_64; + //If the amount after slippage is less than 0.0001, then fail + if (amount_after_slippage_before_dust_rounding<100000000) { + LOG_ERROR("The whole converted amount will be burnt through slippage - aborting"); + return false; + } + //Round the slippage up, so that the remaining amount after slippage has only zeros after the 4 digit after the decimal point + //for example 1234.567800000000 + slippage = slippage_final_before_dust_rounding_64+(amount_after_slippage_before_dust_rounding % 100000000); + } + + LOG_PRINT_L1("final slippage amount = " << slippage); // SAnity check that there is _some_ slippage being applied if (slippage == 0) { @@ -860,6 +929,12 @@ namespace cryptonote LOG_ERROR("Invalid slippage amount (0) - aborting"); return false; } + + if (slippage >= amount) { + // Not a valid slippage amount + LOG_ERROR("Slippage is not smaller than the converted amount - aborting"); + return false; + } return true; } @@ -1564,6 +1639,7 @@ namespace cryptonote } } } + CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys"); remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys)); diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 6b5e2d041..f55242b75 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -499,12 +499,20 @@ namespace cryptonote return false; } } else { - // make sure there is no burnt/mint set for transfers, since these numbers will affect circulating supply. - if (tx.amount_burnt || tx.amount_minted) { + // make sure there is no burnt/mint set for transfers, unless it is a burn, since these numbers will affect circulating supply. + + if ((tx.amount_burnt && hf_version 0 for a transfer tx."); tvc.m_verifivation_failed = true; return false; } + if ((hf_version >= HF_VERSION_BURN) && tx.amount_minted) { + LOG_ERROR("error: Invalid Tx found. Amount mint > 0 for a transfer tx."); + tvc.m_verifivation_failed = true; + return false; + } + + // make sure no pr height set if (tx.pricing_record_height) { LOG_ERROR("error: Invalid Tx found. Tx pricing_record_height > 0 for a transfer tx."); @@ -1564,9 +1572,11 @@ namespace cryptonote std::list> remove; m_blockchain.for_all_txpool_txes([this, &remove](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata_ref*) { uint64_t tx_age = time(nullptr) - meta.receive_time; + bool has_conv_fee = (meta.offshore_fee > 0); if((tx_age > CRYPTONOTE_MEMPOOL_TX_LIVETIME && !meta.kept_by_block) || - (tx_age > CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && meta.kept_by_block) ) + (tx_age > CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME && meta.kept_by_block) || + (has_conv_fee && tx_age > CRYPTONOTE_MEMPOOL_TX_CONVERSION_LIVETIME && !meta.kept_by_block)) //Remove conversions faster, as their pricing record is outdated { LOG_PRINT_L1("Tx " << txid << " removed from tx pool due to outdated, age: " << tx_age ); auto sorted_it = find_tx_in_sorted_container(txid); diff --git a/src/hardforks/hardforks.cpp b/src/hardforks/hardforks.cpp index a5e0c835d..ba6892e0b 100644 --- a/src/hardforks/hardforks.cpp +++ b/src/hardforks/hardforks.cpp @@ -49,7 +49,8 @@ const hardfork_t mainnet_hard_forks[] = { { 20, 1272875, 0, 1671618321 }, // Fork time is on or around 9th January 2023 at 10:00 GMT. Fork time finalised on 2022-12-21. { 21, 1439500, 0, 1690797000 }, // Fork time is on or around 29th August 2023 at 10:00 GMT. Fork time finalised on 2023-07-31. { 22, 1439544, 0, 1693999500 }, // Fork time is on or around 29th August 2023 at 12:05 GMT. Fork time finalised on 2023-09-06. - { 23, 1656000, 0, 1719672007 } // Fork time is on or around 8th July 2024 at 09:00 GMT. Fork time finalised on 2024-06-29. + { 23, 1656000, 0, 1719672007 }, // Fork time is on or around 8th July 2024 at 09:00 GMT. Fork time finalised on 2024-06-29. + { 24, 1691182, 0, 1724716500 } // Fork time is on or around 26th August 2024 at 23:55 GMT. }; const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); const uint64_t mainnet_hard_fork_version_1_till = 1009826; @@ -72,7 +73,8 @@ const hardfork_t testnet_hard_forks[] = { { 20, 100, 0, 1657094479 }, { 21, 300, 0, 1680518049 }, { 22, 400, 0, 1693999500 }, - { 23, 450, 0, 1714641723 } + { 23, 450, 0, 1714641723 }, + { 24, 500, 0, 1724716500 } }; const size_t num_testnet_hard_forks = sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]); const uint64_t testnet_hard_fork_version_1_till = 624633; diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp index b362914d7..163900a5c 100644 --- a/src/ringct/rctSigs.cpp +++ b/src/ringct/rctSigs.cpp @@ -1700,7 +1700,23 @@ namespace rct { CHECK_AND_ASSERT_MES(amount_collateral, false, "0 collateral requirement something went wrong! rejecting tx.."); } } + + if (strSource == strDest) { + CHECK_AND_ASSERT_MES(pr.empty(), false, "Pricing record found for a transfer! rejecting tx.."); + CHECK_AND_ASSERT_MES(amount_collateral==0, false, "Collateral found for a transfer! rejecting tx.."); + CHECK_AND_ASSERT_MES(amount_slippage==0, false, "Slippage found for a transfer! rejecting tx.."); + if (version < HF_VERSION_BURN) { + CHECK_AND_ASSERT_MES(amount_burnt==0, false, "amount_burnt found for a transfer tx! rejecting tx.. "); + } + } + + uint64_t amount_supply_burnt = 0; + + if ((tx_type == tt::TRANSFER || tx_type == tt::OFFSHORE_TRANSFER || tx_type == tt::XASSET_TRANSFER) && version >= HF_VERSION_BURN && amount_burnt>0){ + amount_supply_burnt = amount_burnt; + } + // OUTPUTS SUMMED FOR EACH COLOUR key zerokey = rct::identity(); // Zi is intentionally set to a different value to zerokey, so that if a bug is introduced in the later logic, any comparison with zerokey will fail @@ -1731,6 +1747,11 @@ namespace rct { LOG_ERROR("Failed to get output type"); return false; } + + if (version >= HF_VERSION_ADDITIONAL_COLLATERAL_CHECKS && (is_collateral || is_collateral_change) && output_asset_type != "XHV"){ + LOG_ERROR("Collateral which is not XHV found"); + return false; + } // Don't exclude the onshore collateral ouputs from proof-of-value calculation if (output_asset_type == strSource) { @@ -1776,6 +1797,8 @@ namespace rct { key txnFeeKey = scalarmultH(d2h(rv.txnFee)); // Calculate offshore conversion fee (also always in C colour) key txnOffshoreFeeKey = scalarmultH(d2h(rv.txnOffshoreFee)); + // Calculate the supply burn (also always in C colour) + key amount_supply_burntKey = scalarmultH(d2h(amount_supply_burnt)); // Sum the consumed outputs in their respective asset types (sumColIns = inputs in D) key sumPseudoOuts = zerokey; @@ -1804,6 +1827,9 @@ namespace rct { // (Note: there are only consumed output commitments in D colour if the transaction is an onshore and requires collateral) subKeys(sumD, sumColIns, sumOutpks_D); + //Remove burnt supply + subKeys(sumC, sumC, amount_supply_burntKey); + if (version >= HF_VERSION_CONVERSION_FEES_IN_XHV) { // NEAC: Convert the fees for conversions to XHV if (tx_type == tt::TRANSFER || tx_type == tt::OFFSHORE || tx_type == tt::OFFSHORE_TRANSFER || tx_type == tt::XASSET_TRANSFER) { @@ -1913,6 +1939,11 @@ namespace rct { if (version >= HF_VERSION_SLIPPAGE) { // Subtract the slippage from the amount_burnt + // Check for potential underflow and fail + if (amount_burnt Date: Tue, 20 Aug 2024 08:37:19 +0000 Subject: [PATCH 2/4] initial implementation of burn in the CLI (#73) * initial implementation of burn in the CLI * additional CLI burn related changes * bugfix - burn tx should not be possible before Haven 4.1 --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w --- src/cryptonote_core/cryptonote_tx_utils.cpp | 16 +- src/cryptonote_core/cryptonote_tx_utils.h | 10 +- src/simplewallet/simplewallet.cpp | 168 +++++++++++++++++++- src/simplewallet/simplewallet.h | 4 + src/wallet/wallet2.cpp | 82 ++++++++-- src/wallet/wallet2.h | 3 + 6 files changed, 258 insertions(+), 25 deletions(-) diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 0e0927d78..013508a7f 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -1537,6 +1537,12 @@ namespace cryptonote (tx_type == transaction_type::XUSD_TO_XASSET) ? get_xusd_to_xasset_fee(destinations, hf_version) : (tx_type == transaction_type::XASSET_TO_XUSD) ? get_xasset_to_xusd_fee(destinations, hf_version) : 0; + uint64_t supply_burnt = 0; + + for(const tx_destination_entry& dst_entr: destinations) { + supply_burnt += dst_entr.supply_burnt; + } + if (shuffle_outs) { std::shuffle(destinations.begin(), destinations.end(), crypto::random_device{}); @@ -1588,14 +1594,18 @@ namespace cryptonote //fill outputs size_t output_index = 0; uint64_t summary_outs_slippage = 0; + uint64_t summary_outs_supply_burn = 0; + for(const tx_destination_entry& dst_entr: destinations) { CHECK_AND_ASSERT_MES(dst_entr.dest_amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.dest_amount); + CHECK_AND_ASSERT_MES(dst_entr.supply_burnt == 0 || hf_version >= HF_VERSION_BURN, false, "Burn transaction before Haven 4.1"); crypto::public_key out_eph_public_key; crypto::view_tag view_tag; // Sum all the slippage across the outputs summary_outs_slippage += dst_entr.slippage; + summary_outs_supply_burn += dst_entr.supply_burnt; hwdev.generate_output_ephemeral_keys(tx.version,sender_account_keys, txkey_pub, tx_key, dst_entr, change_addr, output_index, @@ -1637,9 +1647,13 @@ namespace cryptonote tx.amount_minted += dst_entr.dest_amount; tx.amount_burnt += dst_entr.amount + dst_entr.slippage; } + } else { + tx.amount_burnt += dst_entr.supply_burnt; } } + + CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys"); remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys)); @@ -1847,7 +1861,7 @@ namespace cryptonote if (!use_simple_rct && amount_in > amount_out) outamounts.push_back(amount_in - amount_out); else - fee = summary_inputs_money - summary_outs_money - offshore_fee; + fee = summary_inputs_money - summary_outs_money - offshore_fee - supply_burnt; // since the col ins are added to the summary_inputs_money above for offshores, subtract it. if (tx_type == transaction_type::OFFSHORE && hf_version >= HF_VERSION_USE_COLLATERAL) { diff --git a/src/cryptonote_core/cryptonote_tx_utils.h b/src/cryptonote_core/cryptonote_tx_utils.h index 98573f15d..98e52bb88 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.h +++ b/src/cryptonote_core/cryptonote_tx_utils.h @@ -106,6 +106,7 @@ namespace cryptonote uint64_t amount; // destination money in source asset uint64_t dest_amount; // destination money in dest asset uint64_t slippage; // destination money in source asset that will be burnt as slippage + uint64_t supply_burnt; // amount of source asset to be permanently burnt as part of a transfer std::string dest_asset_type; // destination asset type account_public_address addr; // destination address bool is_subaddress; @@ -113,10 +114,10 @@ namespace cryptonote bool is_collateral; bool is_collateral_change; - tx_destination_entry() : amount(0), dest_amount(0), slippage(0), addr(AUTO_VAL_INIT(addr)), is_subaddress(false), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } - tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress, bool is_collateral, bool is_collateral_change) : amount(a), dest_amount(a), slippage(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(is_collateral), is_collateral_change(is_collateral_change), dest_asset_type("XHV") { } - tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress) : amount(a), slippage(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } - tx_destination_entry(const std::string &o, uint64_t a, const account_public_address &ad, bool is_subaddress) : original(o), amount(a), slippage(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } + tx_destination_entry() : amount(0), dest_amount(0), slippage(0), supply_burnt(0), addr(AUTO_VAL_INIT(addr)), is_subaddress(false), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } + tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress, bool is_collateral, bool is_collateral_change) : amount(a), dest_amount(a), slippage(0), supply_burnt(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(is_collateral), is_collateral_change(is_collateral_change), dest_asset_type("XHV") { } + tx_destination_entry(uint64_t a, const account_public_address &ad, bool is_subaddress) : amount(a), slippage(0), supply_burnt(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } + tx_destination_entry(const std::string &o, uint64_t a, const account_public_address &ad, bool is_subaddress) : original(o), amount(a), slippage(0), supply_burnt(0), addr(ad), is_subaddress(is_subaddress), is_integrated(false), is_collateral(false), is_collateral_change(false), dest_asset_type("XHV") { } std::string address(network_type nettype, const crypto::hash &payment_id) const { @@ -138,6 +139,7 @@ namespace cryptonote VARINT_FIELD(amount) VARINT_FIELD(dest_amount) VARINT_FIELD(slippage) + //VARINT_FIELD(supply_burnt) FIELD(dest_asset_type) FIELD(addr) FIELD(is_subaddress) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 20febea89..a69ca74cd 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -156,9 +156,23 @@ typedef cryptonote::simple_wallet sw; } \ } while(0) +#define CHECK_BURN_ENABLED() \ + do \ + { \ + if (!m_wallet->is_burn_enabled()) \ + { \ + fail_msg_writer() << tr("Burn is disabled."); \ + fail_msg_writer() << tr("Burn is an experimental feature and may have bugs. Things that could go wrong include: loss of entire funds in the wallet, corruption of wallet."); \ + fail_msg_writer() << tr("You can enable it with:"); \ + fail_msg_writer() << tr(" set enable-burn-experimental 1"); \ + return false; \ + } \ + } while(0) + enum TransferType { Transfer, TransferLocked, + TransferBurn, }; static std::string get_human_readable_timespan(std::chrono::seconds seconds); @@ -198,11 +212,14 @@ namespace const char* USAGE_PAYMENTS("payments [ ... ]"); const char* USAGE_PAYMENT_ID("payment_id"); const char* USAGE_TRANSFER("transfer [index=[,,...]] [] [] ( |
) []"); + const char* USAGE_TRANSFER_BURN("transfer_burn [index=[,,...]] [] [] ( |
) []"); const char* USAGE_LOCKED_TRANSFER("locked_transfer [index=[,,...]] [] [] ( | ) []"); const char* USAGE_OFFSHORE("offshore [index=[,,...]] [] [] ( |
[memo=])"); const char* USAGE_OFFSHORE_TRANSFER("offshore_transfer [index=[,,...]] [] [] ( |
[memo=])"); + const char* USAGE_OFFSHORE_TRANSFER_BURN("offshore_transfer_burn [index=[,,...]] [] [] ( |
[memo=])"); const char* USAGE_ONSHORE("onshore [index=[,,...]] [] [] ( |
[memo=])"); const char* USAGE_XASSET_TRANSFER("xasset_transfer [index=[,,...]] [] [] ( |
) [memo=]"); + const char* USAGE_XASSET_TRANSFER_BURN("xasset_transfer_burn [index=[,,...]] [] [] ( |
) [memo=]"); const char* USAGE_XASSET_TO_XUSD("xasset_to_xusd [index=[,,...]] [] [] ( |
) [memo=]"); const char* USAGE_XUSD_TO_XASSET("xusd_to_xasset [index=[,,...]] [] [] ( |
) [memo=]"); const char* USAGE_LOCKED_SWEEP_ALL("locked_sweep_all [index=[,,...] | index=all] [] []
[]"); @@ -3139,6 +3156,25 @@ bool simple_wallet::set_enable_multisig(const std::vector &args/* = return true; } +bool simple_wallet::set_enable_burn(const std::vector &args/* = std::vector()*/) +{ + if (args.size() < 2) + { + fail_msg_writer() << tr("Value not specified"); + return true; + } + + const auto pwd_container = get_and_verify_password(); + if (pwd_container) + { + parse_bool_and_use(args[1], [&](bool r) { + m_wallet->enable_burn(r); + m_wallet->rewrite(m_wallet_file, pwd_container->password()); + }); + } + return true; +} + bool simple_wallet::help(const std::vector &args/* = std::vector()*/) { if(args.empty()) @@ -3310,6 +3346,9 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::on_command, this, &simple_wallet::transfer, _1), tr(USAGE_TRANSFER), tr("Transfer to
. If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or etcetera (before the payment ID, if it's included)")); + m_cmd_binder.set_handler("transfer_burn", boost::bind(&simple_wallet::on_command, this, &simple_wallet::transfer_burn, _1), + tr(USAGE_TRANSFER_BURN), + tr("Transfer to
, burning . If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or etcetera (before the payment ID, if it's included)")); m_cmd_binder.set_handler("locked_transfer", boost::bind(&simple_wallet::on_command, this, &simple_wallet::locked_transfer,_1), tr(USAGE_LOCKED_TRANSFER), @@ -3322,6 +3361,10 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::offshore_transfer, this, _1), tr(USAGE_OFFSHORE_TRANSFER), tr("Transfer xUSD from current offshore balance to
. If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or etcetera (before the payment ID, if it's included)")); + m_cmd_binder.set_handler("offshore_transfer_burn", + boost::bind(&simple_wallet::offshore_transfer_burn, this, _1), + tr(USAGE_OFFSHORE_TRANSFER_BURN), + tr("Transfer xUSD and burn from current offshore balance to
. If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or etcetera (before the payment ID, if it's included)")); m_cmd_binder.set_handler("onshore", boost::bind(&simple_wallet::onshore, this, _1), tr(USAGE_ONSHORE), @@ -3330,6 +3373,10 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::xasset_transfer, this, _1), tr(USAGE_XASSET_TRANSFER), tr("Transfer of xAsset type from current balance to
. If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made (using the same asset type) at once by adding URI_2 or etcetera (before the payment ID, if it's included). If is provided, only 1 destination address / URI may be specified.")); + m_cmd_binder.set_handler("xasset_transfer_burn", + boost::bind(&simple_wallet::xasset_transfer_burn, this, _1), + tr(USAGE_XASSET_TRANSFER_BURN), + tr("Transfer and burn of xAsset type from current balance to
. If the parameter \"index=[,,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. is the number of inputs to include for untraceability. Multiple payments can be made (using the same asset type) at once by adding URI_2 or etcetera (before the payment ID, if it's included). If is provided, only 1 destination address / URI may be specified.")); m_cmd_binder.set_handler("xasset_to_xusd", boost::bind(&simple_wallet::xasset_to_xusd, this, _1), tr(USAGE_XASSET_TO_XUSD), @@ -3514,6 +3561,8 @@ simple_wallet::simple_wallet() " Set this if you would like to display the wallet name when locked.\n " "enable-multisig-experimental <1|0>\n " " Set this to allow multisig commands. Multisig may currently be exploitable if parties do not trust each other.\n " + "enable-burn-experimental <1|0>\n " + " Set this to allow burning of funds. This feature can result in complete funds loss. Do not use.\n " "inactivity-lock-timeout \n " " How many seconds to wait before locking the wallet (0 to disable).")); m_cmd_binder.set_handler("encrypted_seed", @@ -3997,6 +4046,7 @@ bool simple_wallet::set_variable(const std::vector &args) CHECK_SIMPLE_VARIABLE("auto-mine-for-rpc-payment-threshold", set_auto_mine_for_rpc_payment_threshold, tr("floating point >= 0")); CHECK_SIMPLE_VARIABLE("credits-target", set_credits_target, tr("unsigned integer")); CHECK_SIMPLE_VARIABLE("enable-multisig-experimental", set_enable_multisig, tr("0 or 1")); + CHECK_SIMPLE_VARIABLE("enable-burn-experimental", set_enable_burn, tr("0 or 1")); } fail_msg_writer() << tr("set: unrecognized argument(s)"); return true; @@ -6703,6 +6753,9 @@ bool simple_wallet::transfer_main( bool called_by_mms ){ + if (transfer_type == TransferBurn){ + CHECK_BURN_ENABLED(); + } // "transfer [index=[,,...]] [] []
[]" if (!try_connect_to_daemon()) return false; @@ -6753,7 +6806,7 @@ bool simple_wallet::transfer_main( return false; } - const size_t min_args = (transfer_type == TransferLocked) ? 2 : 1; + const size_t min_args = (transfer_type == TransferLocked) ? 2 : (transfer_type == TransferBurn) ? 2 : 1; if(local_args.size() < min_args) { fail_msg_writer() << tr("wrong number of arguments"); @@ -6798,7 +6851,33 @@ bool simple_wallet::transfer_main( local_args.pop_back(); } - // check fot blocked xjpy + uint64_t amount_supply_burnt = 0; + bool amount_supply_burnt_applied = false; + if (transfer_type == TransferBurn) + { + // check if burn is allowed + CHECK_BURN_ENABLED(); + if (!m_wallet->use_fork_rules(HF_VERSION_BURN, 0)) { + fail_msg_writer() << tr("Burn transactions not allowed before Haven 4.1"); + return false; + } + try + { + bool ok = cryptonote::parse_amount(amount_supply_burnt, local_args.back()); + if (!ok) { + fail_msg_writer() << tr("bad parameter:") << " " << local_args.back(); + return false; + } + } + catch (const std::exception &e) + { + fail_msg_writer() << tr("bad parameter:") << " " << local_args.back(); + return false; + } + local_args.pop_back(); + } + + // check for blocked xjpy if (m_wallet->use_fork_rules(HF_VERSION_HAVEN2, 0)) { if (source_asset == "XJPY" || dest_asset == "XJPY") { fail_msg_writer() << tr("XJPY transaction are disabled after haven2 fork."); @@ -6846,6 +6925,11 @@ bool simple_wallet::transfer_main( bool has_uri = m_wallet->parse_uri(local_args[i], address_uri, payment_id_uri, amount, tx_description, recipient_name, unknown_parameters, error); if (has_uri) { + if (amount_supply_burnt>0) + { + fail_msg_writer() << tr("URI not supported for burn transactions"); + return false; + } r = cryptonote::get_account_address_from_str_or_url(info, m_wallet->nettype(), address_uri, oa_prompter); if (payment_id_uri.size() == 16) { @@ -6874,6 +6958,11 @@ bool simple_wallet::transfer_main( fail_msg_writer() << tr("failed to get max destination amount: ") << err; return false; } + if (amount_supply_burnt > 0) + { + fail_msg_writer() << tr("usage of max not supported for burn transactions"); + return false; + } de.amount = amount; } else { fail_msg_writer() << tr("amount is wrong: ") << local_args[i] << ' ' << local_args[i + 1] << @@ -6882,6 +6971,10 @@ bool simple_wallet::transfer_main( } } de.original = local_args[i]; + if (amount_supply_burnt>0 && !amount_supply_burnt_applied){ + de.supply_burnt=amount_supply_burnt; + amount_supply_burnt_applied=true; + } i += 2; } else @@ -6964,6 +7057,9 @@ bool simple_wallet::transfer_main( case Transfer: ptx_vector = m_wallet->create_transactions_2(dsts, source_asset, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices); break; + case TransferBurn: + ptx_vector = m_wallet->create_transactions_2(dsts, source_asset, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices); + break; } if (ptx_vector.empty()) @@ -7034,6 +7130,7 @@ bool simple_wallet::transfer_main( uint64_t total_col = 0; uint64_t total_slippage = 0; uint64_t total_tx_fee = 0; + uint64_t total_suppy_burnt = 0; uint64_t total_offshore_fee = 0; uint64_t dust_not_in_fee = 0; uint64_t dust_in_fee = 0; @@ -7041,6 +7138,8 @@ bool simple_wallet::transfer_main( for (size_t n = 0; n < ptx_vector.size(); ++n) { total_tx_fee += ptx_vector[n].tx.rct_signatures.txnFee; + if (tx_type == tt::TRANSFER || tx_type == tt::OFFSHORE_TRANSFER || tx_type == tt::XASSET_TRANSFER) + total_suppy_burnt += ptx_vector[n].tx.amount_burnt; total_offshore_fee += ptx_vector[n].tx.rct_signatures.txnOffshoreFee; for (auto i: ptx_vector[n].selected_transfers) if (m_wallet->get_transfer_details(i).asset_type == source_asset) @@ -7080,7 +7179,13 @@ bool simple_wallet::transfer_main( } uint64_t conversion_fee_in_C = total_offshore_fee; if (source_asset == dest_asset) { - prompt << boost::format(tr("Sending %s %s.\n")) % print_money(total_sent) % source_asset; + prompt << boost::format(tr("Sending %s %s.\n")) % print_money(total_sent-total_suppy_burnt) % source_asset; + if (total_suppy_burnt > 0) { + message_writer(console_color_red, false) << boost::format(tr("WARNING WARNING WARNING !!!.\n")); + message_writer(console_color_red, false) << boost::format(tr("PERMANENTLY DESTROYING %s %s , MAKE SURE THIS IS INTENTIONAL !!!.\n")) % print_money(total_suppy_burnt) % source_asset; + message_writer(console_color_red, false) << boost::format(tr("ABORT IMMEDIATELLY UNLESS ABSOLUTELY CERTAIN !!!.\n")); + prompt << boost::format(tr("!!!! PERMANENTLY DESTROYING %s %s , MAKE SURE THIS IS INTENTIONAL !!!.\n")) % print_money(total_suppy_burnt) % source_asset; + } } else { double total_slippage_pct = double(total_slippage) / double(total_sent) * 100; switch (tx_type) @@ -7278,6 +7383,18 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::transfer_burn(const std::vector &args_) +{ + CHECK_BURN_ENABLED(); + if (args_.size() < 2) + { + PRINT_USAGE(USAGE_TRANSFER_BURN); + return true; + } + transfer_main(TransferBurn, "XHV", "XHV", args_, false); + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::locked_transfer(const std::vector &args_) { if (args_.size() < 1) @@ -7323,6 +7440,18 @@ bool simple_wallet::offshore_transfer(const std::vector &args_) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::offshore_transfer_burn(const std::vector &args_) +{ + CHECK_BURN_ENABLED(); + if (args_.size() < 3) + { + PRINT_USAGE(USAGE_OFFSHORE_TRANSFER_BURN); + return true; + } + transfer_main(TransferBurn, "XUSD", "XUSD", args_, false); + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::xasset_to_xusd(const std::vector &args_) { // Verify the arguments provided @@ -7353,6 +7482,7 @@ bool simple_wallet::xasset_to_xusd(const std::vector &args_) transfer_main(Transfer, source_asset, "XUSD", local_args, false); return true; } +//---------------------------------------------------------------------------------------------------- bool simple_wallet::xasset_transfer(const std::vector &args) { // Verify the arguments provided @@ -7384,6 +7514,38 @@ bool simple_wallet::xasset_transfer(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- +bool simple_wallet::xasset_transfer_burn(const std::vector &args) +{ + CHECK_BURN_ENABLED(); + // Verify the arguments provided + if (args.size() < 4) { + PRINT_USAGE(USAGE_XASSET_TRANSFER_BURN); + return true; + } + + // copy args + std::vector local_args = args; + + // check and remove the asset type + std::string asset = boost::algorithm::to_upper_copy(*(local_args.end() - 1)); + if (std::find(offshore::ASSET_TYPES.begin(), offshore::ASSET_TYPES.end(), asset) == offshore::ASSET_TYPES.end()) { + fail_msg_writer() << boost::format(tr("Invalid currency '%s' specified")) % asset; + return false; + } + if (asset == "XUSD") { + fail_msg_writer() << "xasset_transfer_burn command is only for xAssets. You have to use 'offshore_transfer_burn' command to burn your xUSD."; + return false; + } + if (asset == "XHV") { + fail_msg_writer() << "xasset_transfer_burn command is only for xAssets. You have to use 'transfer_burn' command to burn your XHV."; + return false; + } + local_args.erase(local_args.end() - 1); + + transfer_main(TransferBurn, asset, asset, local_args, false); + return true; +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::xusd_to_xasset(const std::vector &args) { // Verify the arguments provided diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index b84407c6b..1f64d3094 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -152,6 +152,7 @@ namespace cryptonote bool set_export_format(const std::vector &args = std::vector()); bool set_load_deprecated_formats(const std::vector &args = std::vector()); bool set_enable_multisig(const std::vector &args = std::vector()); + bool set_enable_burn(const std::vector &args = std::vector()); bool set_persistent_rpc_client_id(const std::vector &args = std::vector()); bool set_auto_mine_for_rpc_payment_threshold(const std::vector &args = std::vector()); bool set_credits_target(const std::vector &args = std::vector()); @@ -170,12 +171,15 @@ namespace cryptonote bool show_blockchain_height(const std::vector &args); bool transfer_main(int transfer_type, const std::string& source_asset, const std::string& dest_asset, const std::vector &args, bool called_by_mms); bool transfer(const std::vector &args); + bool transfer_burn(const std::vector &args); bool offshore(const std::vector &args); bool onshore(const std::vector &args); bool offshore_transfer(const std::vector &args); + bool offshore_transfer_burn(const std::vector &args); bool xusd_to_xasset(const std::vector &args); bool xasset_to_xusd(const std::vector &args); bool xasset_transfer(const std::vector &args); + bool xasset_transfer_burn(const std::vector &args); bool locked_transfer(const std::vector &args); bool locked_sweep_all(const std::vector &args); bool sweep_main(uint32_t account, uint64_t below, bool locked, const std::vector &args); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b7ab84f80..3db449534 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1225,6 +1225,7 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std m_load_deprecated_formats(false), m_credits_target(0), m_enable_multisig(false), + m_enable_burn(false), m_has_ever_refreshed_from_node(false), m_allow_mismatched_daemon_version(false) { @@ -4681,6 +4682,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st m_auto_mine_for_rpc_payment_threshold = -1.0f; m_credits_target = 0; m_enable_multisig = false; + m_enable_burn = false; m_allow_mismatched_daemon_version = false; } else if(json.IsObject()) @@ -4916,6 +4918,9 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st m_credits_target = field_credits_target; GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, enable_multisig, int, Int, false, false); m_enable_multisig = field_enable_multisig; + + m_enable_burn = false; + } else { @@ -9581,6 +9586,7 @@ void wallet2::transfer_selected_rct( uint64_t upper_transaction_weight_limit = get_upper_transaction_weight_limit(); uint64_t needed_money = fee; uint64_t needed_slippage = 0; + uint64_t needed_supply_burnt = 0; uint64_t needed_col = 0; uint8_t hf_version = get_current_hard_fork(); uint64_t current_height = get_blockchain_current_height()-1; @@ -9593,12 +9599,17 @@ void wallet2::transfer_selected_rct( for(auto& dt: dsts) { THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_amount); + if (dt.supply_burnt>0){ + THROW_WALLET_EXCEPTION_IF(!m_enable_burn, error::wallet_internal_error, "Burn transaction is not enabled in the wallet"); + THROW_WALLET_EXCEPTION_IF(hf_version < HF_VERSION_BURN, error::wallet_internal_error, "Burn transaction not enabled before Haven 4.1"); + } // exclude the onshore collateral from needed money if (!using_onshore_collateral || !dt.is_collateral) { - needed_money += dt.amount + dt.slippage; + needed_money += dt.amount + dt.slippage + dt.supply_burnt; needed_slippage += dt.slippage; + needed_supply_burnt += dt.supply_burnt; LOG_PRINT_L2("transfer: adding " << print_money(dt.amount) << ", for a total of " << print_money (needed_money)); - THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount + dt.slippage, error::tx_sum_overflow, dsts, fee, m_nettype); + THROW_WALLET_EXCEPTION_IF(needed_money < dt.amount + dt.slippage + dt.supply_burnt, error::tx_sum_overflow, dsts, fee, m_nettype); } } @@ -10675,6 +10686,24 @@ std::vector wallet2::create_transactions_2( std::set subaddr_indices ){ + bool is_supply_burnt = false; + bool is_burn_enabled = false; + + is_burn_enabled = m_enable_burn && use_fork_rules(HF_VERSION_BURN, 0); + + //Check if one of the destinations has a permanently burnt amount + for (const auto& dt: dsts) { + if (dt.supply_burnt > 0){ + is_supply_burnt = true; + } + } + //We should only burn funds if the wallet has this feature enabled + if (!is_burn_enabled){ + //TO-DO add proper error message + THROW_WALLET_EXCEPTION_IF(is_supply_burnt, error::not_enough_unlocked_money, + 0, 0, 0); + } + //ensure device is let in NONE mode in any case hw::device &hwdev = m_account.get_device(); boost::unique_lock hwdev_lock (hwdev); @@ -10706,7 +10735,12 @@ std::vector wallet2::create_transactions_2( /* Add an output to the transaction. * Returns True if the output was added, False if there are no more available output slots. */ - bool add(const cryptonote::tx_destination_entry &de, uint64_t amount, uint64_t amount_slippage, unsigned int original_output_index, bool merge_destinations, size_t max_dsts) { + bool add(const cryptonote::tx_destination_entry &de, uint64_t amount, uint64_t amount_slippage, uint64_t amount_supply_burnt, unsigned int original_output_index, bool merge_destinations, size_t max_dsts, bool burn_enabled = false) { + if (!burn_enabled){ + //TO-DO add proper error message + THROW_WALLET_EXCEPTION_IF(amount_supply_burnt>0, error::not_enough_unlocked_money, + 0, 0, 0); + } if (merge_destinations) { std::vector::iterator i; @@ -10722,6 +10756,7 @@ std::vector wallet2::create_transactions_2( } i->amount += amount; i->slippage += amount_slippage; + i->supply_burnt += amount_supply_burnt; } else { @@ -10734,10 +10769,12 @@ std::vector wallet2::create_transactions_2( dsts.push_back(de); dsts.back().amount = 0; dsts.back().slippage = 0; + dsts.back().supply_burnt = 0; } THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &de.addr, sizeof(de.addr)), error::wallet_internal_error, "Mismatched destination address"); dsts[original_output_index].amount += amount; dsts[original_output_index].slippage += amount_slippage; + dsts[original_output_index].supply_burnt += amount_supply_burnt; } return true; } @@ -10803,6 +10840,7 @@ std::vector wallet2::create_transactions_2( needed_money = 0; uint64_t needed_col = 0; uint64_t needed_slippage = 0; + uint64_t needed_supply_burnt = 0; for(auto& dt: dsts) { THROW_WALLET_EXCEPTION_IF(0 == dt.amount, error::zero_amount); @@ -10852,12 +10890,14 @@ std::vector wallet2::create_transactions_2( needed_col += collateral_amount; } } - needed_money += dt.amount + dt.slippage; + needed_money += dt.amount + dt.slippage + dt.supply_burnt; if (dt.slippage) LOG_PRINT_L2("transfer: adding " << print_money(dt.amount) << " with " << print_money(dt.slippage) << " slippage, for a total of " << print_money (needed_money)); + else if (dt.supply_burnt) + LOG_PRINT_L2("transfer: adding " << print_money(dt.amount) << " with " << print_money(dt.supply_burnt) << " supply burnt, for a total of " << print_money (needed_money)); else LOG_PRINT_L2("transfer: adding " << print_money(dt.amount) << ", for a total of " << print_money (needed_money)); - THROW_WALLET_EXCEPTION_IF(needed_money < (dt.amount + dt.slippage), error::tx_sum_overflow, dsts, 0, m_nettype); + THROW_WALLET_EXCEPTION_IF(needed_money < (dt.amount + dt.slippage+dt.supply_burnt), error::tx_sum_overflow, dsts, 0, m_nettype); } // throw if attempting a transaction with no money @@ -11065,13 +11105,13 @@ std::vector wallet2::create_transactions_2( std::vector* unused_dust_indices = &unused_dust_indices_per_subaddr[0].second; hwdev.set_mode(hw::device::TRANSACTION_CREATE_FAKE); - while ((!dsts.empty() && (dsts[0].amount + dsts[0].slippage) > 0) || adding_fee || !preferred_inputs.empty() || should_pick_a_second_output(use_rct, txes.back().selected_transfers.size(), *unused_transfers_indices, *unused_dust_indices)) { + while ((!dsts.empty() && (dsts[0].amount + dsts[0].slippage+dsts[0].supply_burnt) > 0) || adding_fee || !preferred_inputs.empty() || should_pick_a_second_output(use_rct, txes.back().selected_transfers.size(), *unused_transfers_indices, *unused_dust_indices)) { TX &tx = txes.back(); LOG_PRINT_L2("Start of loop with " << unused_transfers_indices->size() << " " << unused_dust_indices->size() << ", tx.dsts.size() " << tx.dsts.size()); LOG_PRINT_L2("unused_transfers_indices: " << strjoin(*unused_transfers_indices, " ")); LOG_PRINT_L2("unused_dust_indices: " << strjoin(*unused_dust_indices, " ")); - LOG_PRINT_L2("dsts size " << dsts.size() << ", first " << (dsts.empty() ? "-" : cryptonote::print_money(dsts[0].amount)) << ", slippage " << dsts[0].slippage); + LOG_PRINT_L2("dsts size " << dsts.size() << ", first " << (dsts.empty() ? "-" : cryptonote::print_money(dsts[0].amount)) << ", slippage " << dsts[0].slippage << ", supply burnt " << +dsts[0].supply_burnt); LOG_PRINT_L2("adding_fee " << adding_fee << ", use_rct " << use_rct); // if we need to spend money and don't have any left, we fail @@ -11087,7 +11127,7 @@ std::vector wallet2::create_transactions_2( idx = pop_back(preferred_inputs); pop_if_present(*unused_transfers_indices, idx); pop_if_present(*unused_dust_indices, idx); - } else if ((dsts.empty() || (dsts[0].amount == 0 && dsts[0].slippage == 0)) && !adding_fee) { + } else if ((dsts.empty() || (dsts[0].amount == 0 && dsts[0].slippage == 0 && dsts[0].supply_burnt == 0)) && !adding_fee) { // the "make rct txes 2/2" case - we pick a small value output to "clean up" the wallet too std::vector indices = get_only_rct(*unused_dust_indices, *unused_transfers_indices); idx = pop_best_value(indices, tx.selected_transfers, true); @@ -11139,31 +11179,38 @@ std::vector wallet2::create_transactions_2( } else { - while (!dsts.empty() && (dsts[0].amount + dsts[0].slippage) <= available_amount && estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag, bulletproof_plus, use_view_tags) < TX_WEIGHT_TARGET(upper_transaction_weight_limit)) + while (!dsts.empty() && (dsts[0].amount + dsts[0].slippage + dsts[0].supply_burnt) <= available_amount && estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag, bulletproof_plus, use_view_tags) < TX_WEIGHT_TARGET(upper_transaction_weight_limit)) { // we can fully pay that destination LOG_PRINT_L2("We can fully pay " << get_account_address_as_str(m_nettype, dsts[0].is_subaddress, dsts[0].addr) << " for " << print_money(dsts[0].amount)); - if (!tx.add(dsts[0], dsts[0].amount, dsts[0].slippage, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1)) + if (!tx.add(dsts[0], dsts[0].amount, dsts[0].slippage, dsts[0].supply_burnt, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1, is_burn_enabled)) { LOG_PRINT_L2("Didn't pay: ran out of output slots"); + if (is_supply_burnt){ + LOG_PRINT_L2("ran out of output slots for a burn transaction"); + THROW_WALLET_EXCEPTION_IF(1, error::tx_not_possible, 0, 0, 0); + } out_slots_exhausted = true; break; } available_amount -= dsts[0].amount; available_amount -= dsts[0].slippage; + available_amount -= dsts[0].supply_burnt; dsts[0].amount = 0; dsts[0].slippage = 0; + dsts[0].supply_burnt = 0; pop_index(dsts, 0); ++original_output_index; } if (!out_slots_exhausted && available_amount > 0 && !dsts.empty() && - estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag, bulletproof_plus, use_view_tags) < TX_WEIGHT_TARGET(upper_transaction_weight_limit)) { + estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag, bulletproof_plus, use_view_tags) < TX_WEIGHT_TARGET(upper_transaction_weight_limit) && + ! is_supply_burnt ) { // we can partially fill that destination LOG_PRINT_L2("We can partially pay " << get_account_address_as_str(m_nettype, dsts[0].is_subaddress, dsts[0].addr) << " for " << print_money(available_amount) << "/" << print_money(dsts[0].amount)); - if (tx.add(dsts[0], available_amount > dsts[0].slippage ? (available_amount - dsts[0].slippage) : 0, available_amount > dsts[0].slippage ? dsts[0].slippage : available_amount, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1)) + if (tx.add(dsts[0], available_amount > dsts[0].slippage ? (available_amount - dsts[0].slippage) : 0, available_amount > dsts[0].slippage ? dsts[0].slippage : available_amount, 0 /*supply burn*/, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1)) { // HERE BE DRAGONS!!! // NEAC: handle situation where there is enough to pay for dt.amount but _not_ dt.slippage (which also needs paying for!!!) @@ -11241,7 +11288,7 @@ std::vector wallet2::create_transactions_2( // The check against original_output_index is to ensure the last entry in tx.dsts is really // a partial payment. Otherwise multiple requested outputs to the same address could // fool this logic into thinking there is a partial payment. - if (needed_fee > available_for_fee && !dsts.empty() && (dsts[0].amount+dsts[0].slippage) > 0 && tx.dsts.size() > original_output_index) + if (needed_fee > available_for_fee && !dsts.empty() && (dsts[0].amount+dsts[0].slippage+dsts[0].supply_burnt) > 0 && tx.dsts.size() > original_output_index) { // we don't have enough for the fee, but we've only partially paid the current address, // so we can take the fee from the paid amount, since we'll have to make another tx anyway @@ -11250,11 +11297,11 @@ std::vector wallet2::create_transactions_2( i = std::find_if(tx.dsts.begin(), tx.dsts.end(), [&](const cryptonote::tx_destination_entry &d) { return !memcmp (&d.addr, &dsts[0].addr, sizeof(dsts[0].addr)); }); THROW_WALLET_EXCEPTION_IF(i == tx.dsts.end(), error::wallet_internal_error, "paid address not found in outputs"); - if ((i->amount+i->slippage) > needed_fee) + if ((i->amount+i->slippage+i->supply_burnt) > needed_fee) { - uint64_t new_paid_amount = i->amount + i->slippage + test_ptx.fee; + uint64_t new_paid_amount = i->amount + i->slippage + i->supply_burnt + test_ptx.fee; LOG_PRINT_L2("Adjusting amount paid to " << get_account_address_as_str(m_nettype, i->is_subaddress, i->addr) << " from " << - print_money(i->amount + i->slippage) << " to " << print_money(new_paid_amount) << " to accommodate " << + print_money(i->amount + i->slippage + i->supply_burnt) << " to " << print_money(new_paid_amount) << " to accommodate " << print_money(needed_fee) << " fee"); if (i->amount >= needed_fee) { // Just take it from the destination amount @@ -11286,6 +11333,7 @@ std::vector wallet2::create_transactions_2( // Sanity check for split TXs if (!dsts.empty()) { THROW_WALLET_EXCEPTION_IF(source_asset != dest_asset, error::wallet_internal_error, "Cannot split conversion TXs - try consolidating your inputs using the appropriate 'sweep' or 'transfer' function"); + THROW_WALLET_EXCEPTION_IF(is_supply_burnt, error::wallet_internal_error, "Cannot split burn TXs - try consolidating your inputs using the appropriate 'sweep' or 'transfer' function"); for (auto &txdt: tx.dsts) { if (txdt.amount != txdt.dest_amount) { // Sanity check that the amount sums to what we want @@ -11300,7 +11348,7 @@ std::vector wallet2::create_transactions_2( uint64_t inputs = 0, outputs = needed_fee; for (size_t idx: tx.selected_transfers) inputs += m_transfers[idx].amount(); - for (const auto &o: tx.dsts) outputs += o.amount + o.slippage; + for (const auto &o: tx.dsts) outputs += o.amount + o.slippage + o.supply_burnt; if (inputs < outputs) { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d5e7ec879..4db8b8d58 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1449,7 +1449,9 @@ namespace tools uint64_t credits_target() const { return m_credits_target; } void credits_target(uint64_t threshold) { m_credits_target = threshold; } bool is_multisig_enabled() const { return m_enable_multisig; } + bool is_burn_enabled() const { return m_enable_burn; } void enable_multisig(bool enable) { m_enable_multisig = enable; } + void enable_burn(bool enable) { m_enable_burn = enable; } bool is_mismatched_daemon_version_allowed() const { return m_allow_mismatched_daemon_version; } void allow_mismatched_daemon_version(bool allow_mismatch) { m_allow_mismatched_daemon_version = allow_mismatch; } @@ -1976,6 +1978,7 @@ namespace tools rpc_payment_state_t m_rpc_payment_state; uint64_t m_credits_target; bool m_enable_multisig; + bool m_enable_burn; bool m_allow_mismatched_daemon_version; // Aux transaction data from device From c8f94752303852c8f62b65d477fc52c71e435608 Mon Sep 17 00:00:00 2001 From: Tay8NWWFKpz9JT4NXU0w Date: Thu, 22 Aug 2024 16:18:08 +0000 Subject: [PATCH 3/4] Haven 4.1 hard fork bugfixing and finalization (#74) * initial implementation of burn in the CLI * additional CLI burn related changes * bugfix - burn tx should not be possible before Haven 4.1 * fix warning message typo * finalize hardfork time * limit txn fee * add enable-burn-experimental to set values in CLI * fix display issues with xasset converions * rewording of CLI help message --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w --- src/cryptonote_config.h | 4 +++- src/hardforks/hardforks.cpp | 4 ++-- src/ringct/rctSigs.cpp | 1 + src/simplewallet/simplewallet.cpp | 9 +++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 30bc047b9..a7c51448c 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -261,6 +261,8 @@ #define HF_VERSION_BURN 24 #define HF_VERSION_CONVERSION_FEES_NOT_BURNT_FINAL 24 #define HF_VERSION_OFFSHORE_FEES_V3 24 +#define HF_VERSION_MAX_CONV_TRANSACTION_FEE 24 +#define MAX_CONV_TRANSACTION_FEE ((uint64_t)10000000000000ull) #define STAGENET_VERSION 0x0e @@ -272,7 +274,7 @@ #define BURNT_CONVERSION_FEES_MINT_HEIGHT ((uint64_t)1656720) #define BURNT_CONVERSION_FEES_MINT_AMOUNT_FINAL ((uint64_t)511812000000000000ull) -#define BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL ((uint64_t)1692002) +#define BURNT_CONVERSION_FEES_MINT_HEIGHT_FINAL ((uint64_t)1692780) #define PER_KB_FEE_QUANTIZATION_DECIMALS 8 #define CRYPTONOTE_SCALING_2021_FEE_ROUNDING_PLACES 2 diff --git a/src/hardforks/hardforks.cpp b/src/hardforks/hardforks.cpp index ba6892e0b..deca2ef5d 100644 --- a/src/hardforks/hardforks.cpp +++ b/src/hardforks/hardforks.cpp @@ -49,8 +49,8 @@ const hardfork_t mainnet_hard_forks[] = { { 20, 1272875, 0, 1671618321 }, // Fork time is on or around 9th January 2023 at 10:00 GMT. Fork time finalised on 2022-12-21. { 21, 1439500, 0, 1690797000 }, // Fork time is on or around 29th August 2023 at 10:00 GMT. Fork time finalised on 2023-07-31. { 22, 1439544, 0, 1693999500 }, // Fork time is on or around 29th August 2023 at 12:05 GMT. Fork time finalised on 2023-09-06. - { 23, 1656000, 0, 1719672007 }, // Fork time is on or around 8th July 2024 at 09:00 GMT. Fork time finalised on 2024-06-29. - { 24, 1691182, 0, 1724716500 } // Fork time is on or around 26th August 2024 at 23:55 GMT. + { 23, 1656000, 0, 1719672007 }, // Fork time is on or around 8th July 2024 at 09:00 GMT. Fork time finalised on 2024-06-29. + { 24, 1692720, 0, 1724274501 } // Fork time is on or around 28th August 2024 at 11:00 GMT. Fork time finalised on 2024-09-21. }; const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); const uint64_t mainnet_hard_fork_version_1_till = 1009826; diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp index 163900a5c..ff36172f5 100644 --- a/src/ringct/rctSigs.cpp +++ b/src/ringct/rctSigs.cpp @@ -1699,6 +1699,7 @@ namespace rct { if (tx_type == tt::OFFSHORE || tx_type == tt::ONSHORE) CHECK_AND_ASSERT_MES(amount_collateral, false, "0 collateral requirement something went wrong! rejecting tx.."); } + CHECK_AND_ASSERT_MES(version < HF_VERSION_MAX_CONV_TRANSACTION_FEE || rv.txnFee < MAX_CONV_TRANSACTION_FEE, false, "Transaction fee too high! rejecting tx.."); } if (strSource == strDest) { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index a69ca74cd..4729b2fc9 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3562,7 +3562,7 @@ simple_wallet::simple_wallet() "enable-multisig-experimental <1|0>\n " " Set this to allow multisig commands. Multisig may currently be exploitable if parties do not trust each other.\n " "enable-burn-experimental <1|0>\n " - " Set this to allow burning of funds. This feature can result in complete funds loss. Do not use.\n " + " Set this to allow burning of funds. This feature can result in complete loss of funds. Do not use.\n " "inactivity-lock-timeout \n " " How many seconds to wait before locking the wallet (0 to disable).")); m_cmd_binder.set_handler("encrypted_seed", @@ -3979,6 +3979,7 @@ bool simple_wallet::set_variable(const std::vector &args) success_msg_writer() << "credits-target = " << m_wallet->credits_target(); success_msg_writer() << "load-deprecated-formats = " << m_wallet->load_deprecated_formats(); success_msg_writer() << "enable-multisig-experimental = " << m_wallet->is_multisig_enabled(); + success_msg_writer() << "enable-burn-experimental = " << m_wallet->is_burn_enabled(); return true; } else @@ -7183,7 +7184,7 @@ bool simple_wallet::transfer_main( if (total_suppy_burnt > 0) { message_writer(console_color_red, false) << boost::format(tr("WARNING WARNING WARNING !!!.\n")); message_writer(console_color_red, false) << boost::format(tr("PERMANENTLY DESTROYING %s %s , MAKE SURE THIS IS INTENTIONAL !!!.\n")) % print_money(total_suppy_burnt) % source_asset; - message_writer(console_color_red, false) << boost::format(tr("ABORT IMMEDIATELLY UNLESS ABSOLUTELY CERTAIN !!!.\n")); + message_writer(console_color_red, false) << boost::format(tr("ABORT IMMEDIATELY UNLESS ABSOLUTELY CERTAIN !!!.\n")); prompt << boost::format(tr("!!!! PERMANENTLY DESTROYING %s %s , MAKE SURE THIS IS INTENTIONAL !!!.\n")) % print_money(total_suppy_burnt) % source_asset; } } else { @@ -7205,11 +7206,11 @@ bool simple_wallet::transfer_main( break; case tt::XUSD_TO_XASSET: conversion_fee_in_C = (total_sent * 3) / 200; - prompt << boost::format(tr("Converting %s XUSD (of which %s XUSD is slippage which is %s) to %s %s.\n")) % print_pct(total_slippage_pct, 2) % print_money(total_sent) % print_money(total_slippage) % print_money(total_received) % dest_asset; + prompt << boost::format(tr("Converting %s XUSD (of which %s XUSD is slippage which is %s) to %s %s.\n")) % print_money(total_sent) % print_money(total_slippage) % print_pct(total_slippage_pct, 2) % print_money(total_received) % dest_asset; break; case tt::XASSET_TO_XUSD: conversion_fee_in_C = (total_sent * 3) / 200; - prompt << boost::format(tr("Converting %s %s (of which %s %s is slippage which is %s) to %s XUSD.\n")) % print_pct(total_slippage_pct, 2) % print_money(total_sent) % source_asset % print_money(total_slippage) % source_asset % print_money(total_received); + prompt << boost::format(tr("Converting %s %s (of which %s %s is slippage which is %s) to %s XUSD.\n")) % print_money(total_sent) % source_asset % print_money(total_slippage) % source_asset % print_pct(total_slippage_pct, 2) % print_money(total_received); break; default: break; From 70e608f67d4afb813d02cfc5f4d768b29e9bf3bb Mon Sep 17 00:00:00 2001 From: goshiz <51964194+goshiz@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:35:39 +0200 Subject: [PATCH 4/4] merge back (#76) * Haven v4.1.0 (#75) * Haven 4.1 (#72) * fix floating point arithmetics differences causing difficulty drift There is a difference in the precision of difficulty calculation between Linux x86_64 and Windows / Linux ARM8. It seems to relate to floating point arithmetic deviations, most likely coming from the additional -m64 flag (rounding to 53 bits) passed in linux.mk in the make depend configuration. Changing the type to long double seems to fix the issue and produce consistent results between Linux x86_64 and other Windows / Linux ARM8. * add a parameter for how long a conversion should remain in the pool * remove conversions faster from the pool * create new hardfork, minting of burnt fees in XHV * add Proof of value rules for transfers with burn * take into account burn transactions in supply calc * add new hard fork * new slippage + mint of XHV validation * support for burn transactions * revert changes for CLI-triggered burn transaction * fix mcap ratio addon was not calculated,formatting * check that slippage is below converted amount * formatting and readability changes * additional security checks * adjust slippage calculation * 20% of on/offshore fees to miners * add mising conf HF_VERSION_OFFSHORE_FEES_V3 --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w * initial implementation of burn in the CLI (#73) * initial implementation of burn in the CLI * additional CLI burn related changes * bugfix - burn tx should not be possible before Haven 4.1 --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w * Haven 4.1 hard fork bugfixing and finalization (#74) * initial implementation of burn in the CLI * additional CLI burn related changes * bugfix - burn tx should not be possible before Haven 4.1 * fix warning message typo * finalize hardfork time * limit txn fee * add enable-burn-experimental to set values in CLI * fix display issues with xasset converions * rewording of CLI help message --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w * bump version --------- Co-authored-by: Tay8NWWFKpz9JT4NXU0w Co-authored-by: Goshiz --- README.md | 2 +- contrib/depends/README.md | 744 ++++++++++++++++++++++++++++++++++++-- src/version.cpp.in | 2 +- 3 files changed, 707 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 5eeb23baa..93cd750c5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Haven Prometheus v4.0.2 +# Haven Prometheus v4.1.0 Copyright (c) 2018-2024 Haven. Portions Copyright (c) 2014-2022 The Monero Project. diff --git a/contrib/depends/README.md b/contrib/depends/README.md index 1aa5b276f..93cd750c5 100644 --- a/contrib/depends/README.md +++ b/contrib/depends/README.md @@ -1,74 +1,740 @@ -### Usage +# Haven Prometheus v4.1.0 -To build dependencies for the current arch+OS: +Copyright (c) 2018-2024 Haven. +Portions Copyright (c) 2014-2022 The Monero Project. +Portions Copyright (c) 2012-2013 The Cryptonote developers. + +## Table of Contents + + - [Development resources](#development-resources) + - [Introduction](#introduction) + - [About this project](#about-this-project) + - [Supporting the project](#supporting-the-project) + - [License](#license) + - [Contributing](#contributing) + - [Compiling Haven from source](#compiling-haven-from-source) + - [Dependencies](#dependencies) + - [Internationalization](#Internationalization) + - [Using Tor](#using-tor) + - [Pruning](#Pruning) + - [Debugging](#Debugging) + - [Known issues](#known-issues) + +## Development resources + +- Web: [havenprotocol.org](https://havenprotocol.org) +- Mail: [team@havenprotocol.org](mailto:team@havenprotocol.org) +- GitHub: [https://github.com/haven-protocol-org/haven-main](https://github.com/haven-protocol-org/haven-main) + +## Introduction + +Haven is a private, secure, untraceable, decentralised digital currency based on Monero core. You are your bank, you control your funds, and nobody can trace your transfers unless you allow them to do so. + +**Privacy:** Haven uses a cryptographically sound system to allow you to send and receive funds without your transactions being easily revealed on the blockchain (the ledger of transactions that everyone has). This ensures that your purchases, receipts, and all transfers remain private by default. + +**Security:** Using the power of a distributed peer-to-peer consensus network, every transaction on the network is cryptographically secured. Individual wallets have a 25-word mnemonic seed that is only displayed once and can be written down to backup the wallet. Wallet files should be encrypted with a strong passphrase to ensure they are useless if ever stolen. + +**Untraceability:** By taking advantage of ring signatures, a special property of a certain type of cryptography, Haven is able to ensure that transactions are not only untraceable but have an optional measure of ambiguity that ensures that transactions cannot easily be tied back to an individual user or computer. + +**Decentralization:** The utility of Haven depends on its decentralised peer-to-peer consensus network - anyone should be able to run the haven software, validate the integrity of the blockchain, and participate in all aspects of the haven network using consumer-grade commodity hardware. Decentralization of the haven network is maintained by software development that minimizes the costs of running the haven software and inhibits the proliferation of specialized, non-commodity hardware. + +## About this project + +This is the core implementation of Haven. It is open source and completely free to use without restrictions, except for those specified in the license agreement below. There are no restrictions on anyone creating an alternative implementation of Haven that uses the protocol and network in a compatible manner. + +As with many development projects, the repository on GitHub is considered to be the "staging" area for the latest changes. Before changes are merged into that branch on the main repository, they are tested by individual developers in their own branches, submitted as a pull request, and then subsequently tested by contributors who focus on testing and code reviews. That having been said, the repository should be carefully considered before using it in a production environment, unless there is a patch in the repository for a particular show-stopping issue you are experiencing. It is generally a better idea to use a tagged release for stability. + +**Anyone is welcome to contribute to Haven's codebase!** If you have a fix or code change, feel free to submit it as a pull request directly to the "master" branch. In cases where the change is relatively small or does not affect other parts of the codebase, it may be merged in immediately by any one of the collaborators. On the other hand, if the change is particularly large or complex, it is expected that it will be discussed at length either well in advance of the pull request being submitted, or even directly on the pull request. + +## Supporting the project + +Haven is a 100% community-sponsored endeavor. If you want to join our efforts, the easiest thing you can do is support the project financially. you can send XHV to the Haven donation address via the `donate` command (type `help` in the command-line wallet for details). + +The Haven (XMR) address to donate to is: +`47SGs9QAcphWhVjPJP2BFJBMvt3FAxEPsH18W7XoBTEjPsvaxhqWeybjob4RqBWGnH6oQzZP8n4Sj122WcJSqXbTKfWByE1` + +The Haven (XHV) address to donate to is: +`hvxy2DK7Ku79XaAkEzJKqwe87qvnWKTtADESpMBWY9M3Heu5Lt9DLUV17kcM7Hkt6n2AY5oMePHVfPgiU4DteDzj56wopoYvqh` + +The Bitcoin (BTC) address to donate to is: +`bc1qykxdrraygumcguen3yp7vkydjfk8hdjtav0ud5` + +The Ethereum (ETH) address to donate to is: +`0xef2f306997e36d6a00685a9dae42ce023b6a6fad` + +The Tether (USDT) address to donate to is: + +ERC-20 (Ethereum Network) +`0xef2f306997e36d6a00685a9dae42ce023b6a6fad` + +TRC-20 (Tron Network) +`TCGbmuc4Hg3jwNr5SPHyqtc2VyqTTXP8Gr` + +The Verge (XVG) address to donate to is: +`DB3QyNgxMy4Z69GLQyGhxonNDdqSZpBVXf` + + +## License + +See [LICENSE](LICENSE). + +## Contributing + +If you want to help out, see [CONTRIBUTING](docs/CONTRIBUTING.md) for a set of guidelines. + +## Compiling Haven from source + +### Dependencies + +The following table summarizes the tools and libraries required to build. A +few of the libraries are also included in this repository (marked as +"Vendored"). By default, the build uses the library installed on the system +and ignores the vendored sources. However, if no library is found installed on +the system, then the vendored source will be built and used. The vendored +sources are also used for statically-linked builds because distribution +packages often include only shared library binaries (`.so`) but not static +library archives (`.a`). + +| Dep | Min. version | Vendored | Debian/Ubuntu pkg | Arch pkg | Void pkg | Fedora pkg | Optional | Purpose | +| ------------ | ------------- | -------- | -------------------- | ------------ | ------------------ | ------------------- | -------- | --------------- | +| GCC | 5 | NO | `build-essential` | `base-devel` | `base-devel` | `gcc` | NO | | +| CMake | 3.5 | NO | `cmake` | `cmake` | `cmake` | `cmake` | NO | | +| pkg-config | any | NO | `pkg-config` | `base-devel` | `base-devel` | `pkgconf` | NO | | +| Boost | 1.58 | NO | `libboost-all-dev` | `boost` | `boost-devel` | `boost-devel` | NO | C++ libraries | +| OpenSSL | basically any | NO | `libssl-dev` | `openssl` | `libressl-devel` | `openssl-devel` | NO | sha256 sum | +| libzmq | 4.2.0 | NO | `libzmq3-dev` | `zeromq` | `zeromq-devel` | `zeromq-devel` | NO | ZeroMQ library | +| OpenPGM | ? | NO | `libpgm-dev` | `libpgm` | | `openpgm-devel` | NO | For ZeroMQ | +| libnorm[2] | ? | NO | `libnorm-dev` | | | | YES | For ZeroMQ | +| libunbound | 1.4.16 | YES | `libunbound-dev` | `unbound` | `unbound-devel` | `unbound-devel` | NO | DNS resolver | +| libsodium | ? | NO | `libsodium-dev` | `libsodium` | `libsodium-devel` | `libsodium-devel` | NO | cryptography | +| libunwind | any | NO | `libunwind8-dev` | `libunwind` | `libunwind-devel` | `libunwind-devel` | YES | Stack traces | +| liblzma | any | NO | `liblzma-dev` | `xz` | `liblzma-devel` | `xz-devel` | YES | For libunwind | +| libreadline | 6.3.0 | NO | `libreadline6-dev` | `readline` | `readline-devel` | `readline-devel` | YES | Input editing | +| expat | 1.1 | NO | `libexpat1-dev` | `expat` | `expat-devel` | `expat-devel` | YES | XML parsing | +| GTest | 1.5 | YES | `libgtest-dev`[1] | `gtest` | `gtest-devel` | `gtest-devel` | YES | Test suite | +| ccache | any | NO | `ccache` | `ccache` | `ccache` | `ccache` | YES | Compil. cache | +| Doxygen | any | NO | `doxygen` | `doxygen` | `doxygen` | `doxygen` | YES | Documentation | +| Graphviz | any | NO | `graphviz` | `graphviz` | `graphviz` | `graphviz` | YES | Documentation | +| lrelease | ? | NO | `qttools5-dev-tools` | `qt5-tools` | `qt5-tools` | `qt5-linguist` | YES | Translations | +| libhidapi | ? | NO | `libhidapi-dev` | `hidapi` | `hidapi-devel` | `hidapi-devel` | YES | Hardware wallet | +| libusb | ? | NO | `libusb-1.0-0-dev` | `libusb` | `libusb-devel` | `libusbx-devel` | YES | Hardware wallet | +| libprotobuf | ? | NO | `libprotobuf-dev` | `protobuf` | `protobuf-devel` | `protobuf-devel` | YES | Hardware wallet | +| protoc | ? | NO | `protobuf-compiler` | `protobuf` | `protobuf` | `protobuf-compiler` | YES | Hardware wallet | +| libudev | ? | NO | `libudev-dev` | `systemd` | `eudev-libudev-devel` | `systemd-devel` | YES | Hardware wallet | + +[1] On Debian/Ubuntu `libgtest-dev` only includes sources and headers. You must +build the library binary manually. This can be done with the following command `sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake . && sudo make` +then: + +* on Debian: + `sudo mv libg* /usr/lib/` +* on Ubuntu: + `sudo mv lib/libg* /usr/lib/` + +[2] libnorm-dev is needed if your zmq library was built with libnorm, and not needed otherwise + +Install all dependencies at once on Debian/Ubuntu: + +``` +sudo apt update && sudo apt install build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz +``` + +Install all dependencies at once on Arch: +``` +sudo pacman -Syu --needed base-devel cmake boost openssl zeromq libpgm unbound libsodium libunwind xz readline expat gtest python3 ccache doxygen graphviz qt5-tools hidapi libusb protobuf systemd +``` + +Install all dependencies at once on Fedora: +``` +sudo dnf install gcc gcc-c++ cmake pkgconf boost-devel openssl-devel zeromq-devel openpgm-devel unbound-devel libsodium-devel libunwind-devel xz-devel readline-devel expat-devel gtest-devel ccache doxygen graphviz qt5-linguist hidapi-devel libusbx-devel protobuf-devel protobuf-compiler systemd-devel +``` + +Install all dependencies at once on openSUSE: + +``` +sudo zypper ref && sudo zypper in cppzmq-devel libboost_chrono-devel libboost_date_time-devel libboost_filesystem-devel libboost_locale-devel libboost_program_options-devel libboost_regex-devel libboost_serialization-devel libboost_system-devel libboost_thread-devel libexpat-devel libminiupnpc-devel libsodium-devel libunwind-devel unbound-devel cmake doxygen ccache fdupes gcc-c++ libevent-devel libopenssl-devel pkgconf-pkg-config readline-devel xz-devel libqt5-qttools-devel patterns-devel-C-C++-devel_C_C++ +``` + +Install all dependencies at once on macOS with the provided Brewfile: + +``` +brew update && brew bundle --file=contrib/brew/Brewfile +``` + +FreeBSD 12.1 one-liner required to build dependencies: + +``` +pkg install git gmake cmake pkgconf boost-libs libzmq4 libsodium unbound +``` + +### Cloning the repository + +Clone recursively to pull-in needed submodule(s): + +``` +git clone --recursive https://github.com/haven-protocol-org/haven-main +``` + +If you already have a repo cloned, initialize and update: + +``` +cd haven-main && git submodule init && git submodule update +``` + +*Note*: If there are submodule differences between branches, you may need +to use `git submodule sync && git submodule update` after changing branches +to build successfully. + +### Build instructions + +Haven uses the CMake build system and a top-level [Makefile](Makefile) that +invokes cmake commands as needed. + +#### On Linux and macOS + +* Install the dependencies +* Change to the root of the source code directory, change to the most recent release branch, and build: + + ```bash + cd haven-main + git checkout master + make + ``` + + *Optional*: If your machine has several cores and enough memory, enable + parallel build by running `make -j` instead of `make`. For + this to be worthwhile, the machine should have one core and about 2GB of RAM + available per thread. + + *Note*: The instructions above will compile the most stable release of the + Haven software. If you would like to use and test the most recent software, + use `git checkout master`. The master branch may contain updates that are + both unstable and incompatible with release software, though testing is always + encouraged. + +* The resulting executables can be found in `build/release/bin` + +* Add `PATH="$PATH:$HOME/haven-main/build/release/bin"` to `.profile` + +* Run Haven with `havend --detach` + +* **Optional**: build and run the test suite to verify the binaries: + + ```bash + make release-test + ``` + + *NOTE*: `core_tests` test may take a few hours to complete. + +* **Optional**: to build binaries suitable for debugging: + + ```bash + make debug + ``` + +* **Optional**: to build statically-linked binaries: + + ```bash + make release-static + ``` + +Dependencies need to be built with -fPIC. Static libraries usually aren't, so you may have to build them yourself with -fPIC. Refer to their documentation for how to build them. + +* **Optional**: build documentation in `doc/html` (omit `HAVE_DOT=YES` if `graphviz` is not installed): + + ```bash + HAVE_DOT=YES doxygen Doxyfile + ``` + +* **Optional**: use ccache not to rebuild translation units, that haven't really changed. Haven's CMakeLists.txt file automatically handles it + + ```bash + sudo apt install ccache + ``` + +#### On the Raspberry Pi + +Tested on a Raspberry Pi Zero with a clean install of minimal Raspbian Stretch (2017-09-07 or later) from https://www.raspberrypi.org/downloads/raspbian/. If you are using Raspian Jessie, [please see note in the following section](#note-for-raspbian-jessie-users). + +* `apt-get update && apt-get upgrade` to install all of the latest software + +* Install the dependencies for Haven from the 'Debian' column in the table above. + +* Increase the system swap size: + + ```bash + sudo /etc/init.d/dphys-swapfile stop + sudo nano /etc/dphys-swapfile + CONF_SWAPSIZE=2048 + sudo /etc/init.d/dphys-swapfile start + ``` + +* If using an external hard disk without an external power supply, ensure it gets enough power to avoid hardware issues when syncing, by adding the line "max_usb_current=1" to /boot/config.txt + +* Clone Haven and checkout the most recent release version: + + ```bash + git clone https://github.com/haven-protocol-org/haven-main.git + cd haven-main + git checkout master + ``` + +* Build: + + ```bash + USE_SINGLE_BUILDDIR=1 make release + ``` + +* Wait 4-6 hours + +* The resulting executables can be found in `build/release/bin` + +* Add `export PATH="$PATH:$HOME/haven-main/build/release/bin"` to `$HOME/.profile` + +* Run `source $HOME/.profile` + +* Run Haven with `havend --detach` + +* You may wish to reduce the size of the swap file after the build has finished, and delete the boost directory from your home directory + +#### *Note for Raspbian Jessie users:* + +If you are using the older Raspbian Jessie image, compiling Haven is a bit more complicated. The version of Boost available in the Debian Jessie repositories is too old to use with Haven, and thus you must compile a newer version yourself. The following explains the extra steps and has been tested on a Raspberry Pi 2 with a clean install of minimal Raspbian Jessie. + +* As before, `apt-get update && apt-get upgrade` to install all of the latest software, and increase the system swap size + + ```bash + sudo /etc/init.d/dphys-swapfile stop + sudo nano /etc/dphys-swapfile + CONF_SWAPSIZE=2048 + sudo /etc/init.d/dphys-swapfile start + ``` + + +* Then, install the dependencies for Haven except for `libunwind` and `libboost-all-dev` + +* Install the latest version of boost (this may first require invoking `apt-get remove --purge libboost*-dev` to remove a previous version if you're not using a clean install): + + ```bash + cd + wget https://sourceforge.net/projects/boost/files/boost/1.72.0/boost_1_72_0.tar.bz2 + tar xvfo boost_1_72_0.tar.bz2 + cd boost_1_72_0 + ./bootstrap.sh + sudo ./b2 + ``` + +* Wait ~8 hours + + ```bash + sudo ./bjam cxxflags=-fPIC cflags=-fPIC -a install + ``` + +* Wait ~4 hours + +* From here, follow the [general Raspberry Pi instructions](#on-the-raspberry-pi) from the "Clone Haven and checkout most recent release version" step. + +#### On Windows: + +Binaries for Windows are built on Windows using the MinGW toolchain within +[MSYS2 environment](https://www.msys2.org). The MSYS2 environment emulates a +POSIX system. The toolchain runs within the environment and *cross-compiles* +binaries that can run outside of the environment as a regular Windows +application. + +**Preparing the build environment** + +* Download and install the [MSYS2 installer](https://www.msys2.org), either the 64-bit or the 32-bit package, depending on your system. +* Open the MSYS shell via the `MSYS2 Shell` shortcut +* Update packages using pacman: + + ```bash + pacman -Syu + ``` + +* Exit the MSYS shell using Alt+F4 +* Edit the properties for the `MSYS2 Shell` shortcut changing "msys2_shell.bat" to "msys2_shell.cmd -mingw64" for 64-bit builds or "msys2_shell.cmd -mingw32" for 32-bit builds +* Restart MSYS shell via modified shortcut and update packages again using pacman: + + ```bash + pacman -Syu + ``` + + +* Install dependencies: + + To build for 64-bit Windows: + + ```bash + pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-unbound + ``` + + To build for 32-bit Windows: + + ```bash + pacman -S mingw-w64-i686-toolchain make mingw-w64-i686-cmake mingw-w64-i686-boost mingw-w64-i686-openssl mingw-w64-i686-zeromq mingw-w64-i686-libsodium mingw-w64-i686-hidapi mingw-w64-i686-unbound + ``` + +* Open the MingW shell via `MinGW-w64-Win64 Shell` shortcut on 64-bit Windows + or `MinGW-w64-Win64 Shell` shortcut on 32-bit Windows. Note that if you are + running 64-bit Windows, you will have both 64-bit and 32-bit MinGW shells. + +**Cloning** + +* To git clone, run: + + ```bash + git clone --recursive https://github.com/haven-protocol-org/haven-main.git + ``` + +**Building** + +* Change to the cloned directory, run: + + ```bash + cd haven-main + ``` + +* If you would like a specific [version/tag](https://github.com/haven-protocol-org/haven-main/tags), do a git checkout for that version. eg. 'v0.18.2.2'. If you don't care about the version and just want binaries from master, skip this step: + + ```bash + git checkout master + ``` + +* If you are on a 64-bit system, run: + + ```bash + make release-static-win64 + ``` + +* If you are on a 32-bit system, run: + + ```bash + make release-static-win32 + ``` + +* The resulting executables can be found in `build/release/bin` + +* **Optional**: to build Windows binaries suitable for debugging on a 64-bit system, run: + + ```bash + make debug-static-win64 + ``` + +* **Optional**: to build Windows binaries suitable for debugging on a 32-bit system, run: + + ```bash + make debug-static-win32 + ``` + +* The resulting executables can be found in `build/debug/bin` + +### On FreeBSD: + +The project can be built from scratch by following instructions for Linux above(but use `gmake` instead of `make`). +If you are running Haven in a jail, you need to add `sysvsem="new"` to your jail configuration, otherwise lmdb will throw the error message: `Failed to open lmdb environment: Function not implemented`. + + + +### On OpenBSD: + +You will need to add a few packages to your system. `pkg_add cmake gmake zeromq libiconv boost`. + +The `doxygen` and `graphviz` packages are optional and require the xbase set. +Running the test suite also requires `py-requests` package. + +Build haven: `env DEVELOPER_LOCAL_TOOLS=1 BOOST_ROOT=/usr/local gmake release-static` + +Note: you may encounter the following error when compiling the latest version of Haven as a normal user: + +``` +LLVM ERROR: out of memory +c++: error: unable to execute command: Abort trap (core dumped) +``` + +Then you need to increase the data ulimit size to 2GB and try again: `ulimit -d 2000000` + +### On NetBSD: + +Check that the dependencies are present: `pkg_info -c libexecinfo boost-headers boost-libs protobuf readline libusb1 zeromq git-base pkgconf gmake cmake | more`, and install any that are reported missing, using `pkg_add` or from your pkgsrc tree. Readline is optional but worth having. + +Third-party dependencies are usually under `/usr/pkg/`, but if you have a custom setup, adjust the "/usr/pkg" (below) accordingly. + +Clone the haven repository recursively and checkout the most recent release as described above. Then build haven: `gmake BOOST_ROOT=/usr/pkg LDFLAGS="-Wl,-R/usr/pkg/lib" release`. The resulting executables can be found in `build/NetBSD/[Release version]/Release/bin/`. + +### On Solaris: + +The default Solaris linker can't be used, you have to install GNU ld, then run cmake manually with the path to your copy of GNU ld: ```bash -make +mkdir -p build/release +cd build/release +cmake -DCMAKE_LINKER=/path/to/ld -D CMAKE_BUILD_TYPE=Release ../.. +cd ../.. ``` -To build for another arch/OS: +Then you can run make as usual. + +### Building portable statically linked binaries + +By default, in either dynamically or statically linked builds, binaries target the specific host processor on which the build happens and are not portable to other processors. Portable binaries can be built using the following targets: + +* ```make release-static-linux-x86_64``` builds binaries on Linux on x86_64 portable across POSIX systems on x86_64 processors +* ```make release-static-linux-i686``` builds binaries on Linux on x86_64 or i686 portable across POSIX systems on i686 processors +* ```make release-static-linux-armv8``` builds binaries on Linux portable across POSIX systems on armv8 processors +* ```make release-static-linux-armv7``` builds binaries on Linux portable across POSIX systems on armv7 processors +* ```make release-static-linux-armv6``` builds binaries on Linux portable across POSIX systems on armv6 processors +* ```make release-static-win64``` builds binaries on 64-bit Windows portable across 64-bit Windows systems +* ```make release-static-win32``` builds binaries on 64-bit or 32-bit Windows portable across 32-bit Windows systems + +### Cross Compiling + +You can also cross-compile static binaries on Linux for Windows and macOS with the `depends` system. + +* ```make depends target=x86_64-linux-gnu``` for 64-bit linux binaries. +* ```make depends target=x86_64-w64-mingw32``` for 64-bit windows binaries. + * Requires: `python3 g++-mingw-w64-x86-64 wine1.6 bc` +* ```make depends target=x86_64-apple-darwin11``` for macOS binaries. + * Requires: `cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev` +* ```make depends target=i686-linux-gnu``` for 32-bit linux binaries. + * Requires: `g++-multilib bc` +* ```make depends target=i686-w64-mingw32``` for 32-bit windows binaries. + * Requires: `python3 g++-mingw-w64-i686` +* ```make depends target=arm-linux-gnueabihf``` for armv7 binaries. + * Requires: `g++-arm-linux-gnueabihf` +* ```make depends target=aarch64-linux-gnu``` for armv8 binaries. + * Requires: `g++-aarch64-linux-gnu` +* ```make depends target=riscv64-linux-gnu``` for RISC V 64 bit binaries. + * Requires: `g++-riscv64-linux-gnu` +* ```make depends target=x86_64-unknown-freebsd``` for freebsd binaries. + * Requires: `clang-8` +* ```make depends target=arm-linux-android``` for 32bit android binaries +* ```make depends target=aarch64-linux-android``` for 64bit android binaries + + +The required packages are the names for each toolchain on apt. Depending on your distro, they may have different names. The `depends` system has been tested on Ubuntu 18.04 and 20.04. + +Using `depends` might also be easier to compile Haven on Windows than using MSYS. Activate Windows Subsystem for Linux (WSL) with a distro (for example Ubuntu), install the apt build-essentials and follow the `depends` steps as depicted above. + +The produced binaries still link libc dynamically. If the binary is compiled on a current distribution, it might not run on an older distribution with an older installation of libc. Passing `-DBACKCOMPAT=ON` to cmake will make sure that the binary will run on systems having at least libc version 2.17. + +* Docker + + ```bash + # Build using all available cores + docker build -t haven -f .docker/Dockerfile . + + # or build using a specific number of cores (reduce RAM requirement) + docker build -t haven --build-arg NPROC=1 -f .docker/Dockerfile . + + # either run in foreground + docker run -it -v /haven/chain:/home/haven/.haven -v /haven/wallet:/wallet -p 17750:17750 haven + + # or in background + docker run -it -d -v /haven/chain:/home/haven/.haven -v /haven/wallet:/wallet -p 17750:17750 haven + ``` + +* The build needs 3 GB space. +* Wait one hour or more + +Packaging for your favorite distribution would be a welcome contribution! + +## Running havend + +The build places the binary in `bin/` sub-directory within the build directory +from which cmake was invoked (repository root by default). To run in the +foreground: ```bash -make HOST=host-platform-triplet +./bin/havend ``` -For example: +To list all available options, run `./bin/havend --help`. Options can be +specified either on the command line or in a configuration file passed by the +`--config-file` argument. To specify an option in the configuration file, add +a line with the syntax `argumentname=value`, where `argumentname` is the name +of the argument without the leading dashes, for example, `log-level=1`. + +To run in background: + +```bash +./bin/havend --log-file havend.log --detach +``` + +To run as a systemd service, copy +[havend.service](utils/systemd/havend.service) to `/etc/systemd/system/` and +[havend.conf](utils/conf/havend.conf) to `/etc/`. The [example +service](utils/systemd/havend.service) assumes that the user `haven` exists +and its home is the data directory specified in the [example +config](utils/conf/havend.conf). + +If you're on Mac, you may need to add the `--max-concurrency 1` option to +haven-wallet-cli, and possibly havend, if you get crashes refreshing. + +## Internationalization + +See [README.i18n.md](docs/README.i18n.md). + +## Using Tor + +> There is a new, still experimental, [integration with Tor](docs/ANONYMITY_NETWORKS.md). The +> feature allows connecting over IPv4 and Tor simultaneously - IPv4 is used for +> relaying blocks and relaying transactions received by peers whereas Tor is +> used solely for relaying transactions received over local RPC. This provides +> privacy and better protection against surrounding node (sybil) attacks. + +While Haven isn't made to integrate with Tor, it can be used wrapped with torsocks, by +setting the following configuration parameters and environment variables: + +* `--p2p-bind-ip 127.0.0.1` on the command line or `p2p-bind-ip=127.0.0.1` in + havend.conf to disable listening for connections on external interfaces. +* `--no-igd` on the command line or `no-igd=1` in havend.conf to disable IGD + (UPnP port forwarding negotiation), which is pointless with Tor. +* `DNS_PUBLIC=tcp` or `DNS_PUBLIC=tcp://x.x.x.x` where x.x.x.x is the IP of the + desired DNS server, for DNS requests to go over TCP, so that they are routed + through Tor. When IP is not specified, havend uses the default list of + servers defined in [src/common/dns_utils.cpp](src/common/dns_utils.cpp). +* `TORSOCKS_ALLOW_INBOUND=1` to tell torsocks to allow havend to bind to interfaces + to accept connections from the wallet. On some Linux systems, torsocks + allows binding to localhost by default, so setting this variable is only + necessary to allow binding to local LAN/VPN interfaces to allow wallets to + connect from remote hosts. On other systems, it may be needed for local wallets + as well. +* Do NOT pass `--detach` when running through torsocks with systemd, (see + [utils/systemd/havend.service](utils/systemd/havend.service) for details). +* If you use the wallet with a Tor daemon via the loopback IP (eg, 127.0.0.1:9050), + then use `--untrusted-daemon` unless it is your own hidden service. + +Example command line to start havend through Tor: ```bash -make HOST=x86_64-w64-mingw32 -j4 +DNS_PUBLIC=tcp torsocks havend --p2p-bind-ip 127.0.0.1 --no-igd ``` -A toolchain will be generated that's suitable for plugging into Monero's -cmake. In the above example, a dir named x86_64-w64-mingw32 will be -created. To use it for Monero: +A helper script is in contrib/tor/haven-over-tor.sh. It assumes Tor is installed +already, and runs Tor and Haven with the right configuration. + +### Using Tor on Tails + +TAILS ships with a very restrictive set of firewall rules. Therefore, you need +to add a rule to allow this connection too, in addition to telling torsocks to +allow inbound connections. Full example: ```bash -cmake -DCMAKE_TOOLCHAIN=`pwd`/contrib/depends/x86_64-w64-mingw32 +sudo iptables -I OUTPUT 2 -p tcp -d 127.0.0.1 -m tcp --dport 17749 -j ACCEPT +DNS_PUBLIC=tcp torsocks ./havend --p2p-bind-ip 127.0.0.1 --no-igd --rpc-bind-ip 127.0.0.1 \ + --data-dir /home/amnesia/Persistent/your/directory/to/the/blockchain ``` -Common `host-platform-triplets` for cross compilation are: +## Pruning + +As of April 2022, the full Haven blockchain file is about 35 GB. One can store a pruned blockchain, which is about 20 GB. +A pruned blockchain can only serve part of the historical chain data to other peers, but is otherwise identical in +functionality to the full blockchain. +To use a pruned blockchain, it is best to start the initial sync with `--prune-blockchain`. However, it is also possible +to prune an existing blockchain using the `haven-blockchain-prune` tool or using the `--prune-blockchain` `havend` option +with an existing chain. If an existing chain exists, pruning will temporarily require disk space to store both the full +and pruned blockchains. + +## Debugging -- `i686-w64-mingw32` for Win32 -- `x86_64-w64-mingw32` for Win64 -- `x86_64-apple-darwin11` for MacOSX x86_64 -- `arm-linux-gnueabihf` for Linux ARM 32 bit -- `aarch64-linux-gnu` for Linux ARM 64 bit -- `riscv64-linux-gnu` for Linux RISCV 64 bit +This section contains general instructions for debugging failed installs or problems encountered with Haven. First, ensure you are running the latest version built from the GitHub repo. -No other options are needed, the paths are automatically configured. +### Obtaining stack traces and core dumps on Unix systems -Dependency Options: -The following can be set when running make: make FOO=bar +We generally use the tool `gdb` (GNU debugger) to provide stack trace functionality, and `ulimit` to provide core dumps in builds which crash or segfault. +* To use `gdb` in order to obtain a stack trace for a build that has stalled: + +Run the build. + +Once it stalls, enter the following command: + +```bash +gdb /path/to/havend `pidof havend` ``` -SOURCES_PATH: downloaded sources will be placed here -BASE_CACHE: built packages will be placed here -FALLBACK_DOWNLOAD_PATH: If a source file can't be fetched, try here before giving up -DEBUG: disable some optimizations and enable more runtime checking -HOST_ID_SALT: Optional salt to use when generating host package ids -BUILD_ID_SALT: Optional salt to use when generating build package ids + +Type `thread apply all bt` within gdb in order to obtain the stack trace + +* If however the core dumps or segfaults: + +Enter `ulimit -c unlimited` on the command line to enable unlimited filesizes for core dumps + +Enter `echo core | sudo tee /proc/sys/kernel/core_pattern` to stop cores from being hijacked by other tools + +Run the build. + +When it terminates with an output along the lines of "Segmentation fault (core dumped)", there should be a core dump file in the same directory as havend. It may be named just `core`, or `core.xxxx` with numbers appended. + +You can now analyse this core dump with `gdb` as follows: + +```bash +gdb /path/to/havend /path/to/dumpfile` ``` -Additional targets: +Print the stack trace with `bt` + * If a program crashed and cores are managed by systemd, the following can also get a stack trace for that crash: + +```bash +coredumpctl -1 gdb ``` -download: run 'make download' to fetch all sources without building them -download-osx: run 'make download-osx' to fetch all sources needed for osx builds -download-win: run 'make download-win' to fetch all sources needed for win builds -download-linux: run 'make download-linux' to fetch all sources needed for linux builds + +#### To run Haven within gdb: + +Type `gdb /path/to/havend` + +Pass command-line options with `--args` followed by the relevant arguments + +Type `run` to run havend + +### Analysing memory corruption + +There are two tools available: + +#### ASAN + +Configure Haven with the -D SANITIZE=ON cmake flag, eg: + +```bash +cd build/debug && cmake -D SANITIZE=ON -D CMAKE_BUILD_TYPE=Debug ../.. ``` -#Mingw builds +You can then run the haven tools normally. Performance will typically halve. + +#### valgrind -Building for 32/64bit mingw requires switching alternatives to a posix mode +Install valgrind and run as `valgrind /path/to/havend`. It will be very slow. + +### LMDB + +Instructions for debugging suspected blockchain corruption as per @HYC + +There is an `mdb_stat` command in the LMDB source that can print statistics about the database but it's not routinely built. This can be built with the following command: ```bash -update-alternatives --set x86_64-w64-mingw32-g++ x86_64-w64-mingw32-g++-posix -update-alternatives --set x86_64-w64-mingw32-gcc x86_64-w64-mingw32-gcc-posix +cd ~/haven/external/db_drivers/liblmdb && make ``` -### Other documentation +The output of `mdb_stat -ea ` will indicate inconsistencies in the blocks, block_heights and block_info table. + +The output of `mdb_dump -s blocks ` and `mdb_dump -s block_info ` is useful for indicating whether blocks and block_info contain the same keys. + +These records are dumped as hex data, where the first line is the key and the second line is the data. + +# Known Issues + +## Protocols + +### Socket-based + +Because of the nature of the socket-based protocols that drive haven, certain protocol weaknesses are somewhat unavoidable at this time. While these weaknesses can theoretically be fully mitigated, the effort required (the means) may not justify the ends. As such, please consider taking the following precautions if you are a haven node operator: + +- Run `havend` on a "secured" machine. If operational security is not your forte, at a very minimum, have a dedicated a computer running `havend` and **do not** browse the web, use email clients, or use any other potentially harmful apps on your `havend` machine. **Do not click links or load URL/MUA content on the same machine**. Doing so may potentially exploit weaknesses in commands which accept "localhost" and "127.0.0.1". +- If you plan on hosting a public "remote" node, start `havend` with `--restricted-rpc`. This is a must. + +### Blockchain-based -- [description.md](description.md): General description of the depends system -- [packages.md](packages.md): Steps for adding packages +Certain blockchain "features" can be considered "bugs" if misused correctly. Consequently, please consider the following: +- When receiving haven, be aware that it may be locked for an arbitrary time if the sender elected to, preventing you from spending that haven until the lock time expires. You may want to hold off acting upon such a transaction until the unlock time lapses. To get a sense of that time, you can consider the remaining blocktime until unlock as seen in the `show_transfers` command. diff --git a/src/version.cpp.in b/src/version.cpp.in index 1adebbd5c..d38b6df07 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -1,6 +1,6 @@ #define DEF_MONERO_VERSION_TAG "@VERSIONTAG@" #define DEF_MONERO_VERSION "0.18.2.2" -#define DEF_HAVEN_VERSION "4.0.2" +#define DEF_HAVEN_VERSION "4.1.0" #define DEF_HAVEN_VERSION_TAG "035defd" #define DEF_MONERO_RELEASE_NAME "Prometheus" #define DEF_MONERO_VERSION_FULL DEF_HAVEN_VERSION "-" DEF_HAVEN_VERSION_TAG ", based on Monero " DEF_MONERO_VERSION "-" DEF_MONERO_VERSION_TAG