From 6100c3ca906d2c14410d41a9bcc23b79b0504a72 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 16 Nov 2025 19:04:57 -0500 Subject: [PATCH] Restore `patches/dalek-ff-group` Ensures `crypto/dalek-ff-group` is pure. --- Cargo.lock | 51 ++++++++++++++++++------------- Cargo.toml | 6 ++-- crypto/dalek-ff-group/Cargo.toml | 1 - crypto/dalek-ff-group/src/lib.rs | 18 ----------- patches/dalek-ff-group/Cargo.toml | 28 +++++++++++++++++ patches/dalek-ff-group/LICENSE | 21 +++++++++++++ patches/dalek-ff-group/README.md | 4 +++ patches/dalek-ff-group/src/lib.rs | 36 ++++++++++++++++++++++ 8 files changed, 122 insertions(+), 43 deletions(-) create mode 100644 patches/dalek-ff-group/Cargo.toml create mode 100644 patches/dalek-ff-group/LICENSE create mode 100644 patches/dalek-ff-group/README.md create mode 100644 patches/dalek-ff-group/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 851dc486..e68352ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1605,7 +1605,7 @@ name = "ciphersuite" version = "0.4.99" dependencies = [ "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "std-shims 0.1.5", "zeroize", ] @@ -2138,7 +2138,6 @@ version = "0.5.0" dependencies = [ "blake2 0.11.0-rc.3", "ciphersuite 0.4.2", - "crypto-bigint 0.5.5", "curve25519-dalek", "ff-group-tests", "hex", @@ -2149,6 +2148,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "dalek-ff-group" +version = "0.5.99" +dependencies = [ + "crypto-bigint 0.5.5", + "crypto-bigint 0.6.1", + "dalek-ff-group 0.5.0", + "prime-field", +] + [[package]] name = "darling" version = "0.20.99" @@ -2433,7 +2442,7 @@ dependencies = [ "blake2 0.11.0-rc.3", "ciphersuite 0.4.2", "ciphersuite-kp256", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg", "dkg-recovery", "ec-divisors", @@ -2458,7 +2467,7 @@ name = "dkg-musig" version = "0.6.0" dependencies = [ "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg", "dkg-recovery", "multiexp", @@ -2530,7 +2539,7 @@ name = "ec-divisors" version = "0.1.0" source = "git+https://github.com/monero-oxide/monero-oxide?rev=dc1b3dbe436aae61ec363505052d4715d38ce1df#dc1b3dbe436aae61ec363505052d4715d38ce1df" dependencies = [ - "dalek-ff-group", + "dalek-ff-group 0.5.99", "ff", "group", "rand_core 0.6.4", @@ -5052,7 +5061,7 @@ version = "0.11.0" dependencies = [ "ciphersuite 0.4.2", "ciphersuite-kp256", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg", "dkg-dealer", "dkg-recovery", @@ -5146,7 +5155,7 @@ version = "0.1.0" source = "git+https://github.com/monero-oxide/monero-oxide?rev=030c60974f0f0306849c1795bca854a3bbb757b4#030c60974f0f0306849c1795bca854a3bbb757b4" dependencies = [ "curve25519-dalek", - "dalek-ff-group", + "dalek-ff-group 0.5.99", "flexible-transcript", "group", "modular-frost", @@ -5189,7 +5198,7 @@ source = "git+https://github.com/monero-oxide/monero-oxide?rev=030c60974f0f03068 dependencies = [ "crypto-bigint 0.5.5", "curve25519-dalek", - "dalek-ff-group", + "dalek-ff-group 0.5.99", "group", "monero-io", "sha3 0.10.8", @@ -5352,7 +5361,7 @@ dependencies = [ name = "multiexp" version = "0.4.2" dependencies = [ - "dalek-ff-group", + "dalek-ff-group 0.5.0", "ff", "group", "k256", @@ -8098,7 +8107,7 @@ name = "schnorr-signatures" version = "0.5.2" dependencies = [ "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "digest 0.11.0-rc.4", "flexible-transcript", "hex", @@ -8316,7 +8325,7 @@ version = "0.1.0" dependencies = [ "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "monero-address", "serai-primitives", ] @@ -8365,7 +8374,7 @@ dependencies = [ "blake2 0.11.0-rc.3", "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg-musig", "env_logger", "frost-schnorrkel", @@ -8452,7 +8461,7 @@ dependencies = [ "blake2 0.11.0-rc.3", "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg", "log", "rand_core 0.6.4", @@ -8690,7 +8699,7 @@ version = "0.1.0" dependencies = [ "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "env_logger", "flexible-transcript", "hex", @@ -8711,7 +8720,7 @@ name = "serai-message-queue-tests" version = "0.1.0" dependencies = [ "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dockertest", "hex", "rand_core 0.6.4", @@ -8728,7 +8737,7 @@ version = "0.1.0" dependencies = [ "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg-evrf", "log", "modular-frost", @@ -8758,7 +8767,7 @@ version = "0.1.0" dependencies = [ "bitcoin-serai", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg", "dkg-dealer", "dkg-evrf", @@ -8790,7 +8799,7 @@ dependencies = [ "ciphersuite-kp256", "clap", "curve25519-dalek", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "embedwards25519", "frame-benchmarking", "futures-util", @@ -8842,7 +8851,7 @@ name = "serai-orchestrator" version = "0.0.1" dependencies = [ "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "embedwards25519", "flexible-transcript", "hex", @@ -8862,7 +8871,7 @@ dependencies = [ "bitvec", "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "dkg-musig", "embedwards25519", "parity-scale-codec", @@ -10786,7 +10795,7 @@ dependencies = [ "blake2 0.11.0-rc.3", "borsh", "ciphersuite 0.4.2", - "dalek-ff-group", + "dalek-ff-group 0.5.0", "flexible-transcript", "futures-channel", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index d4c69f40..7fc6e583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,19 +165,19 @@ panic = "unwind" overflow-checks = true [patch.crates-io] -# Point to empty crates for unused crates in our tree +# Point to empty crates for crates unused within in our tree ark-ff-3 = { package = "ark-ff", path = "patches/ethereum/ark-ff-0.3" } ark-ff-4 = { package = "ark-ff", path = "patches/ethereum/ark-ff-0.4" } c-kzg = { path = "patches/ethereum/c-kzg" } secp256k1-30 = { package = "secp256k1", path = "patches/ethereum/secp256k1-30" } -# Dependencies from monero-oxide which originate from within our own tree +# Dependencies from monero-oxide which originate from within our own tree, potentially shimmed to account for deviations since publishing std-shims = { path = "patches/std-shims" } simple-request = { path = "patches/simple-request" } multiexp = { path = "crypto/multiexp" } flexible-transcript = { path = "crypto/transcript" } ciphersuite = { path = "patches/ciphersuite" } -dalek-ff-group = { path = "crypto/dalek-ff-group" } +dalek-ff-group = { path = "patches/dalek-ff-group" } minimal-ed448 = { path = "crypto/ed448" } modular-frost = { path = "crypto/frost" } diff --git a/crypto/dalek-ff-group/Cargo.toml b/crypto/dalek-ff-group/Cargo.toml index 223edd85..ea2f323b 100644 --- a/crypto/dalek-ff-group/Cargo.toml +++ b/crypto/dalek-ff-group/Cargo.toml @@ -25,7 +25,6 @@ rand_core = { version = "0.6", default-features = false } sha2 = { version = "0.11.0-rc.2", default-features = false, features = ["zeroize"] } blake2 = { version = "0.11.0-rc.2", default-features = false, features = ["zeroize"] } -crypto-bigint = { version = "0.5", default-features = false } prime-field = { path = "../prime-field", default-features = false } ciphersuite = { version = "0.4.2", path = "../ciphersuite", default-features = false } diff --git a/crypto/dalek-ff-group/src/lib.rs b/crypto/dalek-ff-group/src/lib.rs index 73b44d09..2080e19d 100644 --- a/crypto/dalek-ff-group/src/lib.rs +++ b/crypto/dalek-ff-group/src/lib.rs @@ -286,21 +286,3 @@ prime_field::odd_prime_field_with_specific_repr!( false, crate::ThirtyTwoArray ); - -impl FieldElement { - /// This method is hidden as it's not part of our API commitment and has no guarantees made for - /// it. It MAY panic for an undefined class of inputs. - // TODO: `monero-oxide` requires this. PR `monero-oxide` to not require this. - #[doc(hidden)] - pub const fn from_u256(value: &crypto_bigint::U256) -> Self { - let mut bytes = [0; 32]; - - let mut i = 0; - while i < 256 { - bytes[i / 32] |= (value.bit_vartime(i) as u8) << (i % 8); - i += 1; - } - - FieldElement::from_bytes(&bytes).unwrap() - } -} diff --git a/patches/dalek-ff-group/Cargo.toml b/patches/dalek-ff-group/Cargo.toml new file mode 100644 index 00000000..5286516c --- /dev/null +++ b/patches/dalek-ff-group/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "dalek-ff-group" +version = "0.5.99" +description = "ff/group bindings around curve25519-dalek" +license = "MIT" +repository = "https://github.com/serai-dex/serai/tree/develop/crypto/dalek-ff-group" +authors = ["Luke Parker "] +keywords = ["curve25519", "ed25519", "ristretto", "dalek", "group"] +edition = "2021" +rust-version = "1.85" + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] + +[workspace] + +[dependencies] +dalek-ff-group = { path = "../../crypto/dalek-ff-group", default-features = false } + +crypto-bigint-05 = { package = "crypto-bigint", version = "0.5", default-features = false, features = ["zeroize"] } +crypto-bigint = { version = "0.6", default-features = false, features = ["zeroize"] } +prime-field = { path = "../../crypto/prime-field", default-features = false } + +[features] +alloc = ["dalek-ff-group/alloc", "prime-field/alloc"] +std = ["alloc", "dalek-ff-group/std", "prime-field/std"] +default = ["std"] diff --git a/patches/dalek-ff-group/LICENSE b/patches/dalek-ff-group/LICENSE new file mode 100644 index 00000000..32ff304a --- /dev/null +++ b/patches/dalek-ff-group/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022-2025 Luke Parker + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/patches/dalek-ff-group/README.md b/patches/dalek-ff-group/README.md new file mode 100644 index 00000000..5a25d05b --- /dev/null +++ b/patches/dalek-ff-group/README.md @@ -0,0 +1,4 @@ +# Dalek FF/Group + +Patch for the `crates.io` `dalek-ff-group` to use the in-tree `dalek-ff-group`, +resolving relevant breaking changes made since. diff --git a/patches/dalek-ff-group/src/lib.rs b/patches/dalek-ff-group/src/lib.rs new file mode 100644 index 00000000..2531e268 --- /dev/null +++ b/patches/dalek-ff-group/src/lib.rs @@ -0,0 +1,36 @@ +#![allow(deprecated)] +#![cfg_attr(docsrs, feature(doc_cfg))] +#![no_std] // Prevents writing new code, in what should be a simple wrapper, which requires std +#![doc = include_str!("../README.md")] +#![allow(clippy::redundant_closure_call)] + +pub use dalek_ff_group::{Scalar, EdwardsPoint, RistrettoPoint, Ed25519, Ristretto}; + +type ThirtyTwoArray = [u8; 32]; +prime_field::odd_prime_field_with_specific_repr!( + FieldElement, + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed", + "02", + false, + crate::ThirtyTwoArray +); + +impl FieldElement { + /// Create a FieldElement from a `crypto_bigint::U256`. + /// + /// This will reduce the `U256` by the modulus, into a member of the field. + #[deprecated] + pub const fn from_u256(u256: &crypto_bigint_05::U256) -> Self { + const MODULUS: crypto_bigint::U256 = crypto_bigint::U256::from_be_hex( + "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed", + ); + let mut u256 = crypto_bigint::U256::from_words(*u256.as_words()); + loop { + let result = FieldElement::from_bytes(&u256.to_le_bytes()); + if let Some(result) = result { + return result; + } + u256 = u256.wrapping_sub(&MODULUS); + } + } +}