Electroneum
cryptonote Namespace Reference

Holds cryptonote related classes and helpers. More...

Namespaces

 bootstrap
 
 json
 
 rpc
 

Classes

struct  acc_addr_tx_t
 
struct  acc_outs_t
 
class  account_base
 
struct  account_keys
 
struct  account_public_address
 
class  ADDR_OUTPUT_EXISTS
 thrown when an output record for an address already exists, but shouldn't, namely when adding a block More...
 
class  ADDR_TX_EXISTS
 
struct  address_outputs
 
struct  address_parse_info
 
struct  address_txs
 
struct  array_hasher
 
struct  blk_height
 
struct  block
 
struct  block_complete_entry
 
class  BLOCK_DNE
 thrown when a requested block does not exist More...
 
class  BLOCK_EXISTS
 thrown when a block exists, but shouldn't, namely when adding a block More...
 
struct  block_header
 
struct  block_header_response
 
class  BLOCK_INVALID
 thrown when something is wrong with the block to be added More...
 
class  BLOCK_PARENT_DNE
 thrown when a block's parent does not exist (and it needed to) More...
 
class  block_queue
 
struct  block_verification_context
 
class  Blockchain
 
class  BlockchainDB
 The BlockchainDB backing store interface declaration/contract. More...
 
class  BlockchainLMDB
 
struct  chainstate_key_t
 
struct  chainstate_value_t
 
class  checkpoints
 A container for blockchain checkpoints. More...
 
struct  COMMAND_RPC_FAST_EXIT
 
struct  COMMAND_RPC_FLUSH_TRANSACTION_POOL
 
struct  COMMAND_RPC_GENERATE_ED25519_KEYPAIR
 
struct  COMMAND_RPC_GENERATEBLOCKS
 
struct  COMMAND_RPC_GET_ADDR_TX_BATCH_HISTORY
 
struct  COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY
 
struct  COMMAND_RPC_GET_ALT_BLOCKS_HASHES
 
struct  COMMAND_RPC_GET_ALTERNATE_CHAINS
 
struct  COMMAND_RPC_GET_BALANCE
 
struct  COMMAND_RPC_GET_BASE_FEE_ESTIMATE
 
struct  COMMAND_RPC_GET_BLOCK
 
struct  COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH
 
struct  COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT
 
struct  COMMAND_RPC_GET_BLOCK_HEADERS_RANGE
 
struct  COMMAND_RPC_GET_BLOCKS_BY_HEIGHT
 
struct  COMMAND_RPC_GET_BLOCKS_FAST
 
struct  COMMAND_RPC_GET_COINBASE_TX_SUM
 
struct  COMMAND_RPC_GET_CONNECTIONS
 
struct  COMMAND_RPC_GET_HASHES_FAST
 
struct  COMMAND_RPC_GET_HEIGHT
 
struct  COMMAND_RPC_GET_INFO
 
struct  COMMAND_RPC_GET_LAST_BLOCK_HEADER
 
struct  COMMAND_RPC_GET_LIMIT
 
struct  COMMAND_RPC_GET_NET_STATS
 
struct  COMMAND_RPC_GET_OUTPUT_DISTRIBUTION
 
struct  COMMAND_RPC_GET_OUTPUT_HISTOGRAM
 
struct  COMMAND_RPC_GET_OUTPUTS
 
struct  COMMAND_RPC_GET_OUTPUTS_BIN
 
struct  COMMAND_RPC_GET_PEER_LIST
 
struct  COMMAND_RPC_GET_RANDOM_OUTS
 
struct  COMMAND_RPC_GET_TAX_DATA
 
struct  COMMAND_RPC_GET_TRANSACTION_POOL
 
struct  COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG
 
struct  COMMAND_RPC_GET_TRANSACTION_POOL_HASHES
 
struct  COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN
 
struct  COMMAND_RPC_GET_TRANSACTION_POOL_STATS
 
struct  COMMAND_RPC_GET_TRANSACTIONS
 
struct  COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES
 
struct  COMMAND_RPC_GET_VERSION
 
struct  COMMAND_RPC_GETBANS
 
struct  COMMAND_RPC_GETBLOCKCOUNT
 
struct  COMMAND_RPC_GETBLOCKHASH
 
struct  COMMAND_RPC_GETBLOCKTEMPLATE
 
struct  COMMAND_RPC_HARD_FORK_INFO
 
struct  COMMAND_RPC_IN_PEERS
 
struct  COMMAND_RPC_INJECT_EMERGENCY_VLIST
 
struct  COMMAND_RPC_IS_KEY_IMAGE_SPENT
 
struct  COMMAND_RPC_IS_PUBLIC_OUTPUT_SPENT
 
struct  COMMAND_RPC_MINING_STATUS
 
struct  COMMAND_RPC_OUT_PEERS
 
struct  COMMAND_RPC_POP_BLOCKS
 
struct  COMMAND_RPC_PRUNE_BLOCKCHAIN
 
struct  COMMAND_RPC_RELAY_TX
 
struct  COMMAND_RPC_SAVE_BC
 
struct  COMMAND_RPC_SEND_RAW_TX
 
struct  COMMAND_RPC_SET_LIMIT
 
struct  COMMAND_RPC_SET_LOG_CATEGORIES
 
struct  COMMAND_RPC_SET_LOG_HASH_RATE
 
struct  COMMAND_RPC_SET_LOG_LEVEL
 
struct  COMMAND_RPC_SET_VALIDATOR_KEY
 
struct  COMMAND_RPC_SETBANS
 
struct  COMMAND_RPC_SIGN_MESSAGE
 
struct  COMMAND_RPC_START_MINING
 
struct  COMMAND_RPC_START_SAVE_GRAPH
 
struct  COMMAND_RPC_STOP_DAEMON
 
struct  COMMAND_RPC_STOP_MINING
 
struct  COMMAND_RPC_STOP_SAVE_GRAPH
 
struct  COMMAND_RPC_SUBMIT_RAW_TX
 
struct  COMMAND_RPC_SUBMITBLOCK
 
struct  COMMAND_RPC_SYNC_INFO
 
struct  COMMAND_RPC_UPDATE
 
struct  config_t
 
struct  connection_info
 
class  core
 handles core cryptonote functionality More...
 
class  core_rpc_server
 
struct  core_stat_info_t
 
struct  CORE_SYNC_DATA
 
struct  cryptonote_connection_context
 
class  cryptonote_protocol_handler_base
 
class  cryptonote_protocol_handler_base_pimpl
 
struct  cryptonote_protocol_stub
 
class  DB_CREATE_FAILURE
 thrown when creating the BlockchainDB fails More...
 
class  DB_ERROR
 A generic BlockchainDB exception. More...
 
class  DB_ERROR_TXN_START
 thrown when there is an error starting a DB transaction More...
 
class  DB_EXCEPTION
 A base class for BlockchainDB exceptions. More...
 
class  DB_OPEN_FAILURE
 thrown when opening the BlockchainDB fails More...
 
class  db_rtxn_guard
 
class  DB_SYNC_FAILURE
 thrown when synchronizing the BlockchainDB to disk fails More...
 
class  db_txn_guard
 
class  db_wtxn_guard
 
struct  get_outputs_out
 
class  HardFork
 
struct  i_cryptonote_protocol
 
struct  i_miner_handler
 
struct  integrated_address
 
class  KEY_IMAGE_EXISTS
 thrown when a spent key image exists, but shouldn't, namely when adding a block More...
 
struct  keypair
 
struct  mdb_block_info_1
 
struct  mdb_block_info_2
 
struct  mdb_block_info_3
 
struct  mdb_block_info_4
 
struct  mdb_rflags
 
struct  mdb_threadinfo
 
struct  mdb_txn_cursors
 
struct  mdb_txn_safe
 
class  miner
 
struct  NOTIFY_EMERGENCY_VALIDATORS_LIST
 
struct  NOTIFY_NEW_BLOCK
 
struct  NOTIFY_NEW_FLUFFY_BLOCK
 
struct  NOTIFY_NEW_TRANSACTIONS
 
struct  NOTIFY_REQUEST_CHAIN
 
struct  NOTIFY_REQUEST_FLUFFY_MISSING_TX
 
struct  NOTIFY_REQUEST_GET_OBJECTS
 
struct  NOTIFY_REQUEST_VALIDATORS_LIST
 
struct  NOTIFY_RESPONSE_CHAIN_ENTRY
 
struct  NOTIFY_RESPONSE_GET_OBJECTS
 
struct  outkey
 
struct  output_data_t
 a struct containing output metadata More...
 
class  OUTPUT_DNE
 thrown when a requested output does not exist More...
 
class  OUTPUT_EXISTS
 thrown when an output exists, but shouldn't, namely when adding a block More...
 
struct  outtx
 
struct  peer
 
struct  pre_rct_outkey
 
class  pruned_transaction
 
struct  public_address_outer_blob
 
struct  public_integrated_address_outer_blob
 
struct  public_output
 
struct  rpc_args
 Processes command line arguments related to server-side RPC. More...
 
class  simple_wallet
 Manages wallet operations. This is the most abstracted wallet class. More...
 
struct  spent_key_image_info
 
struct  subaddress_index
 
struct  subaddress_receive_info
 
class  t_cryptonote_protocol_handler
 
struct  t_hash_json
 struct for loading many checkpoints from json More...
 
struct  t_hashline
 struct for loading a checkpoint from json More...
 
struct  test_options
 
class  transaction
 
class  transaction_prefix
 
struct  tx_backlog_entry
 
struct  tx_data_t
 
struct  tx_destination_entry
 
class  TX_DNE
 thrown when a requested transaction does not exist More...
 
class  TX_EXISTS
 thrown when a transaction exists, but shouldn't, namely when adding a block More...
 
struct  tx_extra_additional_pub_keys
 
struct  tx_extra_bridge_smartchain_address
 
struct  tx_extra_bridge_source_address
 
struct  tx_extra_merge_mining_tag
 
struct  tx_extra_mysterious_minergate
 
struct  tx_extra_nonce
 
struct  tx_extra_padding
 
struct  tx_extra_pub_key
 
struct  tx_info
 
struct  tx_input_t
 
class  tx_memory_pool
 Transaction pool, handles transactions which are not part of a block. More...
 
struct  tx_out
 
struct  tx_source_entry
 
struct  tx_verification_context
 
class  txCompare
 
struct  txin_gen
 
struct  txin_to_key
 
struct  txin_to_key_public
 
struct  txin_to_script
 
struct  txin_to_scripthash
 
struct  txindex
 
struct  txout_to_key
 
struct  txout_to_key_public
 
struct  txout_to_script
 
struct  txout_to_scripthash
 
struct  txpool_histo
 
struct  txpool_stats
 
struct  txpool_tx_meta_t
 a struct containing txpool per transaction metadata More...
 
class  UTXO_EXISTS
 thrown when a utxo already exists, but shouldn't, namely when adding a block More...
 
struct  validator_db
 

Typedefs

typedef std::pair< crypto::hash, uint64_ttx_out_index
 
typedef struct cryptonote::mdb_block_info_1 mdb_block_info_1
 
typedef struct cryptonote::mdb_block_info_2 mdb_block_info_2
 
typedef struct cryptonote::mdb_block_info_3 mdb_block_info_3
 
typedef struct cryptonote::mdb_block_info_4 mdb_block_info_4
 
typedef mdb_block_info_4 mdb_block_info
 
typedef struct cryptonote::blk_height blk_height
 
typedef struct cryptonote::pre_rct_outkey pre_rct_outkey
 
typedef struct cryptonote::outkey outkey
 
typedef struct cryptonote::outtx outtx
 
typedef struct cryptonote::acc_outs_t acc_outs_t
 
typedef struct cryptonote::acc_addr_tx_t acc_addr_tx_t
 
typedef struct cryptonote::txindex txindex
 
typedef struct cryptonote::mdb_txn_cursors mdb_txn_cursors
 
typedef struct cryptonote::mdb_rflags mdb_rflags
 
typedef struct cryptonote::mdb_threadinfo mdb_threadinfo
 
typedef std::string blobdata
 
typedef epee::span< const char > blobdata_ref
 
typedef std::vector< crypto::signaturering_signature
 
typedef boost::variant< txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_to_key_publictxin_v
 
typedef boost::variant< txout_to_script, txout_to_scripthash, txout_to_key, txout_to_key_publictxout_target_v
 
typedef epee::misc_utils::struct_init< core_stat_info_tcore_stat_info
 
typedef boost::multiprecision::uint128_t difficulty_type
 
typedef boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergatetx_extra_field
 
typedef std::function< const epee::span< const unsigned char >cryptonote::network_type network)> GetCheckpointsCallback
 Callback routine that returns checkpoints data for specific network type. More...
 
typedef std::pair< std::pair< double, std::time_t >, crypto::hashtx_by_fee_and_receive_time_entry
 pair of <transaction fee, transaction hash> for organization More...
 
typedef std::set< tx_by_fee_and_receive_time_entry, txComparesorted_tx_container
 container for sorting transactions by fee per unit size More...
 

Enumerations

enum  { prune_mode_prune, prune_mode_update, prune_mode_check }
 
enum  network_type : uint8_t {
  MAINNET = 0, TESTNET, STAGENET, FAKECHAIN,
  UNDEFINED = 255
}
 
enum  blockchain_db_sync_mode { db_defaultsync, db_sync, db_async, db_nosync }
 
enum  SPENT_STATUS { UNSPENT = 0, SPENT_IN_BLOCKCHAIN = 1, SPENT_IN_POOL = 2 }
 

Functions

size_t slow_memmem (const void *start_buff, size_t buflen, const void *pat, size_t patlen)
 
bool blockchain_valid_db_type (const std::string &db_type)
 
std::string blockchain_db_types (const std::string &sep)
 
BlockchainDBnew_db (const std::string &db_type)
 
void lmdb_resized (MDB_env *env)
 
