Electroneum
gen_trezor_live_refresh Class Reference

#include <trezor_tests.h>

Inheritance diagram for gen_trezor_live_refresh:
Collaboration diagram for gen_trezor_live_refresh:

Public Member Functions

bool generate (std::vector< test_event_entry > &events) override
 
- Public Member Functions inherited from gen_trezor_base
 gen_trezor_base ()
 
 gen_trezor_base (const gen_trezor_base &other)
 
virtual ~gen_trezor_base ()
 
virtual void setup_args (const std::string &trezor_path, bool heavy_tests=false)
 
virtual void load (std::vector< test_event_entry > &events)
 
virtual void fix_hf (std::vector< test_event_entry > &events)
 
virtual void update_trackers (std::vector< test_event_entry > &events)
 
virtual void fork (gen_trezor_base &other)
 
virtual void clear ()
 
virtual void add_shared_events (std::vector< test_event_entry > &events)
 
virtual void test_setup (std::vector< test_event_entry > &events)
 
virtual void add_transactions_to_events (std::vector< test_event_entry > &events, test_generator &generator, const std::vector< cryptonote::transaction > &txs)
 
virtual void test_trezor_tx (std::vector< test_event_entry > &events, std::vector< tools::wallet2::pending_tx > &ptxs, std::vector< cryptonote::address_parse_info > &dsts_info, test_generator &generator, std::vector< tools::wallet2 *> wallets, bool is_sweep=false)
 
virtual void test_get_tx (std::vector< test_event_entry > &events, std::vector< tools::wallet2 *> wallets, const std::vector< tools::wallet2::pending_tx > &ptxs, const std::vector< std::string > &aux_tx_info)
 
virtual void mine_and_test (std::vector< test_event_entry > &events)
 
virtual void rewind_blocks (std::vector< test_event_entry > &events, size_t rewind_n, uint8_t hf)
 
virtual void set_hard_fork (uint8_t hf)
 
crypto::hash head_hash () const
 
cryptonote::block head_block () const
 
bool heavy_tests () const
 
void rct_config (rct::RCTConfig rct_config)
 
uint8_t cur_hf () const
 
cryptonote::network_type nettype () const
 
std::shared_ptr< mock_daemondaemon () const
 
void daemon (std::shared_ptr< mock_daemon > daemon)
 
- 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
 
- Static Public Attributes inherited from gen_trezor_base
static const uint64_t m_ts_start = 1397862000
 
static const uint64_t m_wallet_ts = m_ts_start - 60*60*24*4
 
static const std::string m_device_name = "Trezor:udp"
 
static const std::string m_master_seed_str = "14821d0bc5659b24cafbc889dc4fc60785ee08b65d71c525f81eeaba4f3a570f"
 
static const std::string m_device_seed = "permit universe parent weapon amused modify essay borrow tobacco budget walnut lunch consider gallery ride amazing frog forget treat market chapter velvet useless topple"
 
static const std::string m_alice_spend_private = m_master_seed_str
 
static const std::string m_alice_view_private = "a6ccd4ac344a295d1387f8d18c81bdd394f1845de84188e204514ef9370fd403"
 
- Protected Member Functions inherited from gen_trezor_base
virtual void setup_trezor ()
 
virtual void init_fields ()
 
virtual void update_client_settings ()
 
virtual bool verify_tx_key (const ::crypto::secret_key &tx_priv, const ::crypto::public_key &tx_pub, const subaddresses_t &subs)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int)
 
- Protected Attributes inherited from gen_trezor_base
test_generator m_generator
 
block_tracker m_bt
 
cryptonote::network_type m_network_type
 
std::shared_ptr< mock_daemonm_daemon
 
uint8_t m_top_hard_fork
 
v_hardforks_t m_hard_forks
 
cryptonote::block m_head
 
std::vector< test_event_entrym_events
 
std::string m_trezor_path
 
bool m_heavy_tests
 
bool m_test_get_tx_key
 
rct::RCTConfig m_rct_config
 
bool m_live_refresh_enabled
 
cryptonote::account_base m_miner_account
 
cryptonote::account_base m_bob_account
 
cryptonote::account_base m_alice_account
 
cryptonote::account_base m_eve_account
 
hw::trezor::device_trezor * m_trezor
 
std::unique_ptr< tools::wallet2m_wl_alice
 
std::unique_ptr< tools::wallet2m_wl_bob
 
std::unique_ptr< tools::wallet2m_wl_eve
 

Detailed Description

Definition at line 243 of file trezor_tests.h.

Member Function Documentation

◆ generate()

bool gen_trezor_live_refresh::generate ( std::vector< test_event_entry > &  events)
overridevirtual

Reimplemented from gen_trezor_base.

Definition at line 1568 of file trezor_tests.cpp.

1569 {
1570  test_generator generator(m_generator);
1571  test_setup(events);
1572 
1573  auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
1574  CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
1575 
1576  if (!dev_cold->is_live_refresh_supported()){
1577  MDEBUG("Trezor does not support live refresh");
1578  return true;
1579  }
1580 
1581  hw::device & sw_device = hw::get_device("default");
1582 
1583  dev_cold->live_refresh_start();
1584  for(unsigned i=0; i<50; ++i)
1585  {
1586  cryptonote::subaddress_index subaddr = {0, i};
1587 
1591  ::crypto::public_key pub_ver;
1593 
1594  ::crypto::random32_unbiased((unsigned char*)r.data);
1596  memcpy(D.data, rct::scalarmultKey(rct::pk2rct(R), rct::sk2rct(m_alice_account.get_keys().m_view_secret_key)).bytes, 32);
1597 
1598  ::crypto::secret_key scalar_step1;
1599  ::crypto::secret_key scalar_step2;
1601  if (i == 0)
1602  {
1603  scalar_step2 = scalar_step1;
1604  }
1605  else
1606  {
1608  sw_device.sc_secret_add(scalar_step2, scalar_step1, subaddr_sk);
1609  }
1610 
1611  ::crypto::secret_key_to_public_key(scalar_step2, pub_ver);
1612  ::crypto::generate_key_image(pub_ver, scalar_step2, ki);
1613 
1614  cryptonote::keypair in_ephemeral;
1615  ::crypto::key_image ki2;
1616 
1617  dev_cold->live_refresh(
1619  pub_ver,
1620  D,
1621  i,
1622  subaddr,
1623  in_ephemeral,
1624  ki2
1625  );
1626 
1627  CHECK_AND_ASSERT_THROW_MES(ki == ki2, "Key image inconsistent");
1628  }
1629 
1630  dev_cold->live_refresh_finish();
1631  return true;
1632 }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
virtual void test_setup(std::vector< test_event_entry > &events)
void derive_secret_key(const key_derivation &derivation, std::size_t output_index, const secret_key &base, secret_key &derived_key)
Definition: crypto.h:282
virtual bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b)=0
POD_CLASS key_derivation
Definition: crypto.h:98
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
cryptonote::account_base m_alice_account
Definition: trezor_tests.h:133
void random32_unbiased(unsigned char *bytes)
Definition: crypto.cpp:110
#define MDEBUG(x)
Definition: misc_log_ex.h:76
const account_keys & get_keys() const
Definition: account.cpp:264
device & get_device(const std::string &device_descriptor)
Definition: device.cpp:95
POD_CLASS public_key
Definition: crypto.h:76
hw::trezor::device_trezor * m_trezor
Definition: trezor_tests.h:135
crypto::secret_key m_view_secret_key
Definition: account.h:45
test_generator m_generator
Definition: trezor_tests.h:115
POD_CLASS key_image
Definition: crypto.h:102
void * memcpy(void *a, const void *b, size_t c)
crypto::secret_key m_spend_secret_key
Definition: account.h:44
virtual crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index)=0
bool secret_key_to_public_key(const secret_key &sec, public_key &pub)
Definition: crypto.h:262
Here is the call graph for this function:

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