Skip to content

Commit 49557e8

Browse files
authored
chore: revert to nightly 2024-11-01 (#31)
* chore: revert to nightly 2024-11-01 * chore: revert generics because nightly 2024-11-01 does not like
1 parent b50ca05 commit 49557e8

File tree

7 files changed

+60
-65
lines changed

7 files changed

+60
-65
lines changed

crates/p2p/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
//! Strata P2P implementation.
2-
#![expect(incomplete_features)] // the generic_const_exprs feature is incomplete
3-
#![feature(generic_const_exprs)] // but necessary for using const generic bounds in
42
53
pub mod commands;
64
pub mod events;

crates/types/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![expect(incomplete_features)] // the generic_const_exprs feature is incomplete
33
#![feature(generic_const_exprs)] // but necessary for using const generic bounds in
44
#![feature(strict_overflow_ops)] // necessary for const wots computations
5+
#![feature(const_strict_overflow_ops)] // necessary for const wots computations
56

67
mod deposit_data;
78
mod operator;

crates/types/src/stake_data.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bitcoin::{
66
};
77
use serde::{Deserialize, Serialize};
88

9-
use crate::{wots::wots_total_digits, Wots256PublicKey, WOTS_SINGLE};
9+
use crate::{Wots256PublicKey, WOTS_SINGLE};
1010

1111
/// Size of a [`sha256::Hash`] in bytes.
1212
pub const HASH_SIZE: usize = 32;
@@ -18,7 +18,7 @@ pub const TXID_SIZE: usize = 32;
1818
pub const VOUT_SIZE: usize = 4;
1919

2020
/// Size of Wots256PublicKey in arrays (2 * 32 + 4 = 68)
21-
const WOTS256_ARRAYS: usize = wots_total_digits(32);
21+
const WOTS256_ARRAYS: usize = 68;
2222

2323
/// Stake data for a single stake transaction.
2424
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Deserialize, Serialize)]
@@ -54,11 +54,11 @@ impl StakeData {
5454
///
5555
/// The byte array is structured as follows:
5656
///
57-
/// - 5,120 (20 * 256) bytes for the withdrawal fulfillment public key.
57+
/// - 1,360 (20 * 68) bytes for the withdrawal fulfillment public key.
5858
/// - 32 bytes for the hash.
5959
/// - 36 (32 + 4) bytes for the operator funds
6060
///
61-
/// Total is 5,188 bytes.
61+
/// Total is 1,428 bytes.
6262
///
6363
/// # Implementation Details
6464
///
@@ -67,18 +67,16 @@ impl StakeData {
6767
pub fn to_flattened_bytes(
6868
&self,
6969
) -> [u8; WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE + TXID_SIZE + VOUT_SIZE] {
70-
let mut bytes =
71-
[0u8; WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE + TXID_SIZE + VOUT_SIZE];
72-
bytes[0..WOTS_SINGLE * Wots256PublicKey::SIZE]
70+
let mut bytes = [0u8; WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE + TXID_SIZE + VOUT_SIZE];
71+
bytes[0..WOTS_SINGLE * WOTS256_ARRAYS]
7372
.copy_from_slice(&self.withdrawal_fulfillment_pk.to_flattened_bytes());
74-
bytes[WOTS_SINGLE * Wots256PublicKey::SIZE
75-
..WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE]
73+
bytes[WOTS_SINGLE * WOTS256_ARRAYS..WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE]
7674
.copy_from_slice(&self.hash.to_byte_array());
77-
bytes[WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE
78-
..WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE + TXID_SIZE]
75+
bytes[WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE
76+
..WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE + TXID_SIZE]
7977
.copy_from_slice(&self.operator_funds.txid.to_byte_array());
80-
bytes[WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE + TXID_SIZE
81-
..WOTS_SINGLE * Wots256PublicKey::SIZE + HASH_SIZE + TXID_SIZE + VOUT_SIZE]
78+
bytes[WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE + TXID_SIZE
79+
..WOTS_SINGLE * WOTS256_ARRAYS + HASH_SIZE + TXID_SIZE + VOUT_SIZE]
8280
.copy_from_slice(&self.operator_funds.vout.to_le_bytes());
8381
bytes
8482
}

crates/types/src/wots.rs

+43-44
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ pub const WOTS_DIGIT_WIDTH: usize = 4;
2222
pub const WOTS_DIGITS_PER_BYTE: usize = 8 / WOTS_DIGIT_WIDTH;
2323

2424
/// The maximum number a WOTS digit can hold.
25+
#[allow(dead_code)]
2526
pub const WOTS_MAX_DIGIT: usize = (2 << WOTS_DIGIT_WIDTH) - 1;
2627

2728
/// The number of WOTS digits required to represent a message for a given message length.
29+
#[allow(dead_code)]
2830
pub const fn wots_msg_digits(msg_len_bytes: usize) -> usize {
2931
WOTS_DIGITS_PER_BYTE * msg_len_bytes
3032
}
@@ -33,6 +35,7 @@ pub const fn wots_msg_digits(msg_len_bytes: usize) -> usize {
3335
///
3436
/// The checksum of a WOTS commitment is the sum of the digit values themselves which is then
3537
/// encoded as a base256 integer. That integer is then signed using the same WOTS scheme.
38+
#[allow(dead_code)]
3639
pub const fn wots_checksum_digits(msg_len_bytes: usize) -> usize {
3740
let max_checksum = wots_msg_digits(msg_len_bytes) * WOTS_MAX_DIGIT;
3841

@@ -52,47 +55,46 @@ pub const fn wots_checksum_digits(msg_len_bytes: usize) -> usize {
5255
}
5356

5457
/// The total number of WOTS digit keys
58+
#[allow(dead_code)]
5559
pub const fn wots_total_digits(msg_len_bytes: usize) -> usize {
5660
wots_msg_digits(msg_len_bytes) + wots_checksum_digits(msg_len_bytes)
5761
}
5862

5963
/// A variable-length Winternitz One-Time Signature (WOTS) public key.
6064
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
6165
#[cfg_attr(feature = "proptest", derive(Arbitrary))]
62-
pub struct WotsPublicKey<const MSG_LEN_BYTES: usize>(
63-
pub [[u8; WOTS_SINGLE]; wots_total_digits(MSG_LEN_BYTES)],
64-
)
66+
pub struct WotsPublicKey<const MSG_LEN_BYTES: usize>(pub [[u8; WOTS_SINGLE]; MSG_LEN_BYTES])
6567
where
66-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized;
68+
[(); MSG_LEN_BYTES]: Sized;
6769

6870
/// 160-bit Winternitz One-Time Signature (WOTS) public key.
69-
pub type Wots160PublicKey = WotsPublicKey<20>;
71+
pub type Wots160PublicKey = WotsPublicKey<44>;
7072

7173
/// 256-bit Winternitz One-Time Signature (WOTS) public key.
72-
pub type Wots256PublicKey = WotsPublicKey<32>;
74+
pub type Wots256PublicKey = WotsPublicKey<68>;
7375

7476
impl<const MSG_LEN_BYTES: usize> WotsPublicKey<MSG_LEN_BYTES>
7577
where
76-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized,
77-
[(); WOTS_SINGLE * wots_total_digits(MSG_LEN_BYTES)]: Sized,
78+
[(); MSG_LEN_BYTES]: Sized,
79+
[(); WOTS_SINGLE * MSG_LEN_BYTES]: Sized,
7880
{
7981
/// The size of this WOTS public key in bytes.
80-
pub const SIZE: usize = wots_total_digits(MSG_LEN_BYTES);
82+
pub const SIZE: usize = MSG_LEN_BYTES;
8183

8284
/// Creates a new WOTS 160-bit public key from a byte array.
83-
pub fn new(bytes: [[u8; WOTS_SINGLE]; wots_total_digits(MSG_LEN_BYTES)]) -> Self {
85+
pub fn new(bytes: [[u8; WOTS_SINGLE]; MSG_LEN_BYTES]) -> Self {
8486
Self(bytes)
8587
}
8688

8789
/// Converts the public key to a byte array.
88-
pub fn to_bytes(&self) -> [[u8; WOTS_SINGLE]; wots_total_digits(MSG_LEN_BYTES)] {
90+
pub fn to_bytes(&self) -> [[u8; WOTS_SINGLE]; MSG_LEN_BYTES] {
8991
self.0
9092
}
9193

9294
/// Converts the public key to a flattened byte array.
9395
pub fn to_flattened_bytes(&self) -> Vec<u8> {
9496
// Changed return type to Vec<u8>
95-
let mut bytes = Vec::with_capacity(WOTS_SINGLE * wots_total_digits(MSG_LEN_BYTES));
97+
let mut bytes = Vec::with_capacity(WOTS_SINGLE * MSG_LEN_BYTES);
9698
for byte_array in &self.0 {
9799
bytes.extend_from_slice(byte_array);
98100
}
@@ -110,11 +112,11 @@ where
110112
pub fn from_flattened_bytes(bytes: &[u8]) -> Self {
111113
assert_eq!(
112114
bytes.len(),
113-
WOTS_SINGLE * (2 * MSG_LEN_BYTES + 4),
115+
WOTS_SINGLE * MSG_LEN_BYTES,
114116
"Invalid byte array length"
115117
);
116118

117-
let mut key = [[0u8; WOTS_SINGLE]; wots_total_digits(MSG_LEN_BYTES)];
119+
let mut key = [[0u8; WOTS_SINGLE]; MSG_LEN_BYTES];
118120
for (i, byte_array) in key.iter_mut().enumerate() {
119121
byte_array.copy_from_slice(&bytes[i * WOTS_SINGLE..(i + 1) * WOTS_SINGLE]);
120122
}
@@ -124,9 +126,9 @@ where
124126

125127
impl<const MSG_LEN_BYTES: usize> Deref for WotsPublicKey<MSG_LEN_BYTES>
126128
where
127-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized,
129+
[(); MSG_LEN_BYTES]: Sized,
128130
{
129-
type Target = [[u8; WOTS_SINGLE]; wots_total_digits(MSG_LEN_BYTES)];
131+
type Target = [[u8; WOTS_SINGLE]; MSG_LEN_BYTES];
130132

131133
fn deref(&self) -> &Self::Target {
132134
&self.0
@@ -135,7 +137,7 @@ where
135137

136138
impl<const MSG_LEN_BYTES: usize> DerefMut for WotsPublicKey<MSG_LEN_BYTES>
137139
where
138-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized,
140+
[(); MSG_LEN_BYTES]: Sized,
139141
{
140142
fn deref_mut(&mut self) -> &mut Self::Target {
141143
&mut self.0
@@ -145,8 +147,8 @@ where
145147
// Custom Serialization for WotsPublicKey
146148
impl<const MSG_LEN_BYTES: usize> Serialize for WotsPublicKey<MSG_LEN_BYTES>
147149
where
148-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized,
149-
[(); WOTS_SINGLE * wots_total_digits(MSG_LEN_BYTES)]: Sized,
150+
[(); MSG_LEN_BYTES]: Sized,
151+
[(); WOTS_SINGLE * MSG_LEN_BYTES]: Sized,
150152
{
151153
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
152154
where
@@ -167,8 +169,8 @@ where
167169
// Custom Deserialization for WotsPublicKey
168170
impl<'de, const MSG_LEN_BYTES: usize> Deserialize<'de> for WotsPublicKey<MSG_LEN_BYTES>
169171
where
170-
[(); wots_total_digits(MSG_LEN_BYTES)]: Sized,
171-
[(); WOTS_SINGLE * wots_total_digits(MSG_LEN_BYTES)]: Sized,
172+
[(); MSG_LEN_BYTES]: Sized,
173+
[(); WOTS_SINGLE * MSG_LEN_BYTES]: Sized,
172174
{
173175
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
174176
where
@@ -178,26 +180,23 @@ where
178180

179181
impl<'de, const M: usize> Visitor<'de> for WotsPublicKeyVisitor<M>
180182
where
181-
[(); wots_total_digits(M)]: Sized,
183+
[(); M]: Sized,
182184
{
183185
type Value = WotsPublicKey<M>;
184186

185187
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
186-
formatter.write_str(&format!(
187-
"a WotsPublicKey with {} bytes",
188-
WOTS_SINGLE * (2 * M + 4)
189-
))
188+
formatter.write_str(&format!("a WotsPublicKey with {} bytes", WOTS_SINGLE * M))
190189
}
191190

192191
fn visit_bytes<E>(self, bytes: &[u8]) -> Result<Self::Value, E>
193192
where
194193
E: de::Error,
195194
{
196-
if bytes.len() != WOTS_SINGLE * (2 * M + 4) {
195+
if bytes.len() != WOTS_SINGLE * M {
197196
return Err(E::invalid_length(bytes.len(), &self));
198197
}
199198

200-
let mut array = [[0u8; WOTS_SINGLE]; wots_total_digits(M)];
199+
let mut array = [[0u8; WOTS_SINGLE]; M];
201200
for (i, chunk) in bytes.chunks(WOTS_SINGLE).enumerate() {
202201
array[i].copy_from_slice(chunk);
203202
}
@@ -208,7 +207,7 @@ where
208207
where
209208
A: SeqAccess<'de>,
210209
{
211-
let mut array = [[0u8; WOTS_SINGLE]; wots_total_digits(M)];
210+
let mut array = [[0u8; WOTS_SINGLE]; M];
212211
for (i, item) in array.iter_mut().enumerate() {
213212
*item = seq
214213
.next_element()?
@@ -249,8 +248,8 @@ mod tests {
249248

250249
#[test]
251250
fn flattened_bytes_roundtrip() {
252-
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(20)]); // 2 * 20 + 4
253-
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(32)]); // 2 * 32 + 4
251+
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; 44]); // 2 * 20 + 4
252+
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; 68]); // 2 * 32 + 4
254253

255254
// Test flattened bytes roundtrip
256255
let flattened160 = key160.to_flattened_bytes();
@@ -265,8 +264,8 @@ mod tests {
265264

266265
#[test]
267266
fn json_serialization() {
268-
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(20)]); // 2 * 20 + 4
269-
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(32)]); // 2 * 32 + 4
267+
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; 44]); // 2 * 20 + 4
268+
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; 68]); // 2 * 32 + 4
270269

271270
// Test JSON serialization
272271
let serialized160 = serde_json::to_string(&key160).unwrap();
@@ -280,8 +279,8 @@ mod tests {
280279

281280
#[test]
282281
fn bincode_serialization() {
283-
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(20)]); // 2 * 20 + 4
284-
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; wots_total_digits(32)]); // 2 * 32 + 4
282+
let key160 = Wots160PublicKey::new([[1u8; WOTS_SINGLE]; 44]); // 2 * 20 + 4
283+
let key256 = Wots256PublicKey::new([[1u8; WOTS_SINGLE]; 68]); // 2 * 32 + 4
285284

286285
// Test bincode serialization
287286
let serialized160 = bincode::serialize(&key160).unwrap();
@@ -304,7 +303,7 @@ mod tests {
304303

305304
#[test]
306305
#[should_panic]
307-
fn deserialize_too_many_elements20() {
306+
fn deserialize_too_many_elements160() {
308307
// Create JSON string with 45 arrays
309308
let mut json = String::from("[");
310309
for i in 0..45 {
@@ -320,7 +319,7 @@ mod tests {
320319

321320
#[test]
322321
#[should_panic]
323-
fn deserialize_too_many_elements32() {
322+
fn deserialize_too_many_elements256() {
324323
// Create JSON string with 33 arrays
325324
let mut json = String::from("[");
326325
for i in 0..33 {
@@ -336,10 +335,10 @@ mod tests {
336335

337336
#[test]
338337
#[should_panic]
339-
fn deserialize_invalid_array_length20() {
338+
fn deserialize_invalid_array_length44() {
340339
// Create JSON with one array having wrong length (19 instead of 20)
341340
let mut json = String::from("[");
342-
for i in 0..WotsPublicKey::<20>::SIZE {
341+
for i in 0..WotsPublicKey::<44>::SIZE {
343342
if i == 14 {
344343
json.push_str("[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]"); // 19 elements
345344
} else {
@@ -356,16 +355,16 @@ mod tests {
356355

357356
#[test]
358357
#[should_panic]
359-
fn deserialize_invalid_array_length32() {
358+
fn deserialize_invalid_array_length256() {
360359
// Create JSON with one array having wrong length (19 instead of 20)
361360
let mut json = String::from("[");
362-
for i in 0..WotsPublicKey::<32>::SIZE {
361+
for i in 0..WotsPublicKey::<68>::SIZE {
363362
if i == 20 {
364363
json.push_str("[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]"); // 19 elements
365364
} else {
366365
json.push_str("[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]");
367366
}
368-
if i < WotsPublicKey::<32>::SIZE - 1 {
367+
if i < WotsPublicKey::<68>::SIZE - 1 {
369368
json.push(',');
370369
}
371370
}
@@ -447,7 +446,7 @@ mod tests {
447446
let flattened = key.to_flattened_bytes();
448447

449448
// Verify the length is correct
450-
prop_assert_eq!(flattened.len(), WOTS_SINGLE * (2 * 20 + 4));
449+
prop_assert_eq!(flattened.len(), WOTS_SINGLE * 44);
451450

452451
// Verify each segment matches the original arrays
453452
for (i, original_array) in key.0.iter().enumerate() {
@@ -461,7 +460,7 @@ mod tests {
461460
let flattened = key.to_flattened_bytes();
462461

463462
// Verify the length is correct
464-
prop_assert_eq!(flattened.len(), WOTS_SINGLE * (2 * 32 + 4));
463+
prop_assert_eq!(flattened.len(), WOTS_SINGLE * 68);
465464

466465
// Verify each segment matches the original arrays
467466
for (i, original_array) in key.0.iter().enumerate() {

crates/wire/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
//! Protobuf definitions for the Strata P2P protocol.
2-
#![expect(incomplete_features)] // the generic_const_exprs feature is incomplete
3-
#![feature(generic_const_exprs)] // but necessary for using const generic bounds in
42
53
pub mod p2p;

crates/wire/src/p2p/v1/typed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use bitcoin::{
99
use musig2::{PartialSignature, PubNonce};
1010
use prost::{DecodeError, Message};
1111
use strata_p2p_types::{
12-
OperatorPubKey, Scope, SessionId, StakeChainId, StakeData, Wots256PublicKey, WotsPublicKey,
13-
WotsPublicKeys, WOTS_SINGLE,
12+
OperatorPubKey, Scope, SessionId, StakeChainId, StakeData, Wots256PublicKey, WotsPublicKeys,
13+
WOTS_SINGLE,
1414
};
1515

1616
use super::proto::{
@@ -231,7 +231,7 @@ impl StakeChainExchange {
231231
curr.read_exact(bytes)
232232
.map_err(|err| DecodeError::new(err.to_string()))?;
233233
}
234-
let wots = WotsPublicKey::<32>::new(wots);
234+
let wots = Wots256PublicKey::new(wots);
235235

236236
// Parse the sha256 hash.
237237
let mut sha256_hash = [0; 32];

rust-toolchain.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[toolchain]
2-
channel = "nightly-2025-02-01"
2+
# update this after https://github.com/rust-lang/rust/issues/134044 is fixed.
3+
channel = "nightly-2024-11-01"
34
components = [
45
"cargo",
56
"clippy",

0 commit comments

Comments
 (0)