diff --git a/coins/monero/build.rs b/coins/monero/build.rs index 71d5e7ef..265b91ea 100644 --- a/coins/monero/build.rs +++ b/coins/monero/build.rs @@ -42,7 +42,7 @@ fn generators(prefix: &'static str, path: &str) { format!( " lazy_static! {{ - static ref GENERATORS: Generators = Generators {{ + pub static ref GENERATORS: Generators = Generators {{ G: [ {} ], diff --git a/coins/monero/src/ringct/bulletproofs/mod.rs b/coins/monero/src/ringct/bulletproofs/mod.rs index 6e7481a7..117cb472 100644 --- a/coins/monero/src/ringct/bulletproofs/mod.rs +++ b/coins/monero/src/ringct/bulletproofs/mod.rs @@ -14,7 +14,9 @@ pub(crate) mod core; use self::core::LOG_N; pub(crate) mod original; +pub use original::GENERATORS as BULLETPROOFS_GENERATORS; pub(crate) mod plus; +pub use plus::GENERATORS as BULLETPROOFS_PLUS_GENERATORS; pub(crate) use self::original::OriginalStruct; pub(crate) use self::plus::PlusStruct; @@ -118,7 +120,7 @@ impl Bulletproofs { } } - pub fn signature_serialize(&self, w: &mut W) -> std::io::Result<()> { + pub(crate) fn signature_serialize(&self, w: &mut W) -> std::io::Result<()> { self.serialize_core(w, |points, w| write_raw_vec(write_point, points, w)) } diff --git a/coins/monero/src/ringct/clsag/mod.rs b/coins/monero/src/ringct/clsag/mod.rs index 3ad1032a..930af467 100644 --- a/coins/monero/src/ringct/clsag/mod.rs +++ b/coins/monero/src/ringct/clsag/mod.rs @@ -51,9 +51,9 @@ pub enum ClsagError { #[derive(Clone, PartialEq, Eq, Debug, Zeroize, ZeroizeOnDrop)] pub struct ClsagInput { // The actual commitment for the true spend - pub commitment: Commitment, + pub(crate) commitment: Commitment, // True spend index, offsets, and ring - pub decoys: Decoys, + pub(crate) decoys: Decoys, } impl ClsagInput { diff --git a/coins/monero/src/ringct/clsag/multisig.rs b/coins/monero/src/ringct/clsag/multisig.rs index e5e7f9cb..3a6df552 100644 --- a/coins/monero/src/ringct/clsag/multisig.rs +++ b/coins/monero/src/ringct/clsag/multisig.rs @@ -55,13 +55,13 @@ impl ClsagInput { } #[derive(Clone, Debug, Zeroize, ZeroizeOnDrop)] -pub struct ClsagDetails { +pub(crate) struct ClsagDetails { input: ClsagInput, mask: Scalar, } impl ClsagDetails { - pub fn new(input: ClsagInput, mask: Scalar) -> ClsagDetails { + pub(crate) fn new(input: ClsagInput, mask: Scalar) -> ClsagDetails { ClsagDetails { input, mask } } } @@ -111,10 +111,6 @@ impl ClsagMultisig { }) } - pub const fn serialized_len() -> usize { - 32 + (2 * 32) - } - fn input(&self) -> ClsagInput { (*self.details.read().unwrap()).as_ref().unwrap().input.clone() } @@ -137,7 +133,7 @@ impl Algorithm for ClsagMultisig { rng: &mut R, view: &FrostView, ) -> Vec { - let mut serialized = Vec::with_capacity(Self::serialized_len()); + let mut serialized = Vec::with_capacity(32 + (2 * 32)); serialized.extend((view.secret_share().0 * self.H).compress().to_bytes()); serialized.extend(write_dleq(rng, self.H, view.secret_share().0)); serialized diff --git a/coins/monero/src/ringct/hash_to_point.rs b/coins/monero/src/ringct/hash_to_point.rs index 5c19b9bd..9fb8f95a 100644 --- a/coins/monero/src/ringct/hash_to_point.rs +++ b/coins/monero/src/ringct/hash_to_point.rs @@ -1,6 +1,6 @@ use curve25519_dalek::edwards::EdwardsPoint; -pub(crate) use monero_generators::{hash_to_point as raw_hash_to_point}; +pub use monero_generators::{hash_to_point as raw_hash_to_point}; pub fn hash_to_point(key: EdwardsPoint) -> EdwardsPoint { raw_hash_to_point(key.compress().to_bytes()) diff --git a/coins/monero/src/ringct/mod.rs b/coins/monero/src/ringct/mod.rs index bd663b65..d37763d0 100644 --- a/coins/monero/src/ringct/mod.rs +++ b/coins/monero/src/ringct/mod.rs @@ -3,7 +3,7 @@ use zeroize::Zeroize; use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwards::EdwardsPoint}; pub(crate) mod hash_to_point; -pub use hash_to_point::hash_to_point; +pub use hash_to_point::{raw_hash_to_point, hash_to_point}; pub mod clsag; pub mod bulletproofs; @@ -127,7 +127,7 @@ impl RctPrunable { }) } - pub fn signature_serialize(&self, w: &mut W) -> std::io::Result<()> { + pub(crate) fn signature_serialize(&self, w: &mut W) -> std::io::Result<()> { match self { RctPrunable::Null => panic!("Serializing RctPrunable::Null for a signature"), RctPrunable::Clsag { bulletproofs, .. } => { diff --git a/coins/monero/src/rpc.rs b/coins/monero/src/rpc.rs index 2fd8bade..0b29a018 100644 --- a/coins/monero/src/rpc.rs +++ b/coins/monero/src/rpc.rs @@ -17,9 +17,9 @@ use crate::{ }; #[derive(Deserialize, Debug)] -pub struct EmptyResponse {} +struct EmptyResponse {} #[derive(Deserialize, Debug)] -pub struct JsonRpcResponse { +struct JsonRpcResponse { result: T, } @@ -205,6 +205,7 @@ impl Rpc { txs.iter().cloned().collect::>() } + // TODO: Remove with https://github.com/serai-dex/serai/issues/25 pub async fn get_transactions_possible( &self, hashes: &[[u8; 32]], @@ -297,7 +298,7 @@ impl Rpc { ) -> Result, RpcError> { #[allow(dead_code)] #[derive(Deserialize, Debug)] - pub struct Distribution { + struct Distribution { distribution: Vec, } @@ -332,7 +333,7 @@ impl Rpc { height: usize, ) -> Result>, RpcError> { #[derive(Deserialize, Debug)] - pub struct Out { + struct Out { key: String, mask: String, txid: String, diff --git a/coins/monero/src/serialize.rs b/coins/monero/src/serialize.rs index 624289fa..1d2a1303 100644 --- a/coins/monero/src/serialize.rs +++ b/coins/monero/src/serialize.rs @@ -5,17 +5,17 @@ use curve25519_dalek::{ edwards::{EdwardsPoint, CompressedEdwardsY}, }; -pub const VARINT_CONTINUATION_MASK: u8 = 0b1000_0000; +const VARINT_CONTINUATION_MASK: u8 = 0b1000_0000; -pub fn varint_len(varint: usize) -> usize { +fn varint_len(varint: usize) -> usize { ((usize::try_from(usize::BITS - varint.leading_zeros()).unwrap().saturating_sub(1)) / 7) + 1 } -pub fn write_byte(byte: &u8, w: &mut W) -> io::Result<()> { +pub(crate) fn write_byte(byte: &u8, w: &mut W) -> io::Result<()> { w.write_all(&[*byte]) } -pub fn write_varint(varint: &u64, w: &mut W) -> io::Result<()> { +pub(crate) fn write_varint(varint: &u64, w: &mut W) -> io::Result<()> { let mut varint = *varint; while { let mut b = u8::try_from(varint & u64::from(!VARINT_CONTINUATION_MASK)).unwrap(); @@ -29,15 +29,15 @@ pub fn write_varint(varint: &u64, w: &mut W) -> io::Result<()> { Ok(()) } -pub fn write_scalar(scalar: &Scalar, w: &mut W) -> io::Result<()> { +pub(crate) fn write_scalar(scalar: &Scalar, w: &mut W) -> io::Result<()> { w.write_all(&scalar.to_bytes()) } -pub fn write_point(point: &EdwardsPoint, w: &mut W) -> io::Result<()> { +pub(crate) fn write_point(point: &EdwardsPoint, w: &mut W) -> io::Result<()> { w.write_all(&point.compress().to_bytes()) } -pub fn write_raw_vec io::Result<()>>( +pub(crate) fn write_raw_vec io::Result<()>>( f: F, values: &[T], w: &mut W, @@ -48,7 +48,7 @@ pub fn write_raw_vec io::Result<()>>( Ok(()) } -pub fn write_vec io::Result<()>>( +pub(crate) fn write_vec io::Result<()>>( f: F, values: &[T], w: &mut W, @@ -57,21 +57,21 @@ pub fn write_vec io::Result<()>>( write_raw_vec(f, values, w) } -pub fn read_bytes(r: &mut R) -> io::Result<[u8; N]> { +pub(crate) fn read_bytes(r: &mut R) -> io::Result<[u8; N]> { let mut res = [0; N]; r.read_exact(&mut res)?; Ok(res) } -pub fn read_byte(r: &mut R) -> io::Result { +pub(crate) fn read_byte(r: &mut R) -> io::Result { Ok(read_bytes::<_, 1>(r)?[0]) } -pub fn read_u64(r: &mut R) -> io::Result { +pub(crate) fn read_u64(r: &mut R) -> io::Result { read_bytes(r).map(u64::from_le_bytes) } -pub fn read_varint(r: &mut R) -> io::Result { +pub(crate) fn read_varint(r: &mut R) -> io::Result { let mut bits = 0; let mut res = 0; while { @@ -91,12 +91,12 @@ pub fn read_varint(r: &mut R) -> io::Result { } // TODO: https://github.com/serai-dex/serai/issues/25 -pub fn read_scalar(r: &mut R) -> io::Result { +pub(crate) fn read_scalar(r: &mut R) -> io::Result { Scalar::from_canonical_bytes(read_bytes(r)?) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "unreduced scalar")) } -pub fn read_point(r: &mut R) -> io::Result { +pub(crate) fn read_point(r: &mut R) -> io::Result { let bytes = read_bytes(r)?; CompressedEdwardsY(bytes) .decompress() @@ -105,7 +105,7 @@ pub fn read_point(r: &mut R) -> io::Result { .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "invalid point")) } -pub fn read_raw_vec io::Result>( +pub(crate) fn read_raw_vec io::Result>( f: F, len: usize, r: &mut R, @@ -117,7 +117,7 @@ pub fn read_raw_vec io::Result>( Ok(res) } -pub fn read_vec io::Result>( +pub(crate) fn read_vec io::Result>( f: F, r: &mut R, ) -> io::Result> { diff --git a/coins/monero/src/wallet/decoys.rs b/coins/monero/src/wallet/decoys.rs index fba66aa0..72388d16 100644 --- a/coins/monero/src/wallet/decoys.rs +++ b/coins/monero/src/wallet/decoys.rs @@ -127,7 +127,7 @@ impl Decoys { self.offsets.len() } - pub(crate) async fn select( + pub async fn select( rng: &mut R, rpc: &Rpc, ring_len: usize,