mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #6403
5de2295
Correct key image check in tx_pool (vtnerd)
This commit is contained in:
commit
228af683a7
4 changed files with 71 additions and 16 deletions
|
@ -161,6 +161,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(txpool_spend_key_all);
|
||||
GENERATE_AND_PLAY(txpool_double_spend_norelay);
|
||||
GENERATE_AND_PLAY(txpool_double_spend_local);
|
||||
GENERATE_AND_PLAY(txpool_double_spend_keyimage);
|
||||
|
||||
// Double spend
|
||||
GENERATE_AND_PLAY(gen_double_spend_in_tx<false>);
|
||||
|
|
|
@ -125,10 +125,12 @@ txpool_double_spend_base::txpool_double_spend_base()
|
|||
, m_no_relay_hashes()
|
||||
, m_all_hashes()
|
||||
, m_no_new_index(0)
|
||||
, m_failed_index(0)
|
||||
, m_new_timestamp_index(0)
|
||||
, m_last_tx(crypto::hash{})
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(txpool_double_spend_base, mark_no_new);
|
||||
REGISTER_CALLBACK_METHOD(txpool_double_spend_base, mark_failed);
|
||||
REGISTER_CALLBACK_METHOD(txpool_double_spend_base, mark_timestamp_change);
|
||||
REGISTER_CALLBACK_METHOD(txpool_double_spend_base, timestamp_change_pause);
|
||||
REGISTER_CALLBACK_METHOD(txpool_double_spend_base, check_unchanged);
|
||||
|
@ -143,6 +145,12 @@ bool txpool_double_spend_base::mark_no_new(cryptonote::core& /*c*/, size_t ev_in
|
|||
return true;
|
||||
}
|
||||
|
||||
bool txpool_double_spend_base::mark_failed(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
|
||||
{
|
||||
m_failed_index = ev_index + 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool txpool_double_spend_base::mark_timestamp_change(cryptonote::core& /*c*/, size_t ev_index, const std::vector<test_event_entry>& /*events*/)
|
||||
{
|
||||
m_new_timestamp_index = ev_index + 1;
|
||||
|
@ -483,6 +491,8 @@ bool txpool_double_spend_base::check_tx_verification_context(const cryptonote::t
|
|||
m_last_tx = cryptonote::get_transaction_hash(tx);
|
||||
if (m_no_new_index == event_idx)
|
||||
return !tvc.m_verifivation_failed && !tx_added;
|
||||
else if (m_failed_index == event_idx)
|
||||
return tvc.m_verifivation_failed;// && !tx_added;
|
||||
else
|
||||
return !tvc.m_verifivation_failed && tx_added;
|
||||
}
|
||||
|
@ -559,3 +569,45 @@ bool txpool_double_spend_local::generate(std::vector<test_event_entry>& events)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool txpool_double_spend_keyimage::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
INIT_MEMPOOL_TEST();
|
||||
|
||||
DO_CALLBACK(events, "check_txpool_spent_keys");
|
||||
SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_local_relay);
|
||||
DO_CALLBACK(events, "mark_no_new");
|
||||
|
||||
const std::size_t tx_index1 = events.size();
|
||||
MAKE_TX(events, tx_0, miner_account, bob_account, send_amount, blk_0);
|
||||
|
||||
DO_CALLBACK(events, "increase_all_tx_count");
|
||||
DO_CALLBACK(events, "check_txpool_spent_keys");
|
||||
DO_CALLBACK(events, "mark_timestamp_change");
|
||||
DO_CALLBACK(events, "check_new_hidden");
|
||||
DO_CALLBACK(events, "timestamp_change_pause");
|
||||
DO_CALLBACK(events, "mark_no_new");
|
||||
const std::size_t tx_index2 = events.size();
|
||||
events.push_back(tx_0);
|
||||
DO_CALLBACK(events, "check_txpool_spent_keys");
|
||||
DO_CALLBACK(events, "mark_timestamp_change");
|
||||
DO_CALLBACK(events, "check_unchanged");
|
||||
|
||||
// use same key image with different id
|
||||
cryptonote::transaction tx_1;
|
||||
{
|
||||
auto events_copy = events;
|
||||
events_copy.erase(events_copy.begin() + tx_index1);
|
||||
events_copy.erase(events_copy.begin() + tx_index2 - 1);
|
||||
MAKE_TX(events_copy, tx_temp, miner_account, bob_account, send_amount, blk_0);
|
||||
tx_1 = tx_temp;
|
||||
}
|
||||
|
||||
// same key image
|
||||
DO_CALLBACK(events, "timestamp_change_pause");
|
||||
DO_CALLBACK(events, "mark_failed");
|
||||
events.push_back(tx_1);
|
||||
DO_CALLBACK(events, "check_unchanged");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ class txpool_double_spend_base : public txpool_base
|
|||
std::unordered_set<crypto::hash> m_no_relay_hashes;
|
||||
std::unordered_map<crypto::hash, uint64_t> m_all_hashes;
|
||||
size_t m_no_new_index;
|
||||
size_t m_failed_index;
|
||||
size_t m_new_timestamp_index;
|
||||
crypto::hash m_last_tx;
|
||||
|
||||
|
@ -86,6 +87,7 @@ public:
|
|||
txpool_double_spend_base();
|
||||
|
||||
bool mark_no_new(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool mark_failed(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool mark_timestamp_change(cryptonote::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
|
||||
//! Pause for 1 second, so that `receive_time` for tx meta changes (tx hidden from public rpc being updated)
|
||||
|
@ -116,3 +118,12 @@ struct txpool_double_spend_local : txpool_double_spend_base
|
|||
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
|
||||
struct txpool_double_spend_keyimage : txpool_double_spend_base
|
||||
{
|
||||
txpool_double_spend_keyimage()
|
||||
: txpool_double_spend_base()
|
||||
{}
|
||||
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue