Replace the term mixin with decoy

https://libera.monerologs.net/monero-research-lab/20211002#c34977
This commit is contained in:
Luke Parker
2022-05-06 08:12:30 -04:00
parent 3dab26cd94
commit a541903895
3 changed files with 34 additions and 34 deletions

View File

@@ -17,7 +17,7 @@ const BLOCK_TIME: usize = 120;
const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME; const BLOCKS_PER_YEAR: usize = 365 * 24 * 60 * 60 / BLOCK_TIME;
const TIP_APPLICATION: f64 = (LOCK_WINDOW * BLOCK_TIME) as f64; const TIP_APPLICATION: f64 = (LOCK_WINDOW * BLOCK_TIME) as f64;
const MIXINS: usize = 11; const DECOYS: usize = 11;
lazy_static! { lazy_static! {
static ref GAMMA: Gamma<f64> = Gamma::new(19.28, 1.0 / 1.61).unwrap(); static ref GAMMA: Gamma<f64> = Gamma::new(19.28, 1.0 / 1.61).unwrap();
@@ -60,11 +60,11 @@ async fn select_single<R: RngCore + CryptoRng>(
} }
// Uses VarInt as this is solely used for key_offsets which is serialized by monero-rs // Uses VarInt as this is solely used for key_offsets which is serialized by monero-rs
fn offset(mixins: &[u64]) -> Vec<VarInt> { fn offset(decoys: &[u64]) -> Vec<VarInt> {
let mut res = vec![VarInt(mixins[0])]; let mut res = vec![VarInt(decoys[0])];
res.resize(mixins.len(), VarInt(0)); res.resize(decoys.len(), VarInt(0));
for m in (1 .. mixins.len()).rev() { for m in (1 .. decoys.len()).rev() {
res[m] = VarInt(mixins[m] - mixins[m - 1]); res[m] = VarInt(decoys[m] - decoys[m - 1]);
} }
res res
} }
@@ -99,44 +99,44 @@ pub(crate) async fn select<R: RngCore + CryptoRng>(
let mut res = Vec::with_capacity(inputs.len()); let mut res = Vec::with_capacity(inputs.len());
for (i, o) in outputs.iter().enumerate() { for (i, o) in outputs.iter().enumerate() {
let mut mixins = Vec::with_capacity(MIXINS); let mut decoys = Vec::with_capacity(DECOYS);
for _ in 0 .. MIXINS { for _ in 0 .. DECOYS {
mixins.push(select_single(rng, rpc, height, &distribution, high, per_second, &mut used).await?); decoys.push(select_single(rng, rpc, height, &distribution, high, per_second, &mut used).await?);
} }
mixins.sort_by(|a, b| a.0.cmp(&b.0)); decoys.sort_by(|a, b| a.0.cmp(&b.0));
// Make sure the TX passes the sanity check that the median output is within the last 40% // Make sure the TX passes the sanity check that the median output is within the last 40%
// This actually checks the median is within the last third, a slightly more aggressive boundary, // This actually checks the median is within the last third, a slightly more aggressive boundary,
// as the height used in this calculation will be slightly under the height this is sanity // as the height used in this calculation will be slightly under the height this is sanity
// checked against // checked against
while mixins[MIXINS / 2].0 < (high * 2 / 3) { while decoys[DECOYS / 2].0 < (high * 2 / 3) {
// If it's not, update the bottom half with new values to ensure the median only moves up // If it's not, update the bottom half with new values to ensure the median only moves up
for m in 0 .. MIXINS / 2 { for m in 0 .. DECOYS / 2 {
// We could not remove this, saving CPU time and removing low values as possibilities, yet // We could not remove this, saving CPU time and removing low values as possibilities, yet
// it'd increase the amount of mixins required to create this transaction and some banned // it'd increase the amount of decoys required to create this transaction and some banned
// outputs may be the best options // outputs may be the best options
used.remove(&mixins[m].0); used.remove(&decoys[m].0);
mixins[m] = select_single(rng, rpc, height, &distribution, high, per_second, &mut used).await?; decoys[m] = select_single(rng, rpc, height, &distribution, high, per_second, &mut used).await?;
} }
mixins.sort_by(|a, b| a.0.cmp(&b.0)); decoys.sort_by(|a, b| a.0.cmp(&b.0));
} }
// Replace the closest selected decoy with the actual // Replace the closest selected decoy with the actual
let mut replace = 0; let mut replace = 0;
let mut distance = u64::MAX; let mut distance = u64::MAX;
for m in 0 .. mixins.len() { for m in 0 .. decoys.len() {
let diff = mixins[m].0.abs_diff(o.0); let diff = decoys[m].0.abs_diff(o.0);
if diff < distance { if diff < distance {
replace = m; replace = m;
distance = diff; distance = diff;
} }
} }
mixins[replace] = outputs[i]; decoys[replace] = outputs[i];
res.push(( res.push((
offset(&mixins.iter().map(|output| output.0).collect::<Vec<_>>()), offset(&decoys.iter().map(|output| output.0).collect::<Vec<_>>()),
u8::try_from(replace).unwrap(), u8::try_from(replace).unwrap(),
mixins.iter().map(|output| output.1).collect() decoys.iter().map(|output| output.1).collect()
)); ));
} }

View File

@@ -37,7 +37,7 @@ use crate::{
#[cfg(feature = "multisig")] #[cfg(feature = "multisig")]
use crate::frost::MultisigError; use crate::frost::MultisigError;
mod mixins; mod decoys;
#[cfg(feature = "multisig")] #[cfg(feature = "multisig")]
mod multisig; mod multisig;
@@ -203,8 +203,8 @@ async fn prepare_inputs<R: RngCore + CryptoRng>(
let mut signable = Vec::with_capacity(inputs.len()); let mut signable = Vec::with_capacity(inputs.len());
// Select mixins // Select decoys
let mixins = mixins::select( let decoys = decoys::select(
rng, rng,
rpc, rpc,
rpc.get_height().await.map_err(|e| TransactionError::RpcError(e))? - 10, rpc.get_height().await.map_err(|e| TransactionError::RpcError(e))? - 10,
@@ -215,8 +215,8 @@ async fn prepare_inputs<R: RngCore + CryptoRng>(
signable.push(( signable.push((
spend + input.key_offset, spend + input.key_offset,
clsag::Input::new( clsag::Input::new(
mixins[i].2.clone(), decoys[i].2.clone(),
mixins[i].1, decoys[i].1,
input.commitment input.commitment
).map_err(|e| TransactionError::ClsagError(e))?, ).map_err(|e| TransactionError::ClsagError(e))?,
key_image::generate(&(spend + input.key_offset)) key_image::generate(&(spend + input.key_offset))
@@ -224,7 +224,7 @@ async fn prepare_inputs<R: RngCore + CryptoRng>(
tx.prefix.inputs.push(TxIn::ToKey { tx.prefix.inputs.push(TxIn::ToKey {
amount: VarInt(0), amount: VarInt(0),
key_offsets: mixins[i].0.clone(), key_offsets: decoys[i].0.clone(),
k_image: KeyImage { image: Hash(signable[i].2.compress().to_bytes()) } k_image: KeyImage { image: Hash(signable[i].2.compress().to_bytes()) }
}); });
} }

View File

@@ -19,7 +19,7 @@ use crate::{
frost::{Transcript, Ed25519}, frost::{Transcript, Ed25519},
key_image, bulletproofs, clsag, key_image, bulletproofs, clsag,
rpc::Rpc, rpc::Rpc,
transaction::{TransactionError, SignableTransaction, mixins} transaction::{TransactionError, SignableTransaction, decoys}
}; };
pub struct TransactionMachine { pub struct TransactionMachine {
@@ -78,9 +78,9 @@ impl SignableTransaction {
// Not only is this an output, but this locks to the base keys to be complete with the above key offsets // Not only is this an output, but this locks to the base keys to be complete with the above key offsets
transcript.append_message(b"change", &self.change.as_bytes()); transcript.append_message(b"change", &self.change.as_bytes());
// Select mixins // Select decoys
let mixins = mixins::select( let decoys = decoys::select(
&mut ChaCha12Rng::from_seed(transcript.rng_seed(b"mixins", None)), &mut ChaCha12Rng::from_seed(transcript.rng_seed(b"decoys", None)),
rpc, rpc,
height, height,
&self.inputs &self.inputs
@@ -99,8 +99,8 @@ impl SignableTransaction {
clsag::Multisig::new( clsag::Multisig::new(
transcript.clone(), transcript.clone(),
clsag::Input::new( clsag::Input::new(
mixins[i].2.clone(), decoys[i].2.clone(),
mixins[i].1, decoys[i].1,
input.commitment input.commitment
).map_err(|e| TransactionError::ClsagError(e))?, ).map_err(|e| TransactionError::ClsagError(e))?,
msg.clone(), msg.clone(),
@@ -113,7 +113,7 @@ impl SignableTransaction {
inputs.push(TxIn::ToKey { inputs.push(TxIn::ToKey {
amount: VarInt(0), amount: VarInt(0),
key_offsets: mixins[i].0.clone(), key_offsets: decoys[i].0.clone(),
k_image: KeyImage { image: Hash([0; 32]) } k_image: KeyImage { image: Hash([0; 32]) }
}); });
} }