From 8b0f0a37130bb57cedebad24c316fe6169f2627e Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 29 Sep 2022 01:24:33 -0500 Subject: [PATCH] Publish an alpha version of the Monero crate (#123) * Label the version as an alpha * Add versions to Cargo.tomls * Update to Zeroize 1.5 * Drop patch versions from monero-serai Cargo.toml * Add a repository field * Move generators to OUT_DIR IIRC, I didn't do this originally as it constantly re-generated them. Unfortunately, since cargo is complaining about .generators, we have to. * Remove Timelock::fee_weight Transaction::fee_weight's has a comment, "Assumes Timelock::None since this library won't let you create a TX with a timelock". Accordingly, this is dead code. --- Cargo.lock | 10 ++++----- coins/monero/.gitignore | 1 - coins/monero/Cargo.toml | 21 ++++++++++--------- coins/monero/build.rs | 7 +++---- coins/monero/generators/Cargo.toml | 4 ++-- .../src/ringct/bulletproofs/original.rs | 2 +- coins/monero/src/ringct/bulletproofs/plus.rs | 2 +- coins/monero/src/transaction.rs | 4 ---- coins/monero/src/wallet/mod.rs | 1 + coins/monero/src/wallet/scan.rs | 3 +-- crypto/dalek-ff-group/Cargo.toml | 4 ++-- crypto/ed448/Cargo.toml | 4 ++-- crypto/frost/Cargo.toml | 4 ++-- crypto/frost/src/key_gen.rs | 4 +++- crypto/frost/src/lib.rs | 5 ++++- crypto/frost/src/sign.rs | 5 +++-- crypto/multiexp/Cargo.toml | 4 ++-- 17 files changed, 43 insertions(+), 42 deletions(-) delete mode 100644 coins/monero/.gitignore diff --git a/Cargo.lock b/Cargo.lock index 845ee466..e3161adc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1370,7 +1370,7 @@ dependencies = [ [[package]] name = "dalek-ff-group" -version = "0.1.4" +version = "0.1.5" dependencies = [ "crypto-bigint", "curve25519-dalek 3.2.0", @@ -4496,7 +4496,7 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "minimal-ed448" -version = "0.1.0" +version = "0.1.1" dependencies = [ "crypto-bigint", "dalek-ff-group", @@ -4541,7 +4541,7 @@ dependencies = [ [[package]] name = "modular-frost" -version = "0.2.1" +version = "0.2.2" dependencies = [ "dalek-ff-group", "dleq", @@ -4585,7 +4585,7 @@ dependencies = [ [[package]] name = "monero-serai" -version = "0.1.0" +version = "0.1.0-alpha" dependencies = [ "base58-monero", "blake2", @@ -4652,7 +4652,7 @@ dependencies = [ [[package]] name = "multiexp" -version = "0.2.0" +version = "0.2.1" dependencies = [ "dalek-ff-group", "ff", diff --git a/coins/monero/.gitignore b/coins/monero/.gitignore deleted file mode 100644 index 15320da4..00000000 --- a/coins/monero/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.generators diff --git a/coins/monero/Cargo.toml b/coins/monero/Cargo.toml index 28b61185..b8b3c369 100644 --- a/coins/monero/Cargo.toml +++ b/coins/monero/Cargo.toml @@ -1,8 +1,9 @@ [package] name = "monero-serai" -version = "0.1.0" +version = "0.1.0-alpha" description = "A modern Monero transaction library" license = "MIT" +repository = "https://github.com/serai-dex/serai" authors = ["Luke Parker "] edition = "2021" @@ -19,7 +20,7 @@ rand_chacha = { version = "0.3", optional = true } rand = "0.8" rand_distr = "0.4" -zeroize = { version = "1.3", features = ["zeroize_derive"] } +zeroize = { version = "1.5", features = ["zeroize_derive"] } subtle = "2.4" sha3 = "0.10" @@ -28,14 +29,14 @@ blake2 = { version = "0.10", optional = true } curve25519-dalek = { version = "3", features = ["std"] } group = { version = "0.12" } -dalek-ff-group = { path = "../../crypto/dalek-ff-group" } -multiexp = { path = "../../crypto/multiexp", features = ["batch"] } +dalek-ff-group = { path = "../../crypto/dalek-ff-group", version = "0.1" } +multiexp = { path = "../../crypto/multiexp", version = "0.2", features = ["batch"] } -transcript = { package = "flexible-transcript", path = "../../crypto/transcript", features = ["recommended"], optional = true } -frost = { package = "modular-frost", path = "../../crypto/frost", features = ["ed25519"], optional = true } -dleq = { path = "../../crypto/dleq", features = ["serialize"], optional = true } +transcript = { package = "flexible-transcript", path = "../../crypto/transcript", version = "0.1", features = ["recommended"], optional = true } +frost = { package = "modular-frost", path = "../../crypto/frost", version = "0.2", features = ["ed25519"], optional = true } +dleq = { path = "../../crypto/dleq", version = "0.1", features = ["serialize"], optional = true } -monero-generators = { path = "generators" } +monero-generators = { path = "generators", version = "0.1" } hex = "0.4" serde = { version = "1.0", features = ["derive"] } @@ -50,8 +51,8 @@ reqwest = { version = "0.11", features = ["json"] } multisig = ["rand_chacha", "blake2", "transcript", "frost", "dleq"] [build-dependencies] -dalek-ff-group = { path = "../../crypto/dalek-ff-group" } -monero-generators = { path = "generators" } +dalek-ff-group = { path = "../../crypto/dalek-ff-group", version = "0.1" } +monero-generators = { path = "generators", version = "0.1" } [dev-dependencies] tokio = { version = "1", features = ["full"] } diff --git a/coins/monero/build.rs b/coins/monero/build.rs index 265b91ea..00f66f13 100644 --- a/coins/monero/build.rs +++ b/coins/monero/build.rs @@ -1,7 +1,8 @@ use std::{ io::Write, + env, path::Path, - fs::{File, DirBuilder, remove_file}, + fs::{File, remove_file}, }; use dalek_ff_group::EdwardsPoint; @@ -33,8 +34,7 @@ fn generators(prefix: &'static str, path: &str) { let mut H_str = "".to_string(); serialize(&mut H_str, &generators.H); - DirBuilder::new().recursive(true).create(".generators").unwrap(); - let path = Path::new(".generators").join(path); + let path = Path::new(&env::var("OUT_DIR").unwrap()).join(path); let _ = remove_file(&path); File::create(&path) .unwrap() @@ -60,7 +60,6 @@ fn generators(prefix: &'static str, path: &str) { } fn main() { - // For some reason, filtering off .generators does not work. This prevents re-building overall println!("cargo:rerun-if-changed=build.rs"); generators("bulletproof", "generators.rs"); diff --git a/coins/monero/generators/Cargo.toml b/coins/monero/generators/Cargo.toml index 3cb6f10e..64cd81ff 100644 --- a/coins/monero/generators/Cargo.toml +++ b/coins/monero/generators/Cargo.toml @@ -18,5 +18,5 @@ tiny-keccak = { version = "2", features = ["keccak"] } curve25519-dalek = { version = "3", features = ["std"] } -group = { version = "0.12" } -dalek-ff-group = { path = "../../../crypto/dalek-ff-group" } +group = "0.12" +dalek-ff-group = { path = "../../../crypto/dalek-ff-group", version = "0.1.4" } diff --git a/coins/monero/src/ringct/bulletproofs/original.rs b/coins/monero/src/ringct/bulletproofs/original.rs index 57f78849..f7e40cc1 100644 --- a/coins/monero/src/ringct/bulletproofs/original.rs +++ b/coins/monero/src/ringct/bulletproofs/original.rs @@ -12,7 +12,7 @@ use multiexp::BatchVerifier; use crate::{Commitment, ringct::bulletproofs::core::*}; -include!("../../../.generators/generators.rs"); +include!(concat!(env!("OUT_DIR"), "/generators.rs")); lazy_static! { static ref ONE_N: ScalarVector = ScalarVector(vec![Scalar::one(); N]); diff --git a/coins/monero/src/ringct/bulletproofs/plus.rs b/coins/monero/src/ringct/bulletproofs/plus.rs index e44095af..bba66a3f 100644 --- a/coins/monero/src/ringct/bulletproofs/plus.rs +++ b/coins/monero/src/ringct/bulletproofs/plus.rs @@ -15,7 +15,7 @@ use crate::{ ringct::{hash_to_point::raw_hash_to_point, bulletproofs::core::*}, }; -include!("../../../.generators/generators_plus.rs"); +include!(concat!(env!("OUT_DIR"), "/generators_plus.rs")); lazy_static! { static ref TRANSCRIPT: [u8; 32] = diff --git a/coins/monero/src/transaction.rs b/coins/monero/src/transaction.rs index bf2c359b..6314a97c 100644 --- a/coins/monero/src/transaction.rs +++ b/coins/monero/src/transaction.rs @@ -119,10 +119,6 @@ impl Timelock { } } - pub(crate) fn fee_weight() -> usize { - 8 - } - fn serialize(&self, w: &mut W) -> std::io::Result<()> { write_varint( &match self { diff --git a/coins/monero/src/wallet/mod.rs b/coins/monero/src/wallet/mod.rs index f5cb22ac..8aa9f11a 100644 --- a/coins/monero/src/wallet/mod.rs +++ b/coins/monero/src/wallet/mod.rs @@ -167,6 +167,7 @@ impl Scanner { /// When a new scanner is created, ALL saved output keys must be passed in to be secure. /// If None is passed, a modified shared key derivation is used which is immune to the burning /// bug (specifically the Guaranteed feature from Featured Addresses). + // TODO: Should this take in a DB access handle to ensure output keys are saved? pub fn from_view( pair: ViewPair, network: Network, diff --git a/coins/monero/src/wallet/scan.rs b/coins/monero/src/wallet/scan.rs index cbcaf6da..bd790693 100644 --- a/coins/monero/src/wallet/scan.rs +++ b/coins/monero/src/wallet/scan.rs @@ -196,8 +196,7 @@ impl SpendableOutput { pub struct Timelocked(Timelock, Vec); impl Drop for Timelocked { fn drop(&mut self) { - self.0.zeroize(); - self.1.zeroize(); + self.zeroize(); } } impl ZeroizeOnDrop for Timelocked {} diff --git a/crypto/dalek-ff-group/Cargo.toml b/crypto/dalek-ff-group/Cargo.toml index 7bf4495f..7ed9c828 100644 --- a/crypto/dalek-ff-group/Cargo.toml +++ b/crypto/dalek-ff-group/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dalek-ff-group" -version = "0.1.4" +version = "0.1.5" description = "ff/group bindings around curve25519-dalek" license = "MIT" repository = "https://github.com/serai-dex/serai" @@ -15,7 +15,7 @@ all-features = true rand_core = "0.6" digest = "0.10" -zeroize = { version = "1.3", features = ["zeroize_derive"] } +zeroize = { version = "1.5", features = ["zeroize_derive"] } subtle = "2.4" ff = "0.12" diff --git a/crypto/ed448/Cargo.toml b/crypto/ed448/Cargo.toml index 9468a081..207e252c 100644 --- a/crypto/ed448/Cargo.toml +++ b/crypto/ed448/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "minimal-ed448" -version = "0.1.0" +version = "0.1.1" description = "Unaudited, inefficient implementation of Ed448 in Rust" license = "MIT" repository = "https://github.com/serai-dex/serai" @@ -17,7 +17,7 @@ lazy_static = "1" rand_core = "0.6" digest = "0.10" -zeroize = { version = "1.3", features = ["zeroize_derive"] } +zeroize = { version = "1.5", features = ["zeroize_derive"] } subtle = "2.4" ff = "0.12" diff --git a/crypto/frost/Cargo.toml b/crypto/frost/Cargo.toml index ed7a12ea..6b11f20d 100644 --- a/crypto/frost/Cargo.toml +++ b/crypto/frost/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "modular-frost" -version = "0.2.1" +version = "0.2.2" description = "Modular implementation of FROST over ff/group" license = "MIT" repository = "https://github.com/serai-dex/serai" @@ -16,7 +16,7 @@ thiserror = "1" rand_core = "0.6" -zeroize = { version = "1.3", features = ["zeroize_derive"] } +zeroize = { version = "1.5", features = ["zeroize_derive"] } hex = "0.4" diff --git a/crypto/frost/src/key_gen.rs b/crypto/frost/src/key_gen.rs index a2789ab7..62e84c3b 100644 --- a/crypto/frost/src/key_gen.rs +++ b/crypto/frost/src/key_gen.rs @@ -6,7 +6,7 @@ use std::{ use rand_core::{RngCore, CryptoRng}; -use zeroize::Zeroize; +use zeroize::{Zeroize, ZeroizeOnDrop}; use group::{ ff::{Field, PrimeField}, @@ -272,6 +272,7 @@ impl Drop for SecretShareMachine { self.zeroize() } } +impl ZeroizeOnDrop for SecretShareMachine {} #[derive(Zeroize)] pub struct KeyMachine { @@ -287,6 +288,7 @@ impl Drop for KeyMachine { self.zeroize() } } +impl ZeroizeOnDrop for KeyMachine {} impl KeyGenMachine { /// Creates a new machine to generate a key for the specified curve in the specified multisig diff --git a/crypto/frost/src/lib.rs b/crypto/frost/src/lib.rs index cf1d0edf..c86f9b4f 100644 --- a/crypto/frost/src/lib.rs +++ b/crypto/frost/src/lib.rs @@ -3,7 +3,7 @@ use std::{io::Read, sync::Arc, collections::HashMap}; use thiserror::Error; -use zeroize::Zeroize; +use zeroize::{Zeroize, ZeroizeOnDrop}; use group::{ ff::{Field, PrimeField}, @@ -160,6 +160,7 @@ impl Drop for FrostCore { self.zeroize() } } +impl ZeroizeOnDrop for FrostCore {} impl Debug for FrostCore { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -287,6 +288,7 @@ impl Drop for FrostKeys { self.zeroize() } } +impl ZeroizeOnDrop for FrostKeys {} // View of keys passable to algorithm implementations #[derive(Clone, Zeroize)] @@ -304,6 +306,7 @@ impl Drop for FrostView { self.zeroize() } } +impl ZeroizeOnDrop for FrostView {} impl FrostKeys { pub fn new(core: FrostCore) -> FrostKeys { diff --git a/crypto/frost/src/sign.rs b/crypto/frost/src/sign.rs index 47c3254c..7c4f4142 100644 --- a/crypto/frost/src/sign.rs +++ b/crypto/frost/src/sign.rs @@ -6,7 +6,7 @@ use std::{ use rand_core::{RngCore, CryptoRng}; -use zeroize::Zeroize; +use zeroize::{Zeroize, ZeroizeOnDrop}; use transcript::Transcript; @@ -55,7 +55,7 @@ impl> Params { Err(FrostError::InvalidParticipantIndex(included[included.len() - 1], params.n))?; } // Same signer included multiple times - for i in 0 .. included.len() - 1 { + for i in 0 .. (included.len() - 1) { if included[i] == included[i + 1] { Err(FrostError::DuplicatedIndex(included[i]))?; } @@ -95,6 +95,7 @@ impl Drop for PreprocessPackage { self.zeroize() } } +impl ZeroizeOnDrop for PreprocessPackage {} // This library unifies the preprocessing step with signing due to security concerns and to provide // a simpler UX diff --git a/crypto/multiexp/Cargo.toml b/crypto/multiexp/Cargo.toml index d1986cec..bf681b30 100644 --- a/crypto/multiexp/Cargo.toml +++ b/crypto/multiexp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "multiexp" -version = "0.2.0" +version = "0.2.1" description = "Multiexponentation algorithms for ff/group" license = "MIT" repository = "https://github.com/serai-dex/serai" @@ -12,7 +12,7 @@ edition = "2021" all-features = true [dependencies] -zeroize = { version = "1.3", features = ["zeroize_derive"] } +zeroize = { version = "1.5", features = ["zeroize_derive"] } ff = "0.12" group = "0.12"