From 69e0be6db603ce332337356f48654a24a595a226 Mon Sep 17 00:00:00 2001 From: sowle Date: Wed, 7 Feb 2024 20:11:09 +0100 Subject: [PATCH] asset_descriptor_operation: opt_amount_commitment -> amount_commitment (made non-optional) --- src/currency_core/currency_basic.h | 12 ++++++------ src/currency_core/currency_format_utils.cpp | 16 ++++++---------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index f1aa8db5..8da2e671 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2023 Zano Project +// Copyright (c) 2014-2024 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2014-2015 The Boolberry developers @@ -771,15 +771,15 @@ namespace currency { uint8_t operation_type = ASSET_DESCRIPTOR_OPERATION_UNDEFINED; asset_descriptor_base descriptor; - boost::optional opt_amount_commitment; // premultiplied by 1/8 TODO: make it non-optional, as it must always be present -- sowle - boost::optional opt_proof; // operation proof - for update/emit - boost::optional opt_asset_id; // target asset_id - for update/emit + crypto::public_key amount_commitment; // premultiplied by 1/8 + boost::optional opt_proof; // operation proof - for update/emit + boost::optional opt_asset_id; // target asset_id - for update/emit uint8_t verion = ASSET_DESCRIPTOR_OPERATION_STRUCTURE_VER; BEGIN_VERSIONED_SERIALIZE(ASSET_DESCRIPTOR_OPERATION_STRUCTURE_VER, verion) FIELD(operation_type) FIELD(descriptor) - FIELD(opt_amount_commitment) + FIELD(amount_commitment) END_VERSION_UNDER(1) FIELD(opt_proof) FIELD(opt_asset_id) @@ -788,7 +788,7 @@ namespace currency BEGIN_BOOST_SERIALIZATION() BOOST_SERIALIZE(operation_type) BOOST_SERIALIZE(descriptor) - BOOST_SERIALIZE(opt_amount_commitment) + BOOST_SERIALIZE(amount_commitment) BOOST_END_VERSION_UNDER(1) BOOST_SERIALIZE(opt_proof) BOOST_SERIALIZE(opt_asset_id) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 5b448f53..f3b5f341 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -590,9 +590,8 @@ namespace currency else { // make sure that amount commitment corresponds to opt_amount_commitment_g_proof - CHECK_AND_ASSERT_MES(context.ado.opt_amount_commitment.has_value(), false, "opt_amount_commitment is absent"); CHECK_AND_ASSERT_MES(aop.opt_amount_commitment_g_proof.has_value(), false, "opt_amount_commitment_g_proof is absent"); - crypto::point_t A = crypto::point_t(context.ado.opt_amount_commitment.get()).modify_mul8() - context.amount_to_validate * context.asset_id_pt; + crypto::point_t A = crypto::point_t(context.ado.amount_commitment).modify_mul8() - context.amount_to_validate * context.asset_id_pt; bool r = crypto::check_signature(context.tx_id, A.to_public_key(), aop.opt_amount_commitment_g_proof.get()); CHECK_AND_ASSERT_MES(r, false, "opt_amount_commitment_g_proof check failed"); @@ -647,13 +646,11 @@ namespace currency if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_REGISTER || ado.operation_type == ASSET_DESCRIPTOR_OPERATION_EMIT) { // opt_amount_commitment supposed to be validated earlier in validate_asset_operation() - CHECK_AND_ASSERT_MES(ado.opt_amount_commitment.has_value(), false, "opt_amount_commitment is not set"); - sum_of_pseudo_out_amount_commitments += crypto::point_t(ado.opt_amount_commitment.get()); // *1/8 + sum_of_pseudo_out_amount_commitments += crypto::point_t(ado.amount_commitment); // *1/8 } else if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_PUBLIC_BURN) { - CHECK_AND_ASSERT_MES(ado.opt_amount_commitment.has_value(), false, "opt_amount_commitment is not set"); - outs_commitments_sum += crypto::point_t(ado.opt_amount_commitment.get()); // *1/8 + outs_commitments_sum += crypto::point_t(ado.amount_commitment); // *1/8 } } size_t zc_sigs_count = 0; @@ -2180,7 +2177,7 @@ namespace currency ado.descriptor.current_supply = amount_of_emitted_asset; // TODO: consider setting current_supply beforehand, not setting it hear in ad-hoc manner -- sowle gen_context.ao_amount_commitment = amount_of_emitted_asset * gen_context.ao_asset_id_pt + gen_context.ao_amount_blinding_mask * crypto::c_point_G; - ado.opt_amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); + ado.amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); } else { @@ -2206,14 +2203,13 @@ namespace currency ado.descriptor.current_supply += amount_of_emitted_asset; gen_context.ao_amount_commitment = amount_of_emitted_asset * gen_context.ao_asset_id_pt + gen_context.ao_amount_blinding_mask * crypto::c_point_G; - ado.opt_amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); + ado.amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); } else if (ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE) { CHECK_AND_ASSERT_MES(ado.opt_asset_id, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE"); //CHECK_AND_ASSERT_MES(ado.opt_proof, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE"); - CHECK_AND_ASSERT_MES(!ado.opt_amount_commitment, false, "ado.opt_asset_id is not found at ado.operation_type == ASSET_DESCRIPTOR_OPERATION_UPDATE"); //fields that not supposed to be changed? } @@ -2247,7 +2243,7 @@ namespace currency ado.descriptor.current_supply -= amount_of_burned_assets; gen_context.ao_amount_commitment = amount_of_burned_assets * gen_context.ao_asset_id_pt + gen_context.ao_amount_blinding_mask * crypto::c_point_G; - ado.opt_amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); + ado.amount_commitment = (crypto::c_scalar_1div8 * gen_context.ao_amount_commitment).to_public_key(); } if (ftp.pevents_dispatcher) ftp.pevents_dispatcher->RAISE_DEBUG_EVENT(wde_construct_tx_handle_asset_descriptor_operation_before_seal{ &ado });