int lmdb_txn_begin (MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
 
int lmdb_txn_renew (MDB_txn *txn)
 
std::string get_protocol_state_string (cryptonote_connection_context::state s)
 
char get_protocol_state_char (cryptonote_connection_context::state s)
 
template<>
unsigned int getpos (binary_archive< true > &ar)
 
template<>
unsigned int getpos (binary_archive< false > &ar)
 
size_t get_min_block_weight (uint8_t version)
 
size_t get_max_tx_size ()
 
bool get_block_reward (size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, uint64_t current_block_height, network_type nettype)
 
uint8_t get_account_address_checksum (const public_address_outer_blob &bl)
 
uint8_t get_account_integrated_address_checksum (const public_integrated_address_outer_blob &bl)
 
std::string get_account_address_as_str (network_type nettype, bool subaddress, account_public_address const &adr)
 
std::string get_account_integrated_address_as_str (network_type nettype, account_public_address const &adr, crypto::hash8 const &payment_id)
 
bool is_coinbase (const transaction &tx)
 
bool get_account_address_from_str (address_parse_info &info, network_type nettype, std::string const &str)
 
bool get_account_address_from_str_or_url (address_parse_info &info, network_type nettype, const std::string &str_or_url, std::function< std::string(const std::string &, const std::vector< std::string > &, bool)> dns_confirm)
 
bool operator== (const cryptonote::transaction &a, const cryptonote::transaction &b)
 
bool operator== (const cryptonote::block &a, const cryptonote::block &b)
 
void get_transaction_prefix_hash (const transaction_prefix &tx, crypto::hash &h)
 
crypto::hash get_transaction_prefix_hash (const transaction_prefix &tx)
 
bool expand_transaction_1 (transaction &tx, bool base_only)
 
bool parse_and_validate_tx_from_blob (const blobdata &tx_blob, transaction &tx)
 
bool parse_and_validate_tx_base_from_blob (const blobdata &tx_blob, transaction &tx)
 
bool parse_and_validate_tx_prefix_from_blob (const blobdata &tx_blob, transaction_prefix &tx)
 
bool parse_and_validate_tx_from_blob (const blobdata &tx_blob, transaction &tx, crypto::hash &tx_hash)
 
bool parse_and_validate_tx_from_blob (const blobdata &tx_blob, transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefix_hash)
 
bool is_v1_tx (const blobdata_ref &tx_blob)
 
bool is_v1_tx (const blobdata &tx_blob)
 
bool generate_key_image_helper (const account_keys &ack, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
 
bool generate_key_image_helper_precomp (const account_keys &ack, const crypto::public_key &out_key, const crypto::key_derivation &recv_derivation, size_t real_output_index, const subaddress_index &received_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
 
uint64_t power_integral (uint64_t a, uint64_t b)
 
bool parse_amount (uint64_t &amount, const std::string &str_amount_)
 
uint64_t get_transaction_weight (const transaction &tx, size_t blob_size)
 
uint64_t get_transaction_weight (const transaction &tx)
 
bool get_tx_fee (const transaction &tx, uint64_t &fee)
 
uint64_t get_tx_fee (const transaction &tx)
 
bool parse_tx_extra (const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
 
bool sort_tx_extra (const std::vector< uint8_t > &tx_extra, std::vector< uint8_t > &sorted_tx_extra, bool allow_partial)
 
crypto::public_key get_tx_pub_key_from_extra (const std::vector< uint8_t > &tx_extra, size_t pk_index)
 
crypto::public_key get_tx_pub_key_from_extra (const transaction_prefix &tx_prefix, size_t pk_index)
 
crypto::public_key get_tx_pub_key_from_extra (const transaction &tx, size_t pk_index)
 
bool add_tx_pub_key_to_extra (transaction &tx, const crypto::public_key &tx_pub_key)
 
bool add_tx_pub_key_to_extra (transaction_prefix &tx, const crypto::public_key &tx_pub_key)
 
bool add_tx_pub_key_to_extra (std::vector< uint8_t > &tx_extra, const crypto::public_key &tx_pub_key)
 
std::vector< crypto::public_keyget_additional_tx_pub_keys_from_extra (const std::vector< uint8_t > &tx_extra)
 
std::vector< crypto::public_keyget_additional_tx_pub_keys_from_extra (const transaction_prefix &tx)
 
bool add_additional_tx_pub_keys_to_extra (std::vector< uint8_t > &tx_extra, const std::vector< crypto::public_key > &additional_pub_keys)
 
bool add_extra_nonce_to_tx_extra (std::vector< uint8_t > &tx_extra, const blobdata &extra_nonce)
 
bool add_bridge_source_address_to_tx_extra (std::vector< uint8_t > &tx_extra, const blobdata &bridge_source_address)
 
bool add_bridge_smartchain_address_to_tx_extra (std::vector< uint8_t > &tx_extra, const blobdata &bridge_smartchain_address)
 
bool remove_field_from_tx_extra (std::vector< uint8_t > &tx_extra, const std::type_info &type)
 
void set_payment_id_to_tx_extra_nonce (blobdata &extra_nonce, const crypto::hash &payment_id)
 
void set_encrypted_payment_id_to_tx_extra_nonce (blobdata &extra_nonce, const crypto::hash8 &payment_id)
 
bool get_payment_id_from_tx_extra_nonce (const blobdata &extra_nonce, crypto::hash &payment_id)
 
bool get_encrypted_payment_id_from_tx_extra_nonce (const blobdata &extra_nonce, crypto::hash8 &payment_id)
 
bool get_inputs_etn_amount (const transaction &tx, uint64_t &etn)
 
uint64_t get_block_height (const block &b)
 
bool check_inputs_types_supported (const transaction &tx)
 
bool check_outs_valid (const transaction &tx)
 
bool check_etn_overflow (const transaction &tx)
 
bool check_inputs_overflow (const transaction &tx)
 
bool check_outs_overflow (const transaction &tx)
 
uint64_t get_outs_etn_amount (const transaction &tx)
 
std::string short_hash_str (const crypto::hash &h)
 
bool is_out_to_acc (const account_keys &acc, const txout_to_key &out_key, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, size_t output_index)
 
boost::optional< subaddress_receive_infois_out_to_acc_precomp (const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::key_derivation &derivation, const std::vector< crypto::key_derivation > &additional_derivations, size_t output_index, hw::device &hwdev)
 
boost::optional< subaddress_receive_infois_out_to_acc_precomp_public (const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const cryptonote::account_public_address output_address)
 
bool lookup_acc_outs (const account_keys &acc, const transaction &tx, std::vector< size_t > &outs, uint64_t &etn_transfered)
 
bool lookup_acc_outs (const account_keys &acc, const transaction &tx, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, std::vector< size_t > &outs, uint64_t &etn_transfered)
 
void get_blob_hash (const epee::span< const char > &blob, crypto::hash &res)
 
void get_blob_hash (const blobdata &blob, crypto::hash &res)
 
void set_default_decimal_point (unsigned int decimal_point)
 
unsigned int get_default_decimal_point ()
 
std::string get_unit (unsigned int decimal_point)
 
std::string print_etn (uint64_t amount, unsigned int decimal_point)
 
crypto::hash get_blob_hash (const blobdata &blob)
 
crypto::hash get_blob_hash (const epee::span< const char > &blob)
 
crypto::hash get_transaction_hash (const transaction &t)
 
bool get_transaction_hash (const transaction &t, crypto::hash &res)
 
bool calculate_transaction_prunable_hash (const transaction &t, const cryptonote::blobdata *blob, crypto::hash &res)
 
crypto::hash get_transaction_prunable_hash (const transaction &t, const cryptonote::blobdata *blobdata)
 
crypto::hash get_pruned_transaction_hash (const transaction &t, const crypto::hash &pruned_data_hash)
 
bool calculate_transaction_hash (const transaction &t, crypto::hash &res, size_t *blob_size)
 
bool get_transaction_hash (const transaction &t, crypto::hash &res, size_t *blob_size)
 
bool get_transaction_hash (const transaction &t, crypto::hash &res, size_t &blob_size)
 
blobdata get_block_hashing_blob (const block &b)
 
bool calculate_block_hash (const block &b, crypto::hash &res, const blobdata *blob)
 
bool get_block_hash (const block &b, crypto::hash &res)
 
crypto::hash get_block_hash (const block &b)
 
bool get_block_longhash (const block &b, crypto::hash &res, uint64_t height)
 
std::vector< uint64_trelative_output_offsets_to_absolute (const std::vector< uint64_t > &off)
 
std::vector< uint64_tabsolute_output_offsets_to_relative (const std::vector< uint64_t > &off)
 
crypto::hash get_block_longhash (const block &b, uint64_t height)
 
bool parse_and_validate_block_from_blob (const blobdata &b_blob, block &b, crypto::hash *block_hash)
 
bool parse_and_validate_block_from_blob (const blobdata &b_blob, block &b)
 
bool parse_and_validate_block_from_blob (const blobdata &b_blob, block &b, crypto::hash &block_hash)
 
blobdata block_to_blob (const block &b)
 
bool block_to_blob (const block &b, blobdata &b_blob)
 
blobdata tx_to_blob (const transaction &tx)
 
bool tx_to_blob (const transaction &tx, blobdata &b_blob)
 
void get_tx_tree_hash (const std::vector< crypto::hash > &tx_hashes, crypto::hash &h)
 
crypto::hash get_tx_tree_hash (const std::vector< crypto::hash > &tx_hashes)
 
crypto::hash get_tx_tree_hash (const block &b)
 
bool is_valid_decomposed_amount (uint64_t amount)
 
void get_hash_stats (uint64_t &tx_hashes_calculated, uint64_t &tx_hashes_cached, uint64_t &block_hashes_calculated, uint64_t &block_hashes_cached)
 
crypto::secret_key encrypt_key (crypto::secret_key key, const epee::wipeable_string &passphrase)
 
crypto::secret_key decrypt_key (crypto::secret_key key, const epee::wipeable_string &passphrase)
 
template<typename T >
bool find_tx_extra_field_by_type (const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
 
template<class t_object >
bool t_serializable_object_from_blob (t_object &to, const blobdata &b_blob)
 
template<class t_object >
bool t_serializable_object_to_blob (const t_object &to, blobdata &b_blob)
 
template<class t_object >
blobdata t_serializable_object_to_blob (const t_object &to)
 
template<class t_object >
bool get_object_hash (const t_object &o, crypto::hash &res)
 
template<class t_object >
size_t get_object_blobsize (const t_object &o)
 
template<class t_object >
bool get_object_hash (const t_object &o, crypto::hash &res, size_t &blob_size)
 
template<typename T >
std::string obj_to_json_str (T &obj)
 
template<typename chunk_handler_t , typename dust_handler_t >
void decompose_amount_into_digits (uint64_t amount, uint64_t dust_threshold, const chunk_handler_t &chunk_handler, const dust_handler_t &dust_handler)
 
bool check_hash_64 (const crypto::hash &hash, uint64_t difficulty)
 checks if a hash fits the given difficulty More...
 
uint64_t next_difficulty_64 (std::vector< std::uint64_t > timestamps, std::vector< uint64_t > cumulative_difficulties, size_t target_seconds, uint8_t version)
 
const difficulty_type max64bit (std::numeric_limits< std::uint64_t >::max())
 
const boost::multiprecision::uint256_t max128bit (std::numeric_limits< boost::multiprecision::uint128_t >::max())
 
const boost::multiprecision::uint512_t max256bit (std::numeric_limits< boost::multiprecision::uint256_t >::max())
 
bool check_hash_128 (const crypto::hash &hash, difficulty_type difficulty)
 
bool check_hash (const crypto::hash &hash, difficulty_type difficulty)
 
difficulty_type next_difficulty (std::vector< uint64_t > timestamps, std::vector< difficulty_type > cumulative_difficulties, size_t target_seconds, uint8_t version)
 
std::string hex (difficulty_type v)
 
difficulty_type next_difficulty (std::vector< std::uint64_t > timestamps, std::vector< difficulty_type > cumulative_difficulties, size_t target_seconds, uint8_t version=1)
 
std::ostream & operator<< (std::ostream &out, const cryptonote::subaddress_index &subaddr_index)
 
const config_tget_config (network_type nettype)
 
block_complete_entry get_block_complete_entry (block &b, tx_memory_pool &pool)
 
double factorial (unsigned int n)
 
void classify_addresses (const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, size_t &num_stdaddresses, size_t &num_subaddresses, account_public_address &single_dest_subaddress)
 
bool construct_miner_tx (size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version, network_type nettype)
 
crypto::public_key get_destination_view_key_pub (const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr)
 
bool construct_tx_with_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, const crypto::secret_key &tx_key, const std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, bool shuffle_outs, const uint32_t account_major_offset, const cryptonote::network_type nettype)
 
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)
 
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)
 
bool generate_genesis_block (block &bl, std::string const &genesis_tx, uint32_t nonce)
 
bool generate_output_ephemeral_keys (const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key, const cryptonote::tx_destination_entry &dst_entr, const boost::optional< cryptonote::account_public_address > &change_addr, const size_t output_index, const bool &need_additional_txkeys, const std::vector< crypto::secret_key > &additional_tx_keys, std::vector< crypto::public_key > &additional_tx_public_keys, std::vector< rct::key > &amount_keys, crypto::public_key &out_eph_public_key)
 
bool tx_sanity_check (Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
 
crypto::secret_key get_multisig_blinded_secret_key (const crypto::secret_key &key)
 
void generate_multisig_N_N (const account_keys &keys, const std::vector< crypto::public_key > &spend_keys, std::vector< crypto::secret_key > &multisig_keys, rct::key &spend_skey, rct::key &spend_pkey)
 
void generate_multisig_N1_N (const account_keys &keys, const std::vector< crypto::public_key > &spend_keys, std::vector< crypto::secret_key > &multisig_keys, rct::key &spend_skey, rct::key &spend_pkey)
 
std::vector< crypto::public_keygenerate_multisig_derivations (const account_keys &keys, const std::vector< crypto::public_key > &derivations)
 generate_multisig_derivations performs common DH key derivation. Each middle round in M/N scheme is DH exchange of public multisig keys of other participants multiplied by secret spend key of current participant. this functions does the following: new multisig key = secret spend * public multisig key More...
 
crypto::secret_key calculate_multisig_signer_key (const std::vector< crypto::secret_key > &multisig_keys)
 
std::vector< crypto::secret_keycalculate_multisig_keys (const std::vector< crypto::public_key > &derivations)
 calculate_multisig_keys. Calculates secret multisig keys from others' participants ones as follows: mi = H(Mi) More...
 
crypto::secret_key generate_multisig_view_secret_key (const crypto::secret_key &skey, const std::vector< crypto::secret_key > &skeys)
 
crypto::public_key generate_multisig_M_N_spend_public_key (const std::vector< crypto::public_key > &pkeys)
 generate_multisig_M_N_spend_public_key calculates multisig wallet's spend public key by summing all of public multisig keys More...
 
bool generate_multisig_key_image (const account_keys &keys, size_t multisig_key_index, const crypto::public_key &out_key, crypto::key_image &ki)
 
void generate_multisig_LR (const crypto::public_key pkey, const crypto::secret_key &k, crypto::public_key &L, crypto::public_key &R)
 
bool generate_multisig_composite_key_image (const account_keys &keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, const std::vector< crypto::key_image > &pkis, crypto::key_image &ki)
 
uint32_t multisig_rounds_required (uint32_t participants, uint32_t threshold)
 

Variables

std::string arg_db_type_description = "Specify database type, available: " + cryptonote::blockchain_db_types(", ")
 
const command_line::arg_descriptor< std::string > arg_db_type
 
const command_line::arg_descriptor< std::string > arg_db_sync_mode
 
const command_line::arg_descriptor< boolarg_db_salvage
 
const command_line::arg_descriptor< boolarg_addr_db_salvage
 
const command_line::arg_descriptor< bool, falsearg_testnet_on
 
const command_line::arg_descriptor< bool, falsearg_stagenet_on
 
const command_line::arg_descriptor< boolarg_regtest_on
 
const command_line::arg_descriptor< difficulty_typearg_fixed_difficulty
 
const command_line::arg_descriptor< boolarg_skip_block_sig_verification
 
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
 
const command_line::arg_descriptor< boolarg_offline
 
const command_line::arg_descriptor< boolarg_disable_dns_checkpoints
 
const command_line::arg_descriptor< size_t > arg_block_download_max_size
 
const command_line::arg_descriptor< boolarg_fallback_to_pow
 
const command_line::arg_descriptor< uint64_targ_fallback_to_pow_checkpoint_height
 
const command_line::arg_descriptor< std::string > arg_fallback_to_pow_checkpoint_hash
 

Detailed Description

Holds cryptonote related classes and helpers.

Typedef Documentation

◆ acc_addr_tx_t

◆ acc_outs_t

◆ blk_height

◆ blobdata

typedef std::string cryptonote::blobdata

Definition at line 39 of file blobdatatype.h.

◆ blobdata_ref

typedef epee::span<const char> cryptonote::blobdata_ref

Definition at line 40 of file blobdatatype.h.

◆ core_stat_info

◆ difficulty_type

typedef boost::multiprecision::uint128_t cryptonote::difficulty_type

Definition at line 43 of file difficulty.h.

◆ GetCheckpointsCallback

typedef std::function<const epee::span<const unsigned char>cryptonote::network_type network)> cryptonote::GetCheckpointsCallback

Callback routine that returns checkpoints data for specific network type.

Parameters
networknetwork type
Returns
checkpoints data, empty span if there ain't any checkpoints for specific network type

Definition at line 92 of file blockchain.h.

◆ mdb_block_info

Definition at line 355 of file db_lmdb.cpp.

◆ mdb_block_info_1

◆ mdb_block_info_2

◆ mdb_block_info_3

◆ mdb_block_info_4

◆ mdb_rflags

◆ mdb_threadinfo

◆ mdb_txn_cursors

◆ outkey

◆ outtx

◆ pre_rct_outkey

◆ ring_signature

Definition at line 57 of file cryptonote_basic.h.

◆ sorted_tx_container

container for sorting transactions by fee per unit size

Definition at line 78 of file tx_pool.h.

◆ tx_by_fee_and_receive_time_entry

typedef std::pair<std::pair<double, std::time_t>, crypto::hash> cryptonote::tx_by_fee_and_receive_time_entry

pair of <transaction fee, transaction hash> for organization

Definition at line 54 of file tx_pool.h.

◆ tx_extra_field

◆ tx_out_index

a pair of <transaction hash, output index>, typedef for convenience

Definition at line 107 of file blockchain_db.h.

◆ txin_v

◆ txindex

◆ txout_target_v

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
prune_mode_prune 
prune_mode_update 
prune_mode_check 

Definition at line 2641 of file db_lmdb.cpp.

◆ blockchain_db_sync_mode

Declares ways in which the BlockchainDB backend should be told to sync

Enumerator
db_defaultsync 

user didn't specify, use db_async

db_sync 

handle syncing calls instead of the backing db, synchronously

db_async 

handle syncing calls instead of the backing db, asynchronously

db_nosync 

Leave syncing up to the backing db (safest, but slowest because of disk I/O)

Definition at line 77 of file blockchain.h.

78  {
80  db_sync,
81  db_async,
82  db_nosync
83  };
handle syncing calls instead of the backing db, asynchronously
Definition: blockchain.h:81
user didn&#39;t specify, use db_async
Definition: blockchain.h:79
handle syncing calls instead of the backing db, synchronously
Definition: blockchain.h:80
Leave syncing up to the backing db (safest, but slowest because of disk I/O)
Definition: blockchain.h:82

◆ network_type

Enumerator
MAINNET 
TESTNET 
STAGENET 
FAKECHAIN 
UNDEFINED 

Definition at line 246 of file cryptonote_config.h.

◆ SPENT_STATUS

Enumerator
UNSPENT 
SPENT_IN_BLOCKCHAIN 
SPENT_IN_POOL 

Definition at line 403 of file core_rpc_server_commands_defs.h.

Function Documentation

◆ absolute_output_offsets_to_relative()

std::vector< uint64_t > cryptonote::absolute_output_offsets_to_relative ( const std::vector< uint64_t > &  off)

Definition at line 1222 of file cryptonote_format_utils.cpp.

1223  {
1224  std::vector<uint64_t> res = off;
1225  if(!off.size())
1226  return res;
1227  std::sort(res.begin(), res.end());//just to be sure, actually it is already should be sorted
1228  for(size_t i = res.size()-1; i != 0; i--)
1229  res[i] -= res[i-1];
1230 
1231  return res;
1232  }
const char * res
Definition: hmac_keccak.cpp:41

◆ add_additional_tx_pub_keys_to_extra()

bool cryptonote::add_additional_tx_pub_keys_to_extra ( std::vector< uint8_t > &  tx_extra,
const std::vector< crypto::public_key > &  additional_pub_keys 
)

Definition at line 574 of file cryptonote_format_utils.cpp.

575  {
576  // convert to variant
577  tx_extra_field field = tx_extra_additional_pub_keys{ additional_pub_keys };
578  // serialize
579  std::ostringstream oss;
580  binary_archive<true> ar(oss);
581  bool r = ::do_serialize(ar, field);
582  CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to serialize tx extra additional tx pub keys");
583  // append
584  std::string tx_extra_str = oss.str();
585  size_t pos = tx_extra.size();
586  tx_extra.resize(tx_extra.size() + tx_extra_str.size());
587  memcpy(&tx_extra[pos], tx_extra_str.data(), tx_extra_str.size());
588  return true;
589  }
::std::string string
Definition: gtest-port.h:1097
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:207
void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address &na)
#define CHECK_AND_NO_ASSERT_MES_L1(expr, fail_ret_val, message)
Definition: misc_log_ex.h:193
void * memcpy(void *a, const void *b, size_t c)
Here is the call graph for this function:

◆ add_bridge_smartchain_address_to_tx_extra()

bool cryptonote::add_bridge_smartchain_address_to_tx_extra ( std::vector< uint8_t > &  tx_extra,
const blobdata bridge_smartchain_address 
)

Definition at line 623 of file cryptonote_format_utils.cpp.

624  {
625  //CHECK_AND_ASSERT_MES(bridge_smartchain_address.size() <= TX_EXTRA_NONCE_MAX_COUNT, false, "extra nonce could be 255 bytes max");
626  size_t start_pos = tx_extra.size();
627  tx_extra.resize(tx_extra.size() + 2 + bridge_smartchain_address.size());
628  //write tag
629  tx_extra[start_pos] = TX_EXTRA_TAG_BRIDGE_SMARTCHAIN_ADDRESS;
630  //write len
631  ++start_pos;
632  tx_extra[start_pos] = static_cast<uint8_t>(bridge_smartchain_address.size());
633  //write data
634  ++start_pos;
635  memcpy(&tx_extra[start_pos], bridge_smartchain_address.data(), bridge_smartchain_address.size());
636  return true;
637  }
unsigned char uint8_t
Definition: stdint.h:124
void * memcpy(void *a, const void *b, size_t c)
#define TX_EXTRA_TAG_BRIDGE_SMARTCHAIN_ADDRESS
Definition: tx_extra.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_bridge_source_address_to_tx_extra()

bool cryptonote::add_bridge_source_address_to_tx_extra ( std::vector< uint8_t > &  tx_extra,
const blobdata bridge_source_address 
)

Definition at line 607 of file cryptonote_format_utils.cpp.

608  {
609  //CHECK_AND_ASSERT_MES(bridge_source_address.size() <= TX_EXTRA_NONCE_MAX_COUNT, false, "extra nonce could be 255 bytes max");
610  size_t start_pos = tx_extra.size();
611  tx_extra.resize(tx_extra.size() + 2 + bridge_source_address.size());
612  //write tag
613  tx_extra[start_pos] = TX_EXTRA_TAG_BRIDGE_SOURCE_ADDRESS;
614  //write len
615  ++start_pos;
616  tx_extra[start_pos] = static_cast<uint8_t>(bridge_source_address.size());
617  //write data
618  ++start_pos;
619  memcpy(&tx_extra[start_pos], bridge_source_address.data(), bridge_source_address.size());
620  return true;
621  }
#define TX_EXTRA_TAG_BRIDGE_SOURCE_ADDRESS
Definition: tx_extra.h:43
unsigned char uint8_t
Definition: stdint.h:124
void * memcpy(void *a, const void *b, size_t c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_extra_nonce_to_tx_extra()

bool cryptonote::add_extra_nonce_to_tx_extra ( std::vector< uint8_t > &  tx_extra,
const blobdata extra_nonce 
)

Definition at line 591 of file cryptonote_format_utils.cpp.

592  {
593  CHECK_AND_ASSERT_MES(extra_nonce.size() <= TX_EXTRA_NONCE_MAX_COUNT, false, "extra nonce could be 255 bytes max");
594  size_t start_pos = tx_extra.size();
595  tx_extra.resize(tx_extra.size() + 2 + extra_nonce.size());
596  //write tag
597  tx_extra[start_pos] = TX_EXTRA_NONCE;
598  //write len
599  ++start_pos;
600  tx_extra[start_pos] = static_cast<uint8_t>(extra_nonce.size());
601  //write data
602  ++start_pos;
603  memcpy(&tx_extra[start_pos], extra_nonce.data(), extra_nonce.size());
604  return true;
605  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
unsigned char uint8_t
Definition: stdint.h:124
#define TX_EXTRA_NONCE_MAX_COUNT
Definition: tx_extra.h:36
#define TX_EXTRA_NONCE
Definition: tx_extra.h:40
void * memcpy(void *a, const void *b, size_t c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_tx_pub_key_to_extra() [1/3]

bool cryptonote::add_tx_pub_key_to_extra ( transaction tx,
const crypto::public_key tx_pub_key 
)

Definition at line 539 of file cryptonote_format_utils.cpp.

540  {
541  return add_tx_pub_key_to_extra(tx.extra, tx_pub_key);
542  }
bool add_tx_pub_key_to_extra(std::vector< uint8_t > &tx_extra, const crypto::public_key &tx_pub_key)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_tx_pub_key_to_extra() [2/3]

bool cryptonote::add_tx_pub_key_to_extra ( transaction_prefix tx,
const crypto::public_key tx_pub_key 
)

Definition at line 544 of file cryptonote_format_utils.cpp.

545  {
546  return add_tx_pub_key_to_extra(tx.extra, tx_pub_key);
547  }
bool add_tx_pub_key_to_extra(std::vector< uint8_t > &tx_extra, const crypto::public_key &tx_pub_key)
Here is the call graph for this function:

◆ add_tx_pub_key_to_extra() [3/3]

bool cryptonote::add_tx_pub_key_to_extra ( std::vector< uint8_t > &  tx_extra,
const crypto::public_key tx_pub_key 
)

Definition at line 549 of file cryptonote_format_utils.cpp.

550  {
551  tx_extra.resize(tx_extra.size() + 1 + sizeof(crypto::public_key));
552  tx_extra[tx_extra.size() - 1 - sizeof(crypto::public_key)] = TX_EXTRA_TAG_PUBKEY;
553  *reinterpret_cast<crypto::public_key*>(&tx_extra[tx_extra.size() - sizeof(crypto::public_key)]) = tx_pub_key;
554  return true;
555  }
POD_CLASS public_key
Definition: crypto.h:76
#define TX_EXTRA_TAG_PUBKEY
Definition: tx_extra.h:39
Here is the caller graph for this function:

◆ block_to_blob() [1/2]

blobdata cryptonote::block_to_blob ( const block b)

Definition at line 1270 of file cryptonote_format_utils.cpp.

1271  {
1273  }
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ block_to_blob() [2/2]

bool cryptonote::block_to_blob ( const block b,
blobdata b_blob 
)

Definition at line 1275 of file cryptonote_format_utils.cpp.

1276  {
1277  return t_serializable_object_to_blob(b, b_blob);
1278  }
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
Here is the call graph for this function:

◆ blockchain_db_types()

std::string cryptonote::blockchain_db_types ( const std::string &  sep)

Definition at line 71 of file blockchain_db.cpp.

72 {
73  int i;
74  std::string ret = "";
75  for (i=0; db_types[i]; i++)
76  {
77  if (i)
78  ret += sep;
79  ret += db_types[i];
80  }
81  return ret;
82 }
::std::string string
Definition: gtest-port.h:1097
Here is the caller graph for this function:

◆ blockchain_valid_db_type()

bool cryptonote::blockchain_valid_db_type ( const std::string &  db_type)

Definition at line 60 of file blockchain_db.cpp.

61 {
62  int i;
63  for (i=0; db_types[i]; i++)
64  {
65  if (db_types[i] == db_type)
66  return true;
67  }
68  return false;
69 }
Here is the caller graph for this function:

◆ calculate_block_hash()

bool cryptonote::calculate_block_hash ( const block b,
crypto::hash res,
const blobdata blob 
)

Definition at line 1174 of file cryptonote_format_utils.cpp.

1175  {
1177  }
const char * res
Definition: hmac_keccak.cpp:41
bool get_object_hash(const t_object &o, crypto::hash &res)
blobdata get_block_hashing_blob(const block &b)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_multisig_keys()

std::vector< crypto::secret_key > cryptonote::calculate_multisig_keys ( const std::vector< crypto::public_key > &  derivations)

calculate_multisig_keys. Calculates secret multisig keys from others' participants ones as follows: mi = H(Mi)

Parameters
derivations- others' participants public multisig keys.
Returns
vector of current wallet's multisig secret keys

Definition at line 111 of file multisig.cpp.

112  {
113  std::vector<crypto::secret_key> multisig_keys;
114  multisig_keys.reserve(derivations.size());
115 
116  for (const auto &k: derivations)
117  {
118  multisig_keys.emplace_back(get_multisig_blinded_secret_key(rct::rct2sk(rct::pk2rct(k))));
119  }
120 
121  return multisig_keys;
122  }
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
Definition: multisig.cpp:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_multisig_signer_key()

crypto::secret_key cryptonote::calculate_multisig_signer_key ( const std::vector< crypto::secret_key > &  multisig_keys)

Definition at line 100 of file multisig.cpp.

101  {
103  for (const auto &k: multisig_keys)
104  {
105  sc_add(secret_key.bytes, secret_key.bytes, (const unsigned char*)k.data);
106  }
107 
108  return rct::rct2sk(secret_key);
109  }
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:82
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
key zero()
Definition: rctOps.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_transaction_hash()

bool cryptonote::calculate_transaction_hash ( const transaction t,
crypto::hash res,
size_t *  blob_size 
)

Definition at line 1076 of file cryptonote_format_utils.cpp.

1077  {
1078  // v1 transactions hash the entire blob
1079  if (t.version == 1)
1080  {
1081  size_t ignored_blob_size, &blob_size_ref = blob_size ? *blob_size : ignored_blob_size;
1082  return get_object_hash(t, res, blob_size_ref);
1083  }
1084 
1085  // v2 transactions hash different parts together, than hash the set of those hashes
1086  crypto::hash hashes[3];
1087 
1088  // prefix
1090 
1091  const blobdata blob = tx_to_blob(t);
1092  const unsigned int unprunable_size = t.unprunable_size;
1093  const unsigned int prefix_size = t.prefix_size;
1094 
1095  // base rct
1096  CHECK_AND_ASSERT_MES(prefix_size <= unprunable_size && unprunable_size <= blob.size(), false, "Inconsistent transaction prefix, unprunable and blob sizes");
1097  cryptonote::get_blob_hash(epee::span<const char>(blob.data() + prefix_size, unprunable_size - prefix_size), hashes[1]);
1098 
1099  // prunable rct
1100  if (t.rct_signatures.type == rct::RCTTypeNull)
1101  {
1102  hashes[2] = crypto::null_hash;
1103  }
1104  else
1105  {
1106  CHECK_AND_ASSERT_MES(calculate_transaction_prunable_hash(t, &blob, hashes[2]), false, "Failed to get tx prunable hash");
1107  }
1108 
1109  // the tx hash is the hash of the 3 hashes
1110  res = cn_fast_hash(hashes, sizeof(hashes));
1111 
1112  // we still need the size
1113  if (blob_size)
1114  {
1115  if (!t.is_blob_size_valid())
1116  {
1117  t.blob_size = blob.size();
1118  t.set_blob_size_valid(true);
1119  }
1120  *blob_size = t.blob_size;
1121  }
1122 
1123  return true;
1124  }
const char * res
Definition: hmac_keccak.cpp:41
crypto::hash get_transaction_prefix_hash(const transaction_prefix &tx)
void get_blob_hash(const epee::span< const char > &blob, crypto::hash &res)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
Non-owning sequence of data. Does not deep copy.
Definition: span.h:56
bool get_object_hash(const t_object &o, crypto::hash &res)
struct hash_func hashes[]
bool calculate_transaction_prunable_hash(const transaction &t, const cryptonote::blobdata *blob, crypto::hash &res)
void cn_fast_hash(const void *data, size_t length, char *hash)
bool tx_to_blob(const transaction &tx, blobdata &b_blob)
std::string blobdata
Definition: blobdatatype.h:39
POD_CLASS hash
Definition: hash.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculate_transaction_prunable_hash()

bool cryptonote::calculate_transaction_prunable_hash ( const transaction t,
const cryptonote::blobdata blob,
crypto::hash res 
)

Definition at line 1009 of file cryptonote_format_utils.cpp.

1010  {
1011  if (t.version == 1)
1012  return false;
1013  const unsigned int unprunable_size = t.unprunable_size;
1014  if (blob && unprunable_size)
1015  {
1016  CHECK_AND_ASSERT_MES(unprunable_size <= blob->size(), false, "Inconsistent transaction unprunable and blob sizes");
1017  cryptonote::get_blob_hash(epee::span<const char>(blob->data() + unprunable_size, blob->size() - unprunable_size), res);
1018  }
1019  else
1020  {
1021  transaction &tt = const_cast<transaction&>(t);
1022  std::stringstream ss;
1023  binary_archive<true> ba(ss);
1024  const size_t inputs = t.vin.size();
1025  const size_t outputs = t.vout.size();
1026  const size_t mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
1027  bool r = tt.rct_signatures.p.serialize_rctsig_prunable(ba, t.rct_signatures.type, inputs, outputs, mixin);
1028  CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures prunable");
1029  cryptonote::get_blob_hash(ss.str(), res);
1030  }
1031  return true;
1032  }
const char * res
Definition: hmac_keccak.cpp:41
void get_blob_hash(const epee::span< const char > &blob, crypto::hash &res)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
Non-owning sequence of data. Does not deep copy.
Definition: span.h:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_etn_overflow()

bool cryptonote::check_etn_overflow ( const transaction tx)

Definition at line 787 of file cryptonote_format_utils.cpp.

788  {
789  return check_inputs_overflow(tx) && check_outs_overflow(tx);
790  }
bool check_outs_overflow(const transaction &tx)
bool check_inputs_overflow(const transaction &tx)
Here is the call graph for this function:

◆ check_hash()

bool cryptonote::check_hash ( const crypto::hash hash,
difficulty_type  difficulty 
)

Definition at line 203 of file difficulty.cpp.

203  {
204  if (difficulty <= max64bit) // if can convert to small difficulty - do it
205  return check_hash_64(hash, difficulty.convert_to<std::uint64_t>());
206  else
207  return check_hash_128(hash, difficulty);
208  }
const difficulty_type max64bit(std::numeric_limits< std::uint64_t >::max())
unsigned __int64 uint64_t
Definition: stdint.h:136
bool check_hash_64(const crypto::hash &hash, uint64_t difficulty)
checks if a hash fits the given difficulty
Definition: difficulty.cpp:106
POD_CLASS hash
Definition: hash.h:50
bool check_hash_128(const crypto::hash &hash, difficulty_type difficulty)
Definition: difficulty.cpp:184
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_hash_128()

bool cryptonote::check_hash_128 ( const crypto::hash hash,
difficulty_type  difficulty 
)

Definition at line 184 of file difficulty.cpp.

184  {
185 #ifndef FORCE_FULL_128_BITS
186  // fast check
187  if (difficulty >= max64bit && ((const uint64_t *) &hash)[3] > 0)
188  return false;
189 #endif
190  // usual slow check
191  boost::multiprecision::uint512_t hashVal = 0;
192 #ifdef FORCE_FULL_128_BITS
193  for(int i = 0; i < 4; i++) { // highest word is zero
194 #else
195  for(int i = 1; i < 4; i++) { // highest word is zero
196 #endif
197  hashVal <<= 64;
198  hashVal |= swap64le(((const uint64_t *) &hash)[3 - i]);
199  }
200  return hashVal * difficulty <= max256bit;
201  }
const difficulty_type max64bit(std::numeric_limits< std::uint64_t >::max())
#define swap64le
Definition: int-util.h:254
const boost::multiprecision::uint512_t max256bit(std::numeric_limits< boost::multiprecision::uint256_t >::max())
unsigned __int64 uint64_t
Definition: stdint.h:136
POD_CLASS hash
Definition: hash.h:50
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_hash_64()

bool cryptonote::check_hash_64 ( const crypto::hash hash,
uint64_t  difficulty 
)

checks if a hash fits the given difficulty

The hash passes if (hash * difficulty) < 2^256. Phrased differently, if (hash * difficulty) fits without overflow into the least significant 256 bits of the 320 bit multiplication result.

Parameters
hashthe hash to check
difficultythe difficulty to check against
Returns
true if valid, else false

Definition at line 106 of file difficulty.cpp.

106  {
107  uint64_t low, high, top, cur;
108  // First check the highest word, this will most likely fail for a random hash.
109  mul(swap64le(((const uint64_t *) &hash)[3]), difficulty, top, high);
110  if (high != 0) {
111  return false;
112  }
113  mul(swap64le(((const uint64_t *) &hash)[0]), difficulty, low, cur);
114  mul(swap64le(((const uint64_t *) &hash)[1]), difficulty, low, high);
115  bool carry = cadd(cur, low);
116  cur = high;
117  mul(swap64le(((const uint64_t *) &hash)[2]), difficulty, low, high);
118  carry = cadc(cur, low, carry);
119  carry = cadc(high, top, carry);
120  return !carry;
121  }
#define swap64le
Definition: int-util.h:254
unsigned __int64 uint64_t
Definition: stdint.h:136
POD_CLASS hash
Definition: hash.h:50
Here is the caller graph for this function:

◆ check_inputs_overflow()

bool cryptonote::check_inputs_overflow ( const transaction tx)

Definition at line 792 of file cryptonote_format_utils.cpp.

793  {
794  uint64_t etn = 0;
795  if(tx.version >= 3)
796  {
797  for(const auto& in: tx.vin)
798  {
799  CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key_public, tokey_in, false);
800  if(etn > tokey_in.amount + etn)
801  return false;
802  etn += tokey_in.amount;
803  }
804  return true;
805  }
806 
807  for(const auto& in: tx.vin)
808  {
809  CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
810  if(etn > tokey_in.amount + etn)
811  return false;
812  etn += tokey_in.amount;
813  }
814  return true;
815  }
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val)
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ check_inputs_types_supported()

bool cryptonote::check_inputs_types_supported ( const transaction tx)

Definition at line 735 of file cryptonote_format_utils.cpp.

736  {
737  for(const auto& in: tx.vin)
738  {
739  if (tx.version == 1 || tx.version == 2)
740  {
741  CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key), false, "wrong variant type: "
742  << in.type().name() << ", expected " << typeid(txin_to_key).name()
743  << ", in transaction id=" << get_transaction_hash(tx));
744  }
745  else //tx.version >= 3 (public transactions: can spend only new inputs)
746  {
747  CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key_public), false, "wrong variant type: "
748  << in.type().name() << ", expected " << typeid(txin_to_key_public).name()
749  << ", in transaction id=" << get_transaction_hash(tx));
750  }
751  }
752  return true;
753  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
const char * name
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_outs_overflow()

