mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Monero: support for legacy transactions (#308)
* add mlsag * fix last commit * fix miner v1 txs * fix non-miner v1 txs * add borromean + fix mlsag * add block hash calculations * fix for the jokester that added unreduced scalars to the borromean signature of 2368d846e671bf79a1f84c6d3af9f0bfe296f043f50cf17ae5e485384a53707b * Add Borromean range proof verifying functionality * Add MLSAG verifying functionality * fmt & clippy :) * update MLSAG, ss2_elements will always be 2 * Add MgSig proving * Tidy block.rs * Tidy Borromean, fix bugs in last commit, replace todo! with unreachable! * Mark legacy EcdhInfo amount decryption as experimental * Correct comments * Write a new impl of the merkle algorithm This one tries to be understandable. * Only pull in things only needed for experimental when experimental * Stop caching the Monero block hash now in processor that we have Block::hash * Corrections for recent processor commit * Use a clearer algorithm for the merkle Should also be more efficient due to not shifting as often. * Tidy Mlsag * Remove verify_rct_* from Mlsag Both methods were ports from Monero, overtly specific without clear documentation. They need to be added back in, with documentation, or included in a node which provides the necessary further context for them to be naturally understandable. * Move mlsag/mod.rs to mlsag.rs This should only be a folder if it has multiple files. * Replace EcdhInfo terminology The ECDH encrypted the amount, yet this struct contained the encrypted amount, not some ECDH. Also corrects the types on the original EcdhInfo struct. * Correct handling of commitment masks when scanning * Route read_array through read_raw_vec * Misc lint * Make a proper RctType enum No longer caches RctType in the RctSignatures as well. * Replace Vec<Bulletproofs> with Bulletproofs Monero uses aggregated range proofs, so there's only ever one Bulletproof. This is enforced with a consensus rule as well, making this safe. As for why Monero uses a vec, it's probably due to the lack of variadic typing used. Its effectively an Option for them, yet we don't need an Option since we do have variadic typing (enums). * Add necessary checks to Eventuality re: supported protocols * Fix for block 202612 and fix merkel root calculations * MLSAG (de)serialisation fix ss_2_elements will not always be 2 as rct type 1 transactions are not enforced to have one input * Revert "MLSAG (de)serialisation fix" This reverts commit5e710e0c96. here it checks number of MGs == number of inputs:0a1eaf26f9/src/cryptonote_core/tx_verification_utils.cpp (L60-59)and here it checks for RctTypeFull number of MGs == 1:0a1eaf26f9/src/ringct/rctSigs.cpp (L1325)so number of inputs == 1 so ss_2_elements == 2 * update `MlsagAggregate` comment * cargo update Resolves a yanked crate * Move location of serai-client in Cargo.toml --------- Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
@@ -53,6 +53,7 @@ pub use builder::SignableTransactionBuilder;
|
||||
mod multisig;
|
||||
#[cfg(feature = "multisig")]
|
||||
pub use multisig::TransactionMachine;
|
||||
use crate::ringct::EncryptedAmount;
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)]
|
||||
@@ -629,7 +630,7 @@ impl SignableTransaction {
|
||||
|
||||
let mut fee = self.inputs.iter().map(|input| input.commitment().amount).sum::<u64>();
|
||||
let mut tx_outputs = Vec::with_capacity(outputs.len());
|
||||
let mut ecdh_info = Vec::with_capacity(outputs.len());
|
||||
let mut encrypted_amounts = Vec::with_capacity(outputs.len());
|
||||
for output in &outputs {
|
||||
fee -= output.commitment.amount;
|
||||
tx_outputs.push(Output {
|
||||
@@ -637,7 +638,7 @@ impl SignableTransaction {
|
||||
key: output.dest.compress(),
|
||||
view_tag: Some(output.view_tag).filter(|_| matches!(self.protocol, Protocol::v16)),
|
||||
});
|
||||
ecdh_info.push(output.amount);
|
||||
encrypted_amounts.push(EncryptedAmount::Compact { amount: output.amount });
|
||||
}
|
||||
|
||||
(
|
||||
@@ -653,14 +654,11 @@ impl SignableTransaction {
|
||||
rct_signatures: RctSignatures {
|
||||
base: RctBase {
|
||||
fee,
|
||||
ecdh_info,
|
||||
encrypted_amounts,
|
||||
pseudo_outs: vec![],
|
||||
commitments: commitments.iter().map(|commitment| commitment.calculate()).collect(),
|
||||
},
|
||||
prunable: RctPrunable::Clsag {
|
||||
bulletproofs: vec![bp],
|
||||
clsags: vec![],
|
||||
pseudo_outs: vec![],
|
||||
},
|
||||
prunable: RctPrunable::Clsag { bulletproofs: bp, clsags: vec![], pseudo_outs: vec![] },
|
||||
},
|
||||
},
|
||||
sum,
|
||||
@@ -706,6 +704,7 @@ impl SignableTransaction {
|
||||
clsags.append(&mut clsag_pairs.iter().map(|clsag| clsag.0.clone()).collect::<Vec<_>>());
|
||||
pseudo_outs.append(&mut clsag_pairs.iter().map(|clsag| clsag.1).collect::<Vec<_>>());
|
||||
}
|
||||
_ => unreachable!("attempted to sign a TX which wasn't CLSAG"),
|
||||
}
|
||||
Ok(tx)
|
||||
}
|
||||
@@ -747,6 +746,16 @@ impl Eventuality {
|
||||
uniqueness(&tx.prefix.inputs),
|
||||
);
|
||||
|
||||
let rct_type = tx.rct_signatures.rct_type();
|
||||
if rct_type != self.protocol.optimal_rct_type() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 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");
|
||||
}
|
||||
|
||||
for (o, (expected, actual)) in outputs.iter().zip(tx.prefix.outputs.iter()).enumerate() {
|
||||
// Verify the output, commitment, and encrypted amount.
|
||||
if (&Output {
|
||||
@@ -755,7 +764,8 @@ impl Eventuality {
|
||||
view_tag: Some(expected.view_tag).filter(|_| matches!(self.protocol, Protocol::v16)),
|
||||
} != actual) ||
|
||||
(Some(&expected.commitment.calculate()) != tx.rct_signatures.base.commitments.get(o)) ||
|
||||
(Some(&expected.amount) != tx.rct_signatures.base.ecdh_info.get(o))
|
||||
(Some(&EncryptedAmount::Compact { amount: expected.amount }) !=
|
||||
tx.rct_signatures.base.encrypted_amounts.get(o))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user