mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-13 14:39:25 +00:00
Begin crate smashing
This commit is contained in:
@@ -5,7 +5,7 @@ use zeroize::Zeroize;
|
||||
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
|
||||
use monero_generators::decompress_point;
|
||||
use monero_io::decompress_point;
|
||||
|
||||
use base58_monero::base58::{encode_check, decode_check};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std_shims::{vec::Vec, collections::HashSet};
|
||||
|
||||
use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||
use zeroize::Zeroize;
|
||||
|
||||
use rand_core::{RngCore, CryptoRng};
|
||||
use rand_distr::{Distribution, Gamma};
|
||||
@@ -10,7 +10,6 @@ use rand_distr::num_traits::Float;
|
||||
use curve25519_dalek::edwards::EdwardsPoint;
|
||||
|
||||
use crate::{
|
||||
serialize::varint_len,
|
||||
wallet::SpendableOutput,
|
||||
rpc::{RpcError, RpcConnection, Rpc},
|
||||
DEFAULT_LOCK_WINDOW, COINBASE_LOCK_WINDOW, BLOCK_TIME,
|
||||
@@ -272,35 +271,38 @@ async fn select_decoys<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Decoy data, containing the actual member as well (at index `i`).
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
pub struct Decoys {
|
||||
pub(crate) i: u8,
|
||||
pub(crate) offsets: Vec<u64>,
|
||||
pub(crate) ring: Vec<[EdwardsPoint; 2]>,
|
||||
pub use monero_primitives::Decoys;
|
||||
|
||||
// TODO: Remove this trait
|
||||
#[cfg(feature = "std")]
|
||||
#[async_trait::async_trait]
|
||||
pub trait DecoySelection {
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng, RPC: Send + Sync + RpcConnection>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
) -> Result<Vec<Decoys>, RpcError>;
|
||||
|
||||
async fn fingerprintable_canonical_select<
|
||||
R: Send + Sync + RngCore + CryptoRng,
|
||||
RPC: Send + Sync + RpcConnection,
|
||||
>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
ring_len: usize,
|
||||
height: usize,
|
||||
inputs: &[SpendableOutput],
|
||||
) -> Result<Vec<Decoys>, RpcError>;
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
impl Decoys {
|
||||
pub fn fee_weight(offsets: &[u64]) -> usize {
|
||||
varint_len(offsets.len()) + offsets.iter().map(|offset| varint_len(*offset)).sum::<usize>()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.offsets.len()
|
||||
}
|
||||
|
||||
pub fn indexes(&self) -> Vec<u64> {
|
||||
let mut res = vec![self.offsets[0]; self.len()];
|
||||
for m in 1 .. res.len() {
|
||||
res[m] = res[m - 1] + self.offsets[m];
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[async_trait::async_trait]
|
||||
impl DecoySelection for Decoys {
|
||||
/// Select decoys using the same distribution as Monero. Relies on the monerod RPC
|
||||
/// response for an output's unlocked status, minimizing trips to the daemon.
|
||||
pub async fn select<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
async fn select<R: Send + Sync + RngCore + CryptoRng, RPC: Send + Sync + RpcConnection>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
ring_len: usize,
|
||||
@@ -318,7 +320,10 @@ impl Decoys {
|
||||
///
|
||||
/// TODO: upstream change to monerod get_outs RPC to accept a height param for checking
|
||||
/// output's unlocked status and remove all usage of fingerprintable_canonical
|
||||
pub async fn fingerprintable_canonical_select<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||
async fn fingerprintable_canonical_select<
|
||||
R: Send + Sync + RngCore + CryptoRng,
|
||||
RPC: Send + Sync + RpcConnection,
|
||||
>(
|
||||
rng: &mut R,
|
||||
rpc: &Rpc<RPC>,
|
||||
ring_len: usize,
|
||||
|
||||
@@ -10,7 +10,8 @@ use curve25519_dalek::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
hash, hash_to_scalar, serialize::write_varint, Commitment, ringct::EncryptedAmount, transaction::Input,
|
||||
hash, hash_to_scalar, serialize::write_varint, Commitment, ringct::EncryptedAmount,
|
||||
transaction::Input,
|
||||
};
|
||||
|
||||
pub mod extra;
|
||||
@@ -26,8 +27,14 @@ use address::{Network, AddressType, SubaddressIndex, AddressSpec, AddressMeta, M
|
||||
mod scan;
|
||||
pub use scan::{ReceivedOutput, SpendableOutput, Timelocked};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
pub mod decoys;
|
||||
pub use decoys::Decoys;
|
||||
#[cfg(not(feature = "std"))]
|
||||
pub mod decoys {
|
||||
pub use monero_primitives::Decoys;
|
||||
pub trait DecoySelection {}
|
||||
}
|
||||
pub use decoys::{DecoySelection, Decoys};
|
||||
|
||||
mod send;
|
||||
pub use send::{FeePriority, Fee, TransactionError, Change, SignableTransaction, Eventuality};
|
||||
|
||||
@@ -9,7 +9,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
|
||||
|
||||
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwards::EdwardsPoint};
|
||||
|
||||
use monero_generators::decompress_point;
|
||||
use monero_io::decompress_point;
|
||||
|
||||
use crate::{
|
||||
Commitment,
|
||||
|
||||
@@ -11,7 +11,7 @@ use rand_core::{RngCore, CryptoRng};
|
||||
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
|
||||
use crate::{random_scalar, wallet::seed::SeedError};
|
||||
use crate::wallet::seed::SeedError;
|
||||
|
||||
pub(crate) const CLASSIC_SEED_LENGTH: usize = 24;
|
||||
pub(crate) const CLASSIC_SEED_LENGTH_WITH_CHECKSUM: usize = 25;
|
||||
@@ -276,7 +276,7 @@ pub(crate) fn seed_to_bytes(lang: Language, words: &str) -> Result<Zeroizing<[u8
|
||||
pub struct ClassicSeed(Language, Zeroizing<String>);
|
||||
impl ClassicSeed {
|
||||
pub(crate) fn new<R: RngCore + CryptoRng>(rng: &mut R, lang: Language) -> ClassicSeed {
|
||||
key_to_seed(lang, Zeroizing::new(random_scalar(rng)))
|
||||
key_to_seed(lang, Zeroizing::new(Scalar::random(rng)))
|
||||
}
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
|
||||
@@ -23,7 +23,7 @@ use dalek_ff_group as dfg;
|
||||
use frost::FrostError;
|
||||
|
||||
use crate::{
|
||||
Protocol, Commitment, hash, random_scalar,
|
||||
Protocol, Commitment, hash,
|
||||
serialize::{
|
||||
read_byte, read_bytes, read_u64, read_scalar, read_point, read_vec, write_byte, write_scalar,
|
||||
write_point, write_raw_vec, write_vec,
|
||||
@@ -616,7 +616,7 @@ impl SignableTransaction {
|
||||
payments.shuffle(&mut rng);
|
||||
|
||||
// Used for all non-subaddress outputs, or if there's only one subaddress output and a change
|
||||
let tx_key = Zeroizing::new(random_scalar(&mut rng));
|
||||
let tx_key = Zeroizing::new(Scalar::random(&mut rng));
|
||||
let mut tx_public_key = tx_key.deref() * ED25519_BASEPOINT_TABLE;
|
||||
|
||||
// If any of these outputs are to a subaddress, we need keys distinct to them
|
||||
@@ -660,7 +660,7 @@ impl SignableTransaction {
|
||||
let (output, payment_id) = match payment {
|
||||
InternalPayment::Payment(payment, need_dummy_payment_id) => {
|
||||
// If this is a subaddress, generate a dedicated r. Else, reuse the TX key
|
||||
let dedicated = Zeroizing::new(random_scalar(&mut rng));
|
||||
let dedicated = Zeroizing::new(Scalar::random(&mut rng));
|
||||
let use_dedicated = additional && payment.0.is_subaddress();
|
||||
let r = if use_dedicated { &dedicated } else { &tx_key };
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ use frost::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
random_scalar,
|
||||
ringct::{
|
||||
clsag::{ClsagInput, ClsagDetails, ClsagAddendum, ClsagMultisig},
|
||||
RctPrunable,
|
||||
@@ -348,7 +347,7 @@ impl SignMachine<Transaction> for TransactionSignMachine {
|
||||
while !sorted.is_empty() {
|
||||
let value = sorted.remove(0);
|
||||
|
||||
let mut mask = random_scalar(&mut rng);
|
||||
let mut mask = Scalar::random(&mut rng);
|
||||
if sorted.is_empty() {
|
||||
mask = output_masks - sum_pseudo_outs;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user