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