bool cryptonote::check_outs_overflow ( const transaction tx)

Definition at line 817 of file cryptonote_format_utils.cpp.

818  {
819  uint64_t etn = 0;
820  for(const auto& o: tx.vout)
821  {
822  if(etn > o.amount + etn)
823  return false;
824  etn += o.amount;
825  }
826  return true;
827  }
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ check_outs_valid()

bool cryptonote::check_outs_valid ( const transaction tx)

Definition at line 755 of file cryptonote_format_utils.cpp.

756  {
757  for(const tx_out& out: tx.vout)
758  {
759  if (tx.version == 1)
760  {
761  CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key), false, "wrong variant type: "
762  << out.target.type().name() << ", expected " << typeid(txout_to_key).name()
763  << ", in transaction id=" << get_transaction_hash(tx));
764 
765  CHECK_AND_NO_ASSERT_MES(0 < out.amount, false, "zero amount output in transaction id=" << get_transaction_hash(tx));
766 
767  if(!check_key(boost::get<txout_to_key>(out.target).key))
768  return false;
769  }
770  else //tx.version >= 2 (public transactions: only new public outputs are allowed)
771  {
772  CHECK_AND_ASSERT_MES(out.target.type() == typeid(txout_to_key_public), false, "wrong variant type: "
773  << out.target.type().name() << ", expected " << typeid(txout_to_key_public).name()
774  << ", in transaction id=" << get_transaction_hash(tx));
775 
776  CHECK_AND_NO_ASSERT_MES(0 < out.amount, false, "zero amount output in transaction id=" << get_transaction_hash(tx));
777 
778  if(!check_key(boost::get<txout_to_key_public>(out.target).address.m_spend_public_key) ||
779  !check_key(boost::get<txout_to_key_public>(out.target).address.m_view_public_key))
780  return false;
781  }
782 
783  }
784  return true;
785  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
#define CHECK_AND_NO_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:189
const char * name
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
bool check_key(const public_key &key)
Definition: crypto.h:256
Here is the call graph for this function:
Here is the caller graph for this function:

◆ classify_addresses()

void cryptonote::classify_addresses ( const std::vector< tx_destination_entry > &  destinations,
const boost::optional< cryptonote::account_public_address > &  change_addr,
size_t &  num_stdaddresses,
size_t &  num_subaddresses,
account_public_address single_dest_subaddress 
)

Definition at line 55 of file cryptonote_tx_utils.cpp.

56  {
57  num_stdaddresses = 0;
58  num_subaddresses = 0;
59  std::unordered_set<cryptonote::account_public_address> unique_dst_addresses;
60  for(const tx_destination_entry& dst_entr: destinations)
61  {
62  if (change_addr && dst_entr.addr == change_addr)
63  continue;
64  if (unique_dst_addresses.count(dst_entr.addr) == 0)
65  {
66  unique_dst_addresses.insert(dst_entr.addr);
67  if (dst_entr.is_subaddress)
68  {
69  ++num_subaddresses;
70  single_dest_subaddress = dst_entr.addr;
71  }
72  else
73  {
74  ++num_stdaddresses;
75  }
76  }
77  }
78  LOG_PRINT_L2("destinations include " << num_stdaddresses << " standard addresses and " << num_subaddresses << " subaddresses");
79  }
#define LOG_PRINT_L2(x)
Definition: misc_log_ex.h:101
Here is the caller graph for this function:

◆ construct_miner_tx()

bool cryptonote::construct_miner_tx ( size_t  height,
size_t  median_weight,
uint64_t  already_generated_coins,
size_t  current_block_weight,
uint64_t  fee,
const account_public_address miner_address,
transaction tx,
const blobdata extra_nonce,
size_t  max_outs,
uint8_t  hard_fork_version,
network_type  nettype 
)

Definition at line 81 of file cryptonote_tx_utils.cpp.

81  {
82  tx.vin.clear();
83  tx.vout.clear();
84  tx.extra.clear();
85 
86  txin_gen in;
87  in.height = height;
88 
89  uint64_t block_reward;
90  if(!get_block_reward(median_weight, current_block_weight, already_generated_coins, block_reward, hard_fork_version, height, nettype))
91  {
92  LOG_PRINT_L0("Block is too big");
93  return false;
94  }
95 
96 #if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
97  LOG_PRINT_L1("Creating block template: reward " << block_reward <<
98  ", fee " << fee);
99 #endif
100  block_reward += fee;
101 
102  // from hard fork 2, we cut out the low significant digits. This makes the tx smaller, and
103  // keeps the paid amount almost the same. The unpaid remainder gets pushed back to the
104  // emission schedule
105  // from hard fork 4, we use a single "dusty" output. This makes the tx even smaller,
106  // and avoids the quantization. These outputs will be added as rct outputs with identity
107  // masks, to they can be used as rct inputs.
108  if (hard_fork_version >= 2 && hard_fork_version < 4) {
109  block_reward = block_reward - block_reward % ::config::BASE_REWARD_CLAMP_THRESHOLD;
110  }
111 
112  std::vector<uint64_t> out_amounts;
113  decompose_amount_into_digits(block_reward, hard_fork_version >= 2 ? 0 : ::config::DEFAULT_DUST_THRESHOLD,
114  [&out_amounts](uint64_t a_chunk) { out_amounts.push_back(a_chunk); },
115  [&out_amounts](uint64_t a_dust) { out_amounts.push_back(a_dust); });
116 
117  CHECK_AND_ASSERT_MES(1 <= max_outs, false, "max_out must be non-zero");
118  if (height == 0 || hard_fork_version >= 4)
119  {
120  // the genesis block was not decomposed, for unknown reasons
121  while (max_outs < out_amounts.size())
122  {
123  //out_amounts[out_amounts.size() - 2] += out_amounts.back();
124  //out_amounts.resize(out_amounts.size() - 1);
125  out_amounts[1] += out_amounts[0];
126  for (size_t n = 1; n < out_amounts.size(); ++n)
127  out_amounts[n - 1] = out_amounts[n];
128  out_amounts.pop_back();
129  }
130  }
131  else
132  {
133  CHECK_AND_ASSERT_MES(max_outs >= out_amounts.size(), false, "max_out exceeded");
134  }
135 
136  uint64_t summary_amounts = 0;
137  if (hard_fork_version >= HF_VERSION_PUBLIC_TX)
138  {
139  for (const auto out_amount : out_amounts)
140  {
141  txout_to_key_public tk;
142  tk.address.m_view_public_key = miner_address.m_view_public_key;
143  tk.address.m_spend_public_key = miner_address.m_spend_public_key;
144  tk.m_address_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
145 
146  tx_out out;
147  summary_amounts += out.amount = out_amount;
148  out.target = tk;
149  tx.vout.push_back(out);
150  }
151 
152  tx.version = 3;
153  }
154  else
155  {
156  keypair txkey = keypair::generate(hw::get_device("default"));
157  add_tx_pub_key_to_extra(tx, txkey.pub);
158  if(!extra_nonce.empty())
159  if(!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
160  return false;
161  if (!sort_tx_extra(tx.extra, tx.extra))
162  return false;
163 
164  for (size_t no = 0; no < out_amounts.size(); no++)
165  {
166  crypto::key_derivation derivation = AUTO_VAL_INIT(derivation);;
167  crypto::public_key out_eph_public_key = AUTO_VAL_INIT(out_eph_public_key);
168  bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation);
169  CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")");
170 
171  r = crypto::derive_public_key(derivation, no, miner_address.m_spend_public_key, out_eph_public_key);
172  CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << no << ", "<< miner_address.m_spend_public_key << ")");
173 
174  txout_to_key tk;
175  tk.key = out_eph_public_key;
176 
177  tx_out out;
178  summary_amounts += out.amount = out_amounts[no];
179  out.target = tk;
180  tx.vout.push_back(out);
181  }
182 
183  tx.version = 1;
184  }
185 
186 
187  CHECK_AND_ASSERT_MES(summary_amounts == block_reward, false, "Failed to construct miner tx, summary_amounts = " << summary_amounts << " not equal block_reward = " << block_reward);
188 
189  //lock
190  tx.unlock_time = height + (hard_fork_version > 7 ? ETN_MINED_ETN_UNLOCK_WINDOW_V8 : CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW);
191  tx.vin.push_back(in);
192 
193  tx.invalidate_hashes();
194 
195  //LOG_PRINT("MINER_TX generated ok, block_reward=" << print_etn(block_reward) << "(" << print_etn(block_reward - fee) << "+" << print_etn(fee)
196  // << "), current_block_size=" << current_block_size << ", already_generated_coins=" << already_generated_coins << ", tx_id=" << get_transaction_hash(tx), LOG_LEVEL_2);
197  return true;
198  }
#define CRYPTONOTE_MINED_ETN_UNLOCK_WINDOW
const config_t & get_config(network_type nettype)
std::vector< std::string > keypair
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX
POD_CLASS key_derivation
Definition: crypto.h:98
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
void decompose_amount_into_digits(uint64_t amount, uint64_t dust_threshold, const chunk_handler_t &chunk_handler, const dust_handler_t &dust_handler)
uint64_t height
Definition: blockchain.cpp:91
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation)
Definition: crypto.h:272
#define ETN_MINED_ETN_UNLOCK_WINDOW_V8
bool add_tx_pub_key_to_extra(transaction &tx, const crypto::public_key &tx_pub_key)
device & get_device(const std::string &device_descriptor)
Definition: device.cpp:95
unsigned __int64 uint64_t
Definition: stdint.h:136
POD_CLASS public_key
Definition: crypto.h:76
uint64_t const BASE_REWARD_CLAMP_THRESHOLD
uint64_t const DEFAULT_DUST_THRESHOLD
bool sort_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< uint8_t > &sorted_tx_extra, bool allow_partial)
bool derive_public_key(const key_derivation &derivation, std::size_t output_index, const public_key &base, public_key &derived_key)
Definition: crypto.h:275
#define HF_VERSION_PUBLIC_TX
bool add_extra_nonce_to_tx_extra(std::vector< uint8_t > &tx_extra, const blobdata &extra_nonce)
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, uint64_t current_block_height, network_type nettype)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_tx()

bool cryptonote::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 
)

Definition at line 684 of file cryptonote_tx_utils.cpp.

685  {
686  std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
687  subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0,0};
688  crypto::secret_key tx_key;
689  std::vector<crypto::secret_key> additional_tx_keys;
690  std::vector<tx_destination_entry> destinations_copy = destinations;
691  return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, false, { rct::RangeProofBorromean, 0}, NULL);
692  }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_tx_and_get_tx_key()

bool cryptonote::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 
)

Definition at line 656 of file cryptonote_tx_utils.cpp.

657  {
658  hw::device &hwdev = sender_account_keys.get_device();
659  hwdev.open_tx(tx_key);
660  try {
661  // figure out if we need to make additional tx pubkeys
662  size_t num_stdaddresses = 0;
663  size_t num_subaddresses = 0;
664  account_public_address single_dest_subaddress;
665  classify_addresses(destinations, change_addr, num_stdaddresses, num_subaddresses, single_dest_subaddress);
666  bool need_additional_txkeys = num_subaddresses > 0 && (num_stdaddresses > 0 || num_subaddresses > 1);
667  if (need_additional_txkeys)
668  {
669  additional_tx_keys.clear();
670  for (const auto &d: destinations)
671  additional_tx_keys.push_back(keypair::generate(sender_account_keys.get_device()).sec);
672  }
673 
674  bool r = construct_tx_with_tx_key(sender_account_keys, subaddresses, sources, destinations, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, rct, rct_config, msout, true, account_major_offset, nettype);
675  hwdev.close_tx();
676  return r;
677  } catch(...) {
678  hwdev.close_tx();
679  throw;
680  }
681  }
bool construct_tx_with_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, const crypto::secret_key &tx_key, const std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, bool shuffle_outs, const uint32_t account_major_offset, const cryptonote::network_type nettype)
virtual bool open_tx(crypto::secret_key &tx_key)=0
void classify_addresses(const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, size_t &num_stdaddresses, size_t &num_subaddresses, account_public_address &single_dest_subaddress)
virtual bool close_tx(void)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ construct_tx_with_tx_key()

bool cryptonote::construct_tx_with_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,
const crypto::secret_key tx_key,
const std::vector< crypto::secret_key > &  additional_tx_keys,
bool  rct,
const rct::RCTConfig rct_config,
rct::multisig_out msout,
bool  shuffle_outs,
const uint32_t  account_major_offset,
const cryptonote::network_type  nettype 
)

Definition at line 222 of file cryptonote_tx_utils.cpp.

