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

#include <integer_overflow.h>

Inheritance diagram for gen_uint_overflow_2:
Collaboration diagram for gen_uint_overflow_2:

Public Member Functions

bool generate (std::vector< test_event_entry > &events) const
Public Member Functions inherited from gen_uint_overflow_base
 gen_uint_overflow_base ()
bool check_tx_verification_context (const cryptonote::tx_verification_context &tvc, bool tx_added, size_t event_idx, const cryptonote::transaction &tx)
bool check_block_verification_context (const cryptonote::block_verification_context &bvc, size_t event_idx, const cryptonote::block &block)
bool mark_last_valid_block (cryptonote::core &c, size_t ev_index, const std::vector< test_event_entry > &events)
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 53 of file integer_overflow.h.

Member Function Documentation

◆ generate()

bool gen_uint_overflow_2::generate ( std::vector< test_event_entry > & events) const

Definition at line 144 of file integer_overflow.cpp.

145{
146 uint64_t ts_start = 1338224400;
147
148 GENERATE_ACCOUNT(miner_account);
149 MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
150 MAKE_ACCOUNT(events, bob_account);
151 MAKE_ACCOUNT(events, alice_account);
152 REWIND_BLOCKS(events, blk_0r, blk_0, miner_account);
153 DO_CALLBACK(events, "mark_last_valid_block");
154
155 // Problem 1. Regular tx outputs overflow
156 std::vector<cryptonote::tx_source_entry> sources;
157 for (size_t i = 0; i < blk_0.miner_tx.vout.size(); ++i)
158 {
159 if (TESTS_DEFAULT_FEE < blk_0.miner_tx.vout[i].amount)
160 {
161 append_tx_source_entry(sources, blk_0.miner_tx, i);
162 break;
163 }
164 }
165 if (sources.empty())
166 {
167 return false;
168 }
169
170 std::vector<cryptonote::tx_destination_entry> destinations;
171 const account_public_address& bob_addr = bob_account.get_keys().m_account_address;
172 destinations.push_back(tx_destination_entry(ETN_SUPPLY, bob_addr, false));
173 destinations.push_back(tx_destination_entry(ETN_SUPPLY - 1, bob_addr, false));
174 // sources.front().amount = destinations[0].amount + destinations[2].amount + destinations[3].amount + TESTS_DEFAULT_FEE
175 destinations.push_back(tx_destination_entry(sources.front().amount - ETN_SUPPLY - ETN_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr, false));
176
177 cryptonote::transaction tx_1;
178 if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1, 0))
179 return false;
180 events.push_back(tx_1);
181
182 MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_account, tx_1);
183 REWIND_BLOCKS(events, blk_1r, blk_1, miner_account);
184
185 // Problem 2. Regular tx inputs overflow
186 sources.clear();
187 for (size_t i = 0; i < tx_1.vout.size(); ++i)
188 {
189 auto& tx_1_out = tx_1.vout[i];
190 if (tx_1_out.amount < ETN_SUPPLY - 1)
191 continue;
192
193 append_tx_source_entry(sources, tx_1, i);
194 }
195
196 destinations.clear();
197 cryptonote::tx_destination_entry de;
198 de.addr = alice_account.get_keys().m_account_address;
200 destinations.push_back(de);
201 destinations.push_back(de);
202
203 cryptonote::transaction tx_2;
204 if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_2, 0))
205 return false;
206 events.push_back(tx_2);
207
208 MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner_account, tx_2);
209
210 return true;
211}
#define REWIND_BLOCKS(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC)
Definition chaingen.h:890
#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 TESTS_DEFAULT_FEE
Definition chaingen.h:1061
#define MAKE_ACCOUNT(VEC_EVENTS, account)
Definition chaingen.h:815
#define GENERATE_ACCOUNT(account)
Definition chaingen.h:801
#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1)
Definition chaingen.h:849
#define ETN_SUPPLY
bool construct_tx(const account_keys &sender_account_keys, std::vector< tx_source_entry > &sources, const 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)
unsigned __int64 uint64_t
Definition stdint.h:136
uint64_t amount
account_public_address addr
Here is the call 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/integer_overflow.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/tests/core_tests/integer_overflow.cpp