added missing test code
This commit is contained in:
@@ -65,11 +65,12 @@ public:
|
||||
, const cryptonote::difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, oracle::asset_type_counts_v2& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, uint64_t audit_total
|
||||
, uint64_t token_total
|
||||
, const cryptonote::network_type nettype
|
||||
, cryptonote::yield_block_info& ybi
|
||||
, cryptonote::audit_block_info& abi
|
||||
|
||||
@@ -87,11 +87,12 @@ namespace
|
||||
const difficulty_type& cumulative_difficulty,
|
||||
const uint64_t& coins_generated,
|
||||
uint64_t num_rct_outs,
|
||||
oracle::asset_type_counts& cum_rct_by_asset_type,
|
||||
oracle::asset_type_counts_v2& cum_rct_by_asset_type,
|
||||
const crypto::hash& blk_hash,
|
||||
uint64_t slippage_total,
|
||||
uint64_t yield_total,
|
||||
uint64_t audit_total,
|
||||
uint64_t token_total,
|
||||
const cryptonote::network_type nettype,
|
||||
cryptonote::yield_block_info& ybi,
|
||||
cryptonote::audit_block_info& abi
|
||||
@@ -178,10 +179,10 @@ static std::unique_ptr<cryptonote::BlockchainAndPool> init_blockchain(const std:
|
||||
|
||||
const block *blk = &boost::get<block>(ev);
|
||||
auto blk_hash = get_block_hash(*blk);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::yield_block_info ybi;
|
||||
cryptonote::audit_block_info abi;
|
||||
bdb->add_block(*blk, 1, 1, 1, 0, 0, num_rct_outs_by_asset_type, blk_hash, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
bdb->add_block(*blk, 1, 1, 1, 0, 0, num_rct_outs_by_asset_type, blk_hash, 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
}
|
||||
|
||||
bool r = bap->blockchain.init(bdb, nettype, true, test_options, 2, nullptr);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -42,7 +42,9 @@ set(unit_tests_sources
|
||||
carrot_impl.cpp
|
||||
carrot_legacy.cpp
|
||||
carrot_mock_helpers.cpp
|
||||
carrot_return_index.cpp
|
||||
carrot_sparc.cpp
|
||||
carrot_return_index.cpp
|
||||
carrot_transcript_fixed.cpp
|
||||
carrot_tx_proof.cpp
|
||||
chacha.cpp
|
||||
|
||||
@@ -165,6 +165,7 @@ static void subtest_multi_account_transfer_over_transaction(const unittest_trans
|
||||
{{0, 0}, AddressDeriveType::Carrot},
|
||||
{},
|
||||
{},
|
||||
"SAL1",
|
||||
tx_proposal);
|
||||
|
||||
// make unsigned transaction
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
// Copyright (c) 2025, The Salvium 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/account_secrets.h"
|
||||
#include "carrot_core/address_utils.h"
|
||||
#include "carrot_core/enote_utils.h"
|
||||
#include "carrot_core/output_set_finalization.h"
|
||||
#include "carrot_core/payment_proposal.h"
|
||||
#include "carrot_core/scan.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/generators.h"
|
||||
#include "ringct/rctOps.h"
|
||||
|
||||
#include "carrot_mock_helpers.h"
|
||||
|
||||
using namespace carrot;
|
||||
|
||||
// Alice sends once to Bob, Bob makes NUM_RETURNS return payments with random amounts,
|
||||
TEST(carrot_return_index, payment_channel_multiple_returns)
|
||||
{
|
||||
constexpr size_t NUM_RETURNS = 10;
|
||||
|
||||
// accounts
|
||||
carrot::carrot_and_legacy_account alice, bob;
|
||||
alice.generate();
|
||||
bob.generate();
|
||||
|
||||
// origin tx (Alice to Bob)
|
||||
const crypto::key_image origin_tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
const input_context_t input_context = make_carrot_input_context(origin_tx_first_key_image);
|
||||
|
||||
// Alice's change output onetime address (K_change)
|
||||
const crypto::public_key K_change = rct::rct2pk(rct::pkGen());
|
||||
|
||||
// Bob's received output onetime address (Ko)
|
||||
const crypto::public_key Ko = rct::rct2pk(rct::pkGen());
|
||||
|
||||
// Alice derives k_return_base
|
||||
crypto::secret_key k_return_base;
|
||||
alice.s_view_balance_dev.make_internal_return_privkey(input_context, Ko, k_return_base);
|
||||
|
||||
// K_return_base = k_return_base * G
|
||||
crypto::public_key K_return_base;
|
||||
crypto::secret_key_to_public_key(k_return_base, K_return_base);
|
||||
|
||||
// s_sr from origin TX (shared between Alice and Bob)
|
||||
unsigned char s_sender_receiver_unctx[32];
|
||||
crypto::rand(32, s_sender_receiver_unctx);
|
||||
|
||||
// Structure to hold Bob's return TX data (what would be on-chain)
|
||||
struct ReturnTxData {
|
||||
crypto::public_key K_r; // return address
|
||||
crypto::public_key onetime_address; // Ko for this return TX
|
||||
mx25519_pubkey enote_ephemeral_pubkey; // D_e
|
||||
encrypted_amount_t amount_enc; // encrypted amount
|
||||
crypto::key_image tx_first_key_image; // for input context
|
||||
};
|
||||
std::vector<ReturnTxData> return_txs(NUM_RETURNS);
|
||||
|
||||
rct::xmr_amount bob_total_sent = 0;
|
||||
|
||||
// Bob returns NUM_RETURNS payments
|
||||
for (uint64_t idx = 0; idx < NUM_RETURNS; ++idx)
|
||||
{
|
||||
// Random amount
|
||||
rct::xmr_amount amount = crypto::rand<rct::xmr_amount>() & 0xFFFFFFFF;
|
||||
bob_total_sent += amount;
|
||||
|
||||
crypto::secret_key k_idx;
|
||||
make_sparc_return_index(s_sender_receiver_unctx, input_context, Ko, idx, k_idx);
|
||||
|
||||
// Bob: K_return_final = K_return_base + k_idx * T
|
||||
rct::key k_idx_T;
|
||||
rct::scalarmultKey(k_idx_T, rct::pk2rct(crypto::get_T()), rct::sk2rct(k_idx));
|
||||
rct::key K_return_final = rct::addKeys(rct::pk2rct(K_return_base), k_idx_T);
|
||||
|
||||
// Bob: K_r = K_return_final + K_change
|
||||
return_txs[idx].K_r = rct::rct2pk(rct::addKeys(K_return_final, rct::pk2rct(K_change)));
|
||||
|
||||
// Bob: return TX enote
|
||||
return_txs[idx].tx_first_key_image = rct::rct2ki(rct::pkGen());
|
||||
return_txs[idx].onetime_address = rct::rct2pk(rct::pkGen());
|
||||
|
||||
// D_e
|
||||
crypto::secret_key d_e;
|
||||
crypto::rand(32, to_bytes(d_e));
|
||||
sc_reduce32(to_bytes(d_e));
|
||||
make_carrot_enote_ephemeral_pubkey_cryptonote(d_e, return_txs[idx].enote_ephemeral_pubkey);
|
||||
|
||||
const input_context_t return_input_context = make_carrot_input_context(return_txs[idx].tx_first_key_image);
|
||||
mx25519_pubkey shared_secret_unctx;
|
||||
crypto::hash shared_secret;
|
||||
make_carrot_uncontextualized_shared_key_sender(d_e, K_return_base, shared_secret_unctx);
|
||||
make_carrot_sender_receiver_secret(shared_secret_unctx.data, return_txs[idx].enote_ephemeral_pubkey, return_input_context, shared_secret);
|
||||
|
||||
// Bob encrypts the amount
|
||||
return_txs[idx].amount_enc = encrypt_carrot_amount(amount, shared_secret, return_txs[idx].onetime_address);
|
||||
}
|
||||
|
||||
// Verify all K_r values are unique
|
||||
for (size_t i = 0; i < NUM_RETURNS; ++i)
|
||||
{
|
||||
for (size_t j = i + 1; j < NUM_RETURNS; ++j)
|
||||
{
|
||||
EXPECT_NE(return_txs[i].K_r, return_txs[j].K_r)
|
||||
<< "K_r for return " << i << " and " << j << " should differ";
|
||||
}
|
||||
}
|
||||
|
||||
// Alice receives and decrypts all return payments
|
||||
rct::xmr_amount alice_total_received = 0;
|
||||
|
||||
for (uint64_t idx = 0; idx < NUM_RETURNS; ++idx)
|
||||
{
|
||||
const auto &rtx = return_txs[idx];
|
||||
|
||||
// k_idx for this return index
|
||||
crypto::secret_key alice_k_idx;
|
||||
make_sparc_return_index(s_sender_receiver_unctx, input_context, Ko, idx, alice_k_idx);
|
||||
|
||||
// Alice: K_return = k_return * G + k_idx * T
|
||||
rct::key alice_K_return_rct;
|
||||
rct::addKeys2(alice_K_return_rct, rct::sk2rct(k_return_base), rct::sk2rct(alice_k_idx), rct::pk2rct(crypto::get_T()));
|
||||
|
||||
// Alice computes K_r = K_return + K_change
|
||||
crypto::public_key alice_K_r = rct::rct2pk(rct::addKeys(alice_K_return_rct, rct::pk2rct(K_change)));
|
||||
|
||||
// Verify Alice's K_r matches what's on-chain (Bob's)
|
||||
ASSERT_EQ(alice_K_r, rtx.K_r) << "K_r mismatch for idx " << idx;
|
||||
|
||||
// Alice derives shared secret using k_return_base
|
||||
const input_context_t return_input_context = make_carrot_input_context(rtx.tx_first_key_image);
|
||||
mx25519_pubkey shared_secret_unctx;
|
||||
crypto::hash shared_secret;
|
||||
make_carrot_uncontextualized_shared_key_receiver(k_return_base, rtx.enote_ephemeral_pubkey, shared_secret_unctx);
|
||||
make_carrot_sender_receiver_secret(shared_secret_unctx.data, rtx.enote_ephemeral_pubkey, return_input_context, shared_secret);
|
||||
|
||||
// Alice decrypts the amount
|
||||
rct::xmr_amount decrypted_amount = decrypt_carrot_amount(rtx.amount_enc, shared_secret, rtx.onetime_address);
|
||||
|
||||
alice_total_received += decrypted_amount;
|
||||
}
|
||||
|
||||
// Final verification: Alice's total matches Bob's total
|
||||
EXPECT_EQ(alice_total_received, bob_total_sent);
|
||||
}
|
||||
+179
-121
@@ -109,15 +109,16 @@ std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key> make_origin_
|
||||
crypto::secret_key k_return;
|
||||
alice.s_view_balance_dev.make_internal_return_privkey(input_context, enote_proposal_out.enote.onetime_address, k_return);
|
||||
|
||||
// compute K_return = k_return * G
|
||||
crypto::public_key return_pub;
|
||||
crypto::secret_key_to_public_key(k_return, return_pub);
|
||||
encrypted_return_pubkey_t K_return;
|
||||
static_assert(sizeof(K_return.bytes) == sizeof(return_pub.data), "Size mismatch");
|
||||
memcpy(K_return.bytes, return_pub.data, sizeof(encrypted_return_pubkey_t));
|
||||
// compute k_idx
|
||||
crypto::secret_key k_idx;
|
||||
//make_sparc_return_index(input_context, enote_proposal_out.enote.onetime_address, 0, k_idx);
|
||||
|
||||
// compute SPARC K_return = k_return * G
|
||||
crypto::public_key K_return;
|
||||
secret_key_to_public_key(k_return, K_return);
|
||||
|
||||
// compute K_o = K_change + K_return
|
||||
crypto::public_key K_o = rct::rct2pk(rct::addKeys(rct::pk2rct(return_pub), rct::pk2rct(enote_proposal_change.enote.onetime_address)));
|
||||
// compute K_r = K_change + K_return
|
||||
crypto::public_key K_r = rct::rct2pk(rct::addKeys(rct::pk2rct(K_return), rct::pk2rct(enote_proposal_change.enote.onetime_address)));
|
||||
|
||||
// calculate the shared secret
|
||||
mx25519_pubkey shared_secret_unctx;
|
||||
@@ -133,16 +134,21 @@ std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key> make_origin_
|
||||
make_sparc_return_pubkey_encryption_mask(shared_secret_unctx.data, input_context, enote_proposal_out.enote.onetime_address, m_return);
|
||||
|
||||
// compute return_enc
|
||||
enote_proposal_out.enote.return_enc = K_return ^ m_return;
|
||||
encrypted_return_pubkey_t return_pub;
|
||||
static_assert(sizeof(K_return.data) == sizeof(return_pub.bytes), "Size mismatch");
|
||||
memcpy(return_pub.bytes, K_return.data, sizeof(encrypted_return_pubkey_t));
|
||||
enote_proposal_out.enote.return_enc = return_pub ^ m_return;
|
||||
|
||||
// Return the enotes and the public return key
|
||||
std::vector<RCTOutputEnoteProposal> tx_enotes{enote_proposal_change, enote_proposal_out};
|
||||
return {tx_enotes, K_o};
|
||||
return {tx_enotes, K_r};
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key> make_return_tx(
|
||||
std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key, rct::xmr_amount> make_return_tx(
|
||||
carrot::carrot_and_legacy_account &bob,
|
||||
std::vector<RCTOutputEnoteProposal> &origin_tx_outputs
|
||||
std::vector<RCTOutputEnoteProposal> &origin_tx_outputs,
|
||||
const uint64_t idx,
|
||||
const uint64_t amount
|
||||
) {
|
||||
// [0] enote is change, [1] enote bob received
|
||||
const auto change_output = origin_tx_outputs[0].enote;
|
||||
@@ -199,23 +205,43 @@ std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key> make_return_
|
||||
);
|
||||
|
||||
// Create a TX fee that needs to be deducted from the returned amount
|
||||
const rct::xmr_amount txnFee = recovered_amount >> 4;
|
||||
const rct::xmr_amount amount_return = recovered_amount - txnFee;
|
||||
const rct::xmr_amount txnFee = amount >> 4;
|
||||
const rct::xmr_amount amount_return = amount - txnFee;
|
||||
|
||||
// compute m_return
|
||||
encrypted_return_pubkey_t m_return;
|
||||
make_sparc_return_pubkey_encryption_mask(origin_tx_shared_secret_unctx.data, input_context, received_output.onetime_address, m_return);
|
||||
|
||||
// compute K_return from return_enc
|
||||
encrypted_return_pubkey_t K_return;
|
||||
K_return = received_output.return_enc ^ m_return;
|
||||
crypto::public_key return_pub;
|
||||
static_assert(sizeof(K_return.bytes) == sizeof(return_pub.data), "Size mismatch");
|
||||
memcpy(return_pub.data, K_return.bytes, sizeof(encrypted_return_pubkey_t));
|
||||
|
||||
encrypted_return_pubkey_t K_return_encrypted;
|
||||
K_return_encrypted = received_output.return_enc ^ m_return;
|
||||
crypto::public_key K_return_base;
|
||||
static_assert(sizeof(K_return_encrypted.bytes) == sizeof(K_return_base.data), "Size mismatch");
|
||||
memcpy(K_return_base.data, K_return_encrypted.bytes, sizeof(encrypted_return_pubkey_t));
|
||||
/*
|
||||
// k_idx
|
||||
crypto::secret_key k_idx;
|
||||
make_sparc_return_index(input_context, received_output.onetime_address, idx, k_idx);
|
||||
|
||||
// k_idx_origin for idx=0
|
||||
crypto::secret_key k_idx_origin;
|
||||
make_sparc_return_index(input_context, received_output.onetime_address, 0, k_idx_origin);
|
||||
|
||||
// k_idx_diff = k_idx - k_idx_origin
|
||||
crypto::secret_key k_idx_diff;
|
||||
sc_sub(to_bytes(k_idx_diff), to_bytes(k_idx), to_bytes(k_idx_origin));
|
||||
|
||||
// K_return: K_return = K_return_base + k_idx_diff * T
|
||||
rct::key K_return_adjusted = rct::addKeys(
|
||||
rct::pk2rct(K_return_base),
|
||||
rct::scalarmultKey(rct::pk2rct(crypto::get_T()), rct::sk2rct(k_idx_diff))
|
||||
);
|
||||
crypto::public_key return_pub = rct::rct2pk(K_return_adjusted);
|
||||
*/
|
||||
|
||||
// Make a destination address for the return
|
||||
CarrotDestinationV1 return_destination;
|
||||
make_carrot_main_address_v1(change_output.onetime_address, return_pub, return_destination);
|
||||
make_carrot_main_address_v1(change_output.onetime_address, K_return_base, return_destination);
|
||||
|
||||
// Create the return proposal, using the return address and the amount
|
||||
const CarrotPaymentProposalV1 proposal_return = CarrotPaymentProposalV1{
|
||||
@@ -226,15 +252,17 @@ std::tuple<std::vector<RCTOutputEnoteProposal>, crypto::public_key> make_return_
|
||||
|
||||
RCTOutputEnoteProposal enote_proposal_return;
|
||||
encrypted_payment_id_t encrypted_payment_id_return;
|
||||
get_output_proposal_return_v1(
|
||||
get_output_proposal_paymentchannel_v1(
|
||||
proposal_return,
|
||||
tx_return_first_key_image,
|
||||
nullptr, // s_view_balance_dev
|
||||
received_output.onetime_address,
|
||||
idx,
|
||||
enote_proposal_return,
|
||||
encrypted_payment_id_return
|
||||
);
|
||||
std::vector<RCTOutputEnoteProposal> tx_enotes{enote_proposal_return};
|
||||
return {tx_enotes, enote_proposal_return.enote.onetime_address};
|
||||
return {tx_enotes, enote_proposal_return.enote.onetime_address, txnFee};
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_sparc, main_address_return_payment_normal_scan_completeness)
|
||||
@@ -242,127 +270,157 @@ TEST(carrot_sparc, main_address_return_payment_normal_scan_completeness)
|
||||
// these will generate a new format carrot address.
|
||||
carrot::carrot_and_legacy_account alice, bob;
|
||||
alice.generate();
|
||||
alice.generate_subaddress_map({1,1});
|
||||
bob.generate();
|
||||
bob.generate_subaddress_map({1,1});
|
||||
|
||||
// make origin tx Alice -> Bob
|
||||
CarrotDestinationV1 bob_address = bob.cryptonote_address();
|
||||
auto [origin_tx_outputs, origin_return_pubkey] = make_origin_tx(alice, bob_address);
|
||||
|
||||
// make return tx Bob -> Alice
|
||||
auto [return_tx_outputs, return_pubkey] = make_return_tx(bob, origin_tx_outputs);
|
||||
const auto return_output = return_tx_outputs[0].enote;
|
||||
std::vector<rct::xmr_amount> amounts;
|
||||
rct::xmr_amount expected_total = 0;
|
||||
for (size_t i=0; i<100; ++i) {
|
||||
amounts.push_back(rct::randXmrAmount(TREASURY_SAL1_MINT_AMOUNT));
|
||||
expected_total += amounts.back();
|
||||
}
|
||||
|
||||
// 1. Alice checks the "hashmap" for a known return_address
|
||||
ASSERT_EQ(origin_return_pubkey, return_pubkey);
|
||||
rct::xmr_amount received_total = 0, fee_total = 0;
|
||||
for (size_t idx=0; idx<amounts.size(); ++idx) {
|
||||
const rct::xmr_amount amount = amounts.at(idx);
|
||||
|
||||
// make return tx Bob -> Alice
|
||||
auto [return_tx_outputs, return_pubkey, txnFee] = make_return_tx(bob, origin_tx_outputs, idx, amount);
|
||||
const auto return_output = return_tx_outputs[0].enote;
|
||||
|
||||
// Alice should now have access to the origin TX, including the "change" and "output" enotes
|
||||
const auto change_output = origin_tx_outputs[0].enote;
|
||||
const auto sent_output = origin_tx_outputs[1].enote;
|
||||
// 1. Alice checks the "hashmap" for a known return_address
|
||||
//ASSERT_EQ(origin_return_pubkey, return_pubkey);
|
||||
|
||||
// 2. compute k_return'
|
||||
const input_context_t input_context = make_carrot_input_context(sent_output.tx_first_key_image);
|
||||
crypto::secret_key k_return;
|
||||
alice.s_view_balance_dev.make_internal_return_privkey(input_context, sent_output.onetime_address, k_return);
|
||||
// Alice should now have access to the origin TX, including the "change" and "output" enotes
|
||||
const auto change_output = origin_tx_outputs[0].enote;
|
||||
const auto sent_output = origin_tx_outputs[1].enote;
|
||||
|
||||
// 2. compute k_return'
|
||||
const input_context_t input_context = make_carrot_input_context(sent_output.tx_first_key_image);
|
||||
crypto::secret_key k_return;
|
||||
alice.s_view_balance_dev.make_internal_return_privkey(input_context, sent_output.onetime_address, k_return);
|
||||
|
||||
// 6. recover the shared secret(s_sr) of return tx
|
||||
// s_sr = k_return * D_e
|
||||
const input_context_t input_context_return = make_carrot_input_context(return_output.tx_first_key_image);
|
||||
mx25519_pubkey shared_secret_return_unctx;
|
||||
crypto::hash shared_secret_return;
|
||||
make_carrot_uncontextualized_shared_key_receiver(k_return, return_output.enote_ephemeral_pubkey, shared_secret_return_unctx);
|
||||
|
||||
// 3. compute k_idx'
|
||||
crypto::secret_key k_idx;
|
||||
make_sparc_return_index(shared_secret_return_unctx.data, input_context_return, sent_output.onetime_address, idx, k_idx);
|
||||
|
||||
// 4. compute SPARC K_return' = k_return' * G + k_idx' * T
|
||||
rct::key K_return;
|
||||
rct::addKeys2(K_return,
|
||||
rct::sk2rct(k_return),
|
||||
rct::sk2rct(k_idx),
|
||||
rct::pk2rct(crypto::get_T()));
|
||||
|
||||
// 5. compute K_r' = K_change + K_return'
|
||||
crypto::public_key K_r_verify = rct::rct2pk(rct::addKeys(K_return, rct::pk2rct(change_output.onetime_address)));
|
||||
ASSERT_EQ(K_r_verify, return_pubkey);
|
||||
|
||||
// 7. recompute the shared secret : s^ctx_sr = H_32(s_sr, D_e, input_context)
|
||||
make_carrot_sender_receiver_secret(shared_secret_return_unctx.data,
|
||||
return_output.enote_ephemeral_pubkey,
|
||||
input_context_return,
|
||||
shared_secret_return);
|
||||
|
||||
// 8. recompute the view_tag and make sure it is correct
|
||||
EXPECT_TRUE(test_carrot_view_tag(shared_secret_return_unctx.data, input_context_return, K_r_verify, return_output.view_tag));
|
||||
|
||||
// 3. compute K_return' = k_return * G
|
||||
crypto::public_key K_return;
|
||||
crypto::secret_key_to_public_key(k_return, K_return);
|
||||
// 9. compute the amount encryption mask and recover the amount
|
||||
rct::xmr_amount recovered_amount_return = decrypt_carrot_amount(return_output.amount_enc, shared_secret_return, return_output.onetime_address);
|
||||
|
||||
// 4. compute K_o' = K_return' + K_change
|
||||
crypto::public_key K_o_verify = rct::rct2pk(rct::addKeys(rct::pk2rct(K_return), rct::pk2rct(change_output.onetime_address)));
|
||||
ASSERT_EQ(K_o_verify, return_pubkey);
|
||||
// 10. compute k_a' = H_n(s^ctx_sr, a', K^j_s', enote_type')
|
||||
crypto::secret_key recovered_amount_blinding_factor_return;
|
||||
make_carrot_amount_blinding_factor(shared_secret_return,
|
||||
recovered_amount_return,
|
||||
change_output.onetime_address,
|
||||
CarrotEnoteType::PAYMENT,
|
||||
recovered_amount_blinding_factor_return);
|
||||
|
||||
// 5. recover the shared secret(s_sr) of return tx
|
||||
// s_sr = k_return * D_e
|
||||
const input_context_t input_context_return = make_carrot_input_context(return_output.tx_first_key_image);
|
||||
mx25519_pubkey shared_secret_return_unctx;
|
||||
crypto::hash shared_secret_return;
|
||||
make_carrot_uncontextualized_shared_key_receiver(k_return, return_output.enote_ephemeral_pubkey, shared_secret_return_unctx);
|
||||
// s^ctx_sr = H_32(s_sr, D_e, input_context)
|
||||
make_carrot_sender_receiver_secret(shared_secret_return_unctx.data,
|
||||
return_output.enote_ephemeral_pubkey,
|
||||
input_context_return,
|
||||
shared_secret_return);
|
||||
// 11. compute C_a' = k_a' G + a' H
|
||||
rct::key recovered_amount_commitment_return = rct::commit(recovered_amount_return, rct::sk2rct(recovered_amount_blinding_factor_return));
|
||||
|
||||
// 6. verify the view_tag
|
||||
EXPECT_TRUE(test_carrot_view_tag(shared_secret_return_unctx.data, input_context_return, return_output.onetime_address, return_output.view_tag));
|
||||
|
||||
// 8. compute the amount encryption mask and recover the amount
|
||||
rct::xmr_amount recovered_amount_return = decrypt_carrot_amount(return_output.amount_enc, shared_secret_return, return_output.onetime_address);
|
||||
// 12. verify the commitment
|
||||
ASSERT_EQ(return_output.amount_commitment, recovered_amount_commitment_return);
|
||||
|
||||
// 10. compute k_a' = H_n(s^ctx_sr, a', K^j_s', enote_type')
|
||||
crypto::secret_key recovered_amount_blinding_factor_return;
|
||||
make_carrot_amount_blinding_factor(shared_secret_return,
|
||||
recovered_amount_return,
|
||||
change_output.onetime_address,
|
||||
CarrotEnoteType::PAYMENT,
|
||||
recovered_amount_blinding_factor_return);
|
||||
|
||||
// 11. compute C_a' = k_a' G + a' H
|
||||
rct::key recovered_amount_commitment_return = rct::commit(recovered_amount_return, rct::sk2rct(recovered_amount_blinding_factor_return));
|
||||
|
||||
// 12. verify the commitment
|
||||
ASSERT_EQ(return_output.amount_commitment, recovered_amount_commitment_return);
|
||||
|
||||
// 13. compute m_pid and pid_enc - not implemented/tested since not supported in SPARC
|
||||
/*
|
||||
if (return_output.encrypted_payment_id)
|
||||
// 13. compute m_pid and pid_enc - not implemented/tested since not supported in SPARC
|
||||
/*
|
||||
if (return_output.encrypted_payment_id)
|
||||
nominal_payment_id_out = decrypt_legacy_payment_id(*encrypted_payment_id, s_sender_receiver, onetime_address);
|
||||
else
|
||||
else
|
||||
nominal_payment_id_out = null_payment_id;
|
||||
encrypted_payment_id_out =encrypt_legacy_payment_id(proposal.destination.payment_id, s_sender_receiver, output_enote_out.enote.onetime_address);
|
||||
*/
|
||||
encrypted_payment_id_out =encrypt_legacy_payment_id(proposal.destination.payment_id, s_sender_receiver, output_enote_out.enote.onetime_address);
|
||||
*/
|
||||
|
||||
// 15. compute m_anchor and anchor'
|
||||
janus_anchor_t recovered_anchor_return = decrypt_carrot_anchor(return_output.anchor_enc, shared_secret_return, return_output.onetime_address);
|
||||
// 15. compute m_anchor and anchor'
|
||||
janus_anchor_t recovered_anchor_return = decrypt_carrot_anchor(return_output.anchor_enc, shared_secret_return, return_output.onetime_address);
|
||||
|
||||
// 17. compute d_e'
|
||||
crypto::secret_key recovered_ephemeral_privkey_return;
|
||||
make_carrot_enote_ephemeral_privkey(recovered_anchor_return, input_context_return, change_output.onetime_address, null_payment_id, recovered_ephemeral_privkey_return);
|
||||
// 17. compute d_e'
|
||||
crypto::secret_key recovered_ephemeral_privkey_return;
|
||||
make_carrot_enote_ephemeral_privkey(recovered_anchor_return, input_context_return, change_output.onetime_address, null_payment_id, recovered_ephemeral_privkey_return);
|
||||
|
||||
// 18. compute D_e'
|
||||
mx25519_pubkey recovered_ephemeral_pubkey_return;
|
||||
make_carrot_enote_ephemeral_pubkey(recovered_ephemeral_privkey_return, change_output.onetime_address, false, recovered_ephemeral_pubkey_return);
|
||||
// 18. compute D_e'
|
||||
mx25519_pubkey recovered_ephemeral_pubkey_return;
|
||||
make_carrot_enote_ephemeral_pubkey(recovered_ephemeral_privkey_return, change_output.onetime_address, false, recovered_ephemeral_pubkey_return);
|
||||
|
||||
// 19. verify the enote ephemeral pubkey
|
||||
ASSERT_EQ(recovered_ephemeral_pubkey_return, return_output.enote_ephemeral_pubkey);
|
||||
// 19. verify the enote ephemeral pubkey
|
||||
ASSERT_EQ(recovered_ephemeral_pubkey_return, return_output.enote_ephemeral_pubkey);
|
||||
|
||||
// Scan the change output
|
||||
crypto::secret_key recovered_sender_extension_g_change;
|
||||
crypto::secret_key recovered_sender_extension_t_change;
|
||||
crypto::public_key recovered_address_spend_pubkey_change;
|
||||
rct::xmr_amount recovered_amount_change;
|
||||
crypto::secret_key recovered_amount_blinding_factor_change;
|
||||
CarrotEnoteType recovered_enote_type_change;
|
||||
janus_anchor_t recovered_internal_message_out_change;
|
||||
crypto::public_key return_address_out;
|
||||
bool is_return_out;
|
||||
const bool scan_success_change = try_scan_carrot_enote_internal_receiver(change_output,
|
||||
alice,
|
||||
recovered_sender_extension_g_change,
|
||||
recovered_sender_extension_t_change,
|
||||
recovered_address_spend_pubkey_change,
|
||||
recovered_amount_change,
|
||||
recovered_amount_blinding_factor_change,
|
||||
recovered_enote_type_change,
|
||||
recovered_internal_message_out_change,
|
||||
return_address_out,
|
||||
is_return_out);
|
||||
ASSERT_TRUE(scan_success_change);
|
||||
// Scan the change output
|
||||
crypto::secret_key recovered_sender_extension_g_change;
|
||||
crypto::secret_key recovered_sender_extension_t_change;
|
||||
crypto::public_key recovered_address_spend_pubkey_change;
|
||||
rct::xmr_amount recovered_amount_change;
|
||||
crypto::secret_key recovered_amount_blinding_factor_change;
|
||||
CarrotEnoteType recovered_enote_type_change;
|
||||
janus_anchor_t recovered_internal_message_out_change;
|
||||
crypto::public_key return_address_out;
|
||||
bool is_return_out;
|
||||
const bool scan_success_change = try_scan_carrot_enote_internal_receiver(change_output,
|
||||
alice,
|
||||
recovered_sender_extension_g_change,
|
||||
recovered_sender_extension_t_change,
|
||||
recovered_address_spend_pubkey_change,
|
||||
recovered_amount_change,
|
||||
recovered_amount_blinding_factor_change,
|
||||
recovered_enote_type_change,
|
||||
recovered_internal_message_out_change,
|
||||
return_address_out,
|
||||
is_return_out);
|
||||
ASSERT_TRUE(scan_success_change);
|
||||
|
||||
// check spendability of the change output
|
||||
EXPECT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key,
|
||||
recovered_sender_extension_g_change,
|
||||
recovered_sender_extension_t_change,
|
||||
change_output.onetime_address));
|
||||
// check spendability of the change output
|
||||
EXPECT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key,
|
||||
recovered_sender_extension_g_change,
|
||||
recovered_sender_extension_t_change,
|
||||
change_output.onetime_address));
|
||||
|
||||
// check spendability of the return_payment
|
||||
crypto::secret_key sum_g;
|
||||
sc_add(to_bytes(sum_g), to_bytes(recovered_sender_extension_g_change), to_bytes(k_return));
|
||||
ASSERT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key,
|
||||
sum_g,
|
||||
recovered_sender_extension_t_change,
|
||||
return_output.onetime_address));
|
||||
// check spendability of the return_payment
|
||||
crypto::secret_key sum_g, sum_t;
|
||||
sc_add(to_bytes(sum_g), to_bytes(recovered_sender_extension_g_change), to_bytes(k_return));
|
||||
sc_add(to_bytes(sum_t), to_bytes(recovered_sender_extension_t_change), to_bytes(k_idx));
|
||||
ASSERT_TRUE(alice.can_open_fcmp_onetime_address(alice.get_keys().m_carrot_account_address.m_spend_public_key,
|
||||
sum_g,
|
||||
sum_t,
|
||||
return_output.onetime_address));
|
||||
|
||||
received_total += recovered_amount_return;
|
||||
fee_total += txnFee;
|
||||
std::cout << "Amount[" << idx << "] received " << recovered_amount_return << ", fee " << txnFee << " from total " << amount << std::endl;
|
||||
}
|
||||
|
||||
// Verify we received all the expected amounts
|
||||
ASSERT_EQ(expected_total, received_total + fee_total);
|
||||
}
|
||||
//----------------------------------------------------------------------------------------------------------------------
|
||||
TEST(carrot_sparc, get_spend_authority_proof_completeness)
|
||||
|
||||
@@ -53,11 +53,12 @@ public:
|
||||
, const cryptonote::difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, oracle::asset_type_counts_v2& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, uint64_t audit_total
|
||||
, uint64_t token_total
|
||||
, const cryptonote::network_type nettype
|
||||
, cryptonote::yield_block_info& ybi
|
||||
, cryptonote::audit_block_info& abi
|
||||
@@ -104,7 +105,7 @@ TEST(major, Only)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -117,27 +118,27 @@ TEST(major, Only)
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 0));
|
||||
ASSERT_FALSE(hf.add(mkblock(2, 2), 0));
|
||||
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
|
||||
// block height 1, only version 1 is accepted
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 1));
|
||||
ASSERT_FALSE(hf.add(mkblock(2, 2), 1));
|
||||
ASSERT_TRUE(hf.add(mkblock(1, 2), 1));
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
|
||||
// block height 2, only version 2 is accepted
|
||||
ASSERT_FALSE(hf.add(mkblock(0, 2), 2));
|
||||
ASSERT_FALSE(hf.add(mkblock(1, 2), 2));
|
||||
ASSERT_FALSE(hf.add(mkblock(3, 2), 2));
|
||||
ASSERT_TRUE(hf.add(mkblock(2, 2), 2));
|
||||
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
}
|
||||
|
||||
TEST(empty_hardforks, Success)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -147,7 +148,7 @@ TEST(empty_hardforks, Success)
|
||||
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
|
||||
|
||||
for (uint64_t h = 0; h <= 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
ASSERT_EQ(hf.get(0), 1);
|
||||
@@ -173,7 +174,7 @@ TEST(check_for_height, Success)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 0, 0, 1, 0); // no voting
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -184,14 +185,14 @@ TEST(check_for_height, Success)
|
||||
for (uint64_t h = 0; h <= 4; ++h) {
|
||||
ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h));
|
||||
ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 5; h <= 10; ++h) {
|
||||
ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low
|
||||
ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h));
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -200,7 +201,7 @@ TEST(get, next_version)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -211,19 +212,19 @@ TEST(get, next_version)
|
||||
|
||||
for (uint64_t h = 0; h <= 4; ++h) {
|
||||
ASSERT_EQ(2, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 5; h <= 9; ++h) {
|
||||
ASSERT_EQ(4, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
for (uint64_t h = 10; h <= 15; ++h) {
|
||||
ASSERT_EQ(4, hf.get_next_version());
|
||||
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -232,7 +233,7 @@ TEST(states, Success)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
|
||||
ASSERT_TRUE(hf.add_fork(1, 0, 0));
|
||||
ASSERT_TRUE(hf.add_fork(2, BLOCKS_PER_YEAR, SECONDS_PER_YEAR));
|
||||
@@ -256,7 +257,7 @@ TEST(steps_asap, Success)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1,0,1,1,1);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -268,7 +269,7 @@ TEST(steps_asap, Success)
|
||||
hf.init();
|
||||
|
||||
for (uint64_t h = 0; h < 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -288,7 +289,7 @@ TEST(steps_1, Success)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1,0,1,1,1);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -298,7 +299,7 @@ TEST(steps_1, Success)
|
||||
hf.init();
|
||||
|
||||
for (uint64_t h = 0 ; h < 10; ++h) {
|
||||
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -312,7 +313,7 @@ TEST(reorganize, Same)
|
||||
for (int history = 1; history <= 12; ++history) {
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, history, 100);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -326,7 +327,7 @@ TEST(reorganize, Same)
|
||||
// index 0 1 2 3 4 5 6 7 8 9
|
||||
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
|
||||
for (uint64_t h = 0; h < 20; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -344,7 +345,7 @@ TEST(reorganize, Changed)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 4, 100);
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -360,7 +361,7 @@ TEST(reorganize, Changed)
|
||||
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
|
||||
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 };
|
||||
for (uint64_t h = 0; h < 16; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE (hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
|
||||
@@ -380,7 +381,7 @@ TEST(reorganize, Changed)
|
||||
ASSERT_EQ(db.height(), 3);
|
||||
hf.reorganize_from_block_height(2);
|
||||
for (uint64_t h = 3; h < 16; ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
ASSERT_EQ (ret, h < 15);
|
||||
}
|
||||
@@ -393,7 +394,7 @@ TEST(reorganize, Changed)
|
||||
|
||||
TEST(voting, threshold)
|
||||
{
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
for (int threshold = 87; threshold <= 88; ++threshold) {
|
||||
@@ -407,7 +408,7 @@ TEST(voting, threshold)
|
||||
|
||||
for (uint64_t h = 0; h <= 8; ++h) {
|
||||
uint8_t v = 1 + !!(h % 8);
|
||||
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
if (h >= 8 && threshold == 87) {
|
||||
// for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1
|
||||
@@ -425,7 +426,7 @@ TEST(voting, threshold)
|
||||
|
||||
TEST(voting, different_thresholds)
|
||||
{
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
for (int threshold = 87; threshold <= 88; ++threshold) {
|
||||
@@ -444,7 +445,7 @@ TEST(voting, different_thresholds)
|
||||
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
|
||||
|
||||
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
bool ret = hf.add(db.get_block_from_height(h), h);
|
||||
ASSERT_EQ(ret, true);
|
||||
}
|
||||
@@ -458,7 +459,7 @@ TEST(voting, info)
|
||||
{
|
||||
TestDB db;
|
||||
HardFork hf(db, 1, 0, 1, 1, 4, 50); // window size 4, default threshold 50%
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type;
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type;
|
||||
cryptonote::audit_block_info abi;
|
||||
cryptonote::yield_block_info ybi;
|
||||
|
||||
@@ -500,7 +501,7 @@ TEST(voting, info)
|
||||
ASSERT_EQ(expected_thresholds[h], threshold);
|
||||
ASSERT_EQ(4, voting);
|
||||
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi);
|
||||
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
|
||||
}
|
||||
}
|
||||
@@ -563,10 +564,10 @@ TEST(reorganize, changed)
|
||||
#define ADD(v, h, a) \
|
||||
do { \
|
||||
cryptonote::block b = mkblock(hf, h, v); \
|
||||
oracle::asset_type_counts num_rct_outs_by_asset_type; \
|
||||
oracle::asset_type_counts_v2 num_rct_outs_by_asset_type; \
|
||||
cryptonote::audit_block_info abi; \
|
||||
cryptonote::yield_block_info ybi; \
|
||||
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \
|
||||
db.add_block(b, 0, 0, 0, 0, 0, num_rct_outs_by_asset_type, crypto::hash(), 0, 0, 0, 0, cryptonote::FAKECHAIN, ybi, abi); \
|
||||
ASSERT_##a(hf.add(b, h)); \
|
||||
} while(0)
|
||||
#define ADD_TRUE(v, h) ADD(v, h, TRUE)
|
||||
|
||||
@@ -57,11 +57,12 @@ public:
|
||||
, const cryptonote::difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, oracle::asset_type_counts_v2& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, uint64_t audit_total
|
||||
, uint64_t token_total
|
||||
, const cryptonote::network_type nettype
|
||||
, cryptonote::yield_block_info& ybi
|
||||
, cryptonote::audit_block_info& abi
|
||||
|
||||
@@ -55,11 +55,12 @@ public:
|
||||
, const difficulty_type& cumulative_difficulty
|
||||
, const uint64_t& coins_generated
|
||||
, uint64_t num_rct_outs
|
||||
, oracle::asset_type_counts& cum_rct_by_asset_type
|
||||
, oracle::asset_type_counts_v2& cum_rct_by_asset_type
|
||||
, const crypto::hash& blk_hash
|
||||
, uint64_t slippage_total
|
||||
, uint64_t yield_total
|
||||
, uint64_t audit_total
|
||||
, uint64_t token_total
|
||||
, const network_type nettype
|
||||
, yield_block_info& ybi
|
||||
, audit_block_info& abi
|
||||
|
||||
@@ -415,6 +415,7 @@ cryptonote::transaction construct_carrot_pruned_transaction_fake_inputs(
|
||||
{{0, 0}, carrot::AddressDeriveType::PreCarrot},
|
||||
{},
|
||||
{},
|
||||
"SAL1",
|
||||
tx_proposal);
|
||||
|
||||
cryptonote::transaction tx;
|
||||
|
||||
@@ -109,6 +109,7 @@ TEST(wallet_tx_builder, input_selection_basic)
|
||||
top_block_index,
|
||||
/*allow_carrot_external_inputs_in_normal_transfers=*/true,
|
||||
/*allow_pre_carrot_inputs_in_normal_transfers=*/true,
|
||||
/*asset_type=*/"",
|
||||
selected_transfer_indices
|
||||
);
|
||||
|
||||
|
||||
@@ -1136,45 +1136,3 @@ class Wallet(object):
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(frozen)
|
||||
|
||||
class BackgroundSyncOptions(object):
|
||||
def __init__(self):
|
||||
self.off = 'off'
|
||||
self.reuse_password = 'reuse-wallet-password'
|
||||
self.custom_password = 'custom-background-password'
|
||||
background_sync_options = BackgroundSyncOptions()
|
||||
|
||||
def setup_background_sync(self, background_sync_type = background_sync_options.off, wallet_password = '', background_cache_password = ''):
|
||||
setup_background_sync = {
|
||||
'method': 'setup_background_sync',
|
||||
'jsonrpc': '2.0',
|
||||
'params' : {
|
||||
'background_sync_type': background_sync_type,
|
||||
'wallet_password': wallet_password,
|
||||
'background_cache_password': background_cache_password,
|
||||
},
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(setup_background_sync)
|
||||
|
||||
def start_background_sync(self):
|
||||
start_background_sync = {
|
||||
'method': 'start_background_sync',
|
||||
'jsonrpc': '2.0',
|
||||
'params' : {},
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(start_background_sync)
|
||||
|
||||
def stop_background_sync(self, wallet_password = '', seed = '', seed_offset = ''):
|
||||
stop_background_sync = {
|
||||
'method': 'stop_background_sync',
|
||||
'jsonrpc': '2.0',
|
||||
'params' : {
|
||||
'wallet_password': wallet_password,
|
||||
'seed': seed,
|
||||
'seed_offset': seed_offset,
|
||||
},
|
||||
'id': '0'
|
||||
}
|
||||
return self.rpc.send_json_rpc_request(stop_background_sync)
|
||||
|
||||
Reference in New Issue
Block a user