mirror of
https://github.com/monero-project/monero.git
synced 2024-12-04 15:41:09 +02:00
Compare commits
9 Commits
5a337f5fcc
...
fb61aa069b
Author | SHA1 | Date | |
---|---|---|---|
|
fb61aa069b | ||
|
3b5d17ab27 | ||
|
b70222c774 | ||
|
8dc6a12ec7 | ||
|
893916ad09 | ||
|
7df0d9bb8f | ||
|
170844bc59 | ||
|
89ad8ac8b1 | ||
|
c51ca53daa |
@ -1085,33 +1085,41 @@ if(STATIC)
|
||||
set(Boost_USE_STATIC_RUNTIME ON)
|
||||
endif()
|
||||
|
||||
set(BOOST_COMPONENTS system filesystem thread date_time chrono regex serialization program_options)
|
||||
if (WIN32)
|
||||
list(APPEND BOOST_COMPONENTS locale)
|
||||
# Find Boost headers
|
||||
set(BOOST_MIN_VER 1.62)
|
||||
find_package(Boost ${BOOST_MIN_VER} QUIET REQUIRED)
|
||||
|
||||
if(NOT Boost_FOUND)
|
||||
die("Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (>=${BOOST_MIN_VER}) or the equivalent")
|
||||
elseif(Boost_FOUND)
|
||||
message(STATUS "Found Boost Version: ${Boost_VERSION_STRING}")
|
||||
|
||||
set(BOOST_COMPONENTS filesystem thread date_time chrono serialization program_options)
|
||||
if (WIN32)
|
||||
list(APPEND BOOST_COMPONENTS locale)
|
||||
endif()
|
||||
|
||||
# Boost System is header-only since 1.69
|
||||
if (Boost_VERSION_STRING VERSION_LESS 1.69.0)
|
||||
list(APPEND BOOST_COMPONENTS system)
|
||||
endif()
|
||||
|
||||
# Boost Regex is header-only since 1.77
|
||||
if (Boost_VERSION_STRING VERSION_LESS 1.77.0)
|
||||
list(APPEND BOOST_COMPONENTS regex)
|
||||
endif()
|
||||
|
||||
message(STATUS "Boost components: ${BOOST_COMPONENTS}")
|
||||
|
||||
# Find required Boost libraries
|
||||
find_package(Boost ${BOOST_MIN_VER} QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})
|
||||
endif()
|
||||
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS ${BOOST_COMPONENTS})
|
||||
|
||||
add_definitions(-DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION)
|
||||
add_definitions(-DBOOST_NO_AUTO_PTR)
|
||||
add_definitions(-DBOOST_UUID_DISABLE_ALIGNMENT) # This restores UUID's std::has_unique_object_representations property
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})
|
||||
if(NOT Boost_FOUND)
|
||||
die("Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (>=1.58) or the equivalent")
|
||||
elseif(Boost_FOUND)
|
||||
message(STATUS "Found Boost Version: ${Boost_VERSION}")
|
||||
if (Boost_VERSION VERSION_LESS 10 AND Boost_VERSION VERSION_LESS 1.62.0 AND NOT (OPENSSL_VERSION VERSION_LESS 1.1))
|
||||
set(BOOST_BEFORE_1_62 true)
|
||||
endif()
|
||||
if (NOT Boost_VERSION VERSION_LESS 10 AND Boost_VERSION VERSION_LESS 106200 AND NOT (OPENSSL_VERSION VERSION_LESS 1.1))
|
||||
set(BOOST_BEFORE_1_62 true)
|
||||
endif()
|
||||
if (BOOST_BEFORE_1_62)
|
||||
message(FATAL_ERROR "Boost ${Boost_VERSION} (older than 1.62) is too old to link with OpenSSL ${OPENSSL_VERSION} (1.1 or newer) found at ${OPENSSL_INCLUDE_DIR} and ${OPENSSL_LIBRARIES}. "
|
||||
"Update Boost or install OpenSSL 1.0 and set path to it when running cmake: "
|
||||
"cmake -DOPENSSL_ROOT_DIR='/usr/include/openssl-1.0'")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
|
||||
if(MINGW)
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
|
||||
|
@ -167,7 +167,7 @@ library archives (`.a`).
|
||||
| GCC | 7 | 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 |
|
||||
| Boost | 1.62 | NO | `libboost-all-dev` | `boost` | `boost-devel` | `boost-devel` | NO | C++ libraries |
|
||||
| OpenSSL | basically any | NO | `libssl-dev` | `openssl` | `openssl-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 |
|
||||
|
@ -178,13 +178,18 @@ namespace string_tools
|
||||
|
||||
std::string get_extension(const std::string& str)
|
||||
{
|
||||
return boost::filesystem::path(str).extension().string();
|
||||
std::string ext_with_dot = boost::filesystem::path(str).extension().string();
|
||||
|
||||
if (ext_with_dot.empty())
|
||||
return {};
|
||||
|
||||
return ext_with_dot.erase(0, 1);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cut_off_extension(const std::string& str)
|
||||
{
|
||||
return boost::filesystem::path(str).stem().string();
|
||||
return boost::filesystem::path(str).replace_extension("").string();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -146,7 +146,9 @@ tools::optional_variant<CarrotPaymentProposalV1, CarrotPaymentProposalSelfSendV1
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void get_output_enote_proposals(std::vector<CarrotPaymentProposalV1> &&normal_payment_proposals,
|
||||
std::vector<CarrotPaymentProposalSelfSendV1> &&selfsend_payment_proposals,
|
||||
const view_balance_secret_device &s_view_balance_dev,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::key_image &tx_first_key_image,
|
||||
std::vector<RCTOutputEnoteProposal> &output_enote_proposals_out,
|
||||
encrypted_payment_id_t &encrypted_payment_id_out)
|
||||
@ -208,18 +210,34 @@ void get_output_enote_proposals(std::vector<CarrotPaymentProposalV1> &&normal_pa
|
||||
encrypted_payment_id_out = encrypted_payment_id;
|
||||
}
|
||||
|
||||
// in the case that the pid is ambiguous, set it to random bytes
|
||||
// in the case that the pid target is ambiguous, set it to random bytes
|
||||
const bool ambiguous_pid_destination = num_integrated == 0 && normal_payment_proposals.size() > 1;
|
||||
if (ambiguous_pid_destination)
|
||||
encrypted_payment_id_out = gen_payment_id();
|
||||
|
||||
// construct selfsend enotes
|
||||
// construct selfsend enotes, preferring internal enotes over special enotes when possible
|
||||
for (const CarrotPaymentProposalSelfSendV1 &selfsend_payment_proposal : selfsend_payment_proposals)
|
||||
{
|
||||
get_output_proposal_internal_v1(selfsend_payment_proposal,
|
||||
s_view_balance_dev,
|
||||
tx_first_key_image,
|
||||
tools::add_element(output_enote_proposals_out));
|
||||
if (s_view_balance_dev != nullptr)
|
||||
{
|
||||
get_output_proposal_internal_v1(selfsend_payment_proposal,
|
||||
*s_view_balance_dev,
|
||||
tx_first_key_image,
|
||||
tools::add_element(output_enote_proposals_out));
|
||||
}
|
||||
else if (k_view_dev != nullptr)
|
||||
{
|
||||
get_output_proposal_special_v1(selfsend_payment_proposal,
|
||||
*k_view_dev,
|
||||
account_spend_pubkey,
|
||||
tx_first_key_image,
|
||||
tools::add_element(output_enote_proposals_out));
|
||||
}
|
||||
else // neither k_v nor s_vb device passed
|
||||
{
|
||||
ASSERT_MES_AND_THROW(
|
||||
"get output enote proposals: neither a view-balance nor view-incoming device was provided");
|
||||
}
|
||||
}
|
||||
|
||||
// sort enotes by D_e and assert uniqueness properties of D_e
|
||||
|
@ -87,11 +87,25 @@ tools::optional_variant<CarrotPaymentProposalV1, CarrotPaymentProposalSelfSendV1
|
||||
const crypto::public_key &change_address_spend_pubkey,
|
||||
const crypto::x25519_pubkey &other_enote_ephemeral_pubkey);
|
||||
/**
|
||||
* brief: get_output_enote_proposals - convert payment proposals into output enote proposals
|
||||
* brief: get_output_enote_proposals - convert a *finalized* set of payment proposals into output enote proposals
|
||||
* param: normal_payment_proposals -
|
||||
* param: selfsend_payment_proposals -
|
||||
* param: s_view_balance_dev - pointer to view-balance device (OPTIONAL)
|
||||
* param: k_view_dev - pointer to view-incoming device (OPTIONAL)
|
||||
* param: account_spend_pubkey - K_s
|
||||
* param: tx_first_key_image - KI_1
|
||||
* outparam: output_enote_proposals_out -
|
||||
* outparam: encrypted_payment_id_out - pid_enc
|
||||
* throw: std::runtime_error if the payment proposals do not represent a valid tx output set, or if no devices
|
||||
*
|
||||
* If s_view_balance_dev is not NULL, then the selfsend payments are converted into *internal* enotes.
|
||||
* Otherwise, if k_view_dev is not NULL, then the selfsend payments are converted into *external* enotes.
|
||||
*/
|
||||
void get_output_enote_proposals(std::vector<CarrotPaymentProposalV1> &&normal_payment_proposals,
|
||||
std::vector<CarrotPaymentProposalSelfSendV1> &&selfsend_payment_proposals,
|
||||
const view_balance_secret_device &s_view_balance_dev,
|
||||
const view_balance_secret_device *s_view_balance_dev,
|
||||
const view_incoming_key_device *k_view_dev,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::key_image &tx_first_key_image,
|
||||
std::vector<RCTOutputEnoteProposal> &output_enote_proposals_out,
|
||||
encrypted_payment_id_t &encrypted_payment_id_out);
|
||||
|
@ -321,7 +321,7 @@ void get_output_proposal_normal_v1(const CarrotPaymentProposalV1 &proposal,
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
void get_output_proposal_special_v1(const CarrotPaymentProposalSelfSendV1 &proposal,
|
||||
const view_incoming_key_device &k_view_dev,
|
||||
const crypto::public_key &primary_address_spend_pubkey,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::key_image &tx_first_key_image,
|
||||
RCTOutputEnoteProposal &output_enote_out)
|
||||
{
|
||||
@ -362,7 +362,7 @@ void get_output_proposal_special_v1(const CarrotPaymentProposalSelfSendV1 &propo
|
||||
k_view_dev.make_janus_anchor_special(proposal.enote_ephemeral_pubkey,
|
||||
input_context,
|
||||
output_enote_out.enote.onetime_address,
|
||||
primary_address_spend_pubkey,
|
||||
account_spend_pubkey,
|
||||
janus_anchor_special);
|
||||
|
||||
// 6. encrypt special anchor: anchor_enc = anchor XOR m_anchor
|
||||
|
@ -129,20 +129,20 @@ void get_output_proposal_normal_v1(const CarrotPaymentProposalV1 &proposal,
|
||||
* brief: get_output_proposal_v1 - convert the carrot proposal to an output proposal (external selfsend)
|
||||
* param: proposal -
|
||||
* param: k_view_dev -
|
||||
* param: primary_address_spend_pubkey -
|
||||
* param: account_spend_pubkey -
|
||||
* param: tx_first_key_image -
|
||||
* outparam: output_enote_out -
|
||||
*/
|
||||
void get_output_proposal_special_v1(const CarrotPaymentProposalSelfSendV1 &proposal,
|
||||
const view_incoming_key_device &k_view_dev,
|
||||
const crypto::public_key &primary_address_spend_pubkey,
|
||||
const crypto::public_key &account_spend_pubkey,
|
||||
const crypto::key_image &tx_first_key_image,
|
||||
RCTOutputEnoteProposal &output_enote_out);
|
||||
/**
|
||||
* brief: get_output_proposal_internal_v1 - convert the carrot proposal to an output proposal (internal)
|
||||
* param: proposal -
|
||||
* param: s_view_balance_dev -
|
||||
* param: primary_address_spend_pubkey -
|
||||
* param: account_spend_pubkey -
|
||||
* param: tx_first_key_image -
|
||||
* outparam: output_enote_out -
|
||||
* outparam: partial_memo_out -
|
||||
|
@ -39,6 +39,7 @@ set(unit_tests_sources
|
||||
bulletproofs_plus.cpp
|
||||
canonical_amounts.cpp
|
||||
carrot_core.cpp
|
||||
carrot_legacy.cpp
|
||||
carrot_transcript_fixed.cpp
|
||||
chacha.cpp
|
||||
checkpoints.cpp
|
||||
|
@ -124,7 +124,7 @@ static bool can_open_fcmp_onetime_address(const crypto::secret_key &k_prove_spen
|
||||
// K_s = k_gi G + k_ps T
|
||||
// K^j_s = k^j_subscal * K_s
|
||||
// Ko = K^j_s + k^o_g G + k^o_t T
|
||||
// = (k^o_g + k^j_subscal * k_gi) + (k^o_t + k^j_subscal * k_ps)
|
||||
// = (k^o_g + k^j_subscal * k_gi) G + (k^o_t + k^j_subscal * k_ps) T
|
||||
|
||||
// combined_g = k^o_g + k^j_subscal * k_gi
|
||||
rct::key combined_g;
|
||||
@ -893,138 +893,74 @@ TEST(carrot_core, main_address_coinbase_scan_completeness)
|
||||
enote.onetime_address));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, main2main_transfer_2out_completeness)
|
||||
static void subtest_2out_transfer_get_output_enote_proposals_completeness(const bool alice_subaddress,
|
||||
const bool bob_subaddress,
|
||||
const bool bob_integrated,
|
||||
const CarrotEnoteType alice_selfsend_type,
|
||||
const bool alice_internal_selfsends)
|
||||
{
|
||||
// generate alice keys and address
|
||||
const mock_carrot_keys alice = mock_carrot_keys::generate();
|
||||
const mock_carrot_keys bob = mock_carrot_keys::generate();
|
||||
|
||||
CarrotDestinationV1 alice_address;
|
||||
make_carrot_main_address_v1(alice.account_spend_pubkey,
|
||||
alice.main_address_view_pubkey,
|
||||
alice_address);
|
||||
|
||||
CarrotDestinationV1 bob_address;
|
||||
make_carrot_main_address_v1(bob.account_spend_pubkey,
|
||||
bob.main_address_view_pubkey,
|
||||
bob_address);
|
||||
|
||||
const crypto::key_image tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
input_context_t input_context;
|
||||
make_carrot_input_context(tx_first_key_image, input_context);
|
||||
|
||||
const CarrotPaymentProposalV1 bob_payment_proposal = CarrotPaymentProposalV1{
|
||||
.destination = bob_address,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.randomness = gen_janus_anchor()
|
||||
};
|
||||
|
||||
const CarrotPaymentProposalSelfSendV1 alice_payment_proposal = CarrotPaymentProposalSelfSendV1{
|
||||
.destination_address_spend_pubkey = alice_address.address_spend_pubkey,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.enote_type = CarrotEnoteType::CHANGE,
|
||||
.enote_ephemeral_pubkey = get_enote_ephemeral_pubkey(bob_payment_proposal, input_context)
|
||||
};
|
||||
|
||||
std::vector<RCTOutputEnoteProposal> enote_proposals;
|
||||
encrypted_payment_id_t encrypted_payment_id;
|
||||
get_output_enote_proposals({bob_payment_proposal},
|
||||
{alice_payment_proposal},
|
||||
alice.s_view_balance_dev,
|
||||
tx_first_key_image,
|
||||
enote_proposals,
|
||||
encrypted_payment_id);
|
||||
|
||||
ASSERT_EQ(2, enote_proposals.size()); // 2-out tx
|
||||
|
||||
// collect enotes
|
||||
std::vector<CarrotEnoteV1> enotes;
|
||||
for (const RCTOutputEnoteProposal &enote_proposal : enote_proposals)
|
||||
enotes.push_back(enote_proposal.enote);
|
||||
|
||||
// check that alice scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> alice_scan_vec;
|
||||
unittest_scan_enote_set(enotes, encrypted_payment_id, alice, alice_scan_vec);
|
||||
ASSERT_EQ(1, alice_scan_vec.size());
|
||||
unittest_carrot_scan_result_t alice_scan = alice_scan_vec.front();
|
||||
|
||||
// check that bob scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> bob_scan_vec;
|
||||
unittest_scan_enote_set(enotes, encrypted_payment_id, bob, bob_scan_vec);
|
||||
ASSERT_EQ(1, bob_scan_vec.size());
|
||||
unittest_carrot_scan_result_t bob_scan = bob_scan_vec.front();
|
||||
|
||||
// set named references to enotes
|
||||
ASSERT_TRUE((alice_scan.output_index == 0 && bob_scan.output_index == 1) ||
|
||||
(alice_scan.output_index == 1 && bob_scan.output_index == 0));
|
||||
const CarrotEnoteV1 &alice_enote = enotes.at(alice_scan.output_index);
|
||||
const CarrotEnoteV1 &bob_enote = enotes.at(bob_scan.output_index);
|
||||
|
||||
// check Alice's recovered data
|
||||
EXPECT_EQ(alice_payment_proposal.destination_address_spend_pubkey, alice_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(alice_payment_proposal.amount, alice_scan.amount);
|
||||
EXPECT_EQ(alice_enote.amount_commitment, rct::commit(alice_scan.amount, rct::sk2rct(alice_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(null_payment_id, alice_scan.payment_id);
|
||||
EXPECT_EQ(alice_payment_proposal.enote_type, alice_scan.enote_type);
|
||||
|
||||
// check Bob's recovered data
|
||||
EXPECT_EQ(bob_payment_proposal.destination.address_spend_pubkey, bob_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(bob_payment_proposal.amount, bob_scan.amount);
|
||||
EXPECT_EQ(bob_enote.amount_commitment, rct::commit(bob_scan.amount, rct::sk2rct(bob_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(null_payment_id, bob_scan.payment_id);
|
||||
EXPECT_EQ(CarrotEnoteType::PAYMENT, bob_scan.enote_type);
|
||||
|
||||
// check Alice spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(alice.k_prove_spend,
|
||||
alice.k_generate_image,
|
||||
crypto::secret_key{{1}},
|
||||
alice_scan.sender_extension_g,
|
||||
alice_scan.sender_extension_t,
|
||||
alice_enote.onetime_address));
|
||||
|
||||
// check Bob spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(bob.k_prove_spend,
|
||||
bob.k_generate_image,
|
||||
crypto::secret_key{{1}},
|
||||
bob_scan.sender_extension_g,
|
||||
bob_scan.sender_extension_t,
|
||||
bob_enote.onetime_address));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, sub2sub_transfer_2out_completeness)
|
||||
{
|
||||
const mock_carrot_keys alice = mock_carrot_keys::generate();
|
||||
const mock_carrot_keys bob = mock_carrot_keys::generate();
|
||||
|
||||
const uint32_t alice_j_major = crypto::rand<uint32_t>();
|
||||
const uint32_t alice_j_minor = crypto::rand<uint32_t>();
|
||||
CarrotDestinationV1 alice_address;
|
||||
make_carrot_subaddress_v1(alice.account_spend_pubkey,
|
||||
alice.account_view_pubkey,
|
||||
alice.s_generate_address,
|
||||
alice_j_major,
|
||||
alice_j_minor,
|
||||
alice_address);
|
||||
|
||||
if (alice_subaddress)
|
||||
{
|
||||
make_carrot_subaddress_v1(alice.account_spend_pubkey,
|
||||
alice.account_view_pubkey,
|
||||
alice.s_generate_address,
|
||||
alice_j_major,
|
||||
alice_j_minor,
|
||||
alice_address);
|
||||
}
|
||||
else
|
||||
{
|
||||
make_carrot_main_address_v1(alice.account_spend_pubkey,
|
||||
alice.main_address_view_pubkey,
|
||||
alice_address);
|
||||
}
|
||||
|
||||
// generate bob keys and address
|
||||
const mock_carrot_keys bob = mock_carrot_keys::generate();
|
||||
const uint32_t bob_j_major = crypto::rand<uint32_t>();
|
||||
const uint32_t bob_j_minor = crypto::rand<uint32_t>();
|
||||
CarrotDestinationV1 bob_address;
|
||||
make_carrot_subaddress_v1(bob.account_spend_pubkey,
|
||||
bob.account_view_pubkey,
|
||||
bob.s_generate_address,
|
||||
bob_j_major,
|
||||
bob_j_minor,
|
||||
bob_address);
|
||||
if (bob_subaddress)
|
||||
{
|
||||
make_carrot_subaddress_v1(bob.account_spend_pubkey,
|
||||
bob.account_view_pubkey,
|
||||
bob.s_generate_address,
|
||||
bob_j_major,
|
||||
bob_j_minor,
|
||||
bob_address);
|
||||
}
|
||||
else if (bob_integrated)
|
||||
{
|
||||
make_carrot_integrated_address_v1(bob.account_spend_pubkey,
|
||||
bob.main_address_view_pubkey,
|
||||
gen_payment_id(),
|
||||
bob_address);
|
||||
}
|
||||
else
|
||||
{
|
||||
make_carrot_main_address_v1(bob.account_spend_pubkey,
|
||||
bob.main_address_view_pubkey,
|
||||
bob_address);
|
||||
}
|
||||
|
||||
// generate input context
|
||||
const crypto::key_image tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
input_context_t input_context;
|
||||
make_carrot_input_context(tx_first_key_image, input_context);
|
||||
|
||||
// outgoing payment proposal to bob
|
||||
const CarrotPaymentProposalV1 bob_payment_proposal = CarrotPaymentProposalV1{
|
||||
.destination = bob_address,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.randomness = gen_janus_anchor()
|
||||
};
|
||||
|
||||
// selfsend payment proposal to alice
|
||||
const CarrotPaymentProposalSelfSendV1 alice_payment_proposal = CarrotPaymentProposalSelfSendV1{
|
||||
.destination_address_spend_pubkey = alice_address.address_spend_pubkey,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
@ -1032,15 +968,18 @@ TEST(carrot_core, sub2sub_transfer_2out_completeness)
|
||||
.enote_ephemeral_pubkey = get_enote_ephemeral_pubkey(bob_payment_proposal, input_context)
|
||||
};
|
||||
|
||||
// turn payment proposals into enotes
|
||||
std::vector<RCTOutputEnoteProposal> enote_proposals;
|
||||
encrypted_payment_id_t encrypted_payment_id;
|
||||
get_output_enote_proposals({bob_payment_proposal},
|
||||
{alice_payment_proposal},
|
||||
alice.s_view_balance_dev,
|
||||
alice_internal_selfsends ? &alice.s_view_balance_dev : nullptr,
|
||||
&alice.k_view_dev,
|
||||
alice.account_spend_pubkey,
|
||||
tx_first_key_image,
|
||||
enote_proposals,
|
||||
encrypted_payment_id);
|
||||
|
||||
|
||||
ASSERT_EQ(2, enote_proposals.size()); // 2-out tx
|
||||
|
||||
// collect enotes
|
||||
@ -1077,7 +1016,7 @@ TEST(carrot_core, sub2sub_transfer_2out_completeness)
|
||||
EXPECT_EQ(bob_payment_proposal.destination.address_spend_pubkey, bob_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(bob_payment_proposal.amount, bob_scan.amount);
|
||||
EXPECT_EQ(bob_enote.amount_commitment, rct::commit(bob_scan.amount, rct::sk2rct(bob_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(null_payment_id, bob_scan.payment_id);
|
||||
EXPECT_EQ(bob_integrated ? bob_address.payment_id : null_payment_id, bob_scan.payment_id);
|
||||
EXPECT_EQ(CarrotEnoteType::PAYMENT, bob_scan.enote_type);
|
||||
|
||||
// check Alice spendability
|
||||
@ -1096,7 +1035,7 @@ TEST(carrot_core, sub2sub_transfer_2out_completeness)
|
||||
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(alice.k_prove_spend,
|
||||
alice.k_generate_image,
|
||||
alice_subaddr_scalar,
|
||||
alice_subaddress ? alice_subaddr_scalar : crypto::secret_key{{1}},
|
||||
alice_scan.sender_extension_g,
|
||||
alice_scan.sender_extension_t,
|
||||
alice_enote.onetime_address));
|
||||
@ -1117,107 +1056,81 @@ TEST(carrot_core, sub2sub_transfer_2out_completeness)
|
||||
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(bob.k_prove_spend,
|
||||
bob.k_generate_image,
|
||||
bob_subaddr_scalar,
|
||||
bob_subaddress ? bob_subaddr_scalar : crypto::secret_key{{1}},
|
||||
bob_scan.sender_extension_g,
|
||||
bob_scan.sender_extension_t,
|
||||
bob_enote.onetime_address));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, main2integ_transfer_2out_completeness)
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_main2main_completeness)
|
||||
{
|
||||
const mock_carrot_keys alice = mock_carrot_keys::generate();
|
||||
const mock_carrot_keys bob = mock_carrot_keys::generate();
|
||||
|
||||
CarrotDestinationV1 alice_address;
|
||||
make_carrot_main_address_v1(alice.account_spend_pubkey,
|
||||
alice.main_address_view_pubkey,
|
||||
alice_address);
|
||||
|
||||
CarrotDestinationV1 bob_address;
|
||||
make_carrot_integrated_address_v1(bob.account_spend_pubkey,
|
||||
bob.main_address_view_pubkey,
|
||||
gen_payment_id(),
|
||||
bob_address);
|
||||
|
||||
const crypto::key_image tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
input_context_t input_context;
|
||||
make_carrot_input_context(tx_first_key_image, input_context);
|
||||
|
||||
const CarrotPaymentProposalV1 bob_payment_proposal = CarrotPaymentProposalV1{
|
||||
.destination = bob_address,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.randomness = gen_janus_anchor()
|
||||
};
|
||||
|
||||
const CarrotPaymentProposalSelfSendV1 alice_payment_proposal = CarrotPaymentProposalSelfSendV1{
|
||||
.destination_address_spend_pubkey = alice_address.address_spend_pubkey,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.enote_type = CarrotEnoteType::CHANGE,
|
||||
.enote_ephemeral_pubkey = get_enote_ephemeral_pubkey(bob_payment_proposal, input_context)
|
||||
};
|
||||
|
||||
std::vector<RCTOutputEnoteProposal> enote_proposals;
|
||||
encrypted_payment_id_t encrypted_payment_id;
|
||||
get_output_enote_proposals({bob_payment_proposal},
|
||||
{alice_payment_proposal},
|
||||
alice.s_view_balance_dev,
|
||||
tx_first_key_image,
|
||||
enote_proposals,
|
||||
encrypted_payment_id);
|
||||
|
||||
ASSERT_EQ(2, enote_proposals.size()); // 2-out tx
|
||||
|
||||
// collect enotes
|
||||
std::vector<CarrotEnoteV1> enotes;
|
||||
for (const RCTOutputEnoteProposal &enote_proposal : enote_proposals)
|
||||
enotes.push_back(enote_proposal.enote);
|
||||
|
||||
// check that alice scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> alice_scan_vec;
|
||||
unittest_scan_enote_set(enotes, encrypted_payment_id, alice, alice_scan_vec);
|
||||
ASSERT_EQ(1, alice_scan_vec.size());
|
||||
unittest_carrot_scan_result_t alice_scan = alice_scan_vec.front();
|
||||
|
||||
// check that bob scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> bob_scan_vec;
|
||||
unittest_scan_enote_set(enotes, encrypted_payment_id, bob, bob_scan_vec);
|
||||
ASSERT_EQ(1, bob_scan_vec.size());
|
||||
unittest_carrot_scan_result_t bob_scan = bob_scan_vec.front();
|
||||
|
||||
// set named references to enotes
|
||||
ASSERT_TRUE((alice_scan.output_index == 0 && bob_scan.output_index == 1) ||
|
||||
(alice_scan.output_index == 1 && bob_scan.output_index == 0));
|
||||
const CarrotEnoteV1 &alice_enote = enotes.at(alice_scan.output_index);
|
||||
const CarrotEnoteV1 &bob_enote = enotes.at(bob_scan.output_index);
|
||||
|
||||
// check Alice's recovered data
|
||||
EXPECT_EQ(alice_payment_proposal.destination_address_spend_pubkey, alice_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(alice_payment_proposal.amount, alice_scan.amount);
|
||||
EXPECT_EQ(alice_enote.amount_commitment, rct::commit(alice_scan.amount, rct::sk2rct(alice_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(null_payment_id, alice_scan.payment_id);
|
||||
EXPECT_EQ(alice_payment_proposal.enote_type, alice_scan.enote_type);
|
||||
|
||||
// check Bob's recovered data
|
||||
EXPECT_EQ(bob_payment_proposal.destination.address_spend_pubkey, bob_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(bob_payment_proposal.amount, bob_scan.amount);
|
||||
EXPECT_EQ(bob_enote.amount_commitment, rct::commit(bob_scan.amount, rct::sk2rct(bob_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(bob_address.payment_id, bob_scan.payment_id); // DIFFERENT FROM MAIN
|
||||
EXPECT_EQ(CarrotEnoteType::PAYMENT, bob_scan.enote_type);
|
||||
|
||||
// check Alice spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(alice.k_prove_spend,
|
||||
alice.k_generate_image,
|
||||
crypto::secret_key{{1}},
|
||||
alice_scan.sender_extension_g,
|
||||
alice_scan.sender_extension_t,
|
||||
alice_enote.onetime_address));
|
||||
|
||||
// check Bob spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address(bob.k_prove_spend,
|
||||
bob.k_generate_image,
|
||||
crypto::secret_key{{1}},
|
||||
bob_scan.sender_extension_g,
|
||||
bob_scan.sender_extension_t,
|
||||
bob_enote.onetime_address));
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_main2sub_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_main2integ_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_sub2main_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_sub2sub_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_internal_ss_sub2integ_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::PAYMENT, true);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::CHANGE, true);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_main2main_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_main2sub_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_main2integ_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_sub2main_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_sub2sub_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_core, get_enote_output_proposals_external_ss_sub2integ_completeness)
|
||||
{
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::PAYMENT, false);
|
||||
subtest_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::CHANGE, false);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
|
291
tests/unit_tests/carrot_legacy.cpp
Normal file
291
tests/unit_tests/carrot_legacy.cpp
Normal file
@ -0,0 +1,291 @@
|
||||
// Copyright (c) 2024, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "carrot_core/carrot_enote_scan.h"
|
||||
#include "carrot_core/device_ram_borrowed.h"
|
||||
#include "carrot_core/enote_utils.h"
|
||||
#include "carrot_core/output_set_finalization.h"
|
||||
#include "carrot_core/payment_proposal.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/generators.h"
|
||||
#include "cryptonote_basic/account.h"
|
||||
#include "cryptonote_basic/subaddress_index.h"
|
||||
#include "device/device_default.hpp"
|
||||
#include "ringct/rctOps.h"
|
||||
|
||||
using namespace carrot;
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
static bool can_open_fcmp_onetime_address_from_legacy_addr(const cryptonote::account_keys &keys,
|
||||
const uint32_t j_major,
|
||||
const uint32_t j_minor,
|
||||
const crypto::secret_key &sender_extension_g,
|
||||
const crypto::secret_key &sender_extension_t,
|
||||
const crypto::public_key &onetime_address)
|
||||
{
|
||||
// K_s = k_s G
|
||||
// m = Hn(k_v || j_major || j_minor) if j else 0
|
||||
// K^j_s = K_s + m G
|
||||
// Ko = K^j_s + k^o_g G + k^o_t T
|
||||
// = (k^o_g + m + k_s) G + k^o_t T
|
||||
|
||||
// m = Hn(k_v || j_major || j_minor) if j else 0
|
||||
crypto::secret_key subaddress_ext{};
|
||||
if (j_major || j_minor)
|
||||
subaddress_ext = keys.get_device().get_subaddress_secret_key(keys.m_view_secret_key, {j_major, j_minor});
|
||||
|
||||
// combined_g = k^o_g + m + k_s
|
||||
rct::key combined_g;
|
||||
sc_add(combined_g.bytes, to_bytes(sender_extension_g), to_bytes(subaddress_ext));
|
||||
sc_add(combined_g.bytes, combined_g.bytes, to_bytes(keys.m_spend_secret_key));
|
||||
|
||||
// Ko' = combined_g G + k^o_t T
|
||||
rct::key recomputed_onetime_address;
|
||||
rct::addKeys2(recomputed_onetime_address, combined_g, rct::sk2rct(sender_extension_t), rct::pk2rct(crypto::get_T()));
|
||||
|
||||
// Ko' ?= Ko
|
||||
return recomputed_onetime_address == onetime_address;
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
struct unittest_carrot_scan_result_t
|
||||
{
|
||||
crypto::public_key address_spend_pubkey = rct::rct2pk(rct::I);
|
||||
crypto::secret_key sender_extension_g = rct::rct2sk(rct::I);
|
||||
crypto::secret_key sender_extension_t = rct::rct2sk(rct::I);
|
||||
|
||||
rct::xmr_amount amount = 0;
|
||||
crypto::secret_key amount_blinding_factor = rct::rct2sk(rct::I);
|
||||
|
||||
CarrotEnoteType enote_type = CarrotEnoteType::PAYMENT;
|
||||
|
||||
payment_id_t payment_id = null_payment_id;
|
||||
|
||||
size_t output_index = 0;
|
||||
};
|
||||
static void unittest_legacy_scan_enote_set(const std::vector<CarrotEnoteV1> &enotes,
|
||||
const encrypted_payment_id_t encrypted_payment_id,
|
||||
const cryptonote::account_base acb,
|
||||
std::vector<unittest_carrot_scan_result_t> &res)
|
||||
{
|
||||
res.clear();
|
||||
|
||||
// external scans
|
||||
for (size_t output_index = 0; output_index < enotes.size(); ++output_index)
|
||||
{
|
||||
const CarrotEnoteV1 &enote = enotes.at(output_index);
|
||||
|
||||
// s_sr = 8 k_v D_e
|
||||
crypto::x25519_pubkey s_sr;
|
||||
make_carrot_uncontextualized_shared_key_receiver(acb.get_keys().m_view_secret_key,
|
||||
enote.enote_ephemeral_pubkey,
|
||||
s_sr);
|
||||
|
||||
unittest_carrot_scan_result_t scan_result{};
|
||||
const bool r = try_scan_carrot_enote_external(enote,
|
||||
encrypted_payment_id,
|
||||
s_sr,
|
||||
view_incoming_key_ram_borrowed_device(acb.get_keys().m_view_secret_key),
|
||||
acb.get_keys().m_account_address.m_spend_public_key,
|
||||
scan_result.sender_extension_g,
|
||||
scan_result.sender_extension_t,
|
||||
scan_result.address_spend_pubkey,
|
||||
scan_result.amount,
|
||||
scan_result.amount_blinding_factor,
|
||||
scan_result.payment_id,
|
||||
scan_result.enote_type);
|
||||
|
||||
scan_result.output_index = output_index;
|
||||
|
||||
if (r)
|
||||
res.push_back(scan_result);
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
static void subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(const bool alice_subaddress,
|
||||
const bool bob_subaddress,
|
||||
const bool bob_integrated,
|
||||
const CarrotEnoteType alice_selfsend_type)
|
||||
{
|
||||
hw::device &hwdev = hw::get_device("default");
|
||||
|
||||
// generate alice keys and address
|
||||
cryptonote::account_base alice;
|
||||
alice.generate();
|
||||
const uint32_t alice_j_major = alice_subaddress ? crypto::rand<uint32_t>() : 0;
|
||||
const uint32_t alice_j_minor = alice_subaddress ? crypto::rand<uint32_t>() : 0;
|
||||
CarrotDestinationV1 alice_address{};
|
||||
cryptonote::account_public_address subaddr = hwdev.get_subaddress(alice.get_keys(),
|
||||
{alice_j_major, alice_j_minor});
|
||||
alice_address.address_spend_pubkey = subaddr.m_spend_public_key;
|
||||
alice_address.address_view_pubkey = subaddr.m_view_public_key;
|
||||
alice_address.is_subaddress = alice_subaddress;
|
||||
alice_address.payment_id = null_payment_id;
|
||||
|
||||
// generate bob keys and address
|
||||
cryptonote::account_base bob;
|
||||
bob.generate();
|
||||
const uint32_t bob_j_major = bob_subaddress ? crypto::rand<uint32_t>() : 0;
|
||||
const uint32_t bob_j_minor = bob_subaddress ? crypto::rand<uint32_t>() : 0;
|
||||
CarrotDestinationV1 bob_address{};
|
||||
subaddr = hwdev.get_subaddress(bob.get_keys(), {bob_j_major, bob_j_minor});
|
||||
bob_address.address_spend_pubkey = subaddr.m_spend_public_key;
|
||||
bob_address.address_view_pubkey = subaddr.m_view_public_key;
|
||||
bob_address.is_subaddress = bob_subaddress;
|
||||
bob_address.payment_id = bob_integrated ? gen_payment_id() : null_payment_id;
|
||||
|
||||
// generate input context
|
||||
const crypto::key_image tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
input_context_t input_context;
|
||||
make_carrot_input_context(tx_first_key_image, input_context);
|
||||
|
||||
// outgoing payment proposal to bob
|
||||
const CarrotPaymentProposalV1 bob_payment_proposal = CarrotPaymentProposalV1{
|
||||
.destination = bob_address,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.randomness = gen_janus_anchor()
|
||||
};
|
||||
|
||||
// selfsend payment proposal to alice
|
||||
const CarrotPaymentProposalSelfSendV1 alice_payment_proposal = CarrotPaymentProposalSelfSendV1{
|
||||
.destination_address_spend_pubkey = alice_address.address_spend_pubkey,
|
||||
.amount = crypto::rand_idx<rct::xmr_amount>(1000000),
|
||||
.enote_type = CarrotEnoteType::CHANGE,
|
||||
.enote_ephemeral_pubkey = get_enote_ephemeral_pubkey(bob_payment_proposal, input_context)
|
||||
};
|
||||
|
||||
// alice mem devices
|
||||
view_incoming_key_ram_borrowed_device alive_k_v_dev(alice.get_keys().m_view_secret_key);
|
||||
|
||||
// turn payment proposals into enotes
|
||||
std::vector<RCTOutputEnoteProposal> enote_proposals;
|
||||
encrypted_payment_id_t encrypted_payment_id;
|
||||
get_output_enote_proposals({bob_payment_proposal},
|
||||
{alice_payment_proposal},
|
||||
nullptr,
|
||||
&alive_k_v_dev,
|
||||
alice.get_keys().m_account_address.m_spend_public_key,
|
||||
tx_first_key_image,
|
||||
enote_proposals,
|
||||
encrypted_payment_id);
|
||||
|
||||
ASSERT_EQ(2, enote_proposals.size()); // 2-out tx
|
||||
|
||||
// collect enotes
|
||||
std::vector<CarrotEnoteV1> enotes;
|
||||
for (const RCTOutputEnoteProposal &enote_proposal : enote_proposals)
|
||||
enotes.push_back(enote_proposal.enote);
|
||||
|
||||
// check that alice scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> alice_scan_vec;
|
||||
unittest_legacy_scan_enote_set(enotes, encrypted_payment_id, alice, alice_scan_vec);
|
||||
ASSERT_EQ(1, alice_scan_vec.size());
|
||||
unittest_carrot_scan_result_t alice_scan = alice_scan_vec.front();
|
||||
|
||||
// check that bob scanned 1 enote
|
||||
std::vector<unittest_carrot_scan_result_t> bob_scan_vec;
|
||||
unittest_legacy_scan_enote_set(enotes, encrypted_payment_id, bob, bob_scan_vec);
|
||||
ASSERT_EQ(1, bob_scan_vec.size());
|
||||
unittest_carrot_scan_result_t bob_scan = bob_scan_vec.front();
|
||||
|
||||
// set named references to enotes
|
||||
ASSERT_TRUE((alice_scan.output_index == 0 && bob_scan.output_index == 1) ||
|
||||
(alice_scan.output_index == 1 && bob_scan.output_index == 0));
|
||||
const CarrotEnoteV1 &alice_enote = enotes.at(alice_scan.output_index);
|
||||
const CarrotEnoteV1 &bob_enote = enotes.at(bob_scan.output_index);
|
||||
|
||||
// check Alice's recovered data
|
||||
EXPECT_EQ(alice_payment_proposal.destination_address_spend_pubkey, alice_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(alice_payment_proposal.amount, alice_scan.amount);
|
||||
EXPECT_EQ(alice_enote.amount_commitment, rct::commit(alice_scan.amount, rct::sk2rct(alice_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(null_payment_id, alice_scan.payment_id);
|
||||
EXPECT_EQ(alice_payment_proposal.enote_type, alice_scan.enote_type);
|
||||
|
||||
// check Bob's recovered data
|
||||
EXPECT_EQ(bob_payment_proposal.destination.address_spend_pubkey, bob_scan.address_spend_pubkey);
|
||||
EXPECT_EQ(bob_payment_proposal.amount, bob_scan.amount);
|
||||
EXPECT_EQ(bob_enote.amount_commitment, rct::commit(bob_scan.amount, rct::sk2rct(bob_scan.amount_blinding_factor)));
|
||||
EXPECT_EQ(bob_integrated ? bob_address.payment_id : null_payment_id, bob_scan.payment_id);
|
||||
EXPECT_EQ(CarrotEnoteType::PAYMENT, bob_scan.enote_type);
|
||||
|
||||
// check Alice spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address_from_legacy_addr(alice.get_keys(),
|
||||
alice_j_major,
|
||||
alice_j_minor,
|
||||
alice_scan.sender_extension_g,
|
||||
alice_scan.sender_extension_t,
|
||||
alice_enote.onetime_address));
|
||||
|
||||
// check Bob spendability
|
||||
EXPECT_TRUE(can_open_fcmp_onetime_address_from_legacy_addr(bob.get_keys(),
|
||||
bob_j_major,
|
||||
bob_j_minor,
|
||||
bob_scan.sender_extension_g,
|
||||
bob_scan.sender_extension_t,
|
||||
bob_enote.onetime_address));
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_main2main_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, false, false, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_main2sub_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, true, false, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_main2integ_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(false, false, true, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_sub2main_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, false, false, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_sub2sub_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, true, false, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_legacy, legacy_get_enote_output_proposals_sub2integ_completeness)
|
||||
{
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::PAYMENT);
|
||||
subtest_legacy_2out_transfer_get_output_enote_proposals_completeness(true, false, true, CarrotEnoteType::CHANGE);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
@ -1443,6 +1443,21 @@ TEST(StringTools, GetIpInt32)
|
||||
EXPECT_EQ(htonl(0xff0aff00), ip);
|
||||
}
|
||||
|
||||
TEST(StringTools, GetExtension)
|
||||
{
|
||||
EXPECT_EQ(std::string{}, epee::string_tools::get_extension(""));
|
||||
EXPECT_EQ(std::string{}, epee::string_tools::get_extension("."));
|
||||
EXPECT_EQ(std::string{"keys"}, epee::string_tools::get_extension("wallet.keys"));
|
||||
EXPECT_EQ(std::string{"3"}, epee::string_tools::get_extension("1.2.3"));
|
||||
}
|
||||
|
||||
TEST(StringTools, CutOffExtension)
|
||||
{
|
||||
EXPECT_EQ(std::string{}, epee::string_tools::cut_off_extension(""));
|
||||
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet"));
|
||||
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet.keys"));
|
||||
}
|
||||
|
||||
TEST(NetUtils, IPv4NetworkAddress)
|
||||
{
|
||||
static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");
|
||||
|
Loading…
Reference in New Issue
Block a user