Electroneum
Loading...
Searching...
No Matches
gen_bp_tx_validation_base Struct Reference

#include <bulletproofs.h>

Inheritance diagram for gen_bp_tx_validation_base:
Collaboration diagram for gen_bp_tx_validation_base:

Public Member Functions

 gen_bp_tx_validation_base ()
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool tx_added, size_t event_idx, const cryptonote::transaction &)
bool check_tx_verification_context_array (const std::vector< cryptonote::tx_verification_context > &tvcs, size_t tx_added, size_t event_idx, const std::vector< cryptonote::transaction > &)
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool mark_invalid_block (cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
bool mark_invalid_tx (cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
bool generate_with (std::vector< test_event_entry > &events, size_t mixin, size_t n_txes, const uint64_t *amounts_paid, bool valid, const rct::RCTConfig *rct_config, const std::function< bool(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations, size_t)> &pre_tx, const std::function< bool(cryptonote::transaction &tx, size_t)> &post_tx) const
bool check_bp (const cryptonote::transaction &tx, size_t tx_idx, const size_t *sizes, const char *context) const
Public Member Functions inherited from test_chain_unit_base
void register_callback (const std::string &cb_name, verify_callback cb)
bool verify (const std::string &cb_name, cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &)
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool, size_t, const cryptonote::transaction &)
bool check_tx_verification_context_array (const std::vector< cryptonote::tx_verification_context > &tvcs, size_t, size_t, const std::vector< cryptonote::transaction > &)

Additional Inherited Members

Public Types inherited from test_chain_unit_base
typedef boost::function< bool(cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)> verify_callback
typedef std::map< std::string, verify_callbackcallbacks_map

Detailed Description

Definition at line 34 of file bulletproofs.h.

Constructor & Destructor Documentation

◆ gen_bp_tx_validation_base()

gen_bp_tx_validation_base::gen_bp_tx_validation_base ( )
inline

Definition at line 36 of file bulletproofs.h.

37 : m_invalid_tx_index(0)
38 , m_invalid_block_index(0)
39 {
42 }
#define REGISTER_CALLBACK_METHOD(CLASS, METHOD)
Definition chaingen.h:830
bool mark_invalid_block(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
bool mark_invalid_tx(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ check_block_verification_context()

bool gen_bp_tx_validation_base::check_block_verification_context ( const cryptonote::block_verification_context & bvc,
size_t event_idx,
const cryptonote::block &  )
inline

Definition at line 64 of file bulletproofs.h.

65 {
66 if (m_invalid_block_index == event_idx)
67 return bvc.m_verification_failed;
68 else
69 return !bvc.m_verification_failed;
70 }

◆ check_bp()

bool gen_bp_tx_validation_base::check_bp ( const cryptonote::transaction & tx,
size_t tx_idx,
const size_t * sizes,
const char * context ) const

Definition at line 188 of file bulletproofs.cpp.

189{
193 size_t n_sizes = 0, n_amounts = 0;
194 for (size_t n = 0; n < tx_idx; ++n)
195 {
196 while (sizes[0] != (size_t)-1)
197 ++sizes;
198 ++sizes;
199 }
200 while (sizes[n_sizes] != (size_t)-1)
201 n_amounts += sizes[n_sizes++];
204 for (size_t n = 0; n < n_sizes; ++n)
206 return true;
207}
#define DEFINE_TESTS_ERROR_CONTEXT(text)
Definition chaingen.h:1056
#define CHECK_TEST_CONDITION(cond)
Definition chaingen.h:1057
bool is_rct_bulletproof(int type)
Definition rctTypes.cpp:227
size_t n_bulletproof_max_amounts(const Bulletproof &proof)
Definition rctTypes.cpp:278
rctSigPrunable p
Definition rctTypes.h:437
std::vector< Bulletproof > bulletproofs
Definition rctTypes.h:320
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_tx_verification_context()

bool gen_bp_tx_validation_base::check_tx_verification_context ( const cryptonote::tx_verification_context & tvc,
bool tx_added,
size_t event_idx,
const cryptonote::transaction &  )
inline

Definition at line 44 of file bulletproofs.h.

45 {
46 if (m_invalid_tx_index == event_idx)
47 return tvc.m_verification_failed;
48 else
49 return !tvc.m_verification_failed && tx_added;
50 }

◆ check_tx_verification_context_array()

bool gen_bp_tx_validation_base::check_tx_verification_context_array ( const std::vector< cryptonote::tx_verification_context > & tvcs,
size_t tx_added,
size_t event_idx,
const std::vector< cryptonote::transaction > &  )
inline

Definition at line 52 of file bulletproofs.h.

53 {
54 size_t failed = 0;
55 for (const cryptonote::tx_verification_context &tvc: tvcs)
56 if (tvc.m_verification_failed)
57 ++failed;
58 if (m_invalid_tx_index == event_idx)
59 return failed > 0;
60 else
61 return failed == 0 && tx_added == tvcs.size();
62 }

◆ generate_with()

bool gen_bp_tx_validation_base::generate_with ( std::vector< test_event_entry > & events,
size_t mixin,
size_t n_txes,
const uint64_t * amounts_paid,
bool valid,
const rct::RCTConfig * rct_config,
const std::function< bool(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations, size_t)> & pre_tx,
const std::function< bool(cryptonote::transaction &tx, size_t)> & post_tx ) const

Definition at line 44 of file bulletproofs.cpp.

48{
49 uint64_t ts_start = 1338224400;
50
51 GENERATE_ACCOUNT(miner_account);
52 MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
53
54 // create 12 miner accounts, and have them mine the next 12 blocks
55 cryptonote::account_base miner_accounts[12];
56 const cryptonote::block *prev_block = &blk_0;
57 cryptonote::block blocks[12 + CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW];
58 for (size_t n = 0; n < 12; ++n) {
59 miner_accounts[n].generate();
60 CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[n], *prev_block, miner_accounts[n],
62 2, 2, prev_block->timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
63 crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
64 false, "Failed to generate block");
65 events.push_back(blocks[n]);
66 prev_block = blocks + n;
67 LOG_PRINT_L0("Initial miner tx " << n << ": " << obj_to_json_str(blocks[n].miner_tx));
68 }
69
70 // rewind
71 cryptonote::block blk_r, blk_last;
72 {
73 blk_last = blocks[11];
74 for (size_t i = 0; i < CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW; ++i)
75 {
76 CHECK_AND_ASSERT_MES(generator.construct_block_manually(blocks[12+i], blk_last, miner_account,
78 2, 2, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
79 crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
80 false, "Failed to generate block");
81 events.push_back(blocks[12+i]);
82 blk_last = blocks[12+i];
83 }
84 blk_r = blk_last;
85 }
86
87 // create 4 txes from these miners in another block, to generate some rct outputs
88 std::vector<transaction> rct_txes;
89 cryptonote::block blk_txes;
90 std::vector<crypto::hash> starting_rct_tx_hashes;
91 static const uint64_t input_amounts_available[] = {5000000000000, 30000000000000, 100000000000, 80000000000};
92 for (size_t n = 0; n < n_txes; ++n)
93 {
94 std::vector<tx_source_entry> sources;
95
96 sources.resize(1);
97 tx_source_entry& src = sources.back();
98
99 const uint64_t needed_amount = input_amounts_available[n];
100 src.amount = input_amounts_available[n];
101 size_t real_index_in_tx = 0;
102 for (size_t m = 0; m <= mixin; ++m) {
103 size_t index_in_tx = 0;
104 for (size_t i = 0; i < blocks[m].miner_tx.vout.size(); ++i)
105 if (blocks[m].miner_tx.vout[i].amount == needed_amount)
106 index_in_tx = i;
107 CHECK_AND_ASSERT_MES(blocks[m].miner_tx.vout[index_in_tx].amount == needed_amount, false, "Expected amount not found");
108 src.push_output(m, boost::get<txout_to_key>(blocks[m].miner_tx.vout[index_in_tx].target).key, src.amount);
109 if (m == n)
110 real_index_in_tx = index_in_tx;
111 }
113 src.real_output = n;
114 src.real_output_in_tx_index = real_index_in_tx;
115 src.mask = rct::identity();
116 src.rct = false;
117
118 //fill outputs entry
119 tx_destination_entry td;
120 td.addr = miner_accounts[n].get_keys().m_account_address;
121 std::vector<tx_destination_entry> destinations;
122 for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o)
123 {
124 td.amount = amounts_paid[o];
125 destinations.push_back(td);
126 }
127
128 if (pre_tx && !pre_tx(sources, destinations, n))
129 {
130 MDEBUG("pre_tx returned failure");
131 return false;
132 }
133
134 crypto::secret_key tx_key;
135 std::vector<crypto::secret_key> additional_tx_keys;
136 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
137 subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
138 rct_txes.resize(rct_txes.size() + 1);
139 bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, rct_config[n]);
140 CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
141
142 if (post_tx && !post_tx(rct_txes.back(), n))
143 {
144 MDEBUG("post_tx returned failure");
145 return false;
146 }
147
148 //events.push_back(rct_txes.back());
149 starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes.back()));
150 LOG_PRINT_L0("Test tx: " << obj_to_json_str(rct_txes.back()));
151
152 for (int o = 0; amounts_paid[o] != (uint64_t)-1; ++o)
153 {
154 crypto::key_derivation derivation;
155 bool r = crypto::generate_key_derivation(destinations[o].addr.m_view_public_key, tx_key, derivation);
156 CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
157 crypto::secret_key amount_key;
158 crypto::derivation_to_scalar(derivation, o, amount_key);
159 rct::key rct_tx_mask;
160 const uint8_t type = rct_txes.back().rct_signatures.type;
162 rct::decodeRctSimple(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
163 else
164 rct::decodeRct(rct_txes.back().rct_signatures, rct::sk2rct(amount_key), o, rct_tx_mask, hw::get_device("default"));
165 }
166
167 while (amounts_paid[0] != (size_t)-1)
168 ++amounts_paid;
169 ++amounts_paid;
170 }
171 if (!valid)
172 DO_CALLBACK(events, "mark_invalid_tx");
173 events.push_back(rct_txes);
174
175 CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes, blk_last, miner_account,
177 10, 10, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
178 crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, 6, 10),
179 false, "Failed to generate block");
180 if (!valid)
181 DO_CALLBACK(events, "mark_invalid_block");
182 events.push_back(blk_txes);
183 blk_last = blk_txes;
184
185 return true;
186}
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
Definition chaingen.h:833
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition chaingen.h:820
#define GENERATE_ACCOUNT(account)
Definition chaingen.h:801
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition account.cpp:158
const account_keys & get_keys() const
Definition account.cpp:264
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
#define MDEBUG(x)
Definition misc_log_ex.h:76
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:82
POD_CLASS key_derivation
Definition crypto.h:101
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition crypto.h:272
POD_CLASS hash
Definition hash.h:50
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition crypto.h:279
std::string obj_to_json_str(T &obj)
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)
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
crypto::hash get_transaction_hash(const transaction &t)
device & get_device(const std::string &device_descriptor)
Definition device.cpp:95
etn_amount decodeRctSimple(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition rctSigs.cpp:1180
etn_amount decodeRct(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition rctSigs.cpp:1150
@ RCTTypeSimple
Definition rctTypes.h:231
@ RCTTypeBulletproof2
Definition rctTypes.h:233
@ RCTTypeBulletproof
Definition rctTypes.h:232
key identity()
Definition rctOps.h:73
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
account_public_address m_account_address
Definition account.h:43
uint64_t amount
account_public_address addr
crypto::public_key real_out_tx_key
uint64_t amount
bool rct
size_t real_output
rct::key mask
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
size_t real_output_in_tx_index
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mark_invalid_block()

bool gen_bp_tx_validation_base::mark_invalid_block ( cryptonote::core & ,
size_t ev_index,
const std::vector< test_event_entry > &  )
inline

Definition at line 72 of file bulletproofs.h.

73 {
74 m_invalid_block_index = ev_index + 1;
75 return true;
76 }
Here is the caller graph for this function:

◆ mark_invalid_tx()

bool gen_bp_tx_validation_base::mark_invalid_tx ( cryptonote::core & ,
size_t ev_index,
const std::vector< test_event_entry > &  )
inline

Definition at line 78 of file bulletproofs.h.

79 {
80 m_invalid_tx_index = ev_index + 1;
81 return true;
82 }
Here is the caller graph for this function:

The documentation for this struct was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/bulletproofs.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/bulletproofs.cpp