Skip to content

Commit

Permalink
Revert "new monero-serai"
Browse files Browse the repository at this point in the history
This reverts commit fe3f6ac.
  • Loading branch information
Boog900 committed Jan 29, 2025
1 parent 51b4a3e commit 4e805b3
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 43 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ futures = { version = "0.3", default-features = false }
hex = { version = "0.4", default-features = false }
hex-literal = { version = "0.4", default-features = false }
indexmap = { version = "2", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "7f52b95", default-features = false }
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6", default-features = false }
paste = { version = "1", default-features = false }
pin-project = { version = "1", default-features = false }
randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev = "0028464", default-features = false }
Expand All @@ -144,8 +144,8 @@ tracing-subscriber = { version = "0.3", default-features = false }
tracing = { version = "0.1", default-features = false }

## workspace.dev-dependencies
monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "7f52b95" }
monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "7f52b95" }
monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6" }
monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "e6fdef6" }
tempfile = { version = "3" }
pretty_assertions = { version = "1" }
proptest = { version = "1" }
Expand Down
4 changes: 1 addition & 3 deletions binaries/cuprated/src/blockchain/manager/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ impl super::BlockchainManager {
batch_prepare_main_chain_blocks(batch.blocks, &mut self.blockchain_context_service, self.blockchain_read_handle.clone())
.await
else {
panic!();
batch.peer_handle.ban_peer(LONG_BAN);
self.stop_current_block_downloader.notify_one();
return;
Expand All @@ -186,7 +185,6 @@ impl super::BlockchainManager {
)
.await
else {
panic!();
batch.peer_handle.ban_peer(LONG_BAN);
self.stop_current_block_downloader.notify_one();
return;
Expand Down Expand Up @@ -435,7 +433,7 @@ impl super::BlockchainManager {
.iter()
.flat_map(|tx| {
tx.tx.prefix().inputs.iter().map(|input| match input {
Input::ToKey { key_image, .. } => key_image.0,
Input::ToKey { key_image, .. } => key_image.compress().0,
Input::Gen(_) => unreachable!(),
})
})
Expand Down
6 changes: 3 additions & 3 deletions consensus/rules/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use monero_serai::{
ringct::RctType,
transaction::{Input, Output, Timelock, Transaction},
};
use monero_serai::io::decompress_point;

pub use cuprate_types::TxVersion;

use crate::{
Expand Down Expand Up @@ -327,7 +327,7 @@ fn check_key_images(input: &Input) -> Result<(), TransactionError> {
match input {
Input::ToKey { key_image, .. } => {
// this happens in monero-serai but we may as well duplicate the check.
if decompress_point(*key_image).is_none_or(|p| !p.is_torsion_free()) {
if !key_image.is_torsion_free() {
return Err(TransactionError::KeyImageIsNotInPrimeSubGroup);
}
}
Expand Down Expand Up @@ -388,7 +388,7 @@ fn check_ring_members_unique(input: &Input, hf: HardFork) -> Result<(), Transact
/// ref: <https://monero-book.cuprate.org/consensus_rules/transactions/inputs.html#sorted-inputs>
fn check_inputs_sorted(inputs: &[Input], hf: HardFork) -> Result<(), TransactionError> {
let get_ki = |inp: &Input| match inp {
Input::ToKey { key_image, .. } => Ok(key_image.to_bytes()),
Input::ToKey { key_image, .. } => Ok(key_image.compress().to_bytes()),
Input::Gen(_) => Err(TransactionError::IncorrectInputType),
};

Expand Down
15 changes: 7 additions & 8 deletions consensus/rules/src/transactions/ring_ct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ fn simple_type_balances(rct_sig: &RctProofs) -> Result<(), RingCTError> {
}
};

let sum_inputs = pseudo_outs.iter().map(|p| p.decompress().unwrap()).sum::<EdwardsPoint>();
let sum_inputs = pseudo_outs.iter().sum::<EdwardsPoint>();
let sum_outputs =
rct_sig.base.commitments.iter().map(|p| p.decompress().unwrap()).sum::<EdwardsPoint>() + Scalar::from(rct_sig.base.fee) * *H;
rct_sig.base.commitments.iter().sum::<EdwardsPoint>() + Scalar::from(rct_sig.base.fee) * *H;

if sum_inputs == sum_outputs {
Ok(())
Expand All @@ -101,7 +101,7 @@ fn check_output_range_proofs(
| RctPrunable::AggregateMlsagBorromean { borromean, .. } => try_par_iter(borromean)
.zip(commitments)
.try_for_each(|(borro, commitment)| {
if borro.verify(&commitment.decompress().unwrap()) {
if borro.verify(commitment) {
Ok(())
} else {
Err(RingCTError::BorromeanRangeInvalid)
Expand Down Expand Up @@ -173,12 +173,12 @@ pub(crate) fn check_input_signatures(
let Input::ToKey { key_image, .. } = inp else {
panic!("How did we build a ring with no decoys?");
};
key_image.decompress().unwrap()
*key_image
})
.collect::<Vec<_>>();

let mut matrix =
AggregateRingMatrixBuilder::new(&proofs.base.commitments.iter().map(|p| p.decompress().unwrap()).collect::<Vec<_>>(), proofs.base.fee);
AggregateRingMatrixBuilder::new(&proofs.base.commitments, proofs.base.fee);

rings.iter().try_for_each(|ring| matrix.push_ring(ring))?;

Expand All @@ -195,11 +195,10 @@ pub(crate) fn check_input_signatures(
panic!("How did we build a ring with no decoys?");
};

// TODO: change monero-serai API
Ok(mlsag.verify(
msg,
&RingMatrix::individual(ring, pseudo_out.decompress().unwrap())?,
&[key_image.decompress().unwrap()],
&RingMatrix::individual(ring, *pseudo_out)?,
&[*key_image],
)?)
}),
RctPrunable::Clsag { clsags, .. } => try_par_iter(clsags)
Expand Down
3 changes: 1 addition & 2 deletions consensus/rules/src/transactions/ring_signatures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub(crate) fn check_input_signatures(
panic!("How did we build a ring with no decoys?");
};

// TODO: change monero-serai API
if !sig.verify(tx_sig_hash, ring, &key_image.decompress().unwrap()) {
if !sig.verify(tx_sig_hash, ring, key_image) {
return Err(TransactionError::RingSignatureIncorrect);
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion consensus/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ pub(crate) async fn check_kis_unique<D: Database>(
txs.try_for_each(|tx| {
tx.tx.prefix().inputs.iter().try_for_each(|input| {
if let Input::ToKey { key_image, .. } = input {
if !spent_kis.insert(key_image.0) {
if !spent_kis.insert(key_image.compress().0) {
tracing::debug!("Duplicate key image found in batch.");
return Err(ConsensusError::Transaction(TransactionError::KeyImageSpent));
}
Expand Down
8 changes: 4 additions & 4 deletions storage/blockchain/src/ops/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn add_tx(
match inputs {
// Key images.
Input::ToKey { key_image, .. } => {
add_key_image(key_image.as_bytes(), tables.key_images_mut())?;
add_key_image(key_image.compress().as_bytes(), tables.key_images_mut())?;
}
// This is a miner transaction, set it for later use.
Input::Gen(_) => miner_tx = true,
Expand Down Expand Up @@ -138,7 +138,7 @@ pub fn add_tx(
// Create commitment.

let commitment = if miner_tx {
compute_zero_commitment(output.amount.unwrap_or(0)).compress()
compute_zero_commitment(output.amount.unwrap_or(0))
} else {
proofs
.as_ref()
Expand All @@ -154,7 +154,7 @@ pub fn add_tx(
height,
output_flags,
tx_idx: tx_id,
commitment: commitment.0,
commitment: commitment.compress().0,
},
tables.rct_outputs_mut(),
)
Expand Down Expand Up @@ -219,7 +219,7 @@ pub fn remove_tx(tx_hash: &TxHash, tables: &mut impl TablesMut) -> DbResult<(TxI
match inputs {
// Key images.
Input::ToKey { key_image, .. } => {
remove_key_image(key_image.as_bytes(), tables.key_images_mut())?;
remove_key_image(key_image.compress().as_bytes(), tables.key_images_mut())?;
}
// This is a miner transaction, set it for later use.
Input::Gen(_) => miner_tx = true,
Expand Down
2 changes: 1 addition & 1 deletion storage/txpool/src/ops/key_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(super) fn remove_tx_key_images(
/// This function will panic if the [`Input`] is not [`Input::ToKey`]
fn ki_from_input(input: &Input) -> [u8; 32] {
match input {
Input::ToKey { key_image, .. } => key_image.0,
Input::ToKey { key_image, .. } => key_image.compress().0,
Input::Gen(_) => panic!("miner tx cannot be added to the txpool"),
}
}
4 changes: 2 additions & 2 deletions types/src/json/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl From<transaction::Transaction> for Transaction {
let key = Key {
amount: amount.unwrap_or(0),
key_offsets,
k_image: HexBytes::<32>(key_image.0),
k_image: HexBytes::<32>(key_image.compress().0),
};

Some(Input { key })
Expand Down Expand Up @@ -169,7 +169,7 @@ impl From<transaction::Transaction> for Transaction {
.base
.commitments
.into_iter()
.map(|point| HexBytes::<32>(point.0))
.map(|point| HexBytes::<32>(point.compress().0))
.collect();

let rct_signatures = RctSignatures::NonCoinbase {
Expand Down
2 changes: 1 addition & 1 deletion types/src/output_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn get_output_commitment(tx: &Transaction, i: usize) -> EdwardsPoint {
.as_ref()
.expect("A V2 transaction with no RCT proofs is a miner tx")
.base
.commitments[i].decompress().unwrap()
.commitments[i]
}
}
}

0 comments on commit 4e805b3

Please sign in to comment.