arbos/features/
mod.rs

1use alloy_primitives::U256;
2use revm::Database;
3
4use arb_storage::StorageBackedBigUint;
5
6const INCREASED_CALLDATA: usize = 0;
7
8/// Feature flags backed by a storage BigUint used as a bitmask.
9pub struct Features<D> {
10    features: StorageBackedBigUint<D>,
11}
12
13pub fn open_features<D: Database>(
14    state: *mut revm::database::State<D>,
15    base_key: alloy_primitives::B256,
16    offset: u64,
17) -> Features<D> {
18    Features {
19        features: StorageBackedBigUint::new(state, base_key, offset),
20    }
21}
22
23impl<D: Database> Features<D> {
24    pub fn set_calldata_price_increase(&self, enabled: bool) -> Result<(), ()> {
25        self.set_bit(INCREASED_CALLDATA, enabled)
26    }
27
28    pub fn is_increased_calldata_price_enabled(&self) -> Result<bool, ()> {
29        self.is_set(INCREASED_CALLDATA)
30    }
31
32    fn set_bit(&self, index: usize, enabled: bool) -> Result<(), ()> {
33        let mut val = self.features.get()?;
34        if enabled {
35            val |= U256::from(1) << index;
36        } else {
37            val &= !(U256::from(1) << index);
38        }
39        self.features.set(val)
40    }
41
42    fn is_set(&self, index: usize) -> Result<bool, ()> {
43        let val = self.features.get()?;
44        Ok((val >> index) & U256::from(1) != U256::ZERO)
45    }
46}