Skip to content

Commit 7cbd0bd

Browse files
committed
Disable legacy-arith by default
1 parent 7f06500 commit 7cbd0bd

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

consensus/state_processing/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ authors = ["Paul Hauner <[email protected]>", "Michael Sproul <michael@sigmapr
55
edition = { workspace = true }
66

77
[features]
8-
default = ["legacy-arith"]
8+
default = []
99
fake_crypto = ["bls/fake_crypto"]
10-
legacy-arith = ["types/legacy-arith"]
1110
arbitrary-fuzz = [
1211
"types/arbitrary-fuzz",
1312
"merkle_proof/arbitrary",
@@ -40,7 +39,7 @@ test_random_derive = { path = "../../common/test_random_derive" }
4039
tracing = { workspace = true }
4140
tree_hash = { workspace = true }
4241
typenum = { workspace = true }
43-
types = { workspace = true }
42+
types = { workspace = true, features = ["saturating-arith"] }
4443

4544
[dev-dependencies]
4645
beacon_chain = { workspace = true }

consensus/types/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ authors = [
88
edition = { workspace = true }
99

1010
[features]
11-
default = ["sqlite", "legacy-arith"]
12-
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
13-
legacy-arith = []
11+
default = ["sqlite"]
12+
# Enable +, -, *, /, % operators for Slot and Epoch types.
13+
# Operations saturate instead of wrapping.
14+
saturating-arith = []
1415
sqlite = ["dep:rusqlite"]
1516
arbitrary = [
1617
"dep:arbitrary",

consensus/types/src/core/slot_epoch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
test_utils::TestRandom,
2323
};
2424

25-
#[cfg(feature = "legacy-arith")]
25+
#[cfg(feature = "saturating-arith")]
2626
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, Sub, SubAssign};
2727

2828
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]

consensus/types/src/core/slot_epoch_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ macro_rules! impl_safe_arith {
117117
}
118118

119119
// Deprecated: prefer `SafeArith` methods for new code.
120-
#[cfg(feature = "legacy-arith")]
120+
#[cfg(feature = "saturating-arith")]
121121
macro_rules! impl_math_between {
122122
($main: ident, $other: ident) => {
123123
impl Add<$other> for $main {
@@ -321,9 +321,9 @@ macro_rules! impl_common {
321321
impl_u64_eq_ord!($type);
322322
impl_safe_arith!($type, $type);
323323
impl_safe_arith!($type, u64);
324-
#[cfg(feature = "legacy-arith")]
324+
#[cfg(feature = "saturating-arith")]
325325
impl_math_between!($type, $type);
326-
#[cfg(feature = "legacy-arith")]
326+
#[cfg(feature = "saturating-arith")]
327327
impl_math_between!($type, u64);
328328
impl_math!($type);
329329
impl_display!($type);

consensus/types/src/state/committee_cache.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ impl CommitteeCache {
7979
.saturating_sub(spec.min_seed_lookahead)
8080
.saturating_sub(1u64);
8181

82-
if reqd_randao_epoch < state.min_randao_epoch() || epoch > state.current_epoch() + 1 {
82+
if reqd_randao_epoch < state.min_randao_epoch()
83+
|| epoch
84+
> state
85+
.current_epoch()
86+
.safe_add(1)
87+
.map_err(BeaconStateError::ArithError)?
88+
{
8389
return Err(BeaconStateError::EpochOutOfBounds);
8490
}
8591

0 commit comments

Comments
 (0)