223  {
224  hw::device &hwdev = sender_account_keys.get_device();
225 
226  if (sources.empty())
227  {
228  LOG_ERROR("Empty sources");
229  return false;
230  }
231 
232  std::vector<rct::key> amount_keys;
233  //test tx is sent through this scope TWICE, once as a test and once for real... therefore we set null before each run.
234  tx.set_null_besides_version();
235 
236  amount_keys.clear();
237  if (msout)
238  {
239  msout->c.clear();
240  }
241 
242  tx.unlock_time = unlock_time;
243 
244  tx.extra = extra;
245  crypto::public_key txkey_pub;
246 
247  // if we have a stealth payment id, find it and encrypt it with the tx key now
248  std::vector<tx_extra_field> tx_extra_fields;
249  if (parse_tx_extra(tx.extra, tx_extra_fields))
250  {
251  // IS TX GOING TO THE SMARTCHAIN BRIDGE? IF SO ADD THE ETN ADDRESS AND NEW SMARTCHAIN ADDRESS TO TX EXTRA:
252  // Portal address is derived from the genesis block hash of the mainnet so nobody knows the private key.
253  cryptonote::account_public_address portal_address;
254  crypto::hash h;
255  crypto::ec_point point;
256  if(nettype == MAINNET){
257  epee::string_tools::hex_to_pod("a2050dacd6a36b6fc71cd6447ee498fb2c42801b74e8fe921213f4fcbd95ddcc", h); // v9 fork
258  }else{
259  epee::string_tools::hex_to_pod("1c5da5c1e1420653825260b8ffc85499fdfb6457153a7df9720e659075b3ce76", h); // genesis hash hex ---> hash type --
260  }
261  crypto::hash_to_point(h, point); // generate curve point (burn address spendkey) deterministically in such a way that we can't recover the private key
262  crypto::public_key portal_address_spendkey;
263  std::copy(std::begin(point.data), std::end(point.data), std::begin(portal_address_spendkey.data)); // serialise point to pubkey type
264  std::string portal_address_spendkey_hex_str = epee::string_tools::pod_to_hex(portal_address_spendkey); // for testing only. pub spend =
265  std::string portal_address_viewkey_hex_str;
266  if(nettype == MAINNET){
267  portal_address_viewkey_hex_str = "2b95a2eb2c62253c57e82b082b850bbf22a1a7829aaea09c7c1511c1cced4375"; //private view is just e5c8af002654f38ec39ac80edbbcd0c03c9b483379d297af0c3ca15568c7300e -
268  }else{
269  portal_address_viewkey_hex_str = "5866666666666666666666666666666666666666666666666666666666666666"; //private view is just 0100000000000000000000000000000000000000000000000000000000000000 -
270  }
271  portal_address.m_spend_public_key = portal_address_spendkey;
272  epee::string_tools::hex_to_pod(portal_address_viewkey_hex_str, portal_address.m_view_public_key);
273  cryptonote::account_public_address dest_address = destinations[0].addr;
274 
275  // Grab the full etnk.... address as a string, which we serialise to the extra as bytestring
276  // Also use secp256k1 library to take their electroneum private key (which will become their smartchain private key)
277  // and use it to create a secp256k1 public key... Then use the public key to
278  // generate their smartchain address 0xABC1D........ and put this in the tx extra in the same fashion
279  // NB the curve private key domain of ed25519 is a subset of that of secp256k1, and therefore no extra modulo
280  // operation is needed before generating the smartchain public key.
281  // This code uses generates an Ethereum address by taking the last 20 bytes of the Keccak-256 hash of the public key
282  // and adding the prefix "0x".
283  if(dest_address == portal_address){
284  LOG_PRINT_L1("Sending a migration transaction:");
285  crypto::secret_key k = sender_account_keys.m_spend_secret_key; // example private key (can hardcode): 5810ba5a47a45a256458dffe9be21b341a7d74c0b9a8b6a232c60474acbed203
286  std::string seckeystring = epee::string_tools::pod_to_hex(sender_account_keys.m_spend_secret_key); //debug purposes
287 
288  // SOURCE ADDRESS
289  std::string bridge_source_address = cryptonote::get_account_address_as_str(nettype, false, sender_account_keys.m_account_address); //OK
290  add_bridge_source_address_to_tx_extra(tx.extra, bridge_source_address); //OK
291  LOG_PRINT_L1("Source address: " << bridge_source_address);
292 
293  // SMARTCHAIN ADDRESS
294  unsigned char seckey1[32];
295  unsigned char public_key64[65];
296  size_t pk_len = 65;
297  secp256k1_pubkey pubkey1;
299  memcpy(seckey1, sender_account_keys.m_spend_secret_key.data, 32);
300  if(secp256k1_ec_seckey_verify(ctx, seckey1) == 0) { // sec key has an unrealistic chance of being invalid (10^-128) https://en.bitcoin.it/wiki/Private_key
301  LOG_ERROR("Invalid private key");
302  return false;
303  }
304 
305  // create the pubkey and serialise it
306  if(secp256k1_ec_pubkey_create(ctx, &pubkey1, seckey1) == 0) { // this format is not sufficient for hashing, hence serialisation
307  LOG_ERROR("Failed to create secp256k1 public key");
308  return false;
309  }
310  secp256k1_ec_pubkey_serialize(ctx, public_key64, &pk_len, &pubkey1, SECP256K1_EC_UNCOMPRESSED); // serialise pubkey1 into publickey_64
311  std::string long_public_key2 = epee::string_tools::pod_to_hex(public_key64); // debug purposes - can check against https://lab.miguelmota.com/ethereum-private-key-to-public-key/example/
312 
313  // Ethereum address generation: Take the last 20 bytes of the Keccak-256 hash of the public key
314  // keccak-1600() is not suitable, but keccak() with 24 rounds and mdlen (=size) of 32 is the same
315  // as keccak-256 with a 32 byte output. 24 rounds is the default in Monero for keccak()
316  // the first byte is the compression type so hash the 64 bytes after the first byte only
317  // I have put the 32 byte hash inside pubkey1.data just to save time
318  keccak(public_key64 + 1, 64, pubkey1.data, 32);
319  unsigned char address[20]; //smartchain address
320  memcpy(address, pubkey1.data + 12, 20); // take the last 20 bytes of the 32 byte array for the address
321  std::string hex_address = epee::string_tools::pod_to_hex(address); // should be 0x12ed7467c3852e6b2Bd3C22AF694be8DF7637B10.
322  std::string bridge_smartchain_address = "0x" + hex_address; //prefix address with 0x
323  LOG_PRINT_L1("Smartchain address: " << bridge_smartchain_address);
324 
326  add_bridge_smartchain_address_to_tx_extra(tx.extra, bridge_smartchain_address);
327  }
328 
329  bool add_dummy_payment_id = true;
330  tx_extra_nonce extra_nonce;
331  if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
332  {
333  crypto::hash payment_id = null_hash;
334  crypto::hash8 payment_id8 = null_hash8;
335  if (get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
336  {
337  LOG_PRINT_L2("Adding cleartext payment ID to extra nonce. Encrypted PIDs are now deprecated." << payment_id8);
338 
339  std::string extra_nonce;
340 
341  memcpy(payment_id.data, payment_id8.data, 8); // convert short pid to regular
342  memset(payment_id.data + 8, 0, 24); // merely a sanity check
343 
344  set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
345  remove_field_from_tx_extra(tx.extra, typeid(tx_extra_nonce));
346  if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
347  {
348  LOG_ERROR("Failed to add payment id to tx extra");
349  return false;
350  }
351  LOG_PRINT_L1("Encrypted payment ID: " << payment_id8);
352  add_dummy_payment_id = false;
353  }
354  else if (get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
355  {
356  add_dummy_payment_id = false;
357  }
358  }
359 
360  // we don't add one if we've got more than the usual 1 destination plus change
361  if (destinations.size() > 2)
362  add_dummy_payment_id = false;
363 
364  if (add_dummy_payment_id)
365  {
366  std::string extra_nonce;
367  crypto::hash payment_id = null_hash;
368 
369  set_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
370  if (!add_extra_nonce_to_tx_extra(tx.extra, extra_nonce))
371  {
372  LOG_ERROR("Failed to add dummy payment id to tx extra");
373  // continue anyway
374  }
375  }
376  }
377  else
378  {
379  MWARNING("Failed to parse tx extra");
380  tx_extra_fields.clear();
381  }
382 
383  struct input_generation_context_data
384  {
385  keypair in_ephemeral;
386  };
387  std::vector<input_generation_context_data> in_contexts;
388 
389  uint64_t summary_inputs_etn = 0;
390  //fill inputs
391  int idx = -1;
392 
393  if(tx.version < 3) {
394  for (const tx_source_entry &src_entr : sources) {
395  ++idx;
396  if (src_entr.real_output >= src_entr.outputs.size()) {//
397  LOG_ERROR("real_output index (" << src_entr.real_output << ")bigger than output_keys.size()="
398  << src_entr.outputs.size());
399  return false;
400  }
401  summary_inputs_etn += src_entr.amount;
402 
403  //key_derivation recv_derivation;
404  in_contexts.push_back(input_generation_context_data());
405  // Tx output private key which gets its value assigned inside generate_key_image_helper
406  keypair &in_ephemeral = in_contexts.back().in_ephemeral;
407  crypto::key_image img;//
408  const auto &out_key = reinterpret_cast<const crypto::public_key &>(src_entr.outputs[src_entr.real_output].second.dest);
409  if (!generate_key_image_helper(sender_account_keys, subaddresses, out_key, src_entr.real_out_tx_key,
410  src_entr.real_out_additional_tx_keys, src_entr.real_output_in_tx_index,
411  in_ephemeral, img, hwdev, account_major_offset)) {
412  LOG_ERROR("Key image generation failed!");
413  return false;
414  }
415 
416  //check that derivated key is equal with real output key (if non multisig)
417  if (!msout && !(in_ephemeral.pub == src_entr.outputs[src_entr.real_output].second.dest)) {
418  LOG_ERROR("derived public key mismatch with output public key at index "
419  << idx << ", real out "
420  << src_entr.real_output << "! "
421  << ENDL << "derived_key:"
422  << string_tools::pod_to_hex(in_ephemeral.pub)
423  << ENDL
424  << "real output_public_key:"
425  << string_tools::pod_to_hex(src_entr.outputs[src_entr.real_output].second.dest));
426 
427  LOG_ERROR("amount " << src_entr.amount << ", rct " << src_entr.rct);
428  LOG_ERROR("tx pubkey " << src_entr.real_out_tx_key << ", real_output_in_tx_index "
429  << src_entr.real_output_in_tx_index);
430  return false;
431  }
432 
433  //put key image into tx input
434  txin_to_key input_to_key;
435  input_to_key.amount = src_entr.amount;
436  input_to_key.k_image = msout ? rct::rct2ki(src_entr.multisig_kLRki.ki) : img;
437 
438  //fill outputs array and use relative offsets
439  for (const tx_source_entry::output_entry &out_entry: src_entr.outputs)
440  input_to_key.key_offsets.push_back(out_entry.first);
441 
442  input_to_key.key_offsets = absolute_output_offsets_to_relative(input_to_key.key_offsets);
443  tx.vin.push_back(input_to_key);
444  }
445 
446  // sort ins by their key image
447  std::vector<size_t> ins_order(sources.size());
448  for (size_t n = 0; n < sources.size(); ++n)
449  ins_order[n] = n;
450  std::sort(ins_order.begin(), ins_order.end(), [&](const size_t i0, const size_t i1) {
451  const txin_to_key &tk0 = boost::get<txin_to_key>(tx.vin[i0]);
452  const txin_to_key &tk1 = boost::get<txin_to_key>(tx.vin[i1]);
453  return memcmp(&tk0.k_image, &tk1.k_image, sizeof(tk0.k_image)) > 0;
454  });
455  tools::apply_permutation(ins_order, [&] (size_t i0, size_t i1) {
456  std::swap(tx.vin[i0], tx.vin[i1]);
457  std::swap(in_contexts[i0], in_contexts[i1]);
458  std::swap(sources[i0], sources[i1]);
459  });
460 
461  if (shuffle_outs)
462  {
463  std::shuffle(destinations.begin(), destinations.end(), std::default_random_engine(crypto::rand<unsigned int>()));
464  }
465  } else{ // tx v3 onwards
466  for (const tx_source_entry &src_entr : sources) {
467  ++idx;
468  summary_inputs_etn += src_entr.amount;
469 
470  txin_to_key_public input;
471  input.amount = src_entr.amount;
472  input.tx_hash = src_entr.tx_hash;
473  input.relative_offset = src_entr.real_output_in_tx_index;
474 
475  tx.vin.push_back(input);
476  }
477  } //END OF WORK WITH INPUTS
478 
479  // figure out if we need to make additional tx pubkeys
480  size_t num_stdaddresses = 0;
481  size_t num_subaddresses = 0;
482  account_public_address single_dest_subaddress;
483  classify_addresses(destinations, change_addr, num_stdaddresses, num_subaddresses, single_dest_subaddress);
484 
485  // if this is a single-destination transfer to a subaddress, we set the tx pubkey to R=s*D
486  //todo: 4.0.0.0
487  if (num_stdaddresses == 0 && num_subaddresses == 1)
488  {
489  txkey_pub = rct::rct2pk(hwdev.scalarmultKey(rct::pk2rct(single_dest_subaddress.m_spend_public_key), rct::sk2rct(tx_key)));
490  }
491  else
492  {
493  txkey_pub = rct::rct2pk(hwdev.scalarmultBase(rct::sk2rct(tx_key)));
494  }
495  remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));
496  add_tx_pub_key_to_extra(tx, txkey_pub);
497 
498  std::vector<crypto::public_key> additional_tx_public_keys;
499 
500  // we don't need to include additional tx keys if:
501  // - all the destinations are standard addresses
502  // - there's only one destination which is a subaddress
503  bool need_additional_txkeys = num_subaddresses > 0 && (num_stdaddresses > 0 || num_subaddresses > 1);
504  if (need_additional_txkeys)
505  CHECK_AND_ASSERT_MES(destinations.size() == additional_tx_keys.size(), false, "Wrong amount of additional tx keys");
506 
507  uint64_t summary_outs_etn = 0;
508  //fill outputs
509  size_t output_index = 0;
510  for (const tx_destination_entry &dst_entr: destinations) {
511  if(tx.version == 1) {
512  crypto::public_key out_eph_public_key;
513 
514  hwdev.generate_output_ephemeral_keys(tx.version, sender_account_keys, txkey_pub, tx_key,
515  dst_entr, change_addr, output_index,
516  need_additional_txkeys, additional_tx_keys,
517  additional_tx_public_keys, amount_keys, out_eph_public_key);
518 
519  tx_out out;
520  out.amount = dst_entr.amount;
521  txout_to_key tk;
522  tk.key = out_eph_public_key;
523  out.target = tk;
524  tx.vout.push_back(out);
525  output_index++;
526  summary_outs_etn += dst_entr.amount;
527  }else{
528  tx_out out;
529  out.amount = dst_entr.amount;
530  txout_to_key_public tkp;
531  tkp.address.m_view_public_key = dst_entr.addr.m_view_public_key;
532  tkp.address.m_spend_public_key = dst_entr.addr.m_spend_public_key;
533  tkp.m_address_prefix = dst_entr.is_subaddress ?
536  out.target = tkp;
537  tx.vout.push_back(out);
538  output_index++;
539  summary_outs_etn += dst_entr.amount;
540  }
541  }
542 
543  CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
544 
545  remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
546 
547  LOG_PRINT_L2("tx pubkey: " << txkey_pub);
548  if (need_additional_txkeys)
549  {
550  LOG_PRINT_L2("additional tx pubkeys: ");
551  for (size_t i = 0; i < additional_tx_public_keys.size(); ++i)
552  LOG_PRINT_L2(additional_tx_public_keys[i]);
553  add_additional_tx_pub_keys_to_extra(tx.extra, additional_tx_public_keys);
554  }
555 
556  if (!sort_tx_extra(tx.extra, tx.extra))
557  return false;
558 
559  //check etn
560  if(summary_outs_etn > summary_inputs_etn )
561  {
562  LOG_ERROR("Transaction inputs ETN ("<< summary_inputs_etn << ") less than outputs ETN (" << summary_outs_etn << ")");
563  return false;
564  }
565 
566  // check for watch only wallet
567  bool zero_secret_key = true;
568  for (size_t i = 0; i < sizeof(sender_account_keys.m_spend_secret_key); ++i)
569  zero_secret_key &= (sender_account_keys.m_spend_secret_key.data[i] == 0);
570  if (zero_secret_key)
571  {
572  MDEBUG("Null secret key, skipping signatures");
573  }
574 
575  //generate ring signatures
576  crypto::hash tx_prefix_hash;
577  hwdev.get_transaction_prefix_hash(tx, tx_prefix_hash);
578 
579  std::stringstream ss_ring_s;
580  size_t i = 0;
581 
582  if(tx.version < 3)
583  {
584  for(const tx_source_entry& src_entr: sources)
585  {
586  ss_ring_s << "pub_keys:" << ENDL;
587  std::vector<const crypto::public_key *> keys_ptrs;
588  std::vector<crypto::public_key> keys(src_entr.outputs.size());
589  size_t ii = 0;
590  for (const tx_source_entry::output_entry &o: src_entr.outputs) {
591  keys[ii] = rct2pk(o.second.dest);
592  keys_ptrs.push_back(&keys[ii]);
593  ss_ring_s << o.second.dest << ENDL;
594  ++ii;
595  }
596 
597  tx.signatures.push_back(std::vector<crypto::signature>());
598  std::vector<crypto::signature> &sigs = tx.signatures.back();
599  sigs.resize(src_entr.outputs.size());
600  if (!zero_secret_key)
601  hwdev.generate_ring_signature(tx_prefix_hash, boost::get<txin_to_key>(tx.vin[i]).k_image, keys_ptrs,
602  in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data());
603  ss_ring_s << "signatures:" << ENDL;
604  std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature &s) { ss_ring_s << s << ENDL; });
605  ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: "
606  << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL;
607  i++;
608 
609  MCINFO("construct_tx",
610  "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL
611  << ss_ring_s.str());
612  }
613  }
614  else
615  { //new public signatures for v3 onwards
616  for(uint64_t i = 0; i< tx.vin.size(); i++) {
618  std::vector<crypto::signature> signature_vec;
619  if (!zero_secret_key) {
620 
621  subaddress_index input_subaddress_index = sources[i].subaddr_index;
622  crypto::secret_key private_view_for_sig;
623  crypto::secret_key private_spend_for_sig;
624 
625  if (input_subaddress_index.major == 0 && input_subaddress_index.minor == 0) {
626  private_view_for_sig = sender_account_keys.m_view_secret_key;
627  private_spend_for_sig = sender_account_keys.m_spend_secret_key;
628  } else {
629  private_spend_for_sig = hwdev.get_subaddress_private_spendkey(sender_account_keys,
630  input_subaddress_index);
631  private_view_for_sig = hwdev.get_subaddress_private_viewkey(sender_account_keys.m_view_secret_key,
632  private_spend_for_sig);
633  }
634 
636  tx_prefix_hash,
637  i,
638  private_view_for_sig,
639  private_spend_for_sig,
640  signature
641  );
642  }
643  signature_vec.push_back(signature);
644  tx.signatures.push_back(signature_vec);
645  }
646 
647  MCINFO("construct_tx",
648  "transaction_created (v3): " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx));
649  }
650 
651  tx.invalidate_hashes();
652 
653  return true;
654  }
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
const config_t & get_config(network_type nettype)
virtual bool scalarmultKey(rct::key &aP, const rct::key &P, const rct::key &a)=0
POD_CLASS ec_point
Definition: crypto.h:70
#define LOG_PRINT_L2(x)
Definition: misc_log_ex.h:101
std::vector< std::string > keypair
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
void apply_permutation(std::vector< size_t > permutation, const F &swap)
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
virtual bool generate_input_signature(const crypto::hash &prefix_hash, const uint32_t input_index, const crypto::secret_key sec_view, const crypto::secret_key sec_spend, crypto::signature &signature)=0
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX
::std::string string
Definition: gtest-port.h:1097
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool add_bridge_smartchain_address_to_tx_extra(std::vector< uint8_t > &tx_extra, const blobdata &bridge_smartchain_address)
bool add_bridge_source_address_to_tx_extra(std::vector< uint8_t > &tx_extra, const blobdata &bridge_source_address)
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx) SECP256K1_ARG_NONNULL(1)
SECP256K1_API int secp256k1_ec_pubkey_serialize(const secp256k1_context *ctx, unsigned char *output, size_t *outputlen, const secp256k1_pubkey *pubkey, unsigned int flags) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
bool add_additional_tx_pub_keys_to_extra(std::vector< uint8_t > &tx_extra, const std::vector< crypto::public_key > &additional_pub_keys)
#define SECP256K1_CONTEXT_SIGN
Definition: secp256k1.h:207
uint64_t amount
Definition: chaingen.h:290
void copy(key &AA, const key &A)
Definition: rctOps.h:79
void hash_to_point(const crypto::hash &h, crypto::ec_point &res)
Definition: crypto.cpp:496
#define MDEBUG(x)
Definition: misc_log_ex.h:76
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_pubkey_create(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
#define SECP256K1_EC_UNCOMPRESSED
Definition: secp256k1.h:214
struct secp256k1_context_struct secp256k1_context
Definition: secp256k1.h:50
bool add_tx_pub_key_to_extra(transaction &tx, const crypto::public_key &tx_pub_key)
std::string pod_to_hex(const t_pod_type &s)
Definition: string_tools.h:317
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ec_seckey_verify(const secp256k1_context *ctx, const unsigned char *seckey) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
virtual crypto::secret_key get_subaddress_private_spendkey(const cryptonote::account_keys &keys, const cryptonote::subaddress_index &subaddr_index)=0
bool generate_key_image_helper(const account_keys &ack, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
std::vector< uint64_t > absolute_output_offsets_to_relative(const std::vector< uint64_t > &off)
std::string obj_to_json_str(T &obj)
unsigned __int64 uint64_t
Definition: stdint.h:136
virtual bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key, const cryptonote::tx_destination_entry &dst_entr, const boost::optional< cryptonote::account_public_address > &change_addr, const size_t output_index, const bool &need_additional_txkeys, const std::vector< crypto::secret_key > &additional_tx_keys, std::vector< crypto::public_key > &additional_tx_public_keys, std::vector< rct::key > &amount_keys, crypto::public_key &out_eph_public_key)=0
bool get_payment_id_from_tx_extra_nonce(const blobdata &extra_nonce, crypto::hash &payment_id)
bool hex_to_pod(const std::string &hex_str, t_pod_type &s)
Definition: string_tools.h:324
void classify_addresses(const std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, size_t &num_stdaddresses, size_t &num_subaddresses, account_public_address &single_dest_subaddress)
POD_CLASS public_key
Definition: crypto.h:76
#define MWARNING(x)
Definition: misc_log_ex.h:74
bool get_encrypted_payment_id_from_tx_extra_nonce(const blobdata &extra_nonce, crypto::hash8 &payment_id)
std::vector< key > c
Definition: rctTypes.h:112
unsigned char data[64]
Definition: secp256k1.h:75
POD_CLASS signature
Definition: crypto.h:108
POD_CLASS hash8
Definition: hash.h:53
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define ENDL
Definition: misc_log_ex.h:149
bool sort_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< uint8_t > &sorted_tx_extra, bool allow_partial)
virtual bool scalarmultBase(rct::key &aG, const rct::key &a)=0
POD_CLASS key_image
Definition: crypto.h:102
void * memcpy(void *a, const void *b, size_t c)
uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX
crypto::hash get_transaction_hash(const transaction &t)
bool remove_field_from_tx_extra(std::vector< uint8_t > &tx_extra, const std::type_info &type)
bool add_extra_nonce_to_tx_extra(std::vector< uint8_t > &tx_extra, const blobdata &extra_nonce)
void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
virtual bool get_transaction_prefix_hash(const cryptonote::transaction_prefix &tx, crypto::hash &tx_prefix_hash)=0
POD_CLASS hash
Definition: hash.h:50
const char * address
Definition: multisig.cpp:37
void set_payment_id_to_tx_extra_nonce(blobdata &extra_nonce, const crypto::hash &payment_id)
#define MCINFO(cat, x)
Definition: misc_log_ex.h:53
virtual bool generate_ring_signature(const crypto::hash &prefix_hash, const crypto::key_image &image, const std::vector< const crypto::public_key *> &pubs, const crypto::secret_key &sec, std::size_t sec_index, crypto::signature *sig)=0
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
virtual crypto::secret_key get_subaddress_private_viewkey(const crypto::secret_key &main_wallet_sec_view, crypto::secret_key &subaddress_sec_spend)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decompose_amount_into_digits()

template<typename chunk_handler_t , typename dust_handler_t >
void cryptonote::decompose_amount_into_digits ( uint64_t  amount,
uint64_t  dust_threshold,
const chunk_handler_t &  chunk_handler,
const dust_handler_t &  dust_handler 
)

Definition at line 211 of file cryptonote_format_utils.h.

212  {
213  if (0 == amount)
214  {
215  return;
216  }
217 
218  bool is_dust_handled = false;
219  uint64_t dust = 0;
220  uint64_t order = 1;
221  while (0 != amount)
222  {
223  uint64_t chunk = (amount % 10) * order;
224  amount /= 10;
225  order *= 10;
226 
227  if (dust + chunk <= dust_threshold)
228  {
229  dust += chunk;
230  }
231  else
232  {
233  if (!is_dust_handled && 0 != dust)
234  {
235  dust_handler(dust);
236  is_dust_handled = true;
237  }
238  if (0 != chunk)
239  {
240  chunk_handler(chunk);
241  }
242  }
243  }
244 
245  if (!is_dust_handled && 0 != dust)
246  {
247  dust_handler(dust);
248  }
249  }
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ decrypt_key()

crypto::secret_key cryptonote::decrypt_key ( crypto::secret_key  key,
const epee::wipeable_string passphrase 
)

Definition at line 1338 of file cryptonote_format_utils.cpp.

1339  {
1341  crypto::cn_slow_hash(passphrase.data(), passphrase.size(), hash);
1342  sc_sub((unsigned char*)key.data, (const unsigned char*)key.data, (const unsigned char*)hash.data);
1343  return key;
1344  }
size_t size() const noexcept
void sc_sub(unsigned char *, const unsigned char *, const unsigned char *)
const char * key
Definition: hmac_keccak.cpp:39
POD_CLASS hash
Definition: hash.h:50
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
const char * data() const noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ encrypt_key()

crypto::secret_key cryptonote::encrypt_key ( crypto::secret_key  key,
const epee::wipeable_string passphrase 
)

Definition at line 1330 of file cryptonote_format_utils.cpp.

1331  {
1333  crypto::cn_slow_hash(passphrase.data(), passphrase.size(), hash);
1334  sc_add((unsigned char*)key.data, (const unsigned char*)key.data, (const unsigned char*)hash.data);
1335  return key;
1336  }
size_t size() const noexcept
const char * key
Definition: hmac_keccak.cpp:39
POD_CLASS hash
Definition: hash.h:50
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
const char * data() const noexcept
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ expand_transaction_1()

bool cryptonote::expand_transaction_1 ( transaction tx,
bool  base_only 
)

Definition at line 128 of file cryptonote_format_utils.cpp.

129  {
130  return true;
131  }
Here is the caller graph for this function:

◆ factorial()

double cryptonote::factorial ( unsigned int  n)

Definition at line 1927 of file cryptonote_core.cpp.

1928  {
1929  if (n <= 1)
1930  return 1.0;
1931  double f = n;
1932  while (n-- > 1)
1933  f *= n;
1934  return f;
1935  }

◆ find_tx_extra_field_by_type()

template<typename T >
bool cryptonote::find_tx_extra_field_by_type ( const std::vector< tx_extra_field > &  tx_extra_fields,
T field,
size_t  index = 0 
)

Definition at line 62 of file cryptonote_format_utils.h.

63  {
64  auto it = std::find_if(tx_extra_fields.begin(), tx_extra_fields.end(), [&index](const tx_extra_field& f) { return typeid(T) == f.type() && !index--; }); // ie index only decremented IF we fiind the right type
65  if(tx_extra_fields.end() == it)
66  return false;
67 
68  field = boost::get<T>(*it);
69  return true;
70  }
const uint32_t T[512]
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:207
Here is the caller graph for this function:

◆ generate_genesis_block()

bool cryptonote::generate_genesis_block ( block bl,
std::string const &  genesis_tx,
uint32_t  nonce 
)

Definition at line 694 of file cryptonote_tx_utils.cpp.

699  {
700  //genesis block
701  bl = boost::value_initialized<block>();
702 
703 
704  account_public_address ac = boost::value_initialized<account_public_address>();
705  std::vector<size_t> sz;
706  construct_miner_tx(0, 0, 0, 0, 0, ac, bl.miner_tx); // zero fee in genesis
707  blobdata txb = tx_to_blob(bl.miner_tx);
708  std::string hex_tx_represent = string_tools::buff_to_hex_nodelimer(txb);
709 
710  std::string genesis_coinbase_tx_hex = genesis_tx;
711 
712  blobdata tx_bl;
713  bool r = string_tools::parse_hexstr_to_binbuff(genesis_tx, tx_bl);
714  CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
715  r = parse_and_validate_tx_from_blob(tx_bl, bl.miner_tx);
716  CHECK_AND_ASSERT_MES(r, false, "failed to parse coinbase tx from hard coded blob");
717  bl.major_version = CURRENT_BLOCK_MAJOR_VERSION;
718  bl.minor_version = CURRENT_BLOCK_MINOR_VERSION;
719  bl.timestamp = 0;
720  bl.nonce = nonce;
721  miner::find_nonce_for_given_block(bl, 1, 0);
722  bl.invalidate_hashes();
723  return true;
724  }
::std::string string
Definition: gtest-port.h:1097
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
blobdata tx_to_blob(const transaction &tx)
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
std::string blobdata
Definition: blobdatatype.h:39
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
#define CURRENT_BLOCK_MINOR_VERSION
bool construct_miner_tx(size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version, network_type nettype)
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
#define CURRENT_BLOCK_MAJOR_VERSION
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_key_image_helper()

bool cryptonote::generate_key_image_helper ( const account_keys ack,
const std::unordered_map< crypto::public_key, subaddress_index > &  subaddresses,
const crypto::public_key out_key,
const crypto::public_key tx_public_key,
const std::vector< crypto::public_key > &  additional_tx_public_keys,
size_t  real_output_index,
keypair in_ephemeral,
crypto::key_image ki,
hw::device hwdev,
const uint32_t  account_major_offset 
)

Definition at line 208 of file cryptonote_format_utils.cpp.

209  {
210  crypto::key_derivation recv_derivation = AUTO_VAL_INIT(recv_derivation);
211  bool r = hwdev.generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation);
212  if (!r)
213  {
214  MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")");
215  memcpy(&recv_derivation, rct::identity().bytes, sizeof(recv_derivation));
216  }
217 
218  std::vector<crypto::key_derivation> additional_recv_derivations;
219  for (size_t i = 0; i < additional_tx_public_keys.size(); ++i)
220  {
221  crypto::key_derivation additional_recv_derivation = AUTO_VAL_INIT(additional_recv_derivation);
222  r = hwdev.generate_key_derivation(additional_tx_public_keys[i], ack.m_view_secret_key, additional_recv_derivation);
223  if (!r)
224  {
225  MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", " << ack.m_view_secret_key << ")");
226  }
227  else
228  {
229  additional_recv_derivations.push_back(additional_recv_derivation);
230  }
231  }
232 
233  boost::optional<subaddress_receive_info> subaddr_recv_info = is_out_to_acc_precomp(subaddresses, out_key, recv_derivation, additional_recv_derivations, real_output_index,hwdev);
234  CHECK_AND_ASSERT_MES(subaddr_recv_info, false, "key image helper: given output pubkey doesn't seem to belong to this address");
235 
236  return generate_key_image_helper_precomp(ack, out_key, subaddr_recv_info->derivation, real_output_index, subaddr_recv_info->index, in_ephemeral, ki, hwdev, account_major_offset);
237  }
bool generate_key_image_helper_precomp(const account_keys &ack, const crypto::public_key &out_key, const crypto::key_derivation &recv_derivation, size_t real_output_index, const subaddress_index &received_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
POD_CLASS key_derivation
Definition: crypto.h:98
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
virtual bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation)=0
boost::optional< subaddress_receive_info > is_out_to_acc_precomp(const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::key_derivation &derivation, const std::vector< crypto::key_derivation > &additional_derivations, size_t output_index, hw::device &hwdev)
#define MWARNING(x)
Definition: misc_log_ex.h:74
key identity()
Definition: rctOps.h:73
void * memcpy(void *a, const void *b, size_t c)
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_key_image_helper_precomp()

bool cryptonote::generate_key_image_helper_precomp ( const account_keys ack,
const crypto::public_key out_key,
const crypto::key_derivation recv_derivation,
size_t  real_output_index,
const subaddress_index received_index,
keypair in_ephemeral,
crypto::key_image ki,
hw::device hwdev,
const uint32_t  account_major_offset 
)

Definition at line 239 of file cryptonote_format_utils.cpp.

