Electroneum
gen_rct_tx_validation_base Struct Reference

#include <rct.h>

Inheritance diagram for gen_rct_tx_validation_base:
Collaboration diagram for gen_rct_tx_validation_base:

Public Member Functions

 gen_rct_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_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, const int *out_idx, int mixin, uint64_t amount_paid, bool valid, const std::function< void(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations)> &pre_tx, const std::function< void(cryptonote::transaction &tx)> &post_tx) 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 35 of file rct.h.

Constructor & Destructor Documentation

◆ gen_rct_tx_validation_base()

gen_rct_tx_validation_base::gen_rct_tx_validation_base ( )
inline

Definition at line 37 of file rct.h.

38  : m_invalid_tx_index(0)
39  , m_invalid_block_index(0)
40  {
43  }
#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 > &)
Definition: rct.h:61
bool mark_invalid_tx(cryptonote::core &, size_t ev_index, const std::vector< test_event_entry > &)
Definition: rct.h:67
Here is the call graph for this function:

Member Function Documentation

◆ check_block_verification_context()

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

Definition at line 53 of file rct.h.

54  {
55  if (m_invalid_block_index == event_idx)
56  return bvc.m_verification_failed;
57  else
58  return !bvc.m_verification_failed;
59  }

◆ check_tx_verification_context()

bool gen_rct_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 45 of file rct.h.

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

◆ generate_with()

bool gen_rct_tx_validation_base::generate_with ( std::vector< test_event_entry > &  events,
const int *  out_idx,
int  mixin,
uint64_t  amount_paid,
bool  valid,
const std::function< void(std::vector< cryptonote::tx_source_entry > &sources, std::vector< cryptonote::tx_destination_entry > &destinations)> &  pre_tx,
const std::function< void(cryptonote::transaction &tx)> &  post_tx 
) const

