1
0
Fork 0
forked from lthn/blockchain

Merge branch 'transfership_refactoring' into develop

This commit is contained in:
sowle 2025-04-10 20:12:25 +03:00
commit cd5b0c22da
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
7 changed files with 61 additions and 68 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2014-2024 Zano Project
// Copyright (c) 2014-2025 Zano Project
// Copyright (c) 2014-2018 The Louisdor Project
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -182,6 +182,8 @@ namespace crypto
BOOST_SERIALIZE(c)
BOOST_SERIALIZE(y)
END_BOOST_SERIALIZATION()
bool is_zero() const { return c.is_zero() && y.is_zero(); }
};
struct generic_double_schnorr_sig_s : public generic_double_schnorr_sig
@ -220,6 +222,25 @@ namespace crypto
END_BOOST_SERIALIZATION()
};
// helper functions
// plain serialization for generic_schnorr_sig_s as hex-encoded 64-bytes string, consisting of two 32-bytes integers (c, y)
inline std::string generic_schnorr_sig_s_to_hex_string(const generic_schnorr_sig_s& s)
{
return crypto::pod_to_hex(s.c) + crypto::pod_to_hex(s.y);
}
inline generic_schnorr_sig_s generic_schnorr_sig_s_from_hex_string(const std::string& hex_str)
{
generic_schnorr_sig_s result{};
if (hex_str.size() != 2 * (sizeof(result.c) + sizeof(result.y)))
return result;
crypto::parse_tpod_from_hex_string(hex_str.substr(0, 2 * sizeof(result.c)), result.c);
crypto::parse_tpod_from_hex_string(hex_str.substr(2 * sizeof(result.c)), result.y);
return result;
}
} // namespace crypto
BLOB_SERIALIZER(crypto::chacha8_iv);

View file

@ -1262,28 +1262,4 @@ namespace currency
return true;
}
//@#@
//TEMPORARY CODE, TODO: talk to @val and re-do it
//----------------------------------------------------------------------------------------------------
inline void schnor_old_to_schnor_new(const crypto::signature& sig, crypto::generic_schnorr_sig& sig_new)
{
static_assert(sizeof(sig.c) == sizeof(sig_new.c));
static_assert(sizeof(sig.r) == sizeof(sig_new.y));
std::memcpy(&sig_new.c, &sig.c, sizeof(sig_new.c));
std::memcpy(&sig_new.y, &sig.r, sizeof(sig_new.y));
}
//----------------------------------------------------------------------------------------------------
inline void schnor_new_to_schnor_old(const crypto::generic_schnorr_sig& sig_new, crypto::signature& sig)
{
static_assert(sizeof(sig.c) == sizeof(sig_new.c));
static_assert(sizeof(sig.r) == sizeof(sig_new.y));
std::memcpy(&sig.c, &sig_new.c, sizeof(sig_new.c));
std::memcpy(&sig.r, &sig_new.y, sizeof(sig_new.y));
}
} // namespace currency

View file

@ -4402,7 +4402,7 @@ bool wallet2::get_utxo_distribution(std::map<uint64_t, uint64_t>& distribution)
return false;
}
//----------------------------------------------------------------------------------------------------
void wallet2::submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const currency::transaction& tx, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked)
void wallet2::submit_externally_signed_asset_tx_impl(const finalized_tx& ft, const transaction& tx, bool unlock_transfers_on_fail, transaction& result_tx, bool& transfers_unlocked)
{
// foolproof
WLT_THROW_IF_FALSE_WALLET_CMN_ERR_EX(ft.ftp.spend_pub_key == m_account.get_keys().account_address.spend_public_key, "The given tx was created in a different wallet, keys missmatch, tx hash: " << ft.tx_id);
@ -4426,30 +4426,29 @@ void wallet2::submit_externally_signed_asset_tx(const currency::finalized_tx& ft
m_tx_keys.insert(std::make_pair(ft.tx_id, ft.one_time_key));
add_sent_tx_detailed_info(tx, ft.ftp.attachments, ft.ftp.prepared_destinations, ft.ftp.selected_transfers);
print_tx_sent_message(tx, "from submit_externally_signed_asset_tx", true, get_tx_fee(tx));
print_tx_sent_message(tx, "from submit_externally_signed_asset_tx_impl", true, get_tx_fee(tx));
result_tx = tx;
}
//----------------------------------------------------------------------------------------------------
void wallet2::submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const crypto::signature& sig, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked)
void wallet2::submit_externally_signed_asset_tx(const finalized_tx& ft, const crypto::generic_schnorr_sig_s& gss_sig, bool unlock_transfers_on_fail, transaction& result_tx, bool& transfers_unlocked)
{
currency::transaction tx = ft.tx;
transaction tx = ft.tx;
currency::asset_operation_ownership_proof aoop_eth{};
currency::schnor_old_to_schnor_new(sig, aoop_eth.gss);
//aoop_eth.gss = sig;
asset_operation_ownership_proof aoop_eth{};
aoop_eth.gss = gss_sig;
tx.proofs.push_back(std::move(aoop_eth));
submit_externally_signed_asset_tx(ft, tx, unlock_transfers_on_fail, result_tx, transfers_unlocked);
submit_externally_signed_asset_tx_impl(ft, tx, unlock_transfers_on_fail, result_tx, transfers_unlocked);
}
//----------------------------------------------------------------------------------------------------
void wallet2::submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const crypto::eth_signature& eth_sig, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked)
void wallet2::submit_externally_signed_asset_tx(const finalized_tx& ft, const crypto::eth_signature& eth_sig, bool unlock_transfers_on_fail, transaction& result_tx, bool& transfers_unlocked)
{
transaction tx = ft.tx;
currency::asset_operation_ownership_proof_eth aoop_eth{};
asset_operation_ownership_proof_eth aoop_eth{};
aoop_eth.eth_sig = eth_sig;
tx.proofs.push_back(std::move(aoop_eth));
submit_externally_signed_asset_tx(ft, tx, unlock_transfers_on_fail, result_tx, transfers_unlocked);
submit_externally_signed_asset_tx_impl(ft, tx, unlock_transfers_on_fail, result_tx, transfers_unlocked);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::attach_asset_descriptor(const wallet_public::COMMAND_ATTACH_ASSET_DESCRIPTOR::request& req, wallet_public::COMMAND_ATTACH_ASSET_DESCRIPTOR::response& resp)
@ -4491,6 +4490,7 @@ bool wallet2::attach_asset_descriptor(const wallet_public::COMMAND_ATTACH_ASSET_
return false;
}
}
//----------------------------------------------------------------------------------------------------
void wallet2::submit_transfer(const std::string& signed_tx_blob, currency::transaction& tx)
{
// decrypt sources

View file

@ -615,9 +615,8 @@ namespace tools
void sign_transfer_files(const std::string& tx_sources_file, const std::string& signed_tx_file, currency::transaction& tx);
void submit_transfer(const std::string& signed_tx_blob, currency::transaction& tx);
void submit_transfer_files(const std::string& signed_tx_file, currency::transaction& tx);
void submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const crypto::generic_schnorr_sig_s& gss_sig, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked);
void submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const crypto::eth_signature& eth_sig, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked);
void submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const crypto::signature& sig, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked);
void submit_externally_signed_asset_tx(const currency::finalized_tx& ft, const currency::transaction& tx, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked);
void sweep_below(size_t fake_outs_count, const currency::account_public_address& destination_addr, uint64_t threshold_amount, const currency::payment_id_t& payment_id,
uint64_t fee, size_t& outs_total, uint64_t& amount_total, size_t& outs_swept, uint64_t& amount_swept, currency::transaction* p_result_tx = nullptr, std::string* p_filename_or_unsigned_tx_blob_str = nullptr);
@ -934,6 +933,8 @@ private:
void build_distribution_for_input(std::vector<uint64_t>& offsets, uint64_t own_index);
void select_decoys(currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount & amount_entry, uint64_t own_g_index);
void submit_externally_signed_asset_tx_impl(const currency::finalized_tx& ft, const currency::transaction& tx, bool unlock_transfers_on_fail, currency::transaction& result_tx, bool& transfers_unlocked);
static void wti_to_csv_entry(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index);
static void wti_to_txt_line(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index);
static void wti_to_json_line(std::ostream& ss, const wallet_public::wallet_transfer_info& wti, size_t index);

View file

@ -2008,7 +2008,7 @@ namespace wallet_public
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) DOC_DSCR("Id of transaction that carries asset registration command, asset would be registered as soon as transaction got confirmed") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE(data_for_external_signing) DOC_DSCR("[optional] Hex-encoded transaction for external signing. ") DOC_EXMP_AGGR() DOC_END
KV_SERIALIZE(data_for_external_signing) DOC_DSCR("[optional] Additional data for external asset tx signing.") DOC_EXMP_AGGR() DOC_END
END_KV_SERIALIZE_MAP()
};
};
@ -2027,11 +2027,11 @@ namespace wallet_public
std::vector<currency::tx_service_attachment> service_entries;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Id of the asset to burn") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
KV_SERIALIZE(burn_amount) DOC_DSCR("Amount to burn") DOC_EXMP(10000000) DOC_END
KV_SERIALIZE(point_tx_to_address) DOC_DSCR("Optional, if we need this transaction to be seen by particular wallet") DOC_EXMP("ZxBvJDuQjMG9R2j4WnYUhBYNrwZPwuyXrC7FHdVmWqaESgowDvgfWtiXeNGu8Px9B24pkmjsA39fzSSiEQG1ekB225ZnrMTBp") DOC_END
KV_SERIALIZE(native_amount) DOC_DSCR("Optional, if we need this transaction to be seen by particular wallet") DOC_EXMP(0) DOC_END
KV_SERIALIZE(service_entries) DOC_DSCR("Optional, if we need to include service entries for burn transaction") DOC_EXMP_AUTO(1) DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Id of the asset to burn") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
KV_SERIALIZE(burn_amount) DOC_DSCR("Amount to burn") DOC_EXMP(10000000) DOC_END
KV_SERIALIZE(point_tx_to_address) DOC_DSCR("[optional] Used when this transaction needs to be visible to a particular wallet.") DOC_EXMP("ZxBvJDuQjMG9R2j4WnYUhBYNrwZPwuyXrC7FHdVmWqaESgowDvgfWtiXeNGu8Px9B24pkmjsA39fzSSiEQG1ekB225ZnrMTBp") DOC_END
KV_SERIALIZE(native_amount) DOC_DSCR("[optional] Used when this transaction needs to be visible to a particular wallet.") DOC_EXMP(0) DOC_END
KV_SERIALIZE(service_entries) DOC_DSCR("[optional] Used when service entries need to be included for a burn transaction.") DOC_EXMP_AUTO(1) DOC_END
END_KV_SERIALIZE_MAP()
};
@ -2053,8 +2053,8 @@ namespace wallet_public
{
currency::blobdata finalized_tx;
currency::blobdata unsigned_tx;
crypto::eth_signature eth_sig = currency::null_eth_signature;
crypto::signature regular_sig = currency::null_sig;
crypto::eth_signature eth_sig = currency::null_eth_signature;
crypto::generic_schnorr_sig_s regular_sig{};
crypto::hash expected_tx_id = currency::null_hash;
bool unlock_transfers_on_fail = false;
@ -2062,7 +2062,7 @@ namespace wallet_public
KV_SERIALIZE_BLOB_AS_BASE64_STRING(finalized_tx)DOC_DSCR("Base64-encoded finalized_tx data structure, which was received from emit_asset call.") DOC_EXMP("ewogICJ2ZXJzaW9uIjogMSwgC....iAgInZpbiI6IFsgewogICAgIC") DOC_END
KV_SERIALIZE_BLOB_AS_BASE64_STRING(unsigned_tx) DOC_DSCR("Base64-encoded unsigned transaction blob, which was received from emit_asset call.") DOC_EXMP("083737bcfd826a973f74bb56a52b4fa562e6579ccaadd2697463498a66de4f1760b2cd40f11c3a00a7a80000") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(eth_sig) DOC_DSCR("HEX-encoded ETH signature (64 bytes), used only if regular_sig is empty") DOC_EXMP("674bb56a5b4fa562e679ccacc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6add697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(regular_sig) DOC_DSCR("HEX-encoded regular signature (64 bytes)") DOC_EXMP("674bb56a5b4fa562e679ccacc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6add697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_CUSTOM(regular_sig, std::string, crypto::generic_schnorr_sig_s_to_hex_string, crypto::generic_schnorr_sig_s_from_hex_string) DOC_DSCR("HEX-encoded regular signature (64 bytes)") DOC_EXMP("674bb56a5b4fa562e679ccacc4e69455e63f4a581257382191de6856c2156630b3fba0db4bdd73ffcfb36b6add697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(expected_tx_id) DOC_DSCR("The expected transaction id. Tx won't be sent if the calculated one doesn't match this one. Consider using 'verified_tx_id' returned by 'decrypt_tx_details' call.") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
KV_SERIALIZE(unlock_transfers_on_fail) DOC_DSCR("If true, all locked wallet transfers, corresponding to the transaction, will be unlocked on sending failure. False by default.") DOC_EXMP(false) DOC_END
END_KV_SERIALIZE_MAP()
@ -2108,7 +2108,7 @@ namespace wallet_public
struct COMMAND_TRANSFER_ASSET_OWNERSHIP
{
DOC_COMMAND("Transfer asset ownership to new public key.");
DOC_COMMAND("Transfer asset ownership to a new public key.");
struct request
{
@ -2117,9 +2117,9 @@ namespace wallet_public
crypto::public_key new_owner = currency::null_pkey; // regular Zano Ed25519 public key
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("Own asset id, that would be transfered to someone else") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(new_owner) DOC_DSCR("Public key of the new owner(default Ed25519 public key, 32 bytes)") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(new_owner_eth_pub_key) DOC_DSCR("Public key of the new owner(ECDSA public key, 33 bytes) Used only if 'owner' field is empty") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a84d") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(asset_id) DOC_DSCR("The ID of the asset, owned by the wallet, that is to be transferred to someone else.") DOC_EXMP("40fa6db923728b38962718c61b4dc3af1acaa1967479c73703e260dc3609c58d") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(new_owner) DOC_DSCR("Public key of the new owner. Standard Ed25519 public key, 32 bytes.") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(new_owner_eth_pub_key) DOC_DSCR("Public key of the new owner. ECDSA public key, 33 bytes. Either new_owner or new_owner_eth_pub_key must be specified.") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a84d") DOC_END
END_KV_SERIALIZE_MAP()
};
@ -2131,8 +2131,8 @@ namespace wallet_public
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status) DOC_DSCR("Status of the call") DOC_EXMP("OK") DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) DOC_DSCR("Id of transaction that carries asset transfer ownership operation") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE(data_for_external_signing) DOC_DSCR("[optional] Additional data for external ownership transfer tx signing(if asset is ownership is belong to third party).") DOC_EXMP_AGGR() DOC_END
KV_SERIALIZE_POD_AS_HEX_STRING(tx_id) DOC_DSCR("Id of the transaction that carries asset transfer ownership operation") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END
KV_SERIALIZE(data_for_external_signing) DOC_DSCR("[optional] Additional data for external ownership transfer tx signing (used when the current asset's owner is ECDSA public key).") DOC_EXMP_AGGR() DOC_END
END_KV_SERIALIZE_MAP()
};
};

