Monero
Loading...
Searching...
No Matches
check_tx_signature.h
Go to the documentation of this file.
1// Copyright (c) 2014-2022, The Monero Project
2//
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without modification, are
6// permitted provided that the following conditions are met:
7//
8// 1. Redistributions of source code must retain the above copyright notice, this list of
9// conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright notice, this list
12// of conditions and the following disclaimer in the documentation and/or other
13// materials provided with the distribution.
14//
15// 3. Neither the name of the copyright holder nor the names of its contributors may be
16// used to endorse or promote products derived from this software without specific
17// prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
31#pragma once
32
33#include <vector>
34
38#include "crypto/crypto.h"
39#include "ringct/rctSigs.h"
40
41#include "multi_tx_test_base.h"
42
43template<size_t a_ring_size, size_t a_outputs, bool a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean, int bp_version = 2>
44class test_check_tx_signature : private multi_tx_test_base<a_ring_size>
45{
46 static_assert(0 < a_ring_size, "ring_size must be greater than 0");
47
48public:
49 static const size_t loop_count = a_rct ? (a_ring_size <= 2 ? 50 : 10) : a_ring_size < 100 ? 100 : 10;
50 static const size_t ring_size = a_ring_size;
51 static const size_t outputs = a_outputs;
52 static const bool rct = a_rct;
53
55
56 bool init()
57 {
58 using namespace cryptonote;
59
60 if (!base_class::init())
61 return false;
62
63 m_alice.generate();
64
65 std::vector<tx_destination_entry> destinations;
66 destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
67 for (size_t n = 1; n < outputs; ++n)
68 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
69
70 crypto::secret_key tx_key;
71 std::vector<crypto::secret_key> additional_tx_keys;
72 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
73 subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
74 rct::RCTConfig rct_config{range_proof_type, bp_version};
75 if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, tx_key, additional_tx_keys, rct, rct_config))
76 return false;
77
79
80 return true;
81 }
82
83 bool test()
84 {
85 if (rct)
86 {
87 if (m_tx.rct_signatures.type == rct::RCTTypeFull)
88 return rct::verRct(m_tx.rct_signatures);
89 else
90 return rct::verRctSimple(m_tx.rct_signatures);
91 }
92 else
93 {
94 const cryptonote::txin_to_key& txin = boost::get<cryptonote::txin_to_key>(m_tx.vin[0]);
95 return crypto::check_ring_signature(m_tx_prefix_hash, txin.k_image, this->m_public_key_ptrs, ring_size, m_tx.signatures[0].data());
96 }
97 }
98
99private:
103};
104
105template<size_t a_ring_size, size_t a_outputs, size_t a_num_txes, size_t extra_outs = 0>
107{
108 static_assert(0 < a_ring_size, "ring_size must be greater than 0");
109
110public:
111 static const size_t loop_count = a_ring_size <= 2 ? 50 : 10;
112 static const size_t ring_size = a_ring_size;
113 static const size_t outputs = a_outputs;
114
116
117 bool init()
118 {
119 using namespace cryptonote;
120
121 if (!base_class::init())
122 return false;
123
124 m_alice.generate();
125
126 std::vector<tx_destination_entry> destinations;
127 destinations.push_back(tx_destination_entry(this->m_source_amount - outputs + 1, m_alice.get_keys().m_account_address, false));
128 for (size_t n = 1; n < outputs; ++n)
129 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
130
131 crypto::secret_key tx_key;
132 std::vector<crypto::secret_key> additional_tx_keys;
133 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
134 subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
135
136 m_txes.resize(a_num_txes + (extra_outs > 0 ? 1 : 0));
137 for (size_t n = 0; n < a_num_txes; ++n)
138 {
139 if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], tx_key, additional_tx_keys, true, {rct::RangeProofPaddedBulletproof, 2}))
140 return false;
141 }
142
143 if (extra_outs)
144 {
145 destinations.clear();
146 destinations.push_back(tx_destination_entry(this->m_source_amount - extra_outs + 1, m_alice.get_keys().m_account_address, false));
147 for (size_t n = 1; n < extra_outs; ++n)
148 destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
149
150 if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes.back(), tx_key, additional_tx_keys, true, {rct::RangeProofMultiOutputBulletproof, 2}))
151 return false;
152 }
153
154 return true;
155 }
156
157 bool test()
158 {
159 std::vector<const rct::rctSig*> rvv;
160 rvv.reserve(m_txes.size());
161 for (size_t n = 0; n < m_txes.size(); ++n)
162 {
163 const rct::rctSig &rv = m_txes[n].rct_signatures;
165 return false;
166 rvv.push_back(&rv);
167 }
168 return rct::verRctSemanticsSimple(rvv);
169 }
170
171private:
173 std::vector<cryptonote::transaction> m_txes;
174};
Definition account.h:74
Definition cryptonote_basic.h:205
Definition multi_tx_test_base.h:42
std::vector< cryptonote::tx_source_entry > m_sources
Definition multi_tx_test_base.h:88
bool init()
Definition multi_tx_test_base.h:49
cryptonote::account_base m_miners[ring_size]
Definition multi_tx_test_base.h:84
static const size_t real_source_idx
Definition multi_tx_test_base.h:47
uint64_t m_source_amount
Definition multi_tx_test_base.h:86
Definition check_tx_signature.h:107
static const size_t loop_count
Definition check_tx_signature.h:111
bool init()
Definition check_tx_signature.h:117
std::vector< cryptonote::transaction > m_txes
Definition check_tx_signature.h:173
multi_tx_test_base< a_ring_size > base_class
Definition check_tx_signature.h:115
static const size_t ring_size
Definition check_tx_signature.h:112
cryptonote::account_base m_alice
Definition check_tx_signature.h:172
bool test()
Definition check_tx_signature.h:157
static const size_t outputs
Definition check_tx_signature.h:113
Definition check_tx_signature.h:45
static const size_t loop_count
Definition check_tx_signature.h:49
bool test()
Definition check_tx_signature.h:83
static const size_t ring_size
Definition check_tx_signature.h:50
crypto::hash m_tx_prefix_hash
Definition check_tx_signature.h:102
cryptonote::transaction m_tx
Definition check_tx_signature.h:101
cryptonote::account_base m_alice
Definition check_tx_signature.h:100
static const size_t outputs
Definition check_tx_signature.h:51
bool init()
Definition check_tx_signature.h:56
multi_tx_test_base< a_ring_size > base_class
Definition check_tx_signature.h:54
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:72
POD_CLASS hash
Definition hash.h:49
bool check_ring_signature(const hash &prefix_hash, const key_image &image, const public_key *const *pubs, std::size_t pubs_count, const signature *sig)
Definition crypto.h:288
Holds cryptonote related classes and helpers.
Definition blockchain_db.cpp:45
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, const std::vector< uint8_t > &extra, transaction &tx, crypto::secret_key &tx_key, std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, bool use_view_tags)
Definition cryptonote_tx_utils.cpp:609
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h, hw::device &hwdev)
Definition cryptonote_format_utils.cpp:131
Definition bulletproofs.cc:64
static bool verRctSimple(const rctSig &rv)
Definition rctSigs.h:135
bool verRct(const rctSig &rv, bool semantics)
Definition rctSigs.cpp:1318
bool verRctSemanticsSimple(const std::vector< const rctSig * > &rvv)
Definition rctSigs.cpp:1381
bool verRctNonSemanticsSimple(const rctSig &rv)
Definition rctSigs.cpp:1521
@ RCTTypeFull
Definition rctTypes.h:300
@ RangeProofMultiOutputBulletproof
Definition rctTypes.h:307
@ RangeProofPaddedBulletproof
Definition rctTypes.h:307
Definition cryptonote_basic.h:512
Definition cryptonote_tx_utils.h:75
Definition cryptonote_basic.h:139
crypto::key_image k_image
Definition cryptonote_basic.h:142
Definition rctTypes.h:308
Definition rctTypes.h:613