Electroneum
Toggle main menu visibility
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
36
#include "
cryptonote_basic/account.h
"
37
#include "
cryptonote_basic/cryptonote_basic.h
"
38
#include "
cryptonote_core/cryptonote_tx_utils.h
"
39
#include "
crypto/crypto.h
"
40
#include "
ringct/rctSigs.h
"
41
42
#include "
multi_tx_test_base.h
"
43
44
template
<
size_t
a_ring_size,
size_t
a_outputs,
bool
a_rct, rct::RangeProofType range_proof_type = rct::RangeProofBorromean,
int
bp_version = 2>
45
class
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
49
public
:
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
55
typedef
multi_tx_test_base<a_ring_size>
base_class
;
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
100
private
:
101
cryptonote::account_base
m_alice;
102
cryptonote::transaction
m_tx;
103
crypto::hash
m_tx_prefix_hash;
104
};
105
106
template
<
size_t
a_ring_size,
size_t
a_outputs,
size_t
a_num_txes,
size_t
extra_outs = 0>
107
class
test_check_tx_signature_aggregated_bulletproofs
:
private
multi_tx_test_base
<a_ring_size>
108
{
109
static_assert
(0 < a_ring_size,
"ring_size must be greater than 0"
);
110
111
public
:
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
116
typedef
multi_tx_test_base<a_ring_size>
base_class
;
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;
165
if
(!
rct::verRctNonSemanticsSimple
(rv))
166
return
false
;
167
rvv.push_back(&rv);
168
}
169
return
rct::verRctSemanticsSimple
(rvv);
170
}
171
172
private
:
173
cryptonote::account_base
m_alice;
174
std::vector<cryptonote::transaction> m_txes;
175
};
account.h
cryptonote::account_base
Definition
account.h:77
cryptonote::transaction
Definition
cryptonote_basic.h:298
multi_tx_test_base
Definition
multi_tx_test_base.h:43
multi_tx_test_base::m_sources
std::vector< cryptonote::tx_source_entry > m_sources
Definition
multi_tx_test_base.h:89
multi_tx_test_base::init
bool init()
Definition
multi_tx_test_base.h:50
multi_tx_test_base::m_miners
cryptonote::account_base m_miners[ring_size]
Definition
multi_tx_test_base.h:85
multi_tx_test_base::real_source_idx
static const size_t real_source_idx
Definition
multi_tx_test_base.h:48
multi_tx_test_base::m_source_amount
uint64_t m_source_amount
Definition
multi_tx_test_base.h:87
test_check_tx_signature_aggregated_bulletproofs
Definition
check_tx_signature.h:108
test_check_tx_signature_aggregated_bulletproofs::loop_count
static const size_t loop_count
Definition
check_tx_signature.h:112
test_check_tx_signature_aggregated_bulletproofs::init
bool init()
Definition
check_tx_signature.h:118
test_check_tx_signature_aggregated_bulletproofs::base_class
multi_tx_test_base< a_ring_size > base_class
Definition
check_tx_signature.h:116
test_check_tx_signature_aggregated_bulletproofs::ring_size
static const size_t ring_size
Definition
check_tx_signature.h:113
test_check_tx_signature_aggregated_bulletproofs::test
bool test()
Definition
check_tx_signature.h:158
test_check_tx_signature_aggregated_bulletproofs::outputs
static const size_t outputs
Definition
check_tx_signature.h:114
test_check_tx_signature
Definition
check_tx_signature.h:46
test_check_tx_signature::loop_count
static const size_t loop_count
Definition
check_tx_signature.h:50
test_check_tx_signature::test
bool test()
Definition
check_tx_signature.h:84
test_check_tx_signature::ring_size
static const size_t ring_size
Definition
check_tx_signature.h:51
test_check_tx_signature::outputs
static const size_t outputs
Definition
check_tx_signature.h:52
test_check_tx_signature::init
bool init()
Definition
check_tx_signature.h:57
test_check_tx_signature::base_class
multi_tx_test_base< a_ring_size > base_class
Definition
check_tx_signature.h:55
crypto.h
cryptonote_basic.h
cryptonote_tx_utils.h
multi_tx_test_base.h
crypto::secret_key
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition
crypto.h:82
crypto::hash
POD_CLASS hash
Definition
hash.h:50
crypto::check_ring_signature
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
cryptonote
Holds cryptonote related classes and helpers.
Definition
ban.cpp:40
cryptonote::construct_tx_and_get_tx_key
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)
Definition
cryptonote_tx_utils.cpp:666
cryptonote::get_transaction_prefix_hash
void get_transaction_prefix_hash(const transaction_prefix &tx, crypto::hash &h)
Definition
cryptonote_format_utils.cpp:112
rct
Definition
bulletproofs.h:39
rct::verRct
bool verRct(const rctSig &rv, bool semantics)
Definition
rctSigs.cpp:913
rct::RCTTypeFull
@ RCTTypeFull
Definition
rctTypes.h:230
rct::verRctSemanticsSimple
bool verRctSemanticsSimple(const std::vector< const rctSig * > &rvv)
Definition
rctSigs.cpp:975
rct::verRctNonSemanticsSimple
bool verRctNonSemanticsSimple(const rctSig &rv)
Definition
rctSigs.cpp:1085
rct::RangeProofMultiOutputBulletproof
@ RangeProofMultiOutputBulletproof
Definition
rctTypes.h:235
rct::RangeProofPaddedBulletproof
@ RangeProofPaddedBulletproof
Definition
rctTypes.h:235
rctSigs.h
cryptonote::account_public_address
Definition
cryptonote_basic.h:75
cryptonote::tx_destination_entry
Definition
cryptonote_tx_utils.h:84
cryptonote::txin_to_key
Definition
cryptonote_basic.h:198
cryptonote::txin_to_key::k_image
crypto::key_image k_image
Definition
cryptonote_basic.h:201
rct::RCTConfig
Definition
rctTypes.h:236
rct::rctSig
Definition
rctTypes.h:436
tests
performance_tests
check_tx_signature.h
Generated on
for Electroneum by
1.17.0