View file

@ -1463,7 +1463,7 @@ namespace tools
try
{
currency::transaction result_tx{};
if (req.regular_sig != currency::null_sig)
if (!req.regular_sig.is_zero())
{
w.get_wallet()->submit_externally_signed_asset_tx(ft, req.regular_sig, req.unlock_transfers_on_fail, result_tx, res.transfers_were_unlocked);
}
@ -1495,14 +1495,15 @@ namespace tools
{
WALLET_RPC_BEGIN_TRY_ENTRY();
currency::asset_owner_pub_key_v new_owner_v;
if (req.new_owner!= currency::null_pkey)
if (req.new_owner != currency::null_pkey && req.new_owner_eth_pub_key == currency::null_eth_public_key)
{
new_owner_v = req.new_owner;
}
else if(req.new_owner_eth_pub_key != currency::null_eth_public_key)
else if(req.new_owner_eth_pub_key != currency::null_eth_public_key && req.new_owner == currency::null_pkey)
{
new_owner_v = req.new_owner_eth_pub_key;
}else
}
else
{
res.status = API_RETURN_CODE_BAD_ARG_INVALID_ADDRESS;
return true;
@ -1510,7 +1511,7 @@ namespace tools
try
{
currency::finalized_tx ft;
currency::finalized_tx ft{};
w.get_wallet()->transfer_asset_ownership(req.asset_id, new_owner_v, ft);
if (ft.ftp.ado_sign_thirdparty)
{

View file

@ -970,25 +970,19 @@ bool sign_signature_with_keys(const t_response& rsp_with_data, tools::wallet_rpc
{
//schnor sig
const crypto::secret_key& signer = boost::get<crypto::secret_key>(signer_v);
crypto::signature sig = AUTO_VAL_INIT(sig);
crypto::generic_schnorr_sig sig_sch = AUTO_VAL_INIT(sig_sch);
r = crypto::generate_schnorr_sig(rsp_with_data.tx_id, signer, sig_sch);
CHECK_AND_ASSERT_MES(r, false, "gailed to generate schnorr signature");
r = crypto::generate_schnorr_sig(rsp_with_data.tx_id, signer, send_signed_req.regular_sig);
CHECK_AND_ASSERT_MES(r, false, "generate_schnorr_sig failed");
//crypto::generate_signature(emm_resp.tx_id, miner_wlt->get_account().get_keys().account_address.spend_public_key, miner_wlt->get_account().get_keys().spend_secret_key, sig);
// instant verification, just in case
r = crypto::verify_schnorr_sig(rsp_with_data.tx_id, boost::get<crypto::public_key>(verifier), sig_sch);
r = crypto::verify_schnorr_sig(rsp_with_data.tx_id, boost::get<crypto::public_key>(verifier), send_signed_req.regular_sig);
CHECK_AND_ASSERT_MES(r, false, "verify_schnorr_sig failed");
currency::schnor_new_to_schnor_old(sig_sch, sig);
send_signed_req.regular_sig = sig;
}
else if (signer_v.type() == typeid(crypto::eth_secret_key))
{
////ecdsa sig
const crypto::eth_secret_key& signer = boost::get<crypto::eth_secret_key>(signer_v);
r = crypto::generate_eth_signature(rsp_with_data.tx_id, signer, send_signed_req.eth_sig);
CHECK_AND_ASSERT_MES(r, false, "gailed to generate schnorr signature");
CHECK_AND_ASSERT_MES(r, false, "generate_eth_signature failed");
r = crypto::verify_eth_signature(rsp_with_data.tx_id, boost::get<crypto::eth_public_key>(verifier), send_signed_req.eth_sig);
CHECK_AND_ASSERT_MES(r, false, "verify_eth_signature failed");