diff --git a/contrib/epee/include/serialization/keyvalue_helpers.h b/contrib/epee/include/serialization/keyvalue_helpers.h index d76fc641..14997aa4 100644 --- a/contrib/epee/include/serialization/keyvalue_helpers.h +++ b/contrib/epee/include/serialization/keyvalue_helpers.h @@ -25,6 +25,8 @@ // #pragma once +#include +#include #include "misc_language.h" namespace epee { @@ -51,24 +53,73 @@ namespace epee } }; + template + struct is_std_optional : std::false_type {}; + + template + struct is_std_optional> : std::true_type {}; + + + template + struct is_std_optional> : std::true_type {}; + + + //basic helpers for pod-to-hex serialization + template + std::string transform_t_pod_to_str_internal(const t_pod_type& a) + { + return epee::string_tools::pod_to_hex(a); + } + + template + std::string transform_t_pod_to_str_internal(const std::optional& a) + { + if (a.has_value()) + return epee::string_tools::pod_to_hex(*a); + else + return ""; + } + + template + std::string transform_t_pod_to_str_internal(const boost::optional& a) + { + if (a.has_value()) + return epee::string_tools::pod_to_hex(*a); + else + return ""; + } //basic helpers for pod-to-hex serialization template std::string transform_t_pod_to_str(const t_pod_type & a) { - return epee::string_tools::pod_to_hex(a); + return transform_t_pod_to_str_internal(a); } - template + + + + template t_pod_type transform_str_to_t_pod(const std::string& a) { - t_pod_type res = AUTO_VAL_INIT(res); + t_pod_type res = AUTO_VAL_INIT(res); if (a.empty()) return res; + if constexpr (is_std_optional::value) + { + t_pod_type::value_type v = AUTO_VAL_INIT(v); + if (!epee::string_tools::hex_to_pod(a, v)) + throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type::value_type).name()); + return v; + } + + if (!epee::string_tools::hex_to_pod(a, res)) throw std::runtime_error(std::string("Unable to transform \"") + a + "\" to pod type " + typeid(t_pod_type).name()); return res; } + + //basic helpers for blob-to-hex serialization inline std::string transform_binbuf_to_hexstr(const std::string& a) diff --git a/src/crypto/eth_signature.cpp b/src/crypto/eth_signature.cpp index 0e33c47f..ba5b1358 100644 --- a/src/crypto/eth_signature.cpp +++ b/src/crypto/eth_signature.cpp @@ -157,6 +157,10 @@ namespace crypto { return o << epee::string_tools::pod_to_hex(v); } + std::ostream& operator<<(std::ostream& o, const eth_signature& v) + { + return o << epee::string_tools::pod_to_hex(v); + } } // namespace crypto diff --git a/src/crypto/eth_signature.h b/src/crypto/eth_signature.h index b186114a..b12d41fe 100644 --- a/src/crypto/eth_signature.h +++ b/src/crypto/eth_signature.h @@ -62,5 +62,6 @@ namespace crypto std::ostream& operator<<(std::ostream& o, const eth_secret_key& v); std::ostream& operator<<(std::ostream& o, const eth_public_key& v); + std::ostream& operator<<(std::ostream& o, const eth_signature& v); } // namespace crypto diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index c05ffc53..6d4cbc1f 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -4116,7 +4116,15 @@ bool blockchain_storage::validate_ado_ownership(asset_op_verification_context& a asset_operation_ownership_proof_eth aoop_eth{}; r = get_type_in_variant_container(avc.tx.proofs, aoop_eth); CHECK_AND_ASSERT_MES(r, false, "Ownership validation failed: asset_operation_ownership_proof_eth is missing"); - return crypto::verify_eth_signature(avc.tx_id, last_ado.descriptor.owner_eth_pub_key.value(), aoop_eth.eth_sig); + if (!crypto::verify_eth_signature(avc.tx_id, last_ado.descriptor.owner_eth_pub_key.value(), aoop_eth.eth_sig)) + { + LOG_ERROR("Failed to validate secp256k1 signature for hash: " << avc.tx_id << ", signature: " << aoop_eth.eth_sig); + return false; + } + else + { + return true; + } } // owner_eth_pub_key has no value -- fallback to default } diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 976207ad..c6581611 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -749,7 +749,7 @@ namespace currency KV_SERIALIZE(meta_info) DOC_DSCR("Any other information associated with the asset in free form.") DOC_EXMP("Stable and private") DOC_END KV_SERIALIZE_POD_AS_HEX_STRING(owner) DOC_DSCR("Owner's key, used only for EMIT and UPDATE validation, can be changed by transferring asset ownership.") DOC_EXMP("f74bb56a5b4fa562e679ccaadd697463498a66de4f1760b2cd40f11c3a00a7a8") DOC_END KV_SERIALIZE(hidden_supply) DOC_DSCR("This field is reserved for future use and will be documented later.") DOC_END - KV_SERIALIZE(owner_eth_pub_key) DOC_DSCR("[Optional] Owner's key in the case when ETH signature is used.") DOC_END + KV_SERIALIZE_POD_AS_HEX_STRING(owner_eth_pub_key) DOC_DSCR("[Optional] Owner's key in the case when ETH signature is used.") DOC_END END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index fb87bd2f..20745cdf 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -395,7 +395,7 @@ const crypto::public_key& wallet2::out_get_pub_key(const currency::tx_out_v& out void wallet2::process_ado_in_new_transaction(const currency::asset_descriptor_operation& ado, process_transaction_context& ptc) { auto print_ado_owner = [ado](std::ostream& o){ - ado.descriptor.owner_eth_pub_key.has_value() ? o << ado.descriptor.owner_eth_pub_key.get() << " (ETH)" : o << ado.descriptor.owner; + ado.descriptor.owner_eth_pub_key.has_value() ? o << ado.descriptor.owner_eth_pub_key.value() << " (ETH)" : o << ado.descriptor.owner; }; do