Definition at line 44 of file rct.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 4 miner accounts, and have them mine the next 4 blocks
55  cryptonote::account_base miner_accounts[4];
56  const cryptonote::block *prev_block = &blk_0;
58  for (size_t n = 0; n < 4; ++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[3];
74  for (size_t i = 0; i < CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW; ++i)
75  {
77  CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_account,
79  2, 2, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
80  crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 0, 2),
81  false, "Failed to generate block");
82  events.push_back(blk);
83  blk_last = blk;
84  }
85  blk_r = blk_last;
86  }
87 
88  // create 4 txes from these miners in another block, to generate some rct outputs
89  transaction rct_txes[4];
90  rct::key rct_tx_masks[16];
91  cryptonote::block blk_txes[4];
92  for (size_t n = 0; n < 4; ++n)
93  {
94  std::vector<crypto::hash> starting_rct_tx_hashes;
95  std::vector<tx_source_entry> sources;
96 
97  sources.resize(1);
98  tx_source_entry& src = sources.back();
99 
100  const size_t index_in_tx = 5;
101  src.amount = 30000000000000;
102  for (int m = 0; m < 4; ++m) {
103  src.push_output(m, boost::get<txout_to_key>(blocks[m].miner_tx.vout[index_in_tx].target).key, src.amount);
104  }
106  src.real_output = n;
107  src.real_output_in_tx_index = index_in_tx;
108  src.mask = rct::identity();
109  src.rct = false;
110 
111  //fill outputs entry
113  td.addr = miner_accounts[n].get_keys().m_account_address;
114  td.amount = 7390000000000;
115  std::vector<tx_destination_entry> destinations;
116  destinations.push_back(td);
117  destinations.push_back(td);
118  destinations.push_back(td);
119  destinations.push_back(td); // 30 -> 7.39 * 4
120 
121  crypto::secret_key tx_key;
122  std::vector<crypto::secret_key> additional_tx_keys;
123  std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
124  subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
125  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[n], 0, tx_key, additional_tx_keys, true);
126  CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
127  events.push_back(rct_txes[n]);
128  starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes[n]));
129 
130  for (size_t o = 0; o < 4; ++o)
131  {
132  crypto::key_derivation derivation;
133  bool r = crypto::generate_key_derivation(destinations[o].addr.m_view_public_key, tx_key, derivation);
134  CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
135  crypto::secret_key amount_key;
136  crypto::derivation_to_scalar(derivation, o, amount_key);
137  const uint8_t type = rct_txes[n].rct_signatures.type;
138  if (type == rct::RCTTypeSimple || type == rct::RCTTypeBulletproof || type == rct::RCTTypeBulletproof2)
139  rct::decodeRctSimple(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default"));
140  else
141  rct::decodeRct(rct_txes[n].rct_signatures, rct::sk2rct(amount_key), o, rct_tx_masks[o+n*4], hw::get_device("default"));
142  }
143 
144  CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk_txes[n], blk_last, miner_account,
146  4, 4, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
147  crypto::hash(), 0, transaction(), starting_rct_tx_hashes, 0, 6, 4),
148  false, "Failed to generate block");
149  events.push_back(blk_txes[n]);
150  blk_last = blk_txes[n];
151  }
152 
153  // rewind
154  {
155  for (size_t i = 0; i < CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW; ++i)
156  {
157  cryptonote::block blk;
158  CHECK_AND_ASSERT_MES(generator.construct_block_manually(blk, blk_last, miner_account,
160  4, 4, blk_last.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN * 2, // v2 has blocks twice as long
161  crypto::hash(), 0, transaction(), std::vector<crypto::hash>(), 0, 6, 4),
162  false, "Failed to generate block");
163  events.push_back(blk);
164  blk_last = blk;
165  }
166  blk_r = blk_last;
167  }
168 
169  // create a tx from the requested ouputs
170  std::vector<tx_source_entry> sources;
171  size_t global_rct_idx = 6; // skip first coinbase (6 outputs)
172  size_t rct_idx = 0;
173  size_t pre_rct_idx = 0;
174  for (size_t out_idx_idx = 0; out_idx[out_idx_idx] >= 0; ++out_idx_idx) {
175  sources.resize(sources.size()+1);
176  tx_source_entry& src = sources.back();
177 
178  src.real_output = 0;
179  if (out_idx[out_idx_idx]) {
180  // rct
181  src.amount = 7390000000000;
182  src.real_out_tx_key = get_tx_pub_key_from_extra(rct_txes[rct_idx/4]);
183  src.real_output_in_tx_index = rct_idx&3;
184  src.mask = rct_tx_masks[rct_idx];
185  src.rct = true;
186  for (int m = 0; m <= mixin; ++m) {
187  rct::ctkey ctkey;
188  ctkey.dest = rct::pk2rct(boost::get<txout_to_key>(rct_txes[rct_idx/4].vout[rct_idx&3].target).key);
189  ctkey.mask = rct_txes[rct_idx/4].rct_signatures.outPk[rct_idx&3].mask;
190  src.outputs.push_back(std::make_pair(global_rct_idx, ctkey));
191  ++rct_idx;
192  ++global_rct_idx;
193  if (global_rct_idx % 10 == 0)
194  global_rct_idx += 6; // skip the coinbase
195  }
196  }
197  else
198  {
199  // pre rct
200  src.amount = 5000000000000;
201  src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(blocks[pre_rct_idx].miner_tx);
202  src.real_output_in_tx_index = 4;
203  src.mask = rct::identity();
204  src.rct = false;
205  for (int m = 0; m <= mixin; ++m) {
206  src.push_output(m, boost::get<txout_to_key>(blocks[pre_rct_idx].miner_tx.vout[4].target).key, src.amount);
207  ++pre_rct_idx;
208  }
209  }
210  }
211 
212  //fill outputs entry
214  td.addr = miner_account.get_keys().m_account_address;
215  td.amount = amount_paid;
216  std::vector<tx_destination_entry> destinations;
217  destinations.push_back(td);
218 
219  if (pre_tx)
220  pre_tx(sources, destinations);
221 
222  transaction tx;
223  crypto::secret_key tx_key;
224  std::vector<crypto::secret_key> additional_tx_keys;
225  std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
226  subaddresses[miner_accounts[0].get_keys().m_account_address.m_spend_public_key] = {0,0};
227  bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_keys, true);
228  CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
229 
230  if (post_tx)
231  post_tx(tx);
232 
233  if (!valid)
234  DO_CALLBACK(events, "mark_invalid_tx");
235  events.push_back(tx);
236  LOG_PRINT_L0("Test tx: " << obj_to_json_str(tx));
237 
238  return true;
239 }
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res)
Definition: crypto.h:279
crypto::public_key real_out_tx_key
POD_CLASS key_derivation
Definition: crypto.h:98
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
const char * key
Definition: hmac_keccak.cpp:39
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
bool rct
unsigned char uint8_t
Definition: stdint.h:124
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition: account.cpp:158
uint64_t amount
key dest
Definition: rctTypes.h:97
uint8_t type
Definition: rctTypes.h:241
etn_amount decodeRct(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition: rctSigs.cpp:1150
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition: crypto.h:272
size_t real_output
const account_keys & get_keys() const
Definition: account.cpp:264
device & get_device(const std::string &device_descriptor)
Definition: device.cpp:95
#define MAKE_GENESIS_BLOCK(VEC_EVENTS, BLK_NAME, MINER_ACC, TS)
Definition: chaingen.h:833
std::string obj_to_json_str(T &obj)
unsigned __int64 uint64_t
Definition: stdint.h:136
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
uint64_t amount
void push_output(uint64_t idx, const crypto::public_key &k, uint64_t amount)
account_public_address addr
account_public_address m_account_address
Definition: account.h:43
key identity()
Definition: rctOps.h:73
size_t real_output_in_tx_index
ctkeyV outPk
Definition: rctTypes.h:247
crypto::hash get_transaction_hash(const transaction &t)
key mask
Definition: rctTypes.h:98
std::vector< output_entry > outputs
POD_CLASS hash
Definition: hash.h:50
#define DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN
#define GENERATE_ACCOUNT(account)
Definition: chaingen.h:801
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)
#define DO_CALLBACK(VEC_EVENTS, CB_NAME)
Definition: chaingen.h:820
etn_amount decodeRctSimple(const rctSig &rv, const key &sk, unsigned int i, key &mask, hw::device &hwdev)
Definition: rctSigs.cpp:1180
rct::key mask
Here is the call graph for this function:

◆ mark_invalid_block()

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

Definition at line 61 of file rct.h.

62  {
63  m_invalid_block_index = ev_index + 1;
64  return true;
65  }
Here is the caller graph for this function:

◆ mark_invalid_tx()

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

Definition at line 67 of file rct.h.

68  {
69  m_invalid_tx_index = ev_index + 1;
70  return true;
71  }
Here is the caller graph for this function:

The documentation for this struct was generated from the following files: