mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-11 05:29:25 +00:00
Meaningful changes from aggressive-clippy
I do want to enable a few specific lints, yet aggressive-clippy as a whole isn't worthwhile.
This commit is contained in:
@@ -241,9 +241,13 @@ impl ZeroizeOnDrop for Scanner {}
|
||||
|
||||
impl Scanner {
|
||||
/// Create a Scanner from a ViewPair.
|
||||
///
|
||||
/// burning_bug is a HashSet of used keys, intended to prevent key reuse which would burn funds.
|
||||
///
|
||||
/// When an output is successfully scanned, the output key MUST be saved to disk.
|
||||
///
|
||||
/// When a new scanner is created, ALL saved output keys must be passed in to be secure.
|
||||
///
|
||||
/// If None is passed, a modified shared key derivation is used which is immune to the burning
|
||||
/// bug (specifically the Guaranteed feature from Featured Addresses).
|
||||
pub fn from_view(pair: ViewPair, burning_bug: Option<HashSet<CompressedEdwardsY>>) -> Scanner {
|
||||
|
||||
@@ -263,6 +263,7 @@ impl<O: Clone + Zeroize> Timelocked<O> {
|
||||
}
|
||||
|
||||
/// Return the outputs if they're not timelocked, or an empty vector if they are.
|
||||
#[must_use]
|
||||
pub fn not_locked(&self) -> Vec<O> {
|
||||
if self.0 == Timelock::None {
|
||||
return self.1.clone();
|
||||
@@ -271,6 +272,7 @@ impl<O: Clone + Zeroize> Timelocked<O> {
|
||||
}
|
||||
|
||||
/// Returns None if the Timelocks aren't comparable. Returns Some(vec![]) if none are unlocked.
|
||||
#[must_use]
|
||||
pub fn unlocked(&self, timelock: Timelock) -> Option<Vec<O>> {
|
||||
// If the Timelocks are comparable, return the outputs if they're now unlocked
|
||||
if self.0 <= timelock {
|
||||
@@ -280,6 +282,7 @@ impl<O: Clone + Zeroize> Timelocked<O> {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn ignore_timelock(&self) -> Vec<O> {
|
||||
self.1.clone()
|
||||
}
|
||||
@@ -293,16 +296,11 @@ impl Scanner {
|
||||
return Timelocked(tx.prefix.timelock, vec![]);
|
||||
}
|
||||
|
||||
let extra = Extra::read::<&[u8]>(&mut tx.prefix.extra.as_ref());
|
||||
let extra = if let Ok(extra) = extra {
|
||||
extra
|
||||
} else {
|
||||
let Ok(extra) = Extra::read::<&[u8]>(&mut tx.prefix.extra.as_ref()) else {
|
||||
return Timelocked(tx.prefix.timelock, vec![]);
|
||||
};
|
||||
|
||||
let (tx_key, additional) = if let Some((tx_key, additional)) = extra.keys() {
|
||||
(tx_key, additional)
|
||||
} else {
|
||||
let Some((tx_key, additional)) = extra.keys() else {
|
||||
return Timelocked(tx.prefix.timelock, vec![]);
|
||||
};
|
||||
|
||||
@@ -453,7 +451,7 @@ impl Scanner {
|
||||
};
|
||||
|
||||
let mut res = vec![];
|
||||
for tx in txs.drain(..) {
|
||||
for tx in txs {
|
||||
if let Some(timelock) = map(self.scan_transaction(&tx), index) {
|
||||
res.push(timelock);
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ impl SignableTransaction {
|
||||
protocol: Protocol,
|
||||
r_seed: Option<Zeroizing<[u8; 32]>>,
|
||||
inputs: Vec<SpendableOutput>,
|
||||
mut payments: Vec<(MoneroAddress, u64)>,
|
||||
payments: Vec<(MoneroAddress, u64)>,
|
||||
change_address: Option<Change>,
|
||||
data: Vec<Vec<u8>>,
|
||||
fee_rate: Fee,
|
||||
@@ -382,7 +382,7 @@ impl SignableTransaction {
|
||||
Err(TransactionError::TooManyOutputs)?;
|
||||
}
|
||||
|
||||
let mut payments = payments.drain(..).map(InternalPayment::Payment).collect::<Vec<_>>();
|
||||
let mut payments = payments.into_iter().map(InternalPayment::Payment).collect::<Vec<_>>();
|
||||
if let Some(change) = change_address {
|
||||
payments.push(InternalPayment::Change(change, in_amount - out_amount));
|
||||
}
|
||||
@@ -562,11 +562,12 @@ impl SignableTransaction {
|
||||
}
|
||||
|
||||
/// Returns the eventuality of this transaction.
|
||||
///
|
||||
/// The eventuality is defined as the TX extra/outputs this transaction will create, if signed
|
||||
/// with the specified seed. This eventuality can be compared to on-chain transactions to see
|
||||
/// if the transaction has already been signed and published.
|
||||
pub fn eventuality(&self) -> Option<Eventuality> {
|
||||
let inputs = self.inputs.iter().map(|input| input.key()).collect::<Vec<_>>();
|
||||
let inputs = self.inputs.iter().map(SpendableOutput::key).collect::<Vec<_>>();
|
||||
let (tx_key, additional, outputs, id) = Self::prepare_payments(
|
||||
self.r_seed.as_ref()?,
|
||||
&inputs,
|
||||
@@ -606,7 +607,7 @@ impl SignableTransaction {
|
||||
|
||||
let (tx_key, additional, outputs, id) = Self::prepare_payments(
|
||||
&r_seed,
|
||||
&self.inputs.iter().map(|input| input.key()).collect::<Vec<_>>(),
|
||||
&self.inputs.iter().map(SpendableOutput::key).collect::<Vec<_>>(),
|
||||
&mut self.payments,
|
||||
uniqueness,
|
||||
);
|
||||
@@ -656,7 +657,7 @@ impl SignableTransaction {
|
||||
fee,
|
||||
encrypted_amounts,
|
||||
pseudo_outs: vec![],
|
||||
commitments: commitments.iter().map(|commitment| commitment.calculate()).collect(),
|
||||
commitments: commitments.iter().map(Commitment::calculate).collect(),
|
||||
},
|
||||
prunable: RctPrunable::Clsag { bulletproofs: bp, clsags: vec![], pseudo_outs: vec![] },
|
||||
},
|
||||
@@ -713,13 +714,18 @@ impl SignableTransaction {
|
||||
impl Eventuality {
|
||||
/// Enables building a HashMap of Extra -> Eventuality for efficiently checking if an on-chain
|
||||
/// transaction may match this eventuality.
|
||||
///
|
||||
/// This extra is cryptographically bound to:
|
||||
/// 1) A specific set of inputs (via their output key)
|
||||
/// 2) A specific seed for the ephemeral keys
|
||||
///
|
||||
/// This extra may be used in a transaction with a distinct set of inputs, yet no honest
|
||||
/// transaction which doesn't satisfy this Eventuality will contain it.
|
||||
pub fn extra(&self) -> &[u8] {
|
||||
&self.extra
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn matches(&self, tx: &Transaction) -> bool {
|
||||
if self.payments.len() != tx.prefix.outputs.len() {
|
||||
return false;
|
||||
@@ -752,9 +758,10 @@ impl Eventuality {
|
||||
}
|
||||
|
||||
// TODO: Remove this when the following for loop is updated
|
||||
if !rct_type.compact_encrypted_amounts() {
|
||||
panic!("created an Eventuality for a very old RctType we don't support proving for");
|
||||
}
|
||||
assert!(
|
||||
rct_type.compact_encrypted_amounts(),
|
||||
"created an Eventuality for a very old RctType we don't support proving for"
|
||||
);
|
||||
|
||||
for (o, (expected, actual)) in outputs.iter().zip(tx.prefix.outputs.iter()).enumerate() {
|
||||
// Verify the output, commitment, and encrypted amount.
|
||||
@@ -815,7 +822,7 @@ impl Eventuality {
|
||||
String::from_utf8(read_vec(read_byte, r)?)
|
||||
.ok()
|
||||
.and_then(|str| MoneroAddress::from_str_raw(&str).ok())
|
||||
.ok_or(io::Error::new(io::ErrorKind::Other, "invalid address"))
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid address"))
|
||||
}
|
||||
|
||||
fn read_payment<R: io::Read>(r: &mut R) -> io::Result<InternalPayment> {
|
||||
|
||||
@@ -274,7 +274,7 @@ impl SignMachine<Transaction> for TransactionSignMachine {
|
||||
// Find out who's included
|
||||
// This may not be a valid set of signers yet the algorithm machine will error if it's not
|
||||
commitments.remove(&self.i); // Remove, if it was included for some reason
|
||||
let mut included = commitments.keys().cloned().collect::<Vec<_>>();
|
||||
let mut included = commitments.keys().copied().collect::<Vec<_>>();
|
||||
included.push(self.i);
|
||||
included.sort_unstable();
|
||||
|
||||
@@ -325,7 +325,7 @@ impl SignMachine<Transaction> for TransactionSignMachine {
|
||||
|
||||
// Remove our preprocess which shouldn't be here. It was just the easiest way to implement the
|
||||
// above
|
||||
for map in commitments.iter_mut() {
|
||||
for map in &mut commitments {
|
||||
map.remove(&self.i);
|
||||
}
|
||||
|
||||
@@ -430,7 +430,9 @@ impl SignatureMachine<Transaction> for TransactionSignatureMachine {
|
||||
pseudo_outs.push(pseudo_out);
|
||||
}
|
||||
}
|
||||
_ => unreachable!("attempted to sign a multisig TX which wasn't CLSAG"),
|
||||
RctPrunable::MlsagBorromean { .. } | RctPrunable::MlsagBulletproofs { .. } => {
|
||||
unreachable!("attempted to sign a multisig TX which wasn't CLSAG")
|
||||
}
|
||||
}
|
||||
Ok(tx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user