Clean the Monero lib for auditing (#577)
* Remove unsafe creation of dalek_ff_group::EdwardsPoint in BP+
* Rename Bulletproofs to Bulletproof, since they are a single Bulletproof
Also bifurcates prove with prove_plus, and adds a few documentation items.
* Make CLSAG signing private
Also adds a bit more documentation and does a bit more tidying.
* Remove the distribution cache
It's a notable bandwidth/performance improvement, yet it's not ready. We need a
dedicated Distribution struct which is managed by the wallet and passed in.
While we can do that now, it's not currently worth the effort.
* Tidy Borromean/MLSAG a tad
* Remove experimental feature from monero-serai
* Move amount_decryption into EncryptedAmount::decrypt
* Various RingCT doc comments
* Begin crate smashing
* Further documentation, start shoring up API boundaries of existing crates
* Document and clean clsag
* Add a dedicated send/recv CLSAG mask struct
Abstracts the types used internally.
Also moves the tests from monero-serai to monero-clsag.
* Smash out monero-bulletproofs
Removes usage of dalek-ff-group/multiexp for curve25519-dalek.
Makes compiling in the generators an optional feature.
Adds a structured batch verifier which should be notably more performant.
Documentation and clean up still necessary.
* Correct no-std builds for monero-clsag and monero-bulletproofs
* Tidy and document monero-bulletproofs
I still don't like the impl of the original Bulletproofs...
* Error if missing documentation
* Smash out MLSAG
* Smash out Borromean
* Tidy up monero-serai as a meta crate
* Smash out RPC, wallet
* Document the RPC
* Improve docs a bit
* Move Protocol to monero-wallet
* Incomplete work on using Option to remove panic cases
* Finish documenting monero-serai
* Remove TODO on reading pseudo_outs for AggregateMlsagBorromean
* Only read transactions with one Input::Gen or all Input::ToKey
Also adds a helper to fetch a transaction's prefix.
* Smash out polyseed
* Smash out seed
* Get the repo to compile again
* Smash out Monero addresses
* Document cargo features
Credit to @hinto-janai for adding such sections to their work on documenting
monero-serai in #568.
* Fix deserializing v2 miner transactions
* Rewrite monero-wallet's send code
I have yet to redo the multisig code and the builder. This should be much
cleaner, albeit slower due to redoing work.
This compiles with clippy --all-features. I have to finish the multisig/builder
for --all-targets to work (and start updating the rest of Serai).
* Add SignableTransaction Read/Write
* Restore Monero multisig TX code
* Correct invalid RPC type def in monero-rpc
* Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
* Clean and document monero-address
* Sync rest of repo with monero-serai changes
* Represent height/block number as a u32
* Diversify ViewPair/Scanner into ViewPair/GuaranteedViewPair and Scanner/GuaranteedScanner
Also cleans the Scanner impl.
* Remove non-small-order view key bound
Guaranteed addresses are in fact guaranteed even with this due to prefixing key
images causing zeroing the ECDH to not zero the shared key.
* Finish documenting monero-serai
* Correct imports for no-std
* Remove possible panic in monero-serai on systems < 32 bits
This was done by requiring the system's usize can represent a certain number.
* Restore the reserialize chain binary
* fmt, machete, GH CI
* Correct misc TODOs in monero-serai
* Have Monero test runner evaluate an Eventuality for all signed TXs
* Fix a pair of bugs in the decoy tests
Unfortunately, this test is still failing.
* Fix remaining bugs in monero-wallet tests
* Reject torsioned spend keys to ensure we can spend the outputs we scan
* Tidy inlined epee code in the RPC
* Correct the accidental swap of stagenet/testnet address bytes
* Remove unused dep from processor
* Handle Monero fee logic properly in the processor
* Document v2 TX/RCT output relation assumed when scanning
* Adjust how we mine the initial blocks due to some CI test failures
* Fix weight estimation for RctType::ClsagBulletproof TXs
* Again increase the amount of blocks we mine prior to running tests
* Correct the if check about when to mine blocks on start
Finally fixes the lack of decoy candidates failures in CI.
* Run Monero on Debian, even for internal testnets
Change made due to a segfault incurred when locally testing.
https://github.com/monero-project/monero/issues/9141 for the upstream.
* Don't attempt running tests on the verify-chain binary
Adds a minimum XMR fee to the processor and runs fmt.
* Increase minimum Monero fee in processor
I'm truly unsure why this is required right now.
* Distinguish fee from necessary_fee in monero-wallet
If there's no change, the fee is difference of the inputs to the outputs. The
prior code wouldn't check that amount is greater than or equal to the necessary
fee, and returning the would-be change amount as the fee isn't necessarily
helpful.
Now the fee is validated in such cases and the necessary fee is returned,
enabling operating off of that.
* Restore minimum Monero fee from develop
2024-07-07 03:57:18 -07:00
|
|
|
use std_shims::{
|
|
|
|
|
vec::Vec,
|
|
|
|
|
io::{self, Read},
|
|
|
|
|
collections::HashMap,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use rand_core::{RngCore, CryptoRng};
|
|
|
|
|
|
|
|
|
|
use group::ff::Field;
|
|
|
|
|
use curve25519_dalek::{traits::Identity, Scalar, EdwardsPoint};
|
|
|
|
|
use dalek_ff_group as dfg;
|
|
|
|
|
|
|
|
|
|
use transcript::{Transcript, RecommendedTranscript};
|
|
|
|
|
use frost::{
|
|
|
|
|
curve::Ed25519,
|
|
|
|
|
Participant, FrostError, ThresholdKeys,
|
|
|
|
|
dkg::lagrange,
|
|
|
|
|
sign::{
|
|
|
|
|
Preprocess, CachedPreprocess, SignatureShare, PreprocessMachine, SignMachine, SignatureMachine,
|
|
|
|
|
AlgorithmMachine, AlgorithmSignMachine, AlgorithmSignatureMachine,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use monero_serai::{
|
|
|
|
|
ringct::{
|
|
|
|
|
clsag::{ClsagContext, ClsagMultisigMaskSender, ClsagAddendum, ClsagMultisig},
|
|
|
|
|
RctPrunable, RctProofs,
|
|
|
|
|
},
|
|
|
|
|
transaction::Transaction,
|
|
|
|
|
};
|
|
|
|
|
use crate::send::{SendError, SignableTransaction, key_image_sort};
|
|
|
|
|
|
|
|
|
|
/// Initial FROST machine to produce a signed transaction.
|
|
|
|
|
pub struct TransactionMachine {
|
|
|
|
|
signable: SignableTransaction,
|
|
|
|
|
|
|
|
|
|
i: Participant,
|
|
|
|
|
|
|
|
|
|
// The key image generator, and the scalar offset from the spend key
|
|
|
|
|
key_image_generators_and_offsets: Vec<(EdwardsPoint, Scalar)>,
|
|
|
|
|
clsags: Vec<(ClsagMultisigMaskSender, AlgorithmMachine<Ed25519, ClsagMultisig>)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Second FROST machine to produce a signed transaction.
|
|
|
|
|
pub struct TransactionSignMachine {
|
|
|
|
|
signable: SignableTransaction,
|
|
|
|
|
|
|
|
|
|
i: Participant,
|
|
|
|
|
|
|
|
|
|
key_image_generators_and_offsets: Vec<(EdwardsPoint, Scalar)>,
|
|
|
|
|
clsags: Vec<(ClsagMultisigMaskSender, AlgorithmSignMachine<Ed25519, ClsagMultisig>)>,
|
|
|
|
|
|
|
|
|
|
our_preprocess: Vec<Preprocess<Ed25519, ClsagAddendum>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Final FROST machine to produce a signed transaction.
|
|
|
|
|
pub struct TransactionSignatureMachine {
|
|
|
|
|
tx: Transaction,
|
|
|
|
|
clsags: Vec<AlgorithmSignatureMachine<Ed25519, ClsagMultisig>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SignableTransaction {
|
|
|
|
|
/// Create a FROST signing machine out of this signable transaction.
|
|
|
|
|
pub fn multisig(self, keys: &ThresholdKeys<Ed25519>) -> Result<TransactionMachine, SendError> {
|
|
|
|
|
let mut clsags = vec![];
|
|
|
|
|
|
|
|
|
|
let mut key_image_generators_and_offsets = vec![];
|
2024-07-08 00:30:42 -04:00
|
|
|
for input in &self.inputs {
|
Clean the Monero lib for auditing (#577)
* Remove unsafe creation of dalek_ff_group::EdwardsPoint in BP+
* Rename Bulletproofs to Bulletproof, since they are a single Bulletproof
Also bifurcates prove with prove_plus, and adds a few documentation items.
* Make CLSAG signing private
Also adds a bit more documentation and does a bit more tidying.
* Remove the distribution cache
It's a notable bandwidth/performance improvement, yet it's not ready. We need a
dedicated Distribution struct which is managed by the wallet and passed in.
While we can do that now, it's not currently worth the effort.
* Tidy Borromean/MLSAG a tad
* Remove experimental feature from monero-serai
* Move amount_decryption into EncryptedAmount::decrypt
* Various RingCT doc comments
* Begin crate smashing
* Further documentation, start shoring up API boundaries of existing crates
* Document and clean clsag
* Add a dedicated send/recv CLSAG mask struct
Abstracts the types used internally.
Also moves the tests from monero-serai to monero-clsag.
* Smash out monero-bulletproofs
Removes usage of dalek-ff-group/multiexp for curve25519-dalek.
Makes compiling in the generators an optional feature.
Adds a structured batch verifier which should be notably more performant.
Documentation and clean up still necessary.
* Correct no-std builds for monero-clsag and monero-bulletproofs
* Tidy and document monero-bulletproofs
I still don't like the impl of the original Bulletproofs...
* Error if missing documentation
* Smash out MLSAG
* Smash out Borromean
* Tidy up monero-serai as a meta crate
* Smash out RPC, wallet
* Document the RPC
* Improve docs a bit
* Move Protocol to monero-wallet
* Incomplete work on using Option to remove panic cases
* Finish documenting monero-serai
* Remove TODO on reading pseudo_outs for AggregateMlsagBorromean
* Only read transactions with one Input::Gen or all Input::ToKey
Also adds a helper to fetch a transaction's prefix.
* Smash out polyseed
* Smash out seed
* Get the repo to compile again
* Smash out Monero addresses
* Document cargo features
Credit to @hinto-janai for adding such sections to their work on documenting
monero-serai in #568.
* Fix deserializing v2 miner transactions
* Rewrite monero-wallet's send code
I have yet to redo the multisig code and the builder. This should be much
cleaner, albeit slower due to redoing work.
This compiles with clippy --all-features. I have to finish the multisig/builder
for --all-targets to work (and start updating the rest of Serai).
* Add SignableTransaction Read/Write
* Restore Monero multisig TX code
* Correct invalid RPC type def in monero-rpc
* Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
* Clean and document monero-address
* Sync rest of repo with monero-serai changes
* Represent height/block number as a u32
* Diversify ViewPair/Scanner into ViewPair/GuaranteedViewPair and Scanner/GuaranteedScanner
Also cleans the Scanner impl.
* Remove non-small-order view key bound
Guaranteed addresses are in fact guaranteed even with this due to prefixing key
images causing zeroing the ECDH to not zero the shared key.
* Finish documenting monero-serai
* Correct imports for no-std
* Remove possible panic in monero-serai on systems < 32 bits
This was done by requiring the system's usize can represent a certain number.
* Restore the reserialize chain binary
* fmt, machete, GH CI
* Correct misc TODOs in monero-serai
* Have Monero test runner evaluate an Eventuality for all signed TXs
* Fix a pair of bugs in the decoy tests
Unfortunately, this test is still failing.
* Fix remaining bugs in monero-wallet tests
* Reject torsioned spend keys to ensure we can spend the outputs we scan
* Tidy inlined epee code in the RPC
* Correct the accidental swap of stagenet/testnet address bytes
* Remove unused dep from processor
* Handle Monero fee logic properly in the processor
* Document v2 TX/RCT output relation assumed when scanning
* Adjust how we mine the initial blocks due to some CI test failures
* Fix weight estimation for RctType::ClsagBulletproof TXs
* Again increase the amount of blocks we mine prior to running tests
* Correct the if check about when to mine blocks on start
Finally fixes the lack of decoy candidates failures in CI.
* Run Monero on Debian, even for internal testnets
Change made due to a segfault incurred when locally testing.
https://github.com/monero-project/monero/issues/9141 for the upstream.
* Don't attempt running tests on the verify-chain binary
Adds a minimum XMR fee to the processor and runs fmt.
* Increase minimum Monero fee in processor
I'm truly unsure why this is required right now.
* Distinguish fee from necessary_fee in monero-wallet
If there's no change, the fee is difference of the inputs to the outputs. The
prior code wouldn't check that amount is greater than or equal to the necessary
fee, and returning the would-be change amount as the fee isn't necessarily
helpful.
Now the fee is validated in such cases and the necessary fee is returned,
enabling operating off of that.
* Restore minimum Monero fee from develop
2024-07-07 03:57:18 -07:00
|
|
|
// Check this is the right set of keys
|
|
|
|
|
let offset = keys.offset(dfg::Scalar(input.key_offset()));
|
|
|
|
|
if offset.group_key().0 != input.key() {
|
|
|
|
|
Err(SendError::WrongPrivateKey)?;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-08 00:30:42 -04:00
|
|
|
let context = ClsagContext::new(input.decoys().clone(), input.commitment().clone())
|
Clean the Monero lib for auditing (#577)
* Remove unsafe creation of dalek_ff_group::EdwardsPoint in BP+
* Rename Bulletproofs to Bulletproof, since they are a single Bulletproof
Also bifurcates prove with prove_plus, and adds a few documentation items.
* Make CLSAG signing private
Also adds a bit more documentation and does a bit more tidying.
* Remove the distribution cache
It's a notable bandwidth/performance improvement, yet it's not ready. We need a
dedicated Distribution struct which is managed by the wallet and passed in.
While we can do that now, it's not currently worth the effort.
* Tidy Borromean/MLSAG a tad
* Remove experimental feature from monero-serai
* Move amount_decryption into EncryptedAmount::decrypt
* Various RingCT doc comments
* Begin crate smashing
* Further documentation, start shoring up API boundaries of existing crates
* Document and clean clsag
* Add a dedicated send/recv CLSAG mask struct
Abstracts the types used internally.
Also moves the tests from monero-serai to monero-clsag.
* Smash out monero-bulletproofs
Removes usage of dalek-ff-group/multiexp for curve25519-dalek.
Makes compiling in the generators an optional feature.
Adds a structured batch verifier which should be notably more performant.
Documentation and clean up still necessary.
* Correct no-std builds for monero-clsag and monero-bulletproofs
* Tidy and document monero-bulletproofs
I still don't like the impl of the original Bulletproofs...
* Error if missing documentation
* Smash out MLSAG
* Smash out Borromean
* Tidy up monero-serai as a meta crate
* Smash out RPC, wallet
* Document the RPC
* Improve docs a bit
* Move Protocol to monero-wallet
* Incomplete work on using Option to remove panic cases
* Finish documenting monero-serai
* Remove TODO on reading pseudo_outs for AggregateMlsagBorromean
* Only read transactions with one Input::Gen or all Input::ToKey
Also adds a helper to fetch a transaction's prefix.
* Smash out polyseed
* Smash out seed
* Get the repo to compile again
* Smash out Monero addresses
* Document cargo features
Credit to @hinto-janai for adding such sections to their work on documenting
monero-serai in #568.
* Fix deserializing v2 miner transactions
* Rewrite monero-wallet's send code
I have yet to redo the multisig code and the builder. This should be much
cleaner, albeit slower due to redoing work.
This compiles with clippy --all-features. I have to finish the multisig/builder
for --all-targets to work (and start updating the rest of Serai).
* Add SignableTransaction Read/Write
* Restore Monero multisig TX code
* Correct invalid RPC type def in monero-rpc
* Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
* Clean and document monero-address
* Sync rest of repo with monero-serai changes
* Represent height/block number as a u32
* Diversify ViewPair/Scanner into ViewPair/GuaranteedViewPair and Scanner/GuaranteedScanner
Also cleans the Scanner impl.
* Remove non-small-order view key bound
Guaranteed addresses are in fact guaranteed even with this due to prefixing key
images causing zeroing the ECDH to not zero the shared key.
* Finish documenting monero-serai
* Correct imports for no-std
* Remove possible panic in monero-serai on systems < 32 bits
This was done by requiring the system's usize can represent a certain number.
* Restore the reserialize chain binary
* fmt, machete, GH CI
* Correct misc TODOs in monero-serai
* Have Monero test runner evaluate an Eventuality for all signed TXs
* Fix a pair of bugs in the decoy tests
Unfortunately, this test is still failing.
* Fix remaining bugs in monero-wallet tests
* Reject torsioned spend keys to ensure we can spend the outputs we scan
* Tidy inlined epee code in the RPC
* Correct the accidental swap of stagenet/testnet address bytes
* Remove unused dep from processor
* Handle Monero fee logic properly in the processor
* Document v2 TX/RCT output relation assumed when scanning
* Adjust how we mine the initial blocks due to some CI test failures
* Fix weight estimation for RctType::ClsagBulletproof TXs
* Again increase the amount of blocks we mine prior to running tests
* Correct the if check about when to mine blocks on start
Finally fixes the lack of decoy candidates failures in CI.
* Run Monero on Debian, even for internal testnets
Change made due to a segfault incurred when locally testing.
https://github.com/monero-project/monero/issues/9141 for the upstream.
* Don't attempt running tests on the verify-chain binary
Adds a minimum XMR fee to the processor and runs fmt.
* Increase minimum Monero fee in processor
I'm truly unsure why this is required right now.
* Distinguish fee from necessary_fee in monero-wallet
If there's no change, the fee is difference of the inputs to the outputs. The
prior code wouldn't check that amount is greater than or equal to the necessary
fee, and returning the would-be change amount as the fee isn't necessarily
helpful.
Now the fee is validated in such cases and the necessary fee is returned,
enabling operating off of that.
* Restore minimum Monero fee from develop
2024-07-07 03:57:18 -07:00
|
|
|
.map_err(SendError::ClsagError)?;
|
|
|
|
|
let (clsag, clsag_mask_send) = ClsagMultisig::new(
|
|
|
|
|
RecommendedTranscript::new(b"Monero Multisignature Transaction"),
|
|
|
|
|
context,
|
|
|
|
|
);
|
|
|
|
|
key_image_generators_and_offsets.push((
|
|
|
|
|
clsag.key_image_generator(),
|
2024-07-08 00:30:42 -04:00
|
|
|
keys.current_offset().unwrap_or(dfg::Scalar::ZERO).0 + input.key_offset(),
|
Clean the Monero lib for auditing (#577)
* Remove unsafe creation of dalek_ff_group::EdwardsPoint in BP+
* Rename Bulletproofs to Bulletproof, since they are a single Bulletproof
Also bifurcates prove with prove_plus, and adds a few documentation items.
* Make CLSAG signing private
Also adds a bit more documentation and does a bit more tidying.
* Remove the distribution cache
It's a notable bandwidth/performance improvement, yet it's not ready. We need a
dedicated Distribution struct which is managed by the wallet and passed in.
While we can do that now, it's not currently worth the effort.
* Tidy Borromean/MLSAG a tad
* Remove experimental feature from monero-serai
* Move amount_decryption into EncryptedAmount::decrypt
* Various RingCT doc comments
* Begin crate smashing
* Further documentation, start shoring up API boundaries of existing crates
* Document and clean clsag
* Add a dedicated send/recv CLSAG mask struct
Abstracts the types used internally.
Also moves the tests from monero-serai to monero-clsag.
* Smash out monero-bulletproofs
Removes usage of dalek-ff-group/multiexp for curve25519-dalek.
Makes compiling in the generators an optional feature.
Adds a structured batch verifier which should be notably more performant.
Documentation and clean up still necessary.
* Correct no-std builds for monero-clsag and monero-bulletproofs
* Tidy and document monero-bulletproofs
I still don't like the impl of the original Bulletproofs...
* Error if missing documentation
* Smash out MLSAG
* Smash out Borromean
* Tidy up monero-serai as a meta crate
* Smash out RPC, wallet
* Document the RPC
* Improve docs a bit
* Move Protocol to monero-wallet
* Incomplete work on using Option to remove panic cases
* Finish documenting monero-serai
* Remove TODO on reading pseudo_outs for AggregateMlsagBorromean
* Only read transactions with one Input::Gen or all Input::ToKey
Also adds a helper to fetch a transaction's prefix.
* Smash out polyseed
* Smash out seed
* Get the repo to compile again
* Smash out Monero addresses
* Document cargo features
Credit to @hinto-janai for adding such sections to their work on documenting
monero-serai in #568.
* Fix deserializing v2 miner transactions
* Rewrite monero-wallet's send code
I have yet to redo the multisig code and the builder. This should be much
cleaner, albeit slower due to redoing work.
This compiles with clippy --all-features. I have to finish the multisig/builder
for --all-targets to work (and start updating the rest of Serai).
* Add SignableTransaction Read/Write
* Restore Monero multisig TX code
* Correct invalid RPC type def in monero-rpc
* Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
* Clean and document monero-address
* Sync rest of repo with monero-serai changes
* Represent height/block number as a u32
* Diversify ViewPair/Scanner into ViewPair/GuaranteedViewPair and Scanner/GuaranteedScanner
Also cleans the Scanner impl.
* Remove non-small-order view key bound
Guaranteed addresses are in fact guaranteed even with this due to prefixing key
images causing zeroing the ECDH to not zero the shared key.
* Finish documenting monero-serai
* Correct imports for no-std
* Remove possible panic in monero-serai on systems < 32 bits
This was done by requiring the system's usize can represent a certain number.
* Restore the reserialize chain binary
* fmt, machete, GH CI
* Correct misc TODOs in monero-serai
* Have Monero test runner evaluate an Eventuality for all signed TXs
* Fix a pair of bugs in the decoy tests
Unfortunately, this test is still failing.
* Fix remaining bugs in monero-wallet tests
* Reject torsioned spend keys to ensure we can spend the outputs we scan
* Tidy inlined epee code in the RPC
* Correct the accidental swap of stagenet/testnet address bytes
* Remove unused dep from processor
* Handle Monero fee logic properly in the processor
* Document v2 TX/RCT output relation assumed when scanning
* Adjust how we mine the initial blocks due to some CI test failures
* Fix weight estimation for RctType::ClsagBulletproof TXs
* Again increase the amount of blocks we mine prior to running tests
* Correct the if check about when to mine blocks on start
Finally fixes the lack of decoy candidates failures in CI.
* Run Monero on Debian, even for internal testnets
Change made due to a segfault incurred when locally testing.
https://github.com/monero-project/monero/issues/9141 for the upstream.
* Don't attempt running tests on the verify-chain binary
Adds a minimum XMR fee to the processor and runs fmt.
* Increase minimum Monero fee in processor
I'm truly unsure why this is required right now.
* Distinguish fee from necessary_fee in monero-wallet
If there's no change, the fee is difference of the inputs to the outputs. The
prior code wouldn't check that amount is greater than or equal to the necessary
fee, and returning the would-be change amount as the fee isn't necessarily
helpful.
Now the fee is validated in such cases and the necessary fee is returned,
enabling operating off of that.
* Restore minimum Monero fee from develop
2024-07-07 03:57:18 -07:00
|
|
|
));
|
|
|
|
|
clsags.push((clsag_mask_send, AlgorithmMachine::new(clsag, offset)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(TransactionMachine {
|
|
|
|
|
signable: self,
|
|
|
|
|
i: keys.params().i(),
|
|
|
|
|
key_image_generators_and_offsets,
|
|
|
|
|
clsags,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PreprocessMachine for TransactionMachine {
|
|
|
|
|
type Preprocess = Vec<Preprocess<Ed25519, ClsagAddendum>>;
|
|
|
|
|
type Signature = Transaction;
|
|
|
|
|
type SignMachine = TransactionSignMachine;
|
|
|
|
|
|
|
|
|
|
fn preprocess<R: RngCore + CryptoRng>(
|
|
|
|
|
mut self,
|
|
|
|
|
rng: &mut R,
|
|
|
|
|
) -> (TransactionSignMachine, Self::Preprocess) {
|
|
|
|
|
// Iterate over each CLSAG calling preprocess
|
|
|
|
|
let mut preprocesses = Vec::with_capacity(self.clsags.len());
|
|
|
|
|
let clsags = self
|
|
|
|
|
.clsags
|
|
|
|
|
.drain(..)
|
|
|
|
|
.map(|(clsag_mask_send, clsag)| {
|
|
|
|
|
let (clsag, preprocess) = clsag.preprocess(rng);
|
|
|
|
|
preprocesses.push(preprocess);
|
|
|
|
|
(clsag_mask_send, clsag)
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
let our_preprocess = preprocesses.clone();
|
|
|
|
|
|
|
|
|
|
(
|
|
|
|
|
TransactionSignMachine {
|
|
|
|
|
signable: self.signable,
|
|
|
|
|
|
|
|
|
|
i: self.i,
|
|
|
|
|
|
|
|
|
|
key_image_generators_and_offsets: self.key_image_generators_and_offsets,
|
|
|
|
|
clsags,
|
|
|
|
|
|
|
|
|
|
our_preprocess,
|
|
|
|
|
},
|
|
|
|
|
preprocesses,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SignMachine<Transaction> for TransactionSignMachine {
|
|
|
|
|
type Params = ();
|
|
|
|
|
type Keys = ThresholdKeys<Ed25519>;
|
|
|
|
|
type Preprocess = Vec<Preprocess<Ed25519, ClsagAddendum>>;
|
|
|
|
|
type SignatureShare = Vec<SignatureShare<Ed25519>>;
|
|
|
|
|
type SignatureMachine = TransactionSignatureMachine;
|
|
|
|
|
|
|
|
|
|
fn cache(self) -> CachedPreprocess {
|
|
|
|
|
unimplemented!(
|
|
|
|
|
"Monero transactions don't support caching their preprocesses due to {}",
|
|
|
|
|
"being already bound to a specific transaction"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn from_cache(
|
|
|
|
|
(): (),
|
|
|
|
|
_: ThresholdKeys<Ed25519>,
|
|
|
|
|
_: CachedPreprocess,
|
|
|
|
|
) -> (Self, Self::Preprocess) {
|
|
|
|
|
unimplemented!(
|
|
|
|
|
"Monero transactions don't support caching their preprocesses due to {}",
|
|
|
|
|
"being already bound to a specific transaction"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn read_preprocess<R: Read>(&self, reader: &mut R) -> io::Result<Self::Preprocess> {
|
|
|
|
|
self.clsags.iter().map(|clsag| clsag.1.read_preprocess(reader)).collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn sign(
|
|
|
|
|
self,
|
|
|
|
|
mut commitments: HashMap<Participant, Self::Preprocess>,
|
|
|
|
|
msg: &[u8],
|
|
|
|
|
) -> Result<(TransactionSignatureMachine, Self::SignatureShare), FrostError> {
|
|
|
|
|
if !msg.is_empty() {
|
|
|
|
|
panic!("message was passed to the TransactionMachine when it generates its own");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We do not need to be included here, yet this set of signers has yet to be validated
|
|
|
|
|
// We explicitly remove ourselves to ensure we aren't included twice, if we were redundantly
|
|
|
|
|
// included
|
|
|
|
|
commitments.remove(&self.i);
|
|
|
|
|
|
|
|
|
|
// Find out who's included
|
|
|
|
|
let mut included = commitments.keys().copied().collect::<Vec<_>>();
|
|
|
|
|
// This push won't duplicate due to the above removal
|
|
|
|
|
included.push(self.i);
|
|
|
|
|
// unstable sort may reorder elements of equal order
|
|
|
|
|
// Given our lack of duplicates, we should have no elements of equal order
|
|
|
|
|
included.sort_unstable();
|
|
|
|
|
|
|
|
|
|
// Start calculating the key images, as needed on the TX level
|
|
|
|
|
let mut key_images = vec![EdwardsPoint::identity(); self.clsags.len()];
|
|
|
|
|
for (image, (generator, offset)) in
|
|
|
|
|
key_images.iter_mut().zip(&self.key_image_generators_and_offsets)
|
|
|
|
|
{
|
|
|
|
|
*image = generator * offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert the serialized nonces commitments to a parallelized Vec
|
|
|
|
|
let mut commitments = (0 .. self.clsags.len())
|
|
|
|
|
.map(|c| {
|
|
|
|
|
included
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|l| {
|
|
|
|
|
let preprocess = if *l == self.i {
|
|
|
|
|
self.our_preprocess[c].clone()
|
|
|
|
|
} else {
|
|
|
|
|
commitments.get_mut(l).ok_or(FrostError::MissingParticipant(*l))?[c].clone()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// While here, calculate the key image as needed to call sign
|
|
|
|
|
// The CLSAG algorithm will independently calculate the key image/verify these shares
|
|
|
|
|
key_images[c] +=
|
|
|
|
|
preprocess.addendum.key_image_share().0 * lagrange::<dfg::Scalar>(*l, &included).0;
|
|
|
|
|
|
|
|
|
|
Ok((*l, preprocess))
|
|
|
|
|
})
|
|
|
|
|
.collect::<Result<HashMap<_, _>, _>>()
|
|
|
|
|
})
|
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
|
|
|
|
|
|
// The above inserted our own preprocess into these maps (which is unnecessary)
|
|
|
|
|
// Remove it now
|
|
|
|
|
for map in &mut commitments {
|
|
|
|
|
map.remove(&self.i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The actual TX will have sorted its inputs by key image
|
|
|
|
|
// We apply the same sort now to our CLSAG machines
|
|
|
|
|
let mut clsags = Vec::with_capacity(self.clsags.len());
|
|
|
|
|
for ((key_image, clsag), commitments) in key_images.iter().zip(self.clsags).zip(commitments) {
|
|
|
|
|
clsags.push((key_image, clsag, commitments));
|
|
|
|
|
}
|
|
|
|
|
clsags.sort_by(|x, y| key_image_sort(x.0, y.0));
|
|
|
|
|
let clsags =
|
|
|
|
|
clsags.into_iter().map(|(_, clsag, commitments)| (clsag, commitments)).collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
// Specify the TX's key images
|
|
|
|
|
let tx = self.signable.with_key_images(key_images);
|
|
|
|
|
|
|
|
|
|
// We now need to decide the masks for each CLSAG
|
|
|
|
|
let clsag_len = clsags.len();
|
|
|
|
|
let output_masks = tx.intent.sum_output_masks(&tx.key_images);
|
|
|
|
|
let mut rng = tx.intent.seeded_rng(b"multisig_pseudo_out_masks");
|
|
|
|
|
let mut sum_pseudo_outs = Scalar::ZERO;
|
|
|
|
|
let mut to_sign = Vec::with_capacity(clsag_len);
|
|
|
|
|
for (i, ((clsag_mask_send, clsag), commitments)) in clsags.into_iter().enumerate() {
|
|
|
|
|
let mut mask = Scalar::random(&mut rng);
|
|
|
|
|
if i == (clsag_len - 1) {
|
|
|
|
|
mask = output_masks - sum_pseudo_outs;
|
|
|
|
|
} else {
|
|
|
|
|
sum_pseudo_outs += mask;
|
|
|
|
|
}
|
|
|
|
|
clsag_mask_send.send(mask);
|
|
|
|
|
to_sign.push((clsag, commitments));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let tx = tx.transaction_without_signatures();
|
2025-08-08 21:28:47 -04:00
|
|
|
let msg = tx.signature_hash().expect("signing a transaction which isn't signed?");
|
Clean the Monero lib for auditing (#577)
* Remove unsafe creation of dalek_ff_group::EdwardsPoint in BP+
* Rename Bulletproofs to Bulletproof, since they are a single Bulletproof
Also bifurcates prove with prove_plus, and adds a few documentation items.
* Make CLSAG signing private
Also adds a bit more documentation and does a bit more tidying.
* Remove the distribution cache
It's a notable bandwidth/performance improvement, yet it's not ready. We need a
dedicated Distribution struct which is managed by the wallet and passed in.
While we can do that now, it's not currently worth the effort.
* Tidy Borromean/MLSAG a tad
* Remove experimental feature from monero-serai
* Move amount_decryption into EncryptedAmount::decrypt
* Various RingCT doc comments
* Begin crate smashing
* Further documentation, start shoring up API boundaries of existing crates
* Document and clean clsag
* Add a dedicated send/recv CLSAG mask struct
Abstracts the types used internally.
Also moves the tests from monero-serai to monero-clsag.
* Smash out monero-bulletproofs
Removes usage of dalek-ff-group/multiexp for curve25519-dalek.
Makes compiling in the generators an optional feature.
Adds a structured batch verifier which should be notably more performant.
Documentation and clean up still necessary.
* Correct no-std builds for monero-clsag and monero-bulletproofs
* Tidy and document monero-bulletproofs
I still don't like the impl of the original Bulletproofs...
* Error if missing documentation
* Smash out MLSAG
* Smash out Borromean
* Tidy up monero-serai as a meta crate
* Smash out RPC, wallet
* Document the RPC
* Improve docs a bit
* Move Protocol to monero-wallet
* Incomplete work on using Option to remove panic cases
* Finish documenting monero-serai
* Remove TODO on reading pseudo_outs for AggregateMlsagBorromean
* Only read transactions with one Input::Gen or all Input::ToKey
Also adds a helper to fetch a transaction's prefix.
* Smash out polyseed
* Smash out seed
* Get the repo to compile again
* Smash out Monero addresses
* Document cargo features
Credit to @hinto-janai for adding such sections to their work on documenting
monero-serai in #568.
* Fix deserializing v2 miner transactions
* Rewrite monero-wallet's send code
I have yet to redo the multisig code and the builder. This should be much
cleaner, albeit slower due to redoing work.
This compiles with clippy --all-features. I have to finish the multisig/builder
for --all-targets to work (and start updating the rest of Serai).
* Add SignableTransaction Read/Write
* Restore Monero multisig TX code
* Correct invalid RPC type def in monero-rpc
* Update monero-wallet tests to compile
Some are _consistently_ failing due to the inputs we attempt to spend being too
young. I'm unsure what's up with that. Most seem to pass _consistently_,
implying it's not a random issue yet some configuration/env aspect.
* Clean and document monero-address
* Sync rest of repo with monero-serai changes
* Represent height/block number as a u32
* Diversify ViewPair/Scanner into ViewPair/GuaranteedViewPair and Scanner/GuaranteedScanner
Also cleans the Scanner impl.
* Remove non-small-order view key bound
Guaranteed addresses are in fact guaranteed even with this due to prefixing key
images causing zeroing the ECDH to not zero the shared key.
* Finish documenting monero-serai
* Correct imports for no-std
* Remove possible panic in monero-serai on systems < 32 bits
This was done by requiring the system's usize can represent a certain number.
* Restore the reserialize chain binary
* fmt, machete, GH CI
* Correct misc TODOs in monero-serai
* Have Monero test runner evaluate an Eventuality for all signed TXs
* Fix a pair of bugs in the decoy tests
Unfortunately, this test is still failing.
* Fix remaining bugs in monero-wallet tests
* Reject torsioned spend keys to ensure we can spend the outputs we scan
* Tidy inlined epee code in the RPC
* Correct the accidental swap of stagenet/testnet address bytes
* Remove unused dep from processor
* Handle Monero fee logic properly in the processor
* Document v2 TX/RCT output relation assumed when scanning
* Adjust how we mine the initial blocks due to some CI test failures
* Fix weight estimation for RctType::ClsagBulletproof TXs
* Again increase the amount of blocks we mine prior to running tests
* Correct the if check about when to mine blocks on start
Finally fixes the lack of decoy candidates failures in CI.
* Run Monero on Debian, even for internal testnets
Change made due to a segfault incurred when locally testing.
https://github.com/monero-project/monero/issues/9141 for the upstream.
* Don't attempt running tests on the verify-chain binary
Adds a minimum XMR fee to the processor and runs fmt.
* Increase minimum Monero fee in processor
I'm truly unsure why this is required right now.
* Distinguish fee from necessary_fee in monero-wallet
If there's no change, the fee is difference of the inputs to the outputs. The
prior code wouldn't check that amount is greater than or equal to the necessary
fee, and returning the would-be change amount as the fee isn't necessarily
helpful.
Now the fee is validated in such cases and the necessary fee is returned,
enabling operating off of that.
* Restore minimum Monero fee from develop
2024-07-07 03:57:18 -07:00
|
|
|
|
|
|
|
|
// Iterate over each CLSAG calling sign
|
|
|
|
|
let mut shares = Vec::with_capacity(to_sign.len());
|
|
|
|
|
let clsags = to_sign
|
|
|
|
|
.drain(..)
|
|
|
|
|
.map(|(clsag, commitments)| {
|
|
|
|
|
let (clsag, share) = clsag.sign(commitments, &msg)?;
|
|
|
|
|
shares.push(share);
|
|
|
|
|
Ok(clsag)
|
|
|
|
|
})
|
|
|
|
|
.collect::<Result<_, _>>()?;
|
|
|
|
|
|
|
|
|
|
Ok((TransactionSignatureMachine { tx, clsags }, shares))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SignatureMachine<Transaction> for TransactionSignatureMachine {
|
|
|
|
|
type SignatureShare = Vec<SignatureShare<Ed25519>>;
|
|
|
|
|
|
|
|
|
|
fn read_share<R: Read>(&self, reader: &mut R) -> io::Result<Self::SignatureShare> {
|
|
|
|
|
self.clsags.iter().map(|clsag| clsag.read_share(reader)).collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn complete(
|
|
|
|
|
mut self,
|
|
|
|
|
shares: HashMap<Participant, Self::SignatureShare>,
|
|
|
|
|
) -> Result<Transaction, FrostError> {
|
|
|
|
|
let mut tx = self.tx;
|
|
|
|
|
match tx {
|
|
|
|
|
Transaction::V2 {
|
|
|
|
|
proofs:
|
|
|
|
|
Some(RctProofs {
|
|
|
|
|
prunable: RctPrunable::Clsag { ref mut clsags, ref mut pseudo_outs, .. },
|
|
|
|
|
..
|
|
|
|
|
}),
|
|
|
|
|
..
|
|
|
|
|
} => {
|
|
|
|
|
for (c, clsag) in self.clsags.drain(..).enumerate() {
|
|
|
|
|
let (clsag, pseudo_out) = clsag.complete(
|
|
|
|
|
shares.iter().map(|(l, shares)| (*l, shares[c].clone())).collect::<HashMap<_, _>>(),
|
|
|
|
|
)?;
|
|
|
|
|
clsags.push(clsag);
|
|
|
|
|
pseudo_outs.push(pseudo_out);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => unreachable!("attempted to sign a multisig TX which wasn't CLSAG"),
|
|
|
|
|
}
|
|
|
|
|
Ok(tx)
|
|
|
|
|
}
|
|
|
|
|
}
|