240  {
241  uint32_t major_index_offset_based = received_index.major + (received_index.major != 0 ? account_major_offset : 0);
242  cryptonote::subaddress_index recv_index = {major_index_offset_based, received_index.minor};
243 
244  if (hwdev.compute_key_image(ack, out_key, recv_derivation, real_output_index, recv_index, in_ephemeral, ki))
245  {
246  return true;
247  }
248 
249  if (ack.m_spend_secret_key == crypto::null_skey)
250  {
251  // for watch-only wallet, simply copy the known output pubkey
252  in_ephemeral.pub = out_key;
253  in_ephemeral.sec = crypto::null_skey;
254  }
255  else
256  {
257  // derive secret key with subaddress - step 1: original CN derivation
258  crypto::secret_key scalar_step1;
259  hwdev.derive_secret_key(recv_derivation, real_output_index, ack.m_spend_secret_key, scalar_step1); // computes Hs(a*R || idx) + b
260 
261  // step 2: add Hs(a || index_major || index_minor)
262  crypto::secret_key subaddr_sk;
263  crypto::secret_key scalar_step2;
264  if (recv_index.is_zero())
265  {
266  scalar_step2 = scalar_step1; // treat index=(0,0) as a special case representing the main address
267  }
268  else
269  {
270  subaddr_sk = hwdev.get_subaddress_secret_key(ack.m_view_secret_key, recv_index);
271  hwdev.sc_secret_add(scalar_step2, scalar_step1,subaddr_sk);
272  }
273 
274  in_ephemeral.sec = scalar_step2;
275 
276  if (ack.m_multisig_keys.empty())
277  {
278  // when not in multisig, we know the full spend secret key, so the output pubkey can be obtained by scalarmultBase
279  CHECK_AND_ASSERT_MES(hwdev.secret_key_to_public_key(in_ephemeral.sec, in_ephemeral.pub), false, "Failed to derive public key");
280  }
281  else
282  {
283  // when in multisig, we only know the partial spend secret key. but we do know the full spend public key, so the output pubkey can be obtained by using the standard CN key derivation
284  CHECK_AND_ASSERT_MES(hwdev.derive_public_key(recv_derivation, real_output_index, ack.m_account_address.m_spend_public_key, in_ephemeral.pub), false, "Failed to derive public key");
285  // and don't forget to add the contribution from the subaddress part
286  if (!recv_index.is_zero())
287  {
288  crypto::public_key subaddr_pk;
289  CHECK_AND_ASSERT_MES(hwdev.secret_key_to_public_key(subaddr_sk, subaddr_pk), false, "Failed to derive public key");
290  add_public_key(in_ephemeral.pub, in_ephemeral.pub, subaddr_pk);
291  }
292  }
293 
294  CHECK_AND_ASSERT_MES(in_ephemeral.pub == out_key,
295  false, "key image helper precomp: given output pubkey doesn't match the derived one");
296  }
297 
298  hwdev.generate_key_image(in_ephemeral.pub, in_ephemeral.sec, ki);
299  return true;
300  }
virtual bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub)=0
virtual bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b)=0
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
const crypto::secret_key null_skey
Definition: crypto.cpp:73
virtual bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub)=0
unsigned int uint32_t
Definition: stdint.h:126
virtual bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image)=0
POD_CLASS public_key
Definition: crypto.h:76
virtual bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec)=0
virtual bool compute_key_image(const cryptonote::account_keys &ack, const crypto::public_key &out_key, const crypto::key_derivation &recv_derivation, size_t real_output_index, const cryptonote::subaddress_index &received_index, cryptonote::keypair &in_ephemeral, crypto::key_image &ki)
Definition: device.hpp:246
virtual crypto::secret_key get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_multisig_composite_key_image()

bool cryptonote::generate_multisig_composite_key_image ( const account_keys keys,
const std::unordered_map< crypto::public_key, subaddress_index > &  subaddresses,
const crypto::public_key out_key,
const crypto::public_key tx_public_key,
const std::vector< crypto::public_key > &  additional_tx_public_keys,
size_t  real_output_index,
const std::vector< crypto::key_image > &  pkis,
crypto::key_image ki 
)

Definition at line 156 of file multisig.cpp.

157  {
158  cryptonote::keypair in_ephemeral;
159  if (!cryptonote::generate_key_image_helper(keys, subaddresses, out_key, tx_public_key, additional_tx_public_keys, real_output_index, in_ephemeral, ki, keys.get_device()))
160  return false;
161  std::unordered_set<crypto::key_image> used;
162  for (size_t m = 0; m < keys.m_multisig_keys.size(); ++m)
163  {
164  crypto::key_image pki;
165  bool r = cryptonote::generate_multisig_key_image(keys, m, out_key, pki);
166  if (!r)
167  return false;
168  used.insert(pki);
169  }
170  for (const auto &pki: pkis)
171  {
172  if (used.find(pki) == used.end())
173  {
174  used.insert(pki);
175  rct::addKeys((rct::key&)ki, rct::ki2rct(ki), rct::ki2rct(pki));
176  }
177  }
178  return true;
179  }
bool generate_multisig_key_image(const account_keys &keys, size_t multisig_key_index, const crypto::public_key &out_key, crypto::key_image &ki)
Definition: multisig.cpp:142
bool generate_key_image_helper(const account_keys &ack, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, const crypto::public_key &out_key, const crypto::public_key &tx_public_key, const std::vector< crypto::public_key > &additional_tx_public_keys, size_t real_output_index, keypair &in_ephemeral, crypto::key_image &ki, hw::device &hwdev, const uint32_t account_major_offset)
POD_CLASS key_image
Definition: crypto.h:102
void addKeys(key &AB, const key &A, const key &B)
Definition: rctOps.cpp:420
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_multisig_derivations()

std::vector< crypto::public_key > cryptonote::generate_multisig_derivations ( const account_keys keys,
const std::vector< crypto::public_key > &  derivations 
)

generate_multisig_derivations performs common DH key derivation. Each middle round in M/N scheme is DH exchange of public multisig keys of other participants multiplied by secret spend key of current participant. this functions does the following: new multisig key = secret spend * public multisig key

Parameters
keys- current wallet's keys
derivations- public multisig keys of other participants
Returns
new public multisig keys derived from previous round. This data needs to be exchange with other participants

Definition at line 87 of file multisig.cpp.

88  {
89  std::vector<crypto::public_key> multisig_keys;
90  crypto::secret_key blinded_skey = get_multisig_blinded_secret_key(keys.m_spend_secret_key);
91  for (const auto &k: derivations)
92  {
93  rct::key d = rct::scalarmultKey(rct::pk2rct(k), rct::sk2rct(blinded_skey));
94  multisig_keys.push_back(rct::rct2pk(d));
95  }
96 
97  return multisig_keys;
98  }
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
Definition: multisig.cpp:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_multisig_key_image()

bool cryptonote::generate_multisig_key_image ( const account_keys keys,
size_t  multisig_key_index,
const crypto::public_key out_key,
crypto::key_image ki 
)

Definition at line 142 of file multisig.cpp.

143  {
144  if (multisig_key_index >= keys.m_multisig_keys.size())
145  return false;
146  crypto::generate_key_image(out_key, keys.m_multisig_keys[multisig_key_index], ki);
147  return true;
148  }
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
Definition: crypto.h:324
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_multisig_LR()

void cryptonote::generate_multisig_LR ( const crypto::public_key  pkey,
const crypto::secret_key k,
crypto::public_key L,
crypto::public_key R 
)

Definition at line 150 of file multisig.cpp.

151  {
152  rct::scalarmultBase((rct::key&)L, rct::sk2rct(k));
154  }
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image)
Definition: crypto.h:324
void scalarmultBase(key &aG, const key &a)
Definition: rctOps.cpp:350
POD_CLASS key_image
Definition: crypto.h:102
Here is the caller graph for this function:

◆ generate_multisig_M_N_spend_public_key()

crypto::public_key cryptonote::generate_multisig_M_N_spend_public_key ( const std::vector< crypto::public_key > &  pkeys)

generate_multisig_M_N_spend_public_key calculates multisig wallet's spend public key by summing all of public multisig keys

Parameters
pkeysunique public multisig keys
Returns
multisig wallet's spend public key

Definition at line 132 of file multisig.cpp.

133  {
134  rct::key spend_public_key = rct::identity();
135  for (const auto &pk: pkeys)
136  {
137  rct::addKeys(spend_public_key, spend_public_key, rct::pk2rct(pk));
138  }
139  return rct::rct2pk(spend_public_key);
140  }
key identity()
Definition: rctOps.h:73
void addKeys(key &AB, const key &A, const key &B)
Definition: rctOps.cpp:420
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_multisig_N1_N()

void cryptonote::generate_multisig_N1_N ( const account_keys keys,
const std::vector< crypto::public_key > &  spend_keys,
std::vector< crypto::secret_key > &  multisig_keys,
rct::key spend_skey,
rct::key spend_pkey 
)

Definition at line 70 of file multisig.cpp.

71  {
72  multisig_keys.clear();
73  spend_pkey = rct::identity();
74  spend_skey = rct::zero();
75 
76  // create all our composite private keys
77  crypto::secret_key blinded_skey = get_multisig_blinded_secret_key(keys.m_spend_secret_key);
78  for (const auto &k: spend_keys)
79  {
80  rct::key sk = rct::scalarmultKey(rct::pk2rct(k), rct::sk2rct(blinded_skey));
82  multisig_keys.push_back(msk);
83  sc_add(spend_skey.bytes, spend_skey.bytes, (const unsigned char*)msk.data);
84  }
85  }
void scalarmultKey(key &aP, const key &P, const key &a)
Definition: rctOps.cpp:368
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
Definition: multisig.cpp:47
unsigned char bytes[32]
Definition: rctTypes.h:86
key identity()
Definition: rctOps.h:73
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
key zero()
Definition: rctOps.h:70
Here is the call graph for this function:

◆ generate_multisig_N_N()

void cryptonote::generate_multisig_N_N ( const account_keys keys,
const std::vector< crypto::public_key > &  spend_keys,
std::vector< crypto::secret_key > &  multisig_keys,
rct::key spend_skey,
rct::key spend_pkey 
)

Definition at line 58 of file multisig.cpp.

59  {
60  // the multisig spend public key is the sum of all spend public keys
61  multisig_keys.clear();
62  const crypto::secret_key spend_secret_key = get_multisig_blinded_secret_key(keys.m_spend_secret_key);
63  CHECK_AND_ASSERT_THROW_MES(crypto::secret_key_to_public_key(spend_secret_key, (crypto::public_key&)spend_pkey), "Failed to derive public key");
64  for (const auto &k: spend_keys)
65  rct::addKeys(spend_pkey, spend_pkey, rct::pk2rct(k));
66  multisig_keys.push_back(spend_secret_key);
67  spend_skey = rct::sk2rct(spend_secret_key);
68  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
Definition: multisig.cpp:47
POD_CLASS public_key
Definition: crypto.h:76
void addKeys(key &AB, const key &A, const key &B)
Definition: rctOps.cpp:420
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:
Here is the caller graph for this function:

◆ generate_multisig_view_secret_key()

crypto::secret_key cryptonote::generate_multisig_view_secret_key ( const crypto::secret_key skey,
const std::vector< crypto::secret_key > &  skeys 
)

Definition at line 124 of file multisig.cpp.

125  {
126  rct::key view_skey = rct::sk2rct(get_multisig_blinded_secret_key(skey));
127  for (const auto &k: skeys)
128  sc_add(view_skey.bytes, view_skey.bytes, rct::sk2rct(k).bytes);
129  return rct::rct2sk(view_skey);
130  }
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key)
Definition: multisig.cpp:47
unsigned char bytes[32]
Definition: rctTypes.h:86
void sc_add(unsigned char *, const unsigned char *, const unsigned char *)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_output_ephemeral_keys()

bool cryptonote::generate_output_ephemeral_keys ( const size_t  tx_version,
const cryptonote::account_keys sender_account_keys,
const crypto::public_key txkey_pub,
const crypto::secret_key tx_key,
const cryptonote::tx_destination_entry dst_entr,
const boost::optional< cryptonote::account_public_address > &  change_addr,
const size_t  output_index,
const bool need_additional_txkeys,
const std::vector< crypto::secret_key > &  additional_tx_keys,
std::vector< crypto::public_key > &  additional_tx_public_keys,
std::vector< rct::key > &  amount_keys,
crypto::public_key out_eph_public_key 
)

◆ get_account_address_as_str()

std::string cryptonote::get_account_address_as_str ( network_type  nettype,
bool  subaddress,
account_public_address const &  adr 
)

Definition at line 207 of file cryptonote_basic_impl.cpp.

212  {
214 
215  return tools::base58::encode_addr(address_prefix, t_serializable_object_to_blob(adr));
216  }
const config_t & get_config(network_type nettype)
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX
unsigned __int64 uint64_t
Definition: stdint.h:136
std::string encode_addr(uint64_t tag, const std::string &data)
Definition: base58.cpp:228
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_address_checksum()

uint8_t cryptonote::get_account_address_checksum ( const public_address_outer_blob bl)

Definition at line 187 of file cryptonote_basic_impl.cpp.

188  {
189  const unsigned char* pbuf = reinterpret_cast<const unsigned char*>(&bl);
190  uint8_t summ = 0;
191  for(size_t i = 0; i!= sizeof(public_address_outer_blob)-1; i++)
192  summ += pbuf[i];
193 
194  return summ;
195  }
unsigned char uint8_t
Definition: stdint.h:124
Here is the caller graph for this function:

◆ get_account_address_from_str()

bool cryptonote::get_account_address_from_str ( address_parse_info info,
network_type  nettype,
std::string const &  str 
)

Definition at line 243 of file cryptonote_basic_impl.cpp.

248  {
250  uint64_t integrated_address_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
252 
253  if (2 * sizeof(public_address_outer_blob) != str.size())
254  {
255  blobdata data;
256  uint64_t prefix;
257  if (!tools::base58::decode_addr(str, prefix, data))
258  {
259  LOG_PRINT_L2("Invalid address format");
260  return false;
261  }
262 
263  if (integrated_address_prefix == prefix)
264  {
265  info.is_subaddress = false;
266  info.has_payment_id = true;
267  }
268  else if (address_prefix == prefix)
269  {
270  info.is_subaddress = false;
271  info.has_payment_id = false;
272  }
273  else if (subaddress_prefix == prefix)
274  {
275  info.is_subaddress = true;
276  info.has_payment_id = false;
277  }
278  else {
279  LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix
280  << " or " << integrated_address_prefix
281  << " or " << subaddress_prefix);
282  return false;
283  }
284 
285  if (info.has_payment_id)
286  {
287  integrated_address iadr;
288  if (!::serialization::parse_binary(data, iadr))
289  {
290  LOG_PRINT_L1("Account public address keys can't be parsed");
291  return false;
292  }
293  info.address = iadr.adr;
294  info.payment_id = iadr.payment_id;
295  }
296  else
297  {
298  if (!::serialization::parse_binary(data, info.address))
299  {
300  LOG_PRINT_L1("Account public address keys can't be parsed");
301  return false;
302  }
303  }
304 
305  if (!crypto::check_key(info.address.m_spend_public_key) || !crypto::check_key(info.address.m_view_public_key))
306  {
307  LOG_PRINT_L1("Failed to validate address keys");
308  return false;
309  }
310  }
311  else
312  {
313  // Old address format
314  std::string buff;
316  return false;
317 
318  if(buff.size()!=sizeof(public_address_outer_blob))
319  {
320  LOG_PRINT_L1("Wrong public address size: " << buff.size() << ", expected size: " << sizeof(public_address_outer_blob));
321  return false;
322  }
323 
324  public_address_outer_blob blob = *reinterpret_cast<const public_address_outer_blob*>(buff.data());
325 
326 
328  {
329  LOG_PRINT_L1("Unknown version of public address: " << blob.m_ver << ", expected " << CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER);
330  return false;
331  }
332 
333  if(blob.check_sum != get_account_address_checksum(blob))
334  {
335  LOG_PRINT_L1("Wrong public address checksum");
336  return false;
337  }
338 
339  //we success
340  info.address = blob.m_address;
341  info.is_subaddress = false;
342  info.has_payment_id = false;
343  }
344 
345  return true;
346  }
const config_t & get_config(network_type nettype)
#define LOG_PRINT_L2(x)
Definition: misc_log_ex.h:101
#define LOG_PRINT_L1(x)
Definition: misc_log_ex.h:100
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX
::std::string string
Definition: gtest-port.h:1097
bool parse_binary(const std::string &blob, T &v)
Definition: binary_utils.h:41
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER
uint8_t get_account_address_checksum(const public_address_outer_blob &bl)
unsigned __int64 uint64_t
Definition: stdint.h:136
std::string blobdata
Definition: blobdatatype.h:39
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX
bool check_key(const public_key &key)
Definition: crypto.h:256
bool decode_addr(const std::string &addr, uint64_t &tag, std::string &data)
Definition: base58.cpp:238
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_address_from_str_or_url()

bool cryptonote::get_account_address_from_str_or_url ( address_parse_info info,
network_type  nettype,
const std::string &  str_or_url,
std::function< std::string(const std::string &, const std::vector< std::string > &, bool)>  dns_confirm 
)

Definition at line 348 of file cryptonote_basic_impl.cpp.

354  {
355  if (get_account_address_from_str(info, nettype, str_or_url))
356  return true;
357  bool dnssec_valid;
358  std::string address_str = tools::dns_utils::get_account_address_as_str_from_url(str_or_url, dnssec_valid, dns_confirm);
359  return !address_str.empty() &&
360  get_account_address_from_str(info, nettype, address_str);
361  }
::std::string string
Definition: gtest-port.h:1097
std::string get_account_address_as_str_from_url(const std::string &url, bool &dnssec_valid, std::function< std::string(const std::string &, const std::vector< std::string > &, bool)> dns_confirm)
Definition: dns_utils.cpp:479
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_integrated_address_as_str()

std::string cryptonote::get_account_integrated_address_as_str ( network_type  nettype,
account_public_address const &  adr,
crypto::hash8 const &  payment_id 
)

Definition at line 218 of file cryptonote_basic_impl.cpp.

223  {
224  uint64_t integrated_address_prefix = get_config(nettype).CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
225 
226  integrated_address iadr = {
227  adr, payment_id
228  };
229  return tools::base58::encode_addr(integrated_address_prefix, t_serializable_object_to_blob(iadr));
230  }
const config_t & get_config(network_type nettype)
unsigned __int64 uint64_t
Definition: stdint.h:136
std::string encode_addr(uint64_t tag, const std::string &data)
Definition: base58.cpp:228
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_account_integrated_address_checksum()

uint8_t cryptonote::get_account_integrated_address_checksum ( const public_integrated_address_outer_blob bl)

Definition at line 197 of file cryptonote_basic_impl.cpp.

198  {
199  const unsigned char* pbuf = reinterpret_cast<const unsigned char*>(&bl);
200  uint8_t summ = 0;
201  for(size_t i = 0; i!= sizeof(public_integrated_address_outer_blob)-1; i++)
202  summ += pbuf[i];
203 
204  return summ;
205  }
unsigned char uint8_t
Definition: stdint.h:124

◆ get_additional_tx_pub_keys_from_extra() [1/2]

std::vector< crypto::public_key > cryptonote::get_additional_tx_pub_keys_from_extra ( const std::vector< uint8_t > &  tx_extra)

Definition at line 557 of file cryptonote_format_utils.cpp.

558  {
559  // parse
560  std::vector<tx_extra_field> tx_extra_fields;
561  parse_tx_extra(tx_extra, tx_extra_fields);
562  // find corresponding field
563  tx_extra_additional_pub_keys additional_pub_keys;
564  if(!find_tx_extra_field_by_type(tx_extra_fields, additional_pub_keys))
565  return {};
566  return additional_pub_keys.data;
567  }
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_additional_tx_pub_keys_from_extra() [2/2]

std::vector< crypto::public_key > cryptonote::get_additional_tx_pub_keys_from_extra ( const transaction_prefix tx)

Definition at line 569 of file cryptonote_format_utils.cpp.

570  {
571  return get_additional_tx_pub_keys_from_extra(tx.extra);
572  }
std::vector< crypto::public_key > get_additional_tx_pub_keys_from_extra(const transaction_prefix &tx)
Here is the caller graph for this function:

◆ get_blob_hash() [1/4]

void cryptonote::get_blob_hash ( const epee::span< const char > &  blob,
crypto::hash res 
)

Definition at line 926 of file cryptonote_format_utils.cpp.

927  {
928  cn_fast_hash(blob.data(), blob.size(), res);
929  }
const char * res
Definition: hmac_keccak.cpp:41
constexpr std::size_t size() const noexcept
Definition: span.h:111
void cn_fast_hash(const void *data, size_t length, char *hash)
constexpr pointer data() const noexcept
Definition: span.h:110
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_blob_hash() [2/4]

void cryptonote::get_blob_hash ( const blobdata blob,
crypto::hash res 
)

Definition at line 931 of file cryptonote_format_utils.cpp.

932  {
933  cn_fast_hash(blob.data(), blob.size(), res);
934  }
const char * res
Definition: hmac_keccak.cpp:41
void cn_fast_hash(const void *data, size_t length, char *hash)
Here is the call graph for this function:

◆ get_blob_hash() [3/4]

crypto::hash cryptonote::get_blob_hash ( const blobdata blob)

Definition at line 982 of file cryptonote_format_utils.cpp.

983  {
984  crypto::hash h = null_hash;
985  get_blob_hash(blob, h);
986  return h;
987  }
crypto::hash get_blob_hash(const epee::span< const char > &blob)
POD_CLASS hash
Definition: hash.h:50

◆ get_blob_hash() [4/4]

crypto::hash cryptonote::get_blob_hash ( const epee::span< const char > &  blob)

Definition at line 989 of file cryptonote_format_utils.cpp.

990  {
991  crypto::hash h = null_hash;
992  get_blob_hash(blob, h);
993  return h;
994  }
crypto::hash get_blob_hash(const epee::span< const char > &blob)
POD_CLASS hash
Definition: hash.h:50

◆ get_block_complete_entry()

block_complete_entry cryptonote::get_block_complete_entry ( block b,
tx_memory_pool pool 
)

Definition at line 1406 of file cryptonote_core.cpp.

1407  {
1408  block_complete_entry bce;
1409  bce.block = cryptonote::block_to_blob(b);
1410  for (const auto &tx_hash: b.tx_hashes)
1411  {
1412  cryptonote::blobdata txblob;
1413  CHECK_AND_ASSERT_THROW_MES(pool.get_transaction(tx_hash, txblob), "Transaction not found in pool");
1414  bce.txs.push_back(txblob);
1415  }
1416  return bce;
1417  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
std::string blobdata
Definition: blobdatatype.h:39
blobdata block_to_blob(const block &b)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_hash() [1/2]

bool cryptonote::get_block_hash ( const block b,
crypto::hash res 
)

Definition at line 1179 of file cryptonote_format_utils.cpp.

1180  {
1181  if (b.is_hash_valid())
1182  {
1183 #ifdef ENABLE_HASH_CASH_INTEGRITY_CHECK
1184  CHECK_AND_ASSERT_THROW_MES(!calculate_block_hash(b, res) || b.hash == res, "block hash cash integrity failure");
1185 #endif
1186  res = b.hash;
1187  ++block_hashes_cached_count;
1188  return true;
1189  }
1190  ++block_hashes_calculated_count;
1191  bool ret = calculate_block_hash(b, res);
1192  if (!ret)
1193  return false;
1194  b.hash = res;
1195  b.set_hash_valid(true);
1196  return true;
1197  }
const char * res
Definition: hmac_keccak.cpp:41
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
bool calculate_block_hash(const block &b, crypto::hash &res, const blobdata *blob)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_hash() [2/2]

crypto::hash cryptonote::get_block_hash ( const block b)

Definition at line 1199 of file cryptonote_format_utils.cpp.

1200  {
1201  crypto::hash p = null_hash;
1202  get_block_hash(b, p);
1203  return p;
1204  }
crypto::hash get_block_hash(uint64_t height)
POD_CLASS hash
Definition: hash.h:50

◆ get_block_hashing_blob()

blobdata cryptonote::get_block_hashing_blob ( const block b)

Definition at line 1165 of file cryptonote_format_utils.cpp.

1166  {
1167  blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b));
1168  crypto::hash tree_root_hash = get_tx_tree_hash(b);
1169  blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
1170  blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
1171  return blob;
1172  }
std::string get_varint_data(const T &v)
Returns the string that represents the varint.
Definition: varint.h:85
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
std::string blobdata
Definition: blobdatatype.h:39
POD_CLASS hash
Definition: hash.h:50
crypto::hash get_tx_tree_hash(const block &b)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_height()

uint64_t cryptonote::get_block_height ( const block b)

Definition at line 728 of file cryptonote_format_utils.cpp.

729  {
730  CHECK_AND_ASSERT_MES(b.miner_tx.vin.size() == 1, 0, "wrong miner tx in block: " << get_block_hash(b) << ", b.miner_tx.vin.size() != 1");
731  CHECKED_GET_SPECIFIC_VARIANT(b.miner_tx.vin[0], const txin_gen, coinbase_in, 0);
732  return coinbase_in.height;
733  }
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
crypto::hash get_block_hash(uint64_t height)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_longhash() [1/2]

bool cryptonote::get_block_longhash ( const block b,
crypto::hash res,
uint64_t  height 
)

Definition at line 1206 of file cryptonote_format_utils.cpp.

1207  {
1209  const int cn_variant = b.major_version == 6 ? b.major_version - 5 : 0; // Emergency HF so anti-asic is only if HF 6
1210  crypto::cn_slow_hash(bd.data(), bd.size(), res, cn_variant);
1211  return true;
1212  }
const char * res
Definition: hmac_keccak.cpp:41
blobdata get_block_hashing_blob(const block &b)
std::string blobdata
Definition: blobdatatype.h:39
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_block_longhash() [2/2]

crypto::hash cryptonote::get_block_longhash ( const block b,
uint64_t  height 
)

Definition at line 1234 of file cryptonote_format_utils.cpp.

1235  {
1236  crypto::hash p = null_hash;
1237  get_block_longhash(b, p, height);
1238  return p;
1239  }
uint64_t height
Definition: blockchain.cpp:91
crypto::hash get_block_longhash(const block &b, uint64_t height)
POD_CLASS hash
Definition: hash.h:50

◆ get_block_reward()

bool cryptonote::get_block_reward ( size_t  median_weight,
size_t  current_block_weight,
uint64_t  already_generated_coins,
uint64_t reward,
uint8_t  version,
uint64_t  current_block_height,
network_type  nettype 
)

Definition at line 91 of file cryptonote_basic_impl.cpp.

