Skip to content

Commit

Permalink
wallet: fix offline signing calling a daemon RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
moneromooo-monero committed Mar 21, 2019
1 parent f5d7652 commit adf6d77
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/cryptonote_basic/cryptonote_boost_serialization.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ namespace boost
if (x.type == rct::RCTTypeBulletproof || x.type == rct::RCTTypeBulletproof2) if (x.type == rct::RCTTypeBulletproof || x.type == rct::RCTTypeBulletproof2)
a & x.p.pseudoOuts; a & x.p.pseudoOuts;
} }

template <class Archive>
inline void serialize(Archive &a, rct::RCTConfig &x, const boost::serialization::version_type ver)
{
a & x.range_proof_type;
a & x.bp_version;
}
} }
} }


Expand Down
8 changes: 4 additions & 4 deletions src/device_trezor/trezor/protocol.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ namespace tx {
} }
} }


static unsigned get_rsig_type(bool use_bulletproof, size_t num_outputs){ static unsigned get_rsig_type(const rct::RCTConfig &rct_config, size_t num_outputs){
if (!use_bulletproof){ if (rct_config.range_proof_type == rct::RangeProofBorromean){
return rct::RangeProofBorromean; return rct::RangeProofBorromean;
} else if (num_outputs > BULLETPROOF_MAX_OUTPUTS){ } else if (num_outputs > BULLETPROOF_MAX_OUTPUTS){
return rct::RangeProofMultiOutputBulletproof; return rct::RangeProofMultiOutputBulletproof;
Expand Down Expand Up @@ -506,9 +506,9 @@ namespace tx {


// Rsig decision // Rsig decision
auto rsig_data = tsx_data.mutable_rsig_data(); auto rsig_data = tsx_data.mutable_rsig_data();
m_ct.rsig_type = get_rsig_type(tx.use_bulletproofs, tx.splitted_dsts.size()); m_ct.rsig_type = get_rsig_type(tx.rct_config, tx.splitted_dsts.size());
rsig_data->set_rsig_type(m_ct.rsig_type); rsig_data->set_rsig_type(m_ct.rsig_type);
if (tx.use_bulletproofs){ if (tx.rct_config.range_proof_type != rct::RangeProofBorromean){
m_ct.bp_version = (m_aux_data->bp_version ? m_aux_data->bp_version.get() : 1); m_ct.bp_version = (m_aux_data->bp_version ? m_aux_data->bp_version.get() : 1);
rsig_data->set_bp_version((uint32_t) m_ct.bp_version); rsig_data->set_bp_version((uint32_t) m_ct.bp_version);
} }
Expand Down
2 changes: 1 addition & 1 deletion src/device_trezor/trezor/protocol.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ namespace tx {
} }


bool is_req_bulletproof() const { bool is_req_bulletproof() const {
return m_ct.tx_data.use_bulletproofs; return m_ct.tx_data.rct_config.range_proof_type != rct::RangeProofBorromean;
} }


bool is_bulletproof() const { bool is_bulletproof() const {
Expand Down
18 changes: 4 additions & 14 deletions src/wallet/wallet2.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6012,12 +6012,7 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, std::vector<wallet2::pendin
LOG_PRINT_L1(" " << (n+1) << ": " << sd.sources.size() << " inputs, ring size " << sd.sources[0].outputs.size()); LOG_PRINT_L1(" " << (n+1) << ": " << sd.sources.size() << " inputs, ring size " << sd.sources[0].outputs.size());
signed_txes.ptx.push_back(pending_tx()); signed_txes.ptx.push_back(pending_tx());
tools::wallet2::pending_tx &ptx = signed_txes.ptx.back(); tools::wallet2::pending_tx &ptx = signed_txes.ptx.back();
rct::RCTConfig rct_config = { rct::RangeProofBorromean, 0 }; rct::RCTConfig rct_config = sd.rct_config;
if (sd.use_bulletproofs)
{
rct_config.range_proof_type = rct::RangeProofPaddedBulletproof;
rct_config.bp_version = use_fork_rules(HF_VERSION_SMALLER_BP, -10) ? 2 : 1;
}
crypto::secret_key tx_key; crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys; std::vector<crypto::secret_key> additional_tx_keys;
rct::multisig_out msout; rct::multisig_out msout;
Expand Down Expand Up @@ -6494,12 +6489,7 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto
cryptonote::transaction tx; cryptonote::transaction tx;
rct::multisig_out msout = ptx.multisig_sigs.front().msout; rct::multisig_out msout = ptx.multisig_sigs.front().msout;
auto sources = sd.sources; auto sources = sd.sources;
rct::RCTConfig rct_config = { rct::RangeProofBorromean, 0 }; rct::RCTConfig rct_config = sd.rct_config;
if (sd.use_bulletproofs)
{
rct_config.range_proof_type = rct::RangeProofPaddedBulletproof;
rct_config.bp_version = use_fork_rules(HF_VERSION_SMALLER_BP, -10) ? 2 : 1;
}
bool r = cryptonote::construct_tx_with_tx_key(m_account.get_keys(), m_subaddresses, sources, sd.splitted_dsts, ptx.change_dts.addr, sd.extra, tx, sd.unlock_time, ptx.tx_key, ptx.additional_tx_keys, sd.use_rct, rct_config, &msout, false); bool r = cryptonote::construct_tx_with_tx_key(m_account.get_keys(), m_subaddresses, sources, sd.splitted_dsts, ptx.change_dts.addr, sd.extra, tx, sd.unlock_time, ptx.tx_key, ptx.additional_tx_keys, sd.use_rct, rct_config, &msout, false);
THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sd.sources, sd.splitted_dsts, sd.unlock_time, m_nettype); THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sd.sources, sd.splitted_dsts, sd.unlock_time, m_nettype);


Expand Down Expand Up @@ -7960,7 +7950,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
ptx.construction_data.extra = tx.extra; ptx.construction_data.extra = tx.extra;
ptx.construction_data.unlock_time = unlock_time; ptx.construction_data.unlock_time = unlock_time;
ptx.construction_data.use_rct = false; ptx.construction_data.use_rct = false;
ptx.construction_data.use_bulletproofs = false; ptx.construction_data.rct_config = { rct::RangeProofBorromean, 0 };
ptx.construction_data.dests = dsts; ptx.construction_data.dests = dsts;
// record which subaddress indices are being used as inputs // record which subaddress indices are being used as inputs
ptx.construction_data.subaddr_account = subaddr_account; ptx.construction_data.subaddr_account = subaddr_account;
Expand Down Expand Up @@ -8242,7 +8232,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
ptx.construction_data.extra = tx.extra; ptx.construction_data.extra = tx.extra;
ptx.construction_data.unlock_time = unlock_time; ptx.construction_data.unlock_time = unlock_time;
ptx.construction_data.use_rct = true; ptx.construction_data.use_rct = true;
ptx.construction_data.use_bulletproofs = !tx.rct_signatures.p.bulletproofs.empty(); ptx.construction_data.rct_config = { tx.rct_signatures.p.bulletproofs.empty() ? rct::RangeProofBorromean : rct::RangeProofPaddedBulletproof, use_fork_rules(HF_VERSION_SMALLER_BP, -10) ? 2 : 1};
ptx.construction_data.dests = dsts; ptx.construction_data.dests = dsts;
// record which subaddress indices are being used as inputs // record which subaddress indices are being used as inputs
ptx.construction_data.subaddr_account = subaddr_account; ptx.construction_data.subaddr_account = subaddr_account;
Expand Down
24 changes: 20 additions & 4 deletions src/wallet/wallet2.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ namespace tools
std::vector<uint8_t> extra; std::vector<uint8_t> extra;
uint64_t unlock_time; uint64_t unlock_time;
bool use_rct; bool use_rct;
bool use_bulletproofs; rct::RCTConfig rct_config;
std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change std::vector<cryptonote::tx_destination_entry> dests; // original setup, does not include change
uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer uint32_t subaddr_account; // subaddress account of your wallet to be used in this transfer
std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer std::set<uint32_t> subaddr_indices; // set of address indices used as inputs in this transfer
Expand All @@ -387,7 +387,7 @@ namespace tools
FIELD(extra) FIELD(extra)
FIELD(unlock_time) FIELD(unlock_time)
FIELD(use_rct) FIELD(use_rct)
FIELD(use_bulletproofs) FIELD(rct_config)
FIELD(dests) FIELD(dests)
FIELD(subaddr_account) FIELD(subaddr_account)
FIELD(subaddr_indices) FIELD(subaddr_indices)
Expand Down Expand Up @@ -1487,7 +1487,7 @@ BOOST_CLASS_VERSION(tools::wallet2::address_book_row, 17)
BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0) BOOST_CLASS_VERSION(tools::wallet2::reserve_proof_entry, 0)
BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0) BOOST_CLASS_VERSION(tools::wallet2::unsigned_tx_set, 0)
BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1) BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1)
BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 3) BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 4)
BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 3) BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 3)
BOOST_CLASS_VERSION(tools::wallet2::multisig_sig, 0) BOOST_CLASS_VERSION(tools::wallet2::multisig_sig, 0)


Expand Down Expand Up @@ -1856,11 +1856,27 @@ namespace boost
a & x.subaddr_account; a & x.subaddr_account;
a & x.subaddr_indices; a & x.subaddr_indices;
if (ver < 2) if (ver < 2)
{
if (!typename Archive::is_saving())
x.rct_config = { rct::RangeProofBorromean, 0 };
return; return;
}
a & x.selected_transfers; a & x.selected_transfers;
if (ver < 3) if (ver < 3)
{
if (!typename Archive::is_saving())
x.rct_config = { rct::RangeProofBorromean, 0 };
return; return;
a & x.use_bulletproofs; }
if (ver < 4)
{
bool use_bulletproofs = x.rct_config.range_proof_type != rct::RangeProofBorromean;
a & use_bulletproofs;
if (!typename Archive::is_saving())
x.rct_config = { use_bulletproofs ? rct::RangeProofBulletproof : rct::RangeProofBorromean, 0 };
return;
}
a & x.rct_config;
} }


template <class Archive> template <class Archive>
Expand Down

0 comments on commit adf6d77

Please sign in to comment.