Update to latest monero-rs

This commit is contained in:
Thomas Eizinger 2021-05-19 14:08:00 +10:00
parent 642f1d8318
commit ec1916161e
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
13 changed files with 59 additions and 83 deletions

11
Cargo.lock generated
View File

@ -848,8 +848,7 @@ dependencies = [
[[package]]
name = "curve25519-dalek"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "639891fde0dbea823fc3d798a0fdf9d2f9440a42d64a78ab3488b0ca025117b3"
source = "git+https://github.com/thomaseizinger/curve25519-dalek?rev=8cc9ad36bd30ceab6073ff64655473c6b5aa4aab#8cc9ad36bd30ceab6073ff64655473c6b5aa4aab"
dependencies = [
"byteorder",
"digest 0.9.0",
@ -2265,10 +2264,11 @@ dependencies = [
[[package]]
name = "monero"
version = "0.12.0"
source = "git+https://github.com/comit-network/monero-rs?branch=fix-bulletproofs#fae784dabbbc7c759334a031a2802813fffec792"
source = "git+https://github.com/comit-network/monero-rs?rev=fee1f7054a4b8500dcf7867ebd1b9e7f693cd566#fee1f7054a4b8500dcf7867ebd1b9e7f693cd566"
dependencies = [
"base58-monero",
"clear_on_drop",
"conquer-once",
"curve25519-dalek",
"fixed-hash",
"hash_edwards_to_edwards",
@ -2277,7 +2277,6 @@ dependencies = [
"integer-encoding",
"itertools 0.10.0",
"keccak-hash",
"lazy_static",
"rand 0.7.3",
"serde",
"serde-big-array",
@ -2309,8 +2308,7 @@ dependencies = [
[[package]]
name = "monero-epee-bin-serde"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13be5b525af150f294b98d4291b0ec01e5bc157db740de2822827c17561d3960"
source = "git+https://github.com/comit-network/monero-epee-bin-serde#f2c8baa39f04ac4e7a71c76a16c2c6f9a5ee3e3b"
dependencies = [
"byteorder",
"serde",
@ -2322,6 +2320,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"futures",
"monero",
"monero-rpc",
"rand 0.7.3",
"spectral",

View File

@ -3,4 +3,6 @@ members = ["monero-adaptor", "monero-harness", "monero-rpc", "swap", "monero-wal
[patch.crates-io]
torut = { git = "https://github.com/bonomat/torut/", branch = "feature-flag-tor-secret-keys", default-features = false, features = [ "v3", "control" ] }
monero = { git = "https://github.com/comit-network/monero-rs", branch = "fix-bulletproofs" }
monero = { git = "https://github.com/comit-network/monero-rs", rev = "fee1f7054a4b8500dcf7867ebd1b9e7f693cd566" }
monero-epee-bin-serde = { git = "https://github.com/comit-network/monero-epee-bin-serde" }
curve25519-dalek = { git = "https://github.com/thomaseizinger/curve25519-dalek", rev = "8cc9ad36bd30ceab6073ff64655473c6b5aa4aab" }

View File

@ -18,10 +18,9 @@ async fn monerod_integration_test() {
let (monero, _monerod_container, _monero_wallet_rpc_containers) =
Monero::new(&cli, vec![]).await.unwrap();
let signing_key = curve25519_dalek::scalar::Scalar::random(&mut rng);
let lock_kp = monero::KeyPair {
view: monero::PrivateKey::from_scalar(curve25519_dalek::scalar::Scalar::random(&mut rng)),
spend: monero::PrivateKey::from_scalar(signing_key),
view: monero::PrivateKey::random(&mut rng),
spend: monero::PrivateKey::random(&mut rng),
};
let spend_amount = 999600000000;

View File

@ -14,3 +14,4 @@ testcontainers = "0.12"
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "time", "macros" ] }
tracing = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = [ "fmt", "ansi", "env-filter", "tracing-log" ] }
monero = "0.12"

View File

@ -1,3 +1,4 @@
use monero::util::key::ScalarExt;
use monero_harness::{Monero, MoneroWalletRpc};
use monero_rpc::wallet::MoneroWalletRpc as _;
use spectral::prelude::*;
@ -45,7 +46,7 @@ async fn fund_transfer_and_check_tx_key() {
// check if tx was actually seen
let tx_id = transfer.tx_hash;
let tx_key = transfer.tx_key.unwrap().to_string();
let tx_key = transfer.tx_key.unwrap().display_hex().to_string();
let res = bob_wallet
.client()
.check_tx_key(tx_id, tx_key, bob_address)

View File

@ -233,7 +233,7 @@ pub struct OutKey {
#[serde(with = "byte_array")]
pub key: PublicKey,
#[serde(with = "byte_array")]
pub mask: ringct::Key,
pub mask: PublicKey,
#[serde(with = "byte_array")]
pub txid: Hash,
pub unlocked: bool,

View File

@ -1,4 +1,5 @@
use anyhow::{Context, Result};
use monero::util::key::ScalarExt;
use serde::{de::Error, Deserialize, Deserializer, Serialize};
#[jsonrpc_client::api(version = "2.0")]
@ -220,7 +221,9 @@ where
return Ok(None);
}
Ok(Some(string.parse().map_err(D::Error::custom)?))
Ok(Some(
monero::PrivateKey::from_str(&string).map_err(D::Error::custom)?,
))
}
#[cfg(test)]

View File

@ -2,15 +2,15 @@ mod v2;
use anyhow::{Context, Result};
use curve25519_dalek::constants::ED25519_BASEPOINT_POINT;
use curve25519_dalek::edwards::{CompressedEdwardsY, EdwardsPoint};
use curve25519_dalek::edwards::EdwardsPoint;
use curve25519_dalek::scalar::Scalar;
use hash_edwards_to_edwards::hash_point_to_point;
use itertools::Itertools;
use monero::blockdata::transaction::{ExtraField, KeyImage, SubField, TxOutTarget};
use monero::cryptonote::hash::Hashable;
use monero::cryptonote::onetime_key::KeyGenerator;
use monero::util::key::H;
use monero::util::ringct::{CtKey, EcdhInfo, Key, RctSig, RctSigBase, RctSigPrunable, RctType};
use monero::util::key::{EdwardsPointExt, H};
use monero::util::ringct::{EcdhInfo, RctSig, RctSigBase, RctSigPrunable, RctType};
use monero::{
Address, KeyPair, OwnedTxOut, PrivateKey, PublicKey, Transaction, TransactionPrefix, TxIn,
TxOut, VarInt,
@ -47,7 +47,7 @@ impl ConfidentialTransactionBuilder {
decoy_inputs: [DecoyInput; 10],
keys: KeyPair,
) -> Self {
let actual_signing_key = input_to_spend.recover_key(&keys).scalar;
let actual_signing_key = input_to_spend.recover_key(&keys);
let signing_pk = actual_signing_key * ED25519_BASEPOINT_POINT;
Self {
@ -77,13 +77,17 @@ impl ConfidentialTransactionBuilder {
let next_index = self.outputs.len();
let ecdh_key = PrivateKey::random(rng);
let (ecdh_info, blinding_factor) = EcdhInfo::new_bulletproof(amount, ecdh_key.scalar);
let (ecdh_info, blinding_factor) = EcdhInfo::new_bulletproof(amount, ecdh_key);
let out = TxOut {
amount: VarInt(0),
target: TxOutTarget::ToKey {
key: KeyGenerator::from_random(to.public_view, to.public_spend, ecdh_key)
.one_time_key(dbg!(next_index)),
key: KeyGenerator::from_random(
to.public_view.decompress().unwrap(),
to.public_spend.decompress().unwrap(),
ecdh_key,
)
.one_time_key(dbg!(next_index)),
},
};
@ -114,7 +118,7 @@ impl ConfidentialTransactionBuilder {
let fee = self.compute_fee();
let fee_key = Scalar::from(fee) * H.point.decompress().unwrap();
let fee_key = Scalar::from(fee) * *H;
fee_key + sum_commitments
}
@ -196,14 +200,7 @@ impl ConfidentialTransactionBuilder {
let rct_sig_base = RctSigBase {
rct_type: RctType::Clsag,
txn_fee: VarInt(fee),
out_pk: output_commitments
.iter()
.map(|p| CtKey {
mask: Key {
key: p.compress().0,
},
})
.collect(),
out_pk: output_commitments,
ecdh_info: self.ecdh_info,
pseudo_outs: vec![], // legacy
};
@ -212,9 +209,7 @@ impl ConfidentialTransactionBuilder {
bulletproofs: vec![bulletproof],
MGs: vec![], // legacy
Clsags: vec![],
pseudo_outs: vec![Key {
key: pseudo_out.compress().to_bytes(),
}],
pseudo_outs: vec![pseudo_out],
};
let mut transaction = Transaction {
prefix,
@ -339,13 +334,10 @@ impl FetchDecoyInputs for monerod::Client {
.outs
.into_iter()
.zip(indices.iter())
.map(|(out_key, index)| {
DecoyInput {
global_output_index: *index,
key: out_key.key.point.decompress().unwrap(), /* TODO: should decompress on
* deserialization */
commitment: CompressedEdwardsY(out_key.mask.key).decompress().unwrap(),
}
.map(|(out_key, index)| DecoyInput {
global_output_index: *index,
key: out_key.key,
commitment: out_key.mask,
})
.collect::<Vec<_>>()
.try_into()

View File

@ -84,8 +84,6 @@ impl TxRefund {
a: bitcoin::SecretKey,
S_b_bitcoin: bitcoin::PublicKey,
) -> Result<monero::PrivateKey> {
let s_a = monero::PrivateKey { scalar: s_a };
let tx_refund_sig = self
.extract_signature_by_key(published_refund_tx, a.public())
.context("Failed to extract signature from Bitcoin refund tx")?;

View File

@ -8,6 +8,7 @@ pub use wallet_rpc::{WalletRpc, WalletRpcProcess};
use crate::bitcoin;
use anyhow::Result;
use monero::util::key::EdwardsPointExt;
use rand::{CryptoRng, RngCore};
use rust_decimal::prelude::*;
use rust_decimal::Decimal;
@ -26,7 +27,7 @@ pub fn private_key_from_secp256k1_scalar(scalar: bitcoin::Scalar) -> PrivateKey
// ed25519 scalar is little endian
bytes.reverse();
PrivateKey::from_scalar(Scalar::from_bytes_mod_order(bytes))
Scalar::from_bytes_mod_order(bytes)
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
@ -34,10 +35,7 @@ pub struct PrivateViewKey(#[serde(with = "monero_private_key")] PrivateKey);
impl PrivateViewKey {
pub fn new_random<R: RngCore + CryptoRng>(rng: &mut R) -> Self {
let scalar = Scalar::random(rng);
let private_key = PrivateKey::from_scalar(scalar);
Self(private_key)
Self(Scalar::random(rng))
}
pub fn public(&self) -> PublicViewKey {
@ -345,9 +343,7 @@ mod tests {
#[test]
fn serde_monero_private_key() {
let key = MoneroPrivateKey(monero::PrivateKey::from_scalar(
crate::monero::Scalar::random(&mut OsRng),
));
let key = MoneroPrivateKey(crate::monero::Scalar::random(&mut OsRng));
let encoded = serde_cbor::to_vec(&key).unwrap();
let decoded: MoneroPrivateKey = serde_cbor::from_slice(&encoded).unwrap();
assert_eq!(key, decoded);

View File

@ -4,6 +4,7 @@ use crate::monero::{
};
use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow::{Context, Result};
use monero::util::key::{EdwardsPointExt, ScalarExt};
use monero_rpc::wallet;
use monero_rpc::wallet::{BlockHeight, CheckTxKey, MoneroWalletRpc as _, Refreshed};
use std::future::Future;
@ -96,8 +97,8 @@ impl Wallet {
.generate_from_keys(
file_name,
address.to_string(),
private_spend_key.to_string(),
PrivateKey::from(private_view_key).to_string(),
private_spend_key.display_hex().to_string(),
PrivateKey::from(private_view_key).display_hex().to_string(),
restore_height.height,
String::from(""),
true,
@ -135,8 +136,8 @@ impl Wallet {
.generate_from_keys(
file_name,
temp_wallet_address.to_string(),
private_spend_key.to_string(),
PrivateKey::from(private_view_key).to_string(),
private_spend_key.display_hex().to_string(),
PrivateKey::from(private_view_key).display_hex().to_string(),
restore_height.height,
String::from(""),
true,
@ -189,7 +190,7 @@ impl Wallet {
tracing::debug!(
"sent transfer of {} to {} in {}",
amount,
public_spend_key,
public_spend_key.display_hex(),
res.tx_hash
);
@ -216,7 +217,7 @@ impl Wallet {
let address = Address::standard(self.network, public_spend_key, public_view_key.into());
let check_interval = tokio::time::interval(self.sync_interval);
let key = transfer_proof.tx_key().to_string();
let key = transfer_proof.tx_key().display_hex().to_string();
wait_for_confirmations(
txid.0,

View File

@ -7,7 +7,8 @@ use crate::monero::TransferProof;
use crate::monero_ext::ScalarExt;
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
use crate::{bitcoin, monero};
use anyhow::{anyhow, bail, Context, Result};
use ::monero::util::key::EdwardsPointExt;
use anyhow::{bail, Context, Result};
use monero_rpc::wallet::BlockHeight;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
@ -134,9 +135,7 @@ impl State0 {
s_a,
v_a,
S_a_bitcoin: S_a_bitcoin.into(),
S_a_monero: monero::PublicKey {
point: S_a_monero.compress(),
},
S_a_monero,
dleq_proof_s_a,
redeem_address,
punish_address,
@ -150,13 +149,7 @@ impl State0 {
pub fn receive(self, msg: Message0) -> Result<(Uuid, State1)> {
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
&msg.dleq_proof_s_b,
(
msg.S_b_bitcoin.into(),
msg.S_b_monero
.point
.decompress()
.ok_or_else(|| anyhow!("S_b is not a monero curve point"))?,
),
(msg.S_b_bitcoin.into(), msg.S_b_monero),
);
if !valid {
@ -353,7 +346,7 @@ impl State3 {
}
pub fn lock_xmr_transfer_request(&self) -> TransferRequest {
let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a });
let S_a = monero::PublicKey::from_private_key(&self.s_a);
let public_spend_key = S_a + self.S_b_monero;
let public_view_key = self.v.public();
@ -370,7 +363,7 @@ impl State3 {
transfer_proof: TransferProof,
conf_target: u64,
) -> WatchRequest {
let S_a = monero::PublicKey::from_private_key(&monero::PrivateKey { scalar: self.s_a });
let S_a = monero::PublicKey::from_private_key(&self.s_a);
let public_spend_key = S_a + self.S_b_monero;
let public_view_key = self.v.public();

View File

@ -7,7 +7,8 @@ use crate::monero::wallet::WatchRequest;
use crate::monero::{monero_private_key, TransferProof};
use crate::monero_ext::ScalarExt;
use crate::protocol::{Message0, Message1, Message2, Message3, Message4, CROSS_CURVE_PROOF_SYSTEM};
use anyhow::{anyhow, bail, Context, Result};
use ::monero::util::key::EdwardsPointExt;
use anyhow::{bail, Context, Result};
use ecdsa_fun::adaptor::{Adaptor, HashTranscript};
use ecdsa_fun::nonce::Deterministic;
use ecdsa_fun::Signature;
@ -110,9 +111,7 @@ impl State0 {
s_b,
v_b,
S_b_bitcoin: bitcoin::PublicKey::from(S_b_bitcoin),
S_b_monero: monero::PublicKey {
point: S_b_monero.compress(),
},
S_b_monero,
btc,
xmr,
dleq_proof_s_b,
@ -138,13 +137,7 @@ impl State0 {
pub async fn receive(self, wallet: &bitcoin::Wallet, msg: Message1) -> Result<State1> {
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
&msg.dleq_proof_s_a,
(
msg.S_a_bitcoin.into(),
msg.S_a_monero
.point
.decompress()
.ok_or_else(|| anyhow!("S_a is not a monero curve point"))?,
),
(msg.S_a_bitcoin.into(), msg.S_a_monero),
);
if !valid {
@ -310,8 +303,7 @@ pub struct State3 {
impl State3 {
pub fn lock_xmr_watch_request(&self, transfer_proof: TransferProof) -> WatchRequest {
let S_b_monero =
monero::PublicKey::from_private_key(&monero::PrivateKey::from_scalar(self.s_b));
let S_b_monero = monero::PublicKey::from_private_key(&self.s_b);
let S = self.S_a_monero + S_b_monero;
WatchRequest {
@ -470,8 +462,7 @@ pub struct State5 {
impl State5 {
pub fn xmr_keys(&self) -> (monero::PrivateKey, monero::PrivateViewKey) {
let s_b = monero::PrivateKey { scalar: self.s_b };
let s = self.s_a + s_b;
let s = self.s_a + self.s_b;
(s, self.v)
}