91  {
92  static_assert(DIFFICULTY_TARGET%60==0,"difficulty target must be a multiple of 60");
93  static_assert(DIFFICULTY_TARGET_V6%60==0,"difficulty target V6 must be a multiple of 60");
94 
95  const int target = version >= 6 ? DIFFICULTY_TARGET_V6 : DIFFICULTY_TARGET;
96 
97  const int target_minutes = target / 60;
98 
99  uint64_t full_reward_zone = get_min_block_weight(version);
100 
101  const uint64_t premine = 1260000000000U;
102  if (median_weight > 0 && already_generated_coins < premine && !(current_block_weight >= 2 * full_reward_zone)) {
103  reward = premine;
104  return true;
105  }
106 
107  uint64_t base_reward;
108 
109  // After v9 the reward drops by ~75%, fixed reward curve that halves every 4 years (up to 2 halvings)
110  if(version >= 9) {
111 
112  uint64_t V9_BLOCK_HEIGHT = 0;
113  switch(nettype) {
114  case MAINNET:
115  V9_BLOCK_HEIGHT = 862866;
116  break;
117  case TESTNET:
118  V9_BLOCK_HEIGHT = 707121;
119  break;
120  case STAGENET:
121  V9_BLOCK_HEIGHT = 39000;
122  break;
123  default:
124  V9_BLOCK_HEIGHT = 39000;
125  }
126 
127  base_reward = version >= 10 ? 100 * COIN : 400 * COIN;
128  uint8_t halvings = (current_block_height - V9_BLOCK_HEIGHT) / 1051200; // Every 4 years
129 
130  // Tail emission after 2nd halving
131  if (halvings > 2) {
132 
133  //Force 2x tail emission after 2nd halving if circulating supply < max supply
134  base_reward = (already_generated_coins >= ETN_SUPPLY) ? FINAL_SUBSIDY_PER_MINUTE : FINAL_SUBSIDY_PER_MINUTE * 2;
135 
136  } else {
137  base_reward >>= halvings;
138  }
139  } else {
140  //After v8 the reward drops by ~75%
141  double emission_speed_factor = (version == 8 ? EMISSION_SPEED_FACTOR_PER_MINUTE_V8 : EMISSION_SPEED_FACTOR_PER_MINUTE) - (target_minutes-1);
142 
143  base_reward = (ETN_SUPPLY - already_generated_coins) / pow(2, emission_speed_factor);
144 
145  if (base_reward < FINAL_SUBSIDY_PER_MINUTE*target_minutes)
146  {
147  base_reward = FINAL_SUBSIDY_PER_MINUTE*target_minutes;
148  }
149  }
150 
151  //make it soft
152  if (median_weight < full_reward_zone) {
153  median_weight = full_reward_zone;
154  }
155 
156  if (current_block_weight <= median_weight) {
157  reward = base_reward;
158  return true;
159  }
160 
161  if(current_block_weight > 2 * median_weight) {
162  MERROR("Block cumulative weight is too big: " << current_block_weight << ", expected less than " << 2 * median_weight);
163  return false;
164  }
165 
166  assert(median_weight < std::numeric_limits<uint32_t>::max());
167  assert(current_block_weight < std::numeric_limits<uint32_t>::max());
168 
169  uint64_t product_hi;
170  // BUGFIX: 32-bit saturation bug (e.g. ARM7), the result was being
171  // treated as 32-bit by default.
172  uint64_t multiplicand = 2 * median_weight - current_block_weight;
173  multiplicand *= current_block_weight;
174  uint64_t product_lo = mul128(base_reward, multiplicand, &product_hi);
175 
176  uint64_t reward_hi;
177  uint64_t reward_lo;
178  div128_32(product_hi, product_lo, static_cast<uint32_t>(median_weight), &reward_hi, &reward_lo);
179  div128_32(reward_hi, reward_lo, static_cast<uint32_t>(median_weight), &reward_hi, &reward_lo);
180  assert(0 == reward_hi);
181  assert(reward_lo < base_reward);
182 
183  reward = reward_lo;
184  return true;
185  }
#define EMISSION_SPEED_FACTOR_PER_MINUTE_V8
#define MERROR(x)
Definition: misc_log_ex.h:73
#define EMISSION_SPEED_FACTOR_PER_MINUTE
size_t get_min_block_weight(uint8_t version)
#define COIN
unsigned char uint8_t
Definition: stdint.h:124
#define ETN_SUPPLY
#define DIFFICULTY_TARGET_V6
unsigned __int64 uint64_t
Definition: stdint.h:136
version
Supported socks variants.
Definition: socks.h:57
#define FINAL_SUBSIDY_PER_MINUTE
#define DIFFICULTY_TARGET
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_config()

const config_t& cryptonote::get_config ( network_type  nettype)
inline

Definition at line 266 of file cryptonote_config.h.

267  {
268  static const config_t mainnet = {
278  };
279  static const config_t testnet = {
289  };
290  static const config_t stagenet = {
300  };
301  switch (nettype)
302  {
303  case MAINNET: return mainnet;
304  case TESTNET: return testnet;
305  case STAGENET: return stagenet;
306  case FAKECHAIN: return mainnet;
307  default: throw std::runtime_error("Invalid network type");
308  }
309  };
uint32_t const GENESIS_NONCE
uint16_t const P2P_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
uint16_t const ZMQ_RPC_DEFAULT_PORT
std::string const GENESIS_TX
uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX
boost::uuids::uuid const NETWORK_ID
uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX
Here is the caller graph for this function:

◆ get_default_decimal_point()

unsigned int cryptonote::get_default_decimal_point ( )

Definition at line 948 of file cryptonote_format_utils.cpp.

949  {
950  return default_decimal_point;
951  }

◆ get_destination_view_key_pub()

crypto::public_key cryptonote::get_destination_view_key_pub ( const std::vector< tx_destination_entry > &  destinations,
const boost::optional< cryptonote::account_public_address > &  change_addr 
)

Definition at line 200 of file cryptonote_tx_utils.cpp.

201  {
202  account_public_address addr = {null_pkey, null_pkey};
203  size_t count = 0;
204  for (const auto &i : destinations)
205  {
206  if (i.amount == 0)
207  continue;
208  if (change_addr && i.addr == *change_addr)
209  continue;
210  if (i.addr == addr)
211  continue;
212  if (count > 0)
213  return null_pkey;
214  addr = i.addr;
215  ++count;
216  }
217  if (count == 0 && change_addr)
218  return change_addr->m_view_public_key;
219  return addr.m_view_public_key;
220  }
mdb_size_t count(MDB_cursor *cur)
const crypto::public_key null_pkey
Definition: crypto.cpp:72
Here is the call graph for this function:

◆ get_encrypted_payment_id_from_tx_extra_nonce()

bool cryptonote::get_encrypted_payment_id_from_tx_extra_nonce ( const blobdata extra_nonce,
crypto::hash8 payment_id 
)

Definition at line 696 of file cryptonote_format_utils.cpp.

697  {
698  if(sizeof(crypto::hash8) + 1 != extra_nonce.size())
699  return false;
700  if (TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID != extra_nonce[0])
701  return false;
702  payment_id = *reinterpret_cast<const crypto::hash8*>(extra_nonce.data() + 1);
703  return true;
704  }
#define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID
Definition: tx_extra.h:48
POD_CLASS hash8
Definition: hash.h:53
Here is the caller graph for this function:

◆ get_hash_stats()

void cryptonote::get_hash_stats ( uint64_t tx_hashes_calculated,
uint64_t tx_hashes_cached,
uint64_t block_hashes_calculated,
uint64_t block_hashes_cached 
)

Definition at line 1322 of file cryptonote_format_utils.cpp.

1323  {
1324  tx_hashes_calculated = tx_hashes_calculated_count;
1325  tx_hashes_cached = tx_hashes_cached_count;
1326  block_hashes_calculated = block_hashes_calculated_count;
1327  block_hashes_cached = block_hashes_cached_count;
1328  }

◆ get_inputs_etn_amount()

bool cryptonote::get_inputs_etn_amount ( const transaction tx,
uint64_t etn 
)

Definition at line 706 of file cryptonote_format_utils.cpp.

707  {
708  etn = 0;
709  if(tx.version == 1 || tx.version == 2) {
710  for(const auto& in: tx.vin)
711  {
712  CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key, tokey_in, false);
713  etn += tokey_in.amount;
714  }
715  }
716  else //tx.version >= 3 (public transactions: can spend only new inputs)
717  {
718  for(const auto& in: tx.vin)
719  {
720  CHECKED_GET_SPECIFIC_VARIANT(in, const txin_to_key_public, tokey_in, false);
721  etn += tokey_in.amount;
722  }
723  }
724 
725  return true;
726  }
#define CHECKED_GET_SPECIFIC_VARIANT(variant_var, specific_type, variable_name, fail_return_val)
Here is the caller graph for this function:

◆ get_max_tx_size()

size_t cryptonote::get_max_tx_size ( )

Definition at line 86 of file cryptonote_basic_impl.cpp.

87  {
89  }
#define CRYPTONOTE_MAX_TX_SIZE

◆ get_min_block_weight()

size_t cryptonote::get_min_block_weight ( uint8_t  version)

Definition at line 73 of file cryptonote_basic_impl.cpp.

74  {
75  if (version < 2)
77  if (version < 5)
79  if (version < 8)
81  if (version < 10)
84  }
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V8
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V10
version
Supported socks variants.
Definition: socks.h:57
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1
Here is the caller graph for this function:

◆ get_multisig_blinded_secret_key()

crypto::secret_key cryptonote::get_multisig_blinded_secret_key ( const crypto::secret_key key)

Definition at line 47 of file multisig.cpp.

48  {
49  rct::keyV data;
50  data.reserve(2);
51  data.push_back(rct::sk2rct(key));
52  data.push_back(multisig_salt);
53  crypto::secret_key result = rct::rct2sk(rct::hash_to_scalar(data));
54  memwipe(&data[0], sizeof(rct::key));
55  return result;
56  }
const char * key
Definition: hmac_keccak.cpp:39
std::vector< key > keyV
Definition: rctTypes.h:88
void hash_to_scalar(key &hash, const void *data, const std::size_t l)
Definition: rctOps.cpp:536
void * memwipe(void *src, size_t n)
Here is the caller graph for this function:

◆ get_object_blobsize()

template<class t_object >
size_t cryptonote::get_object_blobsize ( const t_object &  o)

Definition at line 184 of file cryptonote_format_utils.h.

185  {
187  return b.size();
188  }
blobdata t_serializable_object_to_blob(const t_object &to)
std::string blobdata
Definition: blobdatatype.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_object_hash() [1/2]

template<class t_object >
bool cryptonote::get_object_hash ( const t_object &  o,
crypto::hash res 
)

Definition at line 177 of file cryptonote_format_utils.h.

178  {
180  return true;
181  }
const char * res
Definition: hmac_keccak.cpp:41
void get_blob_hash(const epee::span< const char > &blob, crypto::hash &res)
blobdata t_serializable_object_to_blob(const t_object &to)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_object_hash() [2/2]

template<class t_object >
bool cryptonote::get_object_hash ( const t_object &  o,
crypto::hash res,
size_t &  blob_size 
)

Definition at line 191 of file cryptonote_format_utils.h.

192  {
194  blob_size = bl.size();
195  get_blob_hash(bl, res);
196  return true;
197  }
const char * res
Definition: hmac_keccak.cpp:41
void get_blob_hash(const epee::span< const char > &blob, crypto::hash &res)
blobdata t_serializable_object_to_blob(const t_object &to)
std::string blobdata
Definition: blobdatatype.h:39
Here is the call graph for this function:

◆ get_outs_etn_amount()

uint64_t cryptonote::get_outs_etn_amount ( const transaction tx)

Definition at line 829 of file cryptonote_format_utils.cpp.

830  {
831  uint64_t outputs_amount = 0;
832  for(const auto& o: tx.vout)
833  outputs_amount += o.amount;
834  return outputs_amount;
835  }
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ get_payment_id_from_tx_extra_nonce()

bool cryptonote::get_payment_id_from_tx_extra_nonce ( const blobdata extra_nonce,
crypto::hash payment_id 
)

Definition at line 686 of file cryptonote_format_utils.cpp.

687  {
688  if(sizeof(crypto::hash) + 1 != extra_nonce.size())
689  return false;
690  if(TX_EXTRA_NONCE_PAYMENT_ID != extra_nonce[0])
691  return false;
692  payment_id = *reinterpret_cast<const crypto::hash*>(extra_nonce.data() + 1);
693  return true;
694  }
POD_CLASS hash
Definition: hash.h:50
#define TX_EXTRA_NONCE_PAYMENT_ID
Definition: tx_extra.h:47
Here is the caller graph for this function:

◆ get_protocol_state_char()

char cryptonote::get_protocol_state_char ( cryptonote_connection_context::state  s)
inline

Definition at line 91 of file connection_context.h.

92  {
93  switch (s)
94  {
95  case cryptonote_connection_context::state_before_handshake:
96  return 'h';
97  case cryptonote_connection_context::state_synchronizing:
98  return 's';
99  case cryptonote_connection_context::state_standby:
100  return 'w';
101  case cryptonote_connection_context::state_idle:
102  return 'i';
103  case cryptonote_connection_context::state_normal:
104  return 'n';
105  default:
106  return 'u';
107  }
108  }

◆ get_protocol_state_string()

std::string cryptonote::get_protocol_state_string ( cryptonote_connection_context::state  s)
inline

Definition at line 72 of file connection_context.h.

73  {
74  switch (s)
75  {
76  case cryptonote_connection_context::state_before_handshake:
77  return "before_handshake";
78  case cryptonote_connection_context::state_synchronizing:
79  return "synchronizing";
80  case cryptonote_connection_context::state_standby:
81  return "standby";
82  case cryptonote_connection_context::state_idle:
83  return "idle";
84  case cryptonote_connection_context::state_normal:
85  return "normal";
86  default:
87  return "unknown";
88  }
89  }

◆ get_pruned_transaction_hash()

crypto::hash cryptonote::get_pruned_transaction_hash ( const transaction t,
const crypto::hash pruned_data_hash 
)

Definition at line 1041 of file cryptonote_format_utils.cpp.

1042  {
1043  // v1 transactions hash the entire blob
1044  CHECK_AND_ASSERT_THROW_MES(t.version > 1, "Hash for pruned v1 tx cannot be calculated");
1045 
1046  // v2 transactions hash different parts together, than hash the set of those hashes
1047  crypto::hash hashes[3];
1048 
1049  // prefix
1051 
1052  transaction &tt = const_cast<transaction&>(t);
1053 
1054  // base rct
1055  {
1056  std::stringstream ss;
1057  binary_archive<true> ba(ss);
1058  const size_t inputs = t.vin.size();
1059  const size_t outputs = t.vout.size();
1060  bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
1061  CHECK_AND_ASSERT_THROW_MES(r, "Failed to serialize rct signatures base");
1062  cryptonote::get_blob_hash(ss.str(), hashes[1]);
1063  }
1064 
1065  // prunable rct
1066  if (t.rct_signatures.type == rct::RCTTypeNull)
1067  hashes[2] = crypto::null_hash;
1068  else
1069  hashes[2] = pruned_data_hash;
1070 
1071  // the tx hash is the hash of the 3 hashes
1073  return res;
1074  }
const char * res
Definition: hmac_keccak.cpp:41
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
crypto::hash get_transaction_prefix_hash(const transaction_prefix &tx)
void get_blob_hash(const epee::span< const char > &blob, crypto::hash &res)
struct hash_func hashes[]
void cn_fast_hash(const void *data, size_t length, char *hash)
POD_CLASS hash
Definition: hash.h:50
Here is the call graph for this function:

◆ get_transaction_hash() [1/4]

crypto::hash cryptonote::get_transaction_hash ( const transaction t)

Definition at line 996 of file cryptonote_format_utils.cpp.

997  {
998  crypto::hash h = null_hash;
999  get_transaction_hash(t, h, NULL);
1000  CHECK_AND_ASSERT_THROW_MES(get_transaction_hash(t, h, NULL), "Failed to calculate transaction hash");
1001  return h;
1002  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
POD_CLASS hash
Definition: hash.h:50
Here is the caller graph for this function:

◆ get_transaction_hash() [2/4]

bool cryptonote::get_transaction_hash ( const transaction t,
crypto::hash res 
)

Definition at line 1004 of file cryptonote_format_utils.cpp.

1005  {
1006  return get_transaction_hash(t, res, NULL);
1007  }
const char * res
Definition: hmac_keccak.cpp:41
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
Here is the call graph for this function:

◆ get_transaction_hash() [3/4]

bool cryptonote::get_transaction_hash ( const transaction t,
crypto::hash res,
size_t *  blob_size 
)

Definition at line 1126 of file cryptonote_format_utils.cpp.

1127  {
1128  if (t.is_hash_valid())
1129  {
1130 #ifdef ENABLE_HASH_CASH_INTEGRITY_CHECK
1131  CHECK_AND_ASSERT_THROW_MES(!calculate_transaction_hash(t, res, blob_size) || t.hash == res, "tx hash cash integrity failure");
1132 #endif
1133  res = t.hash;
1134  if (blob_size)
1135  {
1136  if (!t.is_blob_size_valid())
1137  {
1138  t.blob_size = get_object_blobsize(t);
1139  t.set_blob_size_valid(true);
1140  }
1141  *blob_size = t.blob_size;
1142  }
1143  ++tx_hashes_cached_count;
1144  return true;
1145  }
1146  ++tx_hashes_calculated_count;
1147  bool ret = calculate_transaction_hash(t, res, blob_size);
1148  if (!ret)
1149  return false;
1150  t.hash = res;
1151  t.set_hash_valid(true);
1152  if (blob_size)
1153  {
1154  t.blob_size = *blob_size;
1155  t.set_blob_size_valid(true);
1156  }
1157  return true;
1158  }
const char * res
Definition: hmac_keccak.cpp:41
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
size_t get_object_blobsize(const t_object &o)
bool calculate_transaction_hash(const transaction &t, crypto::hash &res, size_t *blob_size)
Here is the call graph for this function:

◆ get_transaction_hash() [4/4]

bool cryptonote::get_transaction_hash ( const transaction t,
crypto::hash res,
size_t &  blob_size 
)

Definition at line 1160 of file cryptonote_format_utils.cpp.

1161  {
1162  return get_transaction_hash(t, res, &blob_size);
1163  }
const char * res
Definition: hmac_keccak.cpp:41
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
Here is the caller graph for this function:

◆ get_transaction_prefix_hash() [1/2]

void cryptonote::get_transaction_prefix_hash ( const transaction_prefix tx,
crypto::hash h 
)

Definition at line 112 of file cryptonote_format_utils.cpp.

113  {
114  std::ostringstream s;
116  ::serialization::serialize(a, const_cast<transaction_prefix&>(tx));
117 
118  crypto::cn_fast_hash(s.str().data(), s.str().size(), h);
119  }
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
void cn_fast_hash(const void *data, size_t length, char *hash)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_transaction_prefix_hash() [2/2]

crypto::hash cryptonote::get_transaction_prefix_hash ( const transaction_prefix tx)

Definition at line 121 of file cryptonote_format_utils.cpp.

122  {
123  crypto::hash h = null_hash;
125  return h;
126  }
crypto::hash get_transaction_prefix_hash(const transaction_prefix &tx)
POD_CLASS hash
Definition: hash.h:50
Here is the caller graph for this function:

◆ get_transaction_prunable_hash()

crypto::hash cryptonote::get_transaction_prunable_hash ( const transaction t,
const cryptonote::blobdata blobdata 
)

Definition at line 1034 of file cryptonote_format_utils.cpp.

1035  {
1036  crypto::hash res;
1037  CHECK_AND_ASSERT_THROW_MES(calculate_transaction_prunable_hash(t, blobdata, res), "Failed to calculate tx prunable hash");
1038  return res;
1039  }
const char * res
Definition: hmac_keccak.cpp:41
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
bool calculate_transaction_prunable_hash(const transaction &t, const cryptonote::blobdata *blob, crypto::hash &res)
std::string blobdata
Definition: blobdatatype.h:39
POD_CLASS hash
Definition: hash.h:50
Here is the call graph for this function:

◆ get_transaction_weight() [1/2]

uint64_t cryptonote::get_transaction_weight ( const transaction tx,
size_t  blob_size 
)

Definition at line 347 of file cryptonote_format_utils.cpp.

348  {
349  return blob_size;
350  }
Here is the caller graph for this function:

◆ get_transaction_weight() [2/2]

uint64_t cryptonote::get_transaction_weight ( const transaction tx)

Definition at line 352 of file cryptonote_format_utils.cpp.

353  {
354  size_t blob_size;
355  if (tx.is_blob_size_valid())
356  {
357  blob_size = tx.blob_size;
358  }
359  else
360  {
361  std::ostringstream s;
363  ::serialization::serialize(a, const_cast<transaction&>(tx));
364  blob_size = s.str().size();
365  }
366  return get_transaction_weight(tx, blob_size);
367  }
uint64_t get_transaction_weight(const transaction &tx)
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Here is the call graph for this function:

◆ get_tx_fee() [1/2]

bool cryptonote::get_tx_fee ( const transaction tx,
uint64_t fee 
)

Definition at line 369 of file cryptonote_format_utils.cpp.

370  {
371  uint64_t amount_in = 0;
372  uint64_t amount_out = 0;
373  for(auto& in: tx.vin)
374  {
375  CHECK_AND_ASSERT_MES(in.type() == typeid(txin_to_key) || in.type() == typeid(txin_to_key_public), 0, "unexpected type id in transaction");
376 
377  if(tx.version == 1 || tx.version == 2)
378  {
379  amount_in += boost::get<txin_to_key>(in).amount;
380  }
381  else
382  {
383  amount_in += boost::get<txin_to_key_public>(in).amount;
384  }
385  }
386  for(auto& o: tx.vout)
387  amount_out += o.amount;
388 
389  CHECK_AND_ASSERT_MES(amount_in >= amount_out, false, "transaction spend (" <<amount_in << ") more than it has (" << amount_out << ")");
390  fee = amount_in - amount_out;
391  return true;
392  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ get_tx_fee() [2/2]

uint64_t cryptonote::get_tx_fee ( const transaction tx)

Definition at line 394 of file cryptonote_format_utils.cpp.

395  {
396  uint64_t r = 0;
397  if(!get_tx_fee(tx, r))
398  return 0;
399  return r;
400  }
unsigned __int64 uint64_t
Definition: stdint.h:136
uint64_t get_tx_fee(const transaction &tx)

◆ get_tx_pub_key_from_extra() [1/3]

crypto::public_key cryptonote::get_tx_pub_key_from_extra ( const std::vector< uint8_t > &  tx_extra,
size_t  pk_index 
)

Definition at line 517 of file cryptonote_format_utils.cpp.

518  {
519  std::vector<tx_extra_field> tx_extra_fields;
520  parse_tx_extra(tx_extra, tx_extra_fields);
521 
522  tx_extra_pub_key pub_key_field;
523  if(!find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, pk_index))
524  return null_pkey;
525 
526  return pub_key_field.pub_key;
527  }
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
const crypto::public_key null_pkey
Definition: crypto.cpp:72
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tx_pub_key_from_extra() [2/3]

crypto::public_key cryptonote::get_tx_pub_key_from_extra ( const transaction_prefix tx_prefix,
size_t  pk_index 
)

Definition at line 529 of file cryptonote_format_utils.cpp.

530  {
531  return get_tx_pub_key_from_extra(tx_prefix.extra, pk_index);
532  }
crypto::public_key get_tx_pub_key_from_extra(const transaction &tx, size_t pk_index)
Here is the call graph for this function:

◆ get_tx_pub_key_from_extra() [3/3]

crypto::public_key cryptonote::get_tx_pub_key_from_extra ( const transaction tx,
size_t  pk_index 
)

Definition at line 534 of file cryptonote_format_utils.cpp.

535  {
536  return get_tx_pub_key_from_extra(tx.extra, pk_index);
537  }
crypto::public_key get_tx_pub_key_from_extra(const transaction &tx, size_t pk_index)
Here is the caller graph for this function:

◆ get_tx_tree_hash() [1/3]

void cryptonote::get_tx_tree_hash ( const std::vector< crypto::hash > &  tx_hashes,
crypto::hash h 
)

Definition at line 1290 of file cryptonote_format_utils.cpp.

1291  {
1292  tree_hash(tx_hashes.data(), tx_hashes.size(), h);
1293  }
void tree_hash(const char(*hashes)[HASH_SIZE], size_t count, char *root_hash)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_tx_tree_hash() [2/3]

crypto::hash cryptonote::get_tx_tree_hash ( const std::vector< crypto::hash > &  tx_hashes)

Definition at line 1295 of file cryptonote_format_utils.cpp.

1296  {
1297  crypto::hash h = null_hash;
1298  get_tx_tree_hash(tx_hashes, h);
1299  return h;
1300  }
POD_CLASS hash
Definition: hash.h:50
crypto::hash get_tx_tree_hash(const block &b)

◆ get_tx_tree_hash() [3/3]

crypto::hash cryptonote::get_tx_tree_hash ( const block b)

Definition at line 1302 of file cryptonote_format_utils.cpp.

1303  {
1304  std::vector<crypto::hash> txs_ids;
1305  txs_ids.reserve(1 + b.tx_hashes.size());
1306  crypto::hash h = null_hash;
1307  size_t bl_sz = 0;
1308  CHECK_AND_ASSERT_THROW_MES(get_transaction_hash(b.miner_tx, h, bl_sz), "Failed to calculate transaction hash");
1309  txs_ids.push_back(h);
1310  for(auto& th: b.tx_hashes)
1311  txs_ids.push_back(th);
1312  return get_tx_tree_hash(txs_ids);
1313  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
POD_CLASS hash
Definition: hash.h:50
crypto::hash get_tx_tree_hash(const block &b)
Here is the caller graph for this function:

◆ get_unit()

std::string cryptonote::get_unit ( unsigned int  decimal_point)

Definition at line 953 of file cryptonote_format_utils.cpp.

954  {
955  if (decimal_point == (unsigned int)-1)
956  decimal_point = default_decimal_point;
957  switch (decimal_point)
958  {
959  case 2:
960  return "electroneum";
961  case 0:
962  return "ecent";
963  default:
964  ASSERT_MES_AND_THROW("Invalid decimal point specification: " << decimal_point);
965  }
966  }
#define ASSERT_MES_AND_THROW(message)
Definition: misc_log_ex.h:172

◆ getpos() [1/2]

template<>
unsigned int cryptonote::getpos ( binary_archive< true > &  ar)
inline

Definition at line 242 of file cryptonote_basic.h.

242 { return ar.stream().tellp(); }
stream_type & stream()
Here is the call graph for this function:

◆ getpos() [2/2]

template<>
unsigned int cryptonote::getpos ( binary_archive< false > &  ar)
inline

Definition at line 243 of file cryptonote_basic.h.

243 { return ar.stream().tellg(); }
stream_type & stream()
Here is the call graph for this function:

◆ hex()

std::string cryptonote::hex ( difficulty_type  v)

Definition at line 254 of file difficulty.cpp.

255  {
256  static const char chars[] = "0123456789abcdef";
257  std::string s;
258  while (v > 0)
259  {
260  s.push_back(chars[(v & 0xf).convert_to<unsigned>()]);
261  v >>= 4;
262  }
263  if (s.empty())
264  s += "0";
265  std::reverse(s.begin(), s.end());
266  return "0x" + s;
267  }
::std::string string
Definition: gtest-port.h:1097

◆ is_coinbase()

bool cryptonote::is_coinbase ( const transaction tx)

Definition at line 232 of file cryptonote_basic_impl.cpp.

233  {
234  if(tx.vin.size() != 1)
235  return false;
236 
237  if(tx.vin[0].type() != typeid(txin_gen))
238  return false;
239 
240  return true;
241  }
Here is the caller graph for this function:

◆ is_out_to_acc()

bool cryptonote::is_out_to_acc ( const account_keys acc,
const txout_to_key out_key,
const crypto::public_key tx_pub_key,
const std::vector< crypto::public_key > &  additional_tx_pub_keys,
size_t  output_index 
)

Definition at line 846 of file cryptonote_format_utils.cpp.

847  {
848  crypto::key_derivation derivation;
849  bool r = acc.get_device().generate_key_derivation(tx_pub_key, acc.m_view_secret_key, derivation);
850  CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
852  r = acc.get_device().derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk);
853  CHECK_AND_ASSERT_MES(r, false, "Failed to derive public key");
854  if (pk == out_key.key)
855  return true;
856  // try additional tx pubkeys if available
857  if (!additional_tx_pub_keys.empty())
858  {
859  CHECK_AND_ASSERT_MES(output_index < additional_tx_pub_keys.size(), false, "wrong number of additional tx pubkeys");
860  r = acc.get_device().generate_key_derivation(additional_tx_pub_keys[output_index], acc.m_view_secret_key, derivation);
861  CHECK_AND_ASSERT_MES(r, false, "Failed to generate key derivation");
862  r = acc.get_device().derive_public_key(derivation, output_index, acc.m_account_address.m_spend_public_key, pk);
863  CHECK_AND_ASSERT_MES(r, false, "Failed to derive public key");
864  return pk == out_key.key;
865  }
866  return false;
867  }
POD_CLASS key_derivation
Definition: crypto.h:98
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
POD_CLASS public_key
Definition: crypto.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_out_to_acc_precomp()

boost::optional< subaddress_receive_info > cryptonote::is_out_to_acc_precomp ( const std::unordered_map< crypto::public_key, subaddress_index > &  subaddresses,
const crypto::public_key out_key,
const crypto::key_derivation derivation,
const std::vector< crypto::key_derivation > &  additional_derivations,
size_t  output_index,
hw::device hwdev 
)

Definition at line 869 of file cryptonote_format_utils.cpp.

870  {
871  // try the shared tx pubkey
872  crypto::public_key subaddress_spendkey;
873  hwdev.derive_subaddress_public_key(out_key, derivation, output_index, subaddress_spendkey);
874  auto found = subaddresses.find(subaddress_spendkey);
875  if (found != subaddresses.end())
876  return subaddress_receive_info{ found->second, derivation };
877  // try additional tx pubkeys if available
878  if (!additional_derivations.empty())
879  {
880  CHECK_AND_ASSERT_MES(output_index < additional_derivations.size(), boost::none, "wrong number of additional derivations");
881  hwdev.derive_subaddress_public_key(out_key, additional_derivations[output_index], output_index, subaddress_spendkey);
882  found = subaddresses.find(subaddress_spendkey);
883  if (found != subaddresses.end())
884  return subaddress_receive_info{ found->second, additional_derivations[output_index] };
885  }
886  return boost::none;
887  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
virtual bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub)=0
POD_CLASS public_key
Definition: crypto.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_out_to_acc_precomp_public()

boost::optional< subaddress_receive_info > cryptonote::is_out_to_acc_precomp_public ( const std::unordered_map< crypto::public_key, subaddress_index > &  subaddresses,
const cryptonote::account_public_address  output_address 
)

Definition at line 889 of file cryptonote_format_utils.cpp.

890  {
891  crypto::public_key subaddress_spendkey = output_address.m_spend_public_key;
892  auto found = subaddresses.find(subaddress_spendkey);
893  if (found != subaddresses.end()){
894  return subaddress_receive_info{found->second, {}};
895  }
896  return boost::none;
897  }
POD_CLASS public_key
Definition: crypto.h:76

◆ is_v1_tx() [1/2]

bool cryptonote::is_v1_tx ( const blobdata_ref tx_blob)

Definition at line 190 of file cryptonote_format_utils.cpp.

191  {
192  //TODO: Public - assure return true. Build logic for prunable v2/v3 tx data later.
193  return true;
194 
196  const char* begin = static_cast<const char*>(tx_blob.data());
197  const char* end = begin + tx_blob.size();
198  int read = tools::read_varint(begin, end, version);
199  if (read <= 0)
200  throw std::runtime_error("Internal error getting transaction version");
201  }
unsigned __int64 uint64_t
Definition: stdint.h:136
version
Supported socks variants.
Definition: socks.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_v1_tx() [2/2]

bool cryptonote::is_v1_tx ( const blobdata tx_blob)

Definition at line 203 of file cryptonote_format_utils.cpp.

204  {
205  return is_v1_tx(blobdata_ref{tx_blob.data(), tx_blob.size()});
206  }
bool is_v1_tx(const blobdata &tx_blob)
epee::span< const char > blobdata_ref
Definition: blobdatatype.h:40
Here is the call graph for this function:

◆ is_valid_decomposed_amount()

bool cryptonote::is_valid_decomposed_amount ( uint64_t  amount)

Definition at line 1315 of file cryptonote_format_utils.cpp.

1316  {
1317  const uint64_t *begin = valid_decomposed_outputs;
1318  const uint64_t *end = valid_decomposed_outputs + sizeof(valid_decomposed_outputs) / sizeof(valid_decomposed_outputs[0]);
1319  return std::binary_search(begin, end, amount);
1320  }
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the caller graph for this function:

◆ lmdb_resized()

void cryptonote::lmdb_resized ( MDB_env env)

Definition at line 502 of file db_lmdb.cpp.

503 {
504  mdb_txn_safe::prevent_new_txns();
505 
506  MGINFO("LMDB map resize detected.");
507 
508  MDB_envinfo mei;
509 
510  mdb_env_info(env, &mei);
511  uint64_t old = mei.me_mapsize;
512 
513  mdb_txn_safe::wait_no_active_txns();
514 
515  int result = mdb_env_set_mapsize(env, 0);
516  if (result)
517  throw0(DB_ERROR(lmdb_error("Failed to set new mapsize: ", result).c_str()));
518 
519  mdb_env_info(env, &mei);
520  uint64_t new_mapsize = mei.me_mapsize;
521 
522  MGINFO("LMDB Mapsize increased." << " Old: " << old / (1024 * 1024) << "MiB" << ", New: " << new_mapsize / (1024 * 1024) << "MiB");
523 
524  mdb_txn_safe::allow_new_txns();
525 }
int mdb_env_set_mapsize(MDB_env *env, mdb_size_t size)
Set the size of the memory map to use for this environment.
int mdb_env_info(MDB_env *env, MDB_envinfo *stat)
Return information about the LMDB environment.
#define MGINFO(x)
Definition: misc_log_ex.h:80
Information about the environment.
Definition: lmdb.h:501
unsigned __int64 uint64_t
Definition: stdint.h:136
mdb_size_t me_mapsize
Definition: lmdb.h:503
Here is the caller graph for this function:

◆ lmdb_txn_begin()

int cryptonote::lmdb_txn_begin ( MDB_env env,
MDB_txn parent,
unsigned int  flags,
MDB_txn **  txn 
)
inline

Definition at line 527 of file db_lmdb.cpp.

528 {
529  int res = mdb_txn_begin(env, parent, flags, txn);
530  if (res == MDB_MAP_RESIZED) {
531  lmdb_resized(env);
532  res = mdb_txn_begin(env, parent, flags, txn);
533  }
534  return res;
535 }
const char * res
Definition: hmac_keccak.cpp:41
void lmdb_resized(MDB_env *env)
Definition: db_lmdb.cpp:502
#define MDB_MAP_RESIZED
Definition: lmdb.h:465
int mdb_txn_begin(MDB_env *env, MDB_txn *parent, unsigned int flags, MDB_txn **txn)
Create a transaction for use with the environment.
Here is the caller graph for this function:

◆ lmdb_txn_renew()

int cryptonote::lmdb_txn_renew ( MDB_txn txn)
inline

Definition at line 537 of file db_lmdb.cpp.

538 {
539  int res = mdb_txn_renew(txn);
540  if (res == MDB_MAP_RESIZED) {
542  res = mdb_txn_renew(txn);
543  }
544  return res;
545 }
const char * res
Definition: hmac_keccak.cpp:41
MDB_env * mdb_txn_env(MDB_txn *txn)
Returns the transaction&#39;s MDB_env.
void lmdb_resized(MDB_env *env)
Definition: db_lmdb.cpp:502
#define MDB_MAP_RESIZED
Definition: lmdb.h:465
int mdb_txn_renew(MDB_txn *txn)
Renew a read-only transaction.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_acc_outs() [1/2]

bool cryptonote::lookup_acc_outs ( const account_keys acc,
const transaction tx,
std::vector< size_t > &  outs,
uint64_t etn_transfered 
)

Definition at line 899 of file cryptonote_format_utils.cpp.

900  {
902  if(null_pkey == tx_pub_key)
903  return false;
904  std::vector<crypto::public_key> additional_tx_pub_keys = get_additional_tx_pub_keys_from_extra(tx);
905  return lookup_acc_outs(acc, tx, tx_pub_key, additional_tx_pub_keys, outs, etn_transfered);
906  }
crypto::public_key get_tx_pub_key_from_extra(const transaction &tx, size_t pk_index)
const crypto::public_key null_pkey
Definition: crypto.cpp:72
POD_CLASS public_key
Definition: crypto.h:76
bool lookup_acc_outs(const account_keys &acc, const transaction &tx, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, std::vector< size_t > &outs, uint64_t &etn_transfered)
std::vector< crypto::public_key > get_additional_tx_pub_keys_from_extra(const transaction_prefix &tx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_acc_outs() [2/2]

bool cryptonote::lookup_acc_outs ( const account_keys acc,
const transaction tx,
const crypto::public_key tx_pub_key,
const std::vector< crypto::public_key > &  additional_tx_pub_keys,
std::vector< size_t > &  outs,
uint64_t etn_transfered 
)

Definition at line 908 of file cryptonote_format_utils.cpp.

909  {
910  CHECK_AND_ASSERT_MES(additional_tx_pub_keys.empty() || additional_tx_pub_keys.size() == tx.vout.size(), false, "wrong number of additional pubkeys" );
911  etn_transfered = 0;
912  size_t i = 0;
913  for(const tx_out& o: tx.vout)
914  {
915  CHECK_AND_ASSERT_MES(o.target.type() == typeid(txout_to_key), false, "wrong type id in transaction out" );
916  if(is_out_to_acc(acc, boost::get<txout_to_key>(o.target), tx_pub_key, additional_tx_pub_keys, i))
917  {
918  outs.push_back(i);
919  etn_transfered += o.amount;
920  }
921  i++;
922  }
923  return true;
924  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool is_out_to_acc(const account_keys &acc, const txout_to_key &out_key, const crypto::public_key &tx_pub_key, const std::vector< crypto::public_key > &additional_tx_pub_keys, size_t output_index)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ max128bit()

const boost::multiprecision::uint256_t cryptonote::max128bit ( std::numeric_limits< boost::multiprecision::uint128_t >  ::max())
Here is the caller graph for this function:

◆ max256bit()

const boost::multiprecision::uint512_t cryptonote::max256bit ( std::numeric_limits< boost::multiprecision::uint256_t >  ::max())
Here is the caller graph for this function:

◆ max64bit()

const difficulty_type cryptonote::max64bit ( std::numeric_limits< std::uint64_t ::max())
Here is the caller graph for this function:

◆ multisig_rounds_required()

uint32_t cryptonote::multisig_rounds_required ( uint32_t  participants,
uint32_t  threshold 
)

Definition at line 181 of file multisig.cpp.

182  {
183  CHECK_AND_ASSERT_THROW_MES(participants >= threshold, "participants must be greater or equal than threshold");
184  return participants - threshold + 1;
185  }
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
Definition: misc_log_ex.h:173
uint8_t threshold
Definition: blockchain.cpp:92

◆ new_db()

BlockchainDB * cryptonote::new_db ( const std::string &  db_type)

Definition at line 107 of file blockchain_db.cpp.

108 {
109  if (db_type == "lmdb")
110  return new BlockchainLMDB();
111 #if defined(BERKELEY_DB)
112  if (db_type == "berkeley")
113  return new BlockchainBDB();
114 #endif
115  return NULL;
116 }
Here is the caller graph for this function:

◆ next_difficulty() [1/2]

difficulty_type cryptonote::next_difficulty ( std::vector< std::uint64_t timestamps,
std::vector< difficulty_type cumulative_difficulties,
size_t  target_seconds,
uint8_t  version = 1 
)

◆ next_difficulty() [2/2]

difficulty_type cryptonote::next_difficulty ( std::vector< uint64_t timestamps,
std::vector< difficulty_type cumulative_difficulties,
size_t  target_seconds,
uint8_t  version 
)

Definition at line 210 of file difficulty.cpp.

210  {
211 
212  const size_t difficultyWindow = version == 6 ? DIFFICULTY_WINDOW_V6 : DIFFICULTY_WINDOW;
213 
214  //cutoff DIFFICULTY_LAG
215  if(timestamps.size() > difficultyWindow)
216  {
217  timestamps.resize(difficultyWindow);
218  cumulative_difficulties.resize(difficultyWindow);
219  }
220 
221 
222  size_t length = timestamps.size();
223  assert(length == cumulative_difficulties.size());
224  if (length <= 1) {
225  return 1;
226  }
227  static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small");
228  static_assert(DIFFICULTY_WINDOW_V6 >= 2, "Window is too small");
229  assert(length <= difficultyWindow);
230  sort(timestamps.begin(), timestamps.end());
231  size_t cut_begin, cut_end;
232  static_assert(2 * DIFFICULTY_CUT <= DIFFICULTY_WINDOW - 2, "Cut length is too large");
233  static_assert(2 * DIFFICULTY_CUT <= DIFFICULTY_WINDOW_V6 - 2, "Cut length is too large");
234  if (length <= difficultyWindow - 2 * DIFFICULTY_CUT) {
235  cut_begin = 0;
236  cut_end = length;
237  } else {
238  cut_begin = (length - (difficultyWindow - 2 * DIFFICULTY_CUT) + 1) / 2;
239  cut_end = cut_begin + (difficultyWindow - 2 * DIFFICULTY_CUT);
240  }
241  assert(/*cut_begin >= 0 &&*/ cut_begin + 2 <= cut_end && cut_end <= length);
242  uint64_t time_span = timestamps[cut_end - 1] - timestamps[cut_begin];
243  if (time_span == 0) {
244  time_span = 1;
245  }
246  difficulty_type total_work = cumulative_difficulties[cut_end - 1] - cumulative_difficulties[cut_begin];
247  assert(total_work > 0);
248  boost::multiprecision::uint256_t res = (boost::multiprecision::uint256_t(total_work) * target_seconds + time_span - 1) / time_span;
249  if(res > max128bit)
250  return 0; // to behave like previous implementation, may be better return max128bit?
251  return res.convert_to<difficulty_type>();
252  }
const char * res
Definition: hmac_keccak.cpp:41
const boost::multiprecision::uint256_t max128bit(std::numeric_limits< boost::multiprecision::uint128_t >::max())
#define DIFFICULTY_WINDOW
unsigned __int64 uint64_t
Definition: stdint.h:136
#define DIFFICULTY_WINDOW_V6
version
Supported socks variants.
Definition: socks.h:57
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
#define DIFFICULTY_CUT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ next_difficulty_64()

uint64_t cryptonote::next_difficulty_64 ( std::vector< std::uint64_t timestamps,
std::vector< uint64_t cumulative_difficulties,
size_t  target_seconds,
uint8_t  version 
)

Definition at line 123 of file difficulty.cpp.

123  {
124 
125  const size_t difficultyWindow = version == 6 ? DIFFICULTY_WINDOW_V6 : DIFFICULTY_WINDOW;
126 
127  if(timestamps.size() > difficultyWindow)
128  {
129  timestamps.resize(difficultyWindow);
130  cumulative_difficulties.resize(difficultyWindow);
131  }
132 
133  size_t length = timestamps.size();
134  assert(length == cumulative_difficulties.size());
135  if (length <= 1) {
136  return 1;
137  }
138 
139  static_assert(DIFFICULTY_WINDOW >= 2, "Window is too small");
140  static_assert(DIFFICULTY_WINDOW_V6 >= 2, "Window is too small");
141  assert(length <= difficultyWindow);
142  sort(timestamps.begin(), timestamps.end());
143  size_t cut_begin, cut_end;
144 
145  static_assert(2 * DIFFICULTY_CUT <= DIFFICULTY_WINDOW - 2, "Cut length is too large");
146  static_assert(2 * DIFFICULTY_CUT <= DIFFICULTY_WINDOW_V6 - 2, "Cut length is too large");
147 
148  if (length <= difficultyWindow - 2 * DIFFICULTY_CUT) {
149  cut_begin = 0;
150  cut_end = length;
151  } else {
152  cut_begin = (length - (difficultyWindow - 2 * DIFFICULTY_CUT) + 1) / 2;
153  cut_end = cut_begin + (difficultyWindow - 2 * DIFFICULTY_CUT);
154  }
155  assert(/*cut_begin >= 0 &&*/ cut_begin + 2 <= cut_end && cut_end <= length);
156  uint64_t time_span = timestamps[cut_end - 1] - timestamps[cut_begin];
157  if (time_span == 0) {
158  time_span = 1;
159  }
160  uint64_t total_work = cumulative_difficulties[cut_end - 1] - cumulative_difficulties[cut_begin];
161  assert(total_work > 0);
162  uint64_t low, high;
163  mul(total_work, target_seconds, low, high);
164  // blockchain errors "difficulty overhead" if this function returns zero.
165  // TODO: consider throwing an exception instead
166  if (high != 0 || low + time_span - 1 < low) {
167  return 0;
168  }
169  return (low + time_span - 1) / time_span;
170  }
#define DIFFICULTY_WINDOW
unsigned __int64 uint64_t
Definition: stdint.h:136
#define DIFFICULTY_WINDOW_V6
version
Supported socks variants.
Definition: socks.h:57
#define DIFFICULTY_CUT

◆ obj_to_json_str()

template<typename T >
std::string cryptonote::obj_to_json_str ( T obj)

Definition at line 200 of file cryptonote_format_utils.h.

201  {
202  std::stringstream ss;
203  json_archive<true> ar(ss, true);
204  bool r = ::serialization::serialize(ar, obj);
205  CHECK_AND_ASSERT_MES(r, "", "obj_to_json_str failed: serialization::serialize returned false");
206  return ss.str();
207  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<()

std::ostream& cryptonote::operator<< ( std::ostream &  out,
const cryptonote::subaddress_index subaddr_index 
)
inline

Definition at line 59 of file subaddress_index.h.

60  {
61  return out << subaddr_index.major << '/' << subaddr_index.minor;
62  }

◆ operator==() [1/2]

bool cryptonote::operator== ( const cryptonote::transaction a,
const cryptonote::transaction b 
)

Definition at line 363 of file cryptonote_basic_impl.cpp.

363  {
365  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
crypto::hash get_transaction_hash(const transaction &t)
Here is the call graph for this function:

◆ operator==() [2/2]

bool cryptonote::operator== ( const cryptonote::block a,
const cryptonote::block b 
)

Definition at line 367 of file cryptonote_basic_impl.cpp.

367  {
369  }
bool get_block_hash(const block &b, crypto::hash &res)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Here is the call graph for this function:

◆ parse_amount()

bool cryptonote::parse_amount ( uint64_t amount,
const std::string &  str_amount_ 
)

Definition at line 312 of file cryptonote_format_utils.cpp.

313  {
314  std::string str_amount = str_amount_;
315  boost::algorithm::trim(str_amount);
316 
317  size_t point_index = str_amount.find_first_of('.');
318  size_t fraction_size;
319  if (std::string::npos != point_index)
320  {
321  fraction_size = str_amount.size() - point_index - 1;
322  while (default_decimal_point < fraction_size && '0' == str_amount.back())
323  {
324  str_amount.erase(str_amount.size() - 1, 1);
325  --fraction_size;
326  }
327  if (default_decimal_point < fraction_size)
328  return false;
329  str_amount.erase(point_index, 1);
330  }
331  else
332  {
333  fraction_size = 0;
334  }
335 
336  if (str_amount.empty())
337  return false;
338 
339  if (fraction_size < default_decimal_point)
340  {
341  str_amount.append(default_decimal_point - fraction_size, '0');
342  }
343 
344  return string_tools::get_xtype_from_string(amount, str_amount);
345  }
::std::string string
Definition: gtest-port.h:1097
std::string & trim(std::string &str)
Definition: string_tools.h:288
PUSH_WARNINGS bool get_xtype_from_string(OUT XType &val, const std::string &str_id)
Definition: string_tools.h:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_and_validate_block_from_blob() [1/3]

bool cryptonote::parse_and_validate_block_from_blob ( const blobdata b_blob,
block b,
crypto::hash block_hash 
)

Definition at line 1241 of file cryptonote_format_utils.cpp.

1242  {
1243  std::stringstream ss;
1244  ss << b_blob;
1245  binary_archive<false> ba(ss);
1246  bool r = ::serialization::serialize(ba, b);
1247  CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
1248  b.invalidate_hashes();
1249  b.miner_tx.invalidate_hashes();
1250  if (block_hash)
1251  {
1252  calculate_block_hash(b, *block_hash, &b_blob);
1253  ++block_hashes_calculated_count;
1254  b.hash = *block_hash;
1255  b.set_hash_valid(true);
1256  }
1257  return true;
1258  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
bool calculate_block_hash(const block &b, crypto::hash &res, const blobdata *blob)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_and_validate_block_from_blob() [2/3]

bool cryptonote::parse_and_validate_block_from_blob ( const blobdata b_blob,
block b 
)

Definition at line 1260 of file cryptonote_format_utils.cpp.

1261  {
1262  return parse_and_validate_block_from_blob(b_blob, b, NULL);
1263  }
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash &block_hash)
Here is the call graph for this function:

◆ parse_and_validate_block_from_blob() [3/3]

bool cryptonote::parse_and_validate_block_from_blob ( const blobdata b_blob,
block b,
crypto::hash block_hash 
)

Definition at line 1265 of file cryptonote_format_utils.cpp.

1266  {
1267  return parse_and_validate_block_from_blob(b_blob, b, &block_hash);
1268  }
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash &block_hash)
Here is the caller graph for this function:

◆ parse_and_validate_tx_base_from_blob()

bool cryptonote::parse_and_validate_tx_base_from_blob ( const blobdata tx_blob,
transaction tx 
)

Definition at line 146 of file cryptonote_format_utils.cpp.

147  {
148  std::stringstream ss;
149  ss << tx_blob;
150  binary_archive<false> ba(ss);
151  bool r = tx.serialize_base(ba);
152  CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
153  CHECK_AND_ASSERT_MES(expand_transaction_1(tx, true), false, "Failed to expand transaction data");
154  tx.invalidate_hashes();
155  return true;
156  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool expand_transaction_1(transaction &tx, bool base_only)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_and_validate_tx_from_blob() [1/3]

bool cryptonote::parse_and_validate_tx_from_blob ( const blobdata tx_blob,
transaction tx 
)

Definition at line 133 of file cryptonote_format_utils.cpp.

134  {
135  std::stringstream ss;
136  ss << tx_blob;
137  binary_archive<false> ba(ss);
138  bool r = ::serialization::serialize(ba, tx);
139  CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
140  CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
141  tx.invalidate_hashes();
142  tx.set_blob_size(tx_blob.size());
143  return true;
144  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool expand_transaction_1(transaction &tx, bool base_only)
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_and_validate_tx_from_blob() [2/3]

bool cryptonote::parse_and_validate_tx_from_blob ( const blobdata tx_blob,
transaction tx,
crypto::hash tx_hash 
)

Definition at line 168 of file cryptonote_format_utils.cpp.

169  {
170  std::stringstream ss;
171  ss << tx_blob;
172  binary_archive<false> ba(ss);
173  bool r = ::serialization::serialize(ba, tx);
174  CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
175  CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
176  tx.invalidate_hashes();
177  //TODO: validate tx
178 
179  return get_transaction_hash(tx, tx_hash);
180  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool expand_transaction_1(transaction &tx, bool base_only)
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
bool get_transaction_hash(const transaction &t, crypto::hash &res, size_t &blob_size)
Here is the call graph for this function:

◆ parse_and_validate_tx_from_blob() [3/3]

bool cryptonote::parse_and_validate_tx_from_blob ( const blobdata tx_blob,
transaction tx,
crypto::hash tx_hash,
crypto::hash tx_prefix_hash 
)

Definition at line 182 of file cryptonote_format_utils.cpp.

183  {
184  if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
185  return false;
186  get_transaction_prefix_hash(tx, tx_prefix_hash);
187  return true;
188  }
crypto::hash get_transaction_prefix_hash(const transaction_prefix &tx)
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefix_hash)
Here is the call graph for this function:

◆ parse_and_validate_tx_prefix_from_blob()

bool cryptonote::parse_and_validate_tx_prefix_from_blob ( const blobdata tx_blob,
transaction_prefix tx 
)

Definition at line 158 of file cryptonote_format_utils.cpp.

159  {
160  std::stringstream ss;
161  ss << tx_blob;
162  binary_archive<false> ba(ss);
163  bool r = ::serialization::serialize_noeof(ba, tx);
164  CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction prefix from blob");
165  return true;
166  }
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
bool serialize_noeof(Archive &ar, T &v)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_tx_extra()

bool cryptonote::parse_tx_extra ( const std::vector< uint8_t > &  tx_extra,
std::vector< tx_extra_field > &  tx_extra_fields 
)

Definition at line 402 of file cryptonote_format_utils.cpp.

403  {
404  tx_extra_fields.clear();
405 
406  if(tx_extra.empty())
407  return true;
408 
409  std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
410  std::istringstream iss(extra_str);
411  binary_archive<false> ar(iss);
412 
413  bool eof = false;
414  while (!eof)
415  {
416  tx_extra_field field;
417  bool r = ::do_serialize(ar, field);
418  CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
419  tx_extra_fields.push_back(field);
420 
421  std::ios_base::iostate state = iss.rdstate();
422  eof = (EOF == iss.peek());
423  iss.clear(state);
424  }
425  CHECK_AND_NO_ASSERT_MES_L1(::serialization::check_stream_state(ar), false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
426 
427  return true;
428  }
::std::string string
Definition: gtest-port.h:1097
bool check_stream_state(Archive &ar, bool noeof=false)
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:207
void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address &na)
#define CHECK_AND_NO_ASSERT_MES_L1(expr, fail_ret_val, message)
Definition: misc_log_ex.h:193
Definition: blake256.h:37
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ power_integral()

uint64_t cryptonote::power_integral ( uint64_t  a,
uint64_t  b 
)

Definition at line 302 of file cryptonote_format_utils.cpp.

303  {
304  if(b == 0)
305  return 1;
306  uint64_t total = a;
307  for(uint64_t i = 1; i != b; i++)
308  total *= a;
309  return total;
310  }
unsigned __int64 uint64_t
Definition: stdint.h:136
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124

◆ print_etn()

std::string cryptonote::print_etn ( uint64_t  amount,
unsigned int  decimal_point 
)

Definition at line 968 of file cryptonote_format_utils.cpp.

969  {
970  if (decimal_point == (unsigned int)-1)
971  decimal_point = default_decimal_point;
972  std::string s = std::to_string(amount);
973  if(s.size() < decimal_point+1)
974  {
975  s.insert(0, decimal_point+1 - s.size(), '0');
976  }
977  if (decimal_point > 0)
978  s.insert(s.size() - decimal_point, ".");
979  return s;
980  }
::std::string string
Definition: gtest-port.h:1097
std::string to_string(t_connection_type type)
Here is the caller graph for this function:

◆ relative_output_offsets_to_absolute()

std::vector< uint64_t > cryptonote::relative_output_offsets_to_absolute ( const std::vector< uint64_t > &  off)

Definition at line 1214 of file cryptonote_format_utils.cpp.

1215  {
1216  std::vector<uint64_t> res = off;
1217  for(size_t i = 1; i < res.size(); i++)
1218  res[i] += res[i-1];
1219  return res;
1220  }
const char * res
Definition: hmac_keccak.cpp:41
Here is the caller graph for this function:

◆ remove_field_from_tx_extra()

bool cryptonote::remove_field_from_tx_extra ( std::vector< uint8_t > &  tx_extra,
const std::type_info &  type 
)

Definition at line 639 of file cryptonote_format_utils.cpp.

640  {
641  if (tx_extra.empty())
642  return true;
643  std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
644  std::istringstream iss(extra_str);
645  binary_archive<false> ar(iss);
646  std::ostringstream oss;
647  binary_archive<true> newar(oss);
648 
649  bool eof = false;
650  while (!eof)
651  {
652  tx_extra_field field;
653  bool r = ::do_serialize(ar, field);
654  CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
655  if (field.type() != type)
656  ::do_serialize(newar, field);
657 
658  std::ios_base::iostate state = iss.rdstate();
659  eof = (EOF == iss.peek());
660  iss.clear(state);
661  }
662  CHECK_AND_NO_ASSERT_MES_L1(::serialization::check_stream_state(ar), false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
663  tx_extra.clear();
664  std::string s = oss.str();
665  tx_extra.reserve(s.size());
666  std::copy(s.begin(), s.end(), std::back_inserter(tx_extra));
667  return true;
668  }
::std::string string
Definition: gtest-port.h:1097
bool check_stream_state(Archive &ar, bool noeof=false)
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:207
void copy(key &AA, const key &A)
Definition: rctOps.h:79
void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address &na)
#define CHECK_AND_NO_ASSERT_MES_L1(expr, fail_ret_val, message)
Definition: misc_log_ex.h:193
Definition: blake256.h:37
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
Here is the call graph for this function:

◆ set_default_decimal_point()

void cryptonote::set_default_decimal_point ( unsigned int  decimal_point)

Definition at line 936 of file cryptonote_format_utils.cpp.

937  {
938  switch (decimal_point)
939  {
940  case 2:
941  default_decimal_point = decimal_point;
942  break;
943  default:
944  ASSERT_MES_AND_THROW("Invalid decimal point specification: " << decimal_point);
945  }
946  }
#define ASSERT_MES_AND_THROW(message)
Definition: misc_log_ex.h:172

◆ set_encrypted_payment_id_to_tx_extra_nonce()

void cryptonote::set_encrypted_payment_id_to_tx_extra_nonce ( blobdata extra_nonce,
const crypto::hash8 payment_id 
)

Definition at line 678 of file cryptonote_format_utils.cpp.

679  {
680  extra_nonce.clear();
681  extra_nonce.push_back(TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID);
682  const uint8_t* payment_id_ptr = reinterpret_cast<const uint8_t*>(&payment_id);
683  std::copy(payment_id_ptr, payment_id_ptr + sizeof(payment_id), std::back_inserter(extra_nonce));
684  }
unsigned char uint8_t
Definition: stdint.h:124
void copy(key &AA, const key &A)
Definition: rctOps.h:79
#define TX_EXTRA_NONCE_ENCRYPTED_PAYMENT_ID
Definition: tx_extra.h:48
Here is the call graph for this function:

◆ set_payment_id_to_tx_extra_nonce()

void cryptonote::set_payment_id_to_tx_extra_nonce ( blobdata extra_nonce,
const crypto::hash payment_id 
)

Definition at line 670 of file cryptonote_format_utils.cpp.

671  {
672  extra_nonce.clear();
673  extra_nonce.push_back(TX_EXTRA_NONCE_PAYMENT_ID);
674  const uint8_t* payment_id_ptr = reinterpret_cast<const uint8_t*>(&payment_id);
675  std::copy(payment_id_ptr, payment_id_ptr + sizeof(payment_id), std::back_inserter(extra_nonce));
676  }
unsigned char uint8_t
Definition: stdint.h:124
void copy(key &AA, const key &A)
Definition: rctOps.h:79
#define TX_EXTRA_NONCE_PAYMENT_ID
Definition: tx_extra.h:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ short_hash_str()

std::string cryptonote::short_hash_str ( const crypto::hash h)

Definition at line 837 of file cryptonote_format_utils.cpp.

838  {
840  CHECK_AND_ASSERT_MES(res.size() == 64, res, "wrong hash256 with string_tools::pod_to_hex conversion");
841  auto erased_pos = res.erase(8, 48);
842  res.insert(8, "....");
843  return res;
844  }
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
std::string pod_to_hex(const t_pod_type &s)
Definition: string_tools.h:317
Here is the call graph for this function:

◆ slow_memmem()

size_t cryptonote::slow_memmem ( const void *  start_buff,
size_t  buflen,
const void *  pat,
size_t  patlen 
)

Definition at line 1315 of file core_rpc_server.cpp.

1316  {
1317  const void* buf = start_buff;
1318  const void* end=(const char*)buf+buflen;
1319  if (patlen > buflen || patlen == 0) return 0;
1320  while(buflen>0 && (buf=memchr(buf,((const char*)pat)[0],buflen-patlen+1)))
1321  {
1322  if(memcmp(buf,pat,patlen)==0)
1323  return (const char*)buf - (const char*)start_buff;
1324  buf=(const char*)buf+1;
1325  buflen = (const char*)end - (const char*)buf;
1326  }
1327  return 0;
1328  }
size_t buflen
Definition: slow_memmem.cpp:73
const char * buf
Definition: slow_memmem.cpp:74
size_t patlen
Definition: slow_memmem.cpp:75
const char * pat
Definition: slow_memmem.cpp:76
Here is the caller graph for this function:

◆ sort_tx_extra()

bool cryptonote::sort_tx_extra ( const std::vector< uint8_t > &  tx_extra,
std::vector< uint8_t > &  sorted_tx_extra,
bool  allow_partial 
)

Definition at line 445 of file cryptonote_format_utils.cpp.

446  {
447  std::vector<tx_extra_field> tx_extra_fields;
448 
449  if(tx_extra.empty())
450  {
451  sorted_tx_extra.clear();
452  return true;
453  }
454 
455  std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
456  std::istringstream iss(extra_str);
457  binary_archive<false> ar(iss);
458 
459  bool eof = false;
460  size_t processed = 0;
461  while (!eof)
462  {
463  tx_extra_field field;
464  bool r = ::do_serialize(ar, field);
465  if (!r)
466  {
467  MWARNING("failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
468  if (!allow_partial)
469  return false;
470  break;
471  }
472  tx_extra_fields.push_back(field);
473  processed = iss.tellg();
474 
475  std::ios_base::iostate state = iss.rdstate();
476  eof = (EOF == iss.peek());
477  iss.clear(state);
478  }
480  {
481  MWARNING("failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
482  if (!allow_partial)
483  return false;
484  }
485  MTRACE("Sorted " << processed << "/" << tx_extra.size());
486 
487  std::ostringstream oss;
488  binary_archive<true> nar(oss);
489 
490  // sort by:
491  if (!pick<tx_extra_pub_key>(nar, tx_extra_fields, TX_EXTRA_TAG_PUBKEY)) return false;
492  if (!pick<tx_extra_additional_pub_keys>(nar, tx_extra_fields, TX_EXTRA_TAG_ADDITIONAL_PUBKEYS)) return false;
493  if (!pick<tx_extra_nonce>(nar, tx_extra_fields, TX_EXTRA_NONCE)) return false;
494  if (!pick<tx_extra_merge_mining_tag>(nar, tx_extra_fields, TX_EXTRA_MERGE_MINING_TAG)) return false;
495  if (!pick<tx_extra_bridge_source_address>(nar, tx_extra_fields, TX_EXTRA_TAG_BRIDGE_SOURCE_ADDRESS)) return false;
496  if (!pick<tx_extra_bridge_smartchain_address>(nar, tx_extra_fields, TX_EXTRA_TAG_BRIDGE_SMARTCHAIN_ADDRESS)) return false;
497  if (!pick<tx_extra_mysterious_minergate>(nar, tx_extra_fields, TX_EXTRA_MYSTERIOUS_MINERGATE_TAG)) return false;
498  if (!pick<tx_extra_padding>(nar, tx_extra_fields, TX_EXTRA_TAG_PADDING)) return false;
499 
500  // if not empty, someone added a new type and did not add a case above
501  if (!tx_extra_fields.empty())
502  {
503  MERROR("tx_extra_fields not empty after sorting, someone forgot to add a case above");
504  return false;
505  }
506 
507  std::string oss_str = oss.str();
508  if (allow_partial && processed < tx_extra.size())
509  {
510  MDEBUG("Appending unparsed data");
511  oss_str += std::string((const char*)tx_extra.data() + processed, tx_extra.size() - processed);
512  }
513  sorted_tx_extra = std::vector<uint8_t>(oss_str.begin(), oss_str.end());
514  return true;
515  }
#define MERROR(x)
Definition: misc_log_ex.h:73
#define TX_EXTRA_MYSTERIOUS_MINERGATE_TAG
Definition: tx_extra.h:45
#define TX_EXTRA_TAG_BRIDGE_SOURCE_ADDRESS
Definition: tx_extra.h:43
#define MTRACE(x)
Definition: misc_log_ex.h:77
::std::string string
Definition: gtest-port.h:1097
bool check_stream_state(Archive &ar, bool noeof=false)
boost::variant< tx_extra_padding, tx_extra_pub_key, tx_extra_nonce, tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_bridge_source_address, tx_extra_bridge_smartchain_address, tx_extra_mysterious_minergate > tx_extra_field
Definition: tx_extra.h:207
#define MDEBUG(x)
Definition: misc_log_ex.h:76
#define TX_EXTRA_MERGE_MINING_TAG
Definition: tx_extra.h:41
#define TX_EXTRA_TAG_PADDING
Definition: tx_extra.h:38
#define TX_EXTRA_TAG_PUBKEY
Definition: tx_extra.h:39
#define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS
Definition: tx_extra.h:42
#define MWARNING(x)
Definition: misc_log_ex.h:74
void do_serialize(boost::mpl::false_, Archive &a, epee::net_utils::network_address &na)
#define TX_EXTRA_NONCE
Definition: tx_extra.h:40
Definition: blake256.h:37
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
#define TX_EXTRA_TAG_BRIDGE_SMARTCHAIN_ADDRESS
Definition: tx_extra.h:44
Here is the call graph for this function:
Here is the caller graph for this function:

◆ t_serializable_object_from_blob()

template<class t_object >
bool cryptonote::t_serializable_object_from_blob ( t_object &  to,
const blobdata b_blob 
)

Definition at line 149 of file cryptonote_format_utils.h.

150  {
151  std::stringstream ss;
152  ss << b_blob;
153  binary_archive<false> ba(ss);
154  bool r = ::serialization::serialize(ba, to);
155  return r;
156  }
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Here is the call graph for this function:

◆ t_serializable_object_to_blob() [1/2]

template<class t_object >
bool cryptonote::t_serializable_object_to_blob ( const t_object &  to,
blobdata b_blob 
)

Definition at line 159 of file cryptonote_format_utils.h.

160  {
161  std::stringstream ss;
162  binary_archive<true> ba(ss);
163  bool r = ::serialization::serialize(ba, const_cast<t_object&>(to));
164  b_blob = ss.str();
165  return r;
166  }
void serialize(Archive &a, unsigned_tx_set &x, const boost::serialization::version_type ver)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ t_serializable_object_to_blob() [2/2]

template<class t_object >
blobdata cryptonote::t_serializable_object_to_blob ( const t_object &  to)

Definition at line 169 of file cryptonote_format_utils.h.

170  {
171  blobdata b;
173  return b;
174  }
blobdata t_serializable_object_to_blob(const t_object &to)
std::string blobdata
Definition: blobdatatype.h:39
Here is the call graph for this function:

◆ tx_sanity_check()

bool cryptonote::tx_sanity_check ( Blockchain blockchain,
const cryptonote::blobdata tx_blob 
)

Definition at line 42 of file tx_sanity_check.cpp.

43 {
45 
47  {
48  MERROR("Failed to parse transaction");
49  return false;
50  }
51 
53  {
54  MERROR("Transaction is coinbase");
55  return false;
56  }
57  std::set<uint64_t> rct_indices;
58  size_t n_indices = 0;
59 
60  for (const auto &txin : tx.vin)
61  {
62  if (txin.type() != typeid(cryptonote::txin_to_key))
63  continue;
64  const cryptonote::txin_to_key &in_to_key = boost::get<cryptonote::txin_to_key>(txin);
65  if (in_to_key.amount != 0)
66  continue;
67  const std::vector<uint64_t> absolute = cryptonote::relative_output_offsets_to_absolute(in_to_key.key_offsets);
68  for (uint64_t offset: absolute)
69  rct_indices.insert(offset);
70  n_indices += in_to_key.key_offsets.size();
71  }
72 
73  if (tx.version < 3 && n_indices <= 10)
74  {
75  MERROR("n_indices is only " << n_indices);
76  return true;
77  }
78 
79  return true;
80 }
#define MERROR(x)
Definition: misc_log_ex.h:73
bool is_coinbase(const transaction &tx)
std::vector< uint64_t > key_offsets
std::vector< uint64_t > relative_output_offsets_to_absolute(const std::vector< uint64_t > &off)
unsigned __int64 uint64_t
Definition: stdint.h:136
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_to_blob() [1/2]

blobdata cryptonote::tx_to_blob ( const transaction tx)

Definition at line 1280 of file cryptonote_format_utils.cpp.

1281  {
1282  return t_serializable_object_to_blob(tx);
1283  }
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_to_blob() [2/2]

bool cryptonote::tx_to_blob ( const transaction tx,
blobdata b_blob 
)

Definition at line 1285 of file cryptonote_format_utils.cpp.

1286  {
1287  return t_serializable_object_to_blob(tx, b_blob);
1288  }
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ arg_addr_db_salvage

const command_line::arg_descriptor< bool, false > cryptonote::arg_addr_db_salvage
Initial value:
= {
"addr-db-salvage"
, "Try to salvage a addr tx database if it seems corrupted"
, false
}

Definition at line 101 of file blockchain_db.cpp.

◆ arg_block_download_max_size

const command_line::arg_descriptor< size_t > cryptonote::arg_block_download_max_size
Initial value:
= {
"block-download-max-size"
, "Set maximum size of block download queue in bytes (0 for default)"
, 0
}

Definition at line 117 of file cryptonote_core.cpp.

◆ arg_data_dir

const command_line::arg_descriptor< std::string, false, true, 2 > cryptonote::arg_data_dir
Initial value:
= {
"data-dir"
, "Specify data directory"
, [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val)->std::string {
if (testnet_stagenet[0])
return (boost::filesystem::path(val) / "testnet").string();
else if (testnet_stagenet[1])
return (boost::filesystem::path(val) / "stagenet").string();
return val;
}
}
::std::string string
Definition: gtest-port.h:1097
const command_line::arg_descriptor< bool, false > arg_stagenet_on
std::string get_default_data_dir()
Returns the default data directory.
Definition: util.cpp:600
const command_line::arg_descriptor< bool, false > arg_testnet_on

Definition at line 96 of file cryptonote_core.cpp.

◆ arg_db_salvage

const command_line::arg_descriptor< bool, false > cryptonote::arg_db_salvage
Initial value:
= {
"db-salvage"
, "Try to salvage a blockchain database if it seems corrupted"
, false
}

Definition at line 95 of file blockchain_db.cpp.

◆ arg_db_sync_mode

const command_line::arg_descriptor< std::string > cryptonote::arg_db_sync_mode
Initial value:
= {
"db-sync-mode"
, "Specify sync option, using format [safe|fast|fastest]:[sync|async]:[<nblocks_per_sync>[blocks]|<nbytes_per_sync>[bytes]]."
, "fast:async:250000000bytes"
}

Definition at line 90 of file blockchain_db.cpp.

◆ arg_db_type

const command_line::arg_descriptor< std::string > cryptonote::arg_db_type
Initial value:
= {
"db-type"
, DEFAULT_DB_TYPE
}
std::string arg_db_type_description

Definition at line 85 of file blockchain_db.cpp.

◆ arg_db_type_description

std::string cryptonote::arg_db_type_description = "Specify database type, available: " + cryptonote::blockchain_db_types(", ")

Definition at line 84 of file blockchain_db.cpp.

◆ arg_disable_dns_checkpoints

const command_line::arg_descriptor<bool> cryptonote::arg_disable_dns_checkpoints
Initial value:
= {
"disable-dns-checkpoints"
, "Do not retrieve checkpoints from DNS"
}

Definition at line 113 of file cryptonote_core.cpp.

◆ arg_fallback_to_pow

const command_line::arg_descriptor< bool > cryptonote::arg_fallback_to_pow
Initial value:
= {
"fallback-to-pow"
, "Disables all Validator feature and fallback consensus to standard Proof-of-Work (CryptoNote V1)."
"This argument is a decentralization safety measure in case something happens with Electroneum Ltd"
"so that users can fork the network to Proof of Work. (Anti Meteor Feature)."
"Before using this flag, please determine whether or not you want to use a checkpoint for the PoW fork (--fallback-to-pow-checkpoint-hash and --fallback-to-pow-checkpoint-height)"
"Please note that this is only a temporary solution so that people can continue the chain in a sensible decentralised way immediately if Electroneum ceased to exist. Long term solutions are explained in our docs folder"
"***WARNING: IF YOU USE THIS ARGUMENT AND MINE BLOCKS AND LATER WISH TO RETURN TO THE TIP OF THE V8 *MODERATED* BLOCKCHAIN, YOU WILL HAVE TO MANUALLY POP BLOCKS BACK USING THE DAEMON (OR IMPORT) PROGRAM"
, false
}

Definition at line 223 of file cryptonote_core.cpp.

◆ arg_fallback_to_pow_checkpoint_hash

const command_line::arg_descriptor< std::string > cryptonote::arg_fallback_to_pow_checkpoint_hash
Initial value:
= {
"fallback-to-pow-checkpoint-hash"
, "Used in conjunction with --fallback-to-pow. This flag allows you to specify the *hash* of a checkpoint that would mark the new beginning of the PoW chain agreed upon by the community"
, ""
}

Definition at line 240 of file cryptonote_core.cpp.

◆ arg_fallback_to_pow_checkpoint_height

const command_line::arg_descriptor< uint64_t > cryptonote::arg_fallback_to_pow_checkpoint_height
Initial value:
= {
"fallback-to-pow-checkpoint-height"
, "Used in conjunction with --fallback-to-pow. This flag allows you to specify the *height* of a checkpoint that would mark the new beginning of the PoW chain agreed upon by the community"
, 0
}

Definition at line 234 of file cryptonote_core.cpp.

◆ arg_fixed_difficulty

const command_line::arg_descriptor< difficulty_type > cryptonote::arg_fixed_difficulty
Initial value:
= {
"fixed-difficulty"
, "Fixed difficulty used for testing."
, 0
}

Definition at line 86 of file cryptonote_core.cpp.

◆ arg_offline

const command_line::arg_descriptor< bool > cryptonote::arg_offline
Initial value:
= {
"offline"
, "Do not listen for peers, nor connect to any"
}

Definition at line 109 of file cryptonote_core.cpp.

◆ arg_regtest_on

const command_line::arg_descriptor< bool, false > cryptonote::arg_regtest_on
Initial value:
= {
"regtest"
, "Run in a regression testing mode."
, false
}

Definition at line 81 of file cryptonote_core.cpp.

◆ arg_skip_block_sig_verification

const command_line::arg_descriptor< bool > cryptonote::arg_skip_block_sig_verification
Initial value:
= {
"ignore-bsig"
, "Ignore block signature & signatory verification. Used for testing."
, false
}

Definition at line 91 of file cryptonote_core.cpp.

◆ arg_stagenet_on

const command_line::arg_descriptor< bool, false > cryptonote::arg_stagenet_on
Initial value:
= {
"stagenet"
, "Run on stagenet. The wallet must be launched with --stagenet flag."
, false
}

Definition at line 76 of file cryptonote_core.cpp.

◆ arg_testnet_on

const command_line::arg_descriptor< bool, false > cryptonote::arg_testnet_on
Initial value:
= {
"testnet"
, "Run on testnet. The wallet must be launched with --testnet flag."
, false
}

Definition at line 71 of file cryptonote_core.cpp.