Skip to content

Commit ff83f43

Browse files
committed
Use features to disable crypto
1 parent 91ade9a commit ff83f43

File tree

10 files changed

+63
-88
lines changed

10 files changed

+63
-88
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,12 @@ test-op-pool-%:
233233
test-network: $(patsubst %,test-network-%,$(TEST_NETWORK_FORKS))
234234

235235
test-network-%:
236+
env FORK_NAME=$* cargo nextest run --no-fail-fast --release \
237+
--features "fork_from_env,fake_crypto,$(TEST_FEATURES)" \
238+
-p network
236239
env FORK_NAME=$* cargo nextest run --no-fail-fast --release \
237240
--features "fork_from_env,$(TEST_FEATURES)" \
241+
-E 'test(name ~ "crypto_on")' \
238242
-p network
239243

240244
# Run the tests in the `slasher` crate for all supported database backends.

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -671,16 +671,13 @@ pub fn signature_verify_chain_segment<T: BeaconChainTypes>(
671671
let pubkey_cache = get_validator_pubkey_cache(chain)?;
672672
let mut signature_verifier = get_signature_verifier(&state, &pubkey_cache, &chain.spec);
673673
for svb in &mut signature_verified_blocks {
674-
signature_verifier
675-
.include_all_signatures(svb.block.as_block(), &mut svb.consensus_context)?;
674+
signature_verifier.include_all_signatures(svb.block.as_block(), &mut svb.consensus_context)?;
676675
}
677676

678677
if signature_verifier.verify().is_err() {
679678
return Err(BlockError::InvalidSignature(InvalidSignature::Unknown));
680679
}
681680

682-
drop(pubkey_cache);
683-
684681
if let Some(signature_verified_block) = signature_verified_blocks.first_mut() {
685682
signature_verified_block.parent = Some(parent);
686683
}
@@ -977,19 +974,17 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
977974
let expected_proposer = proposer.index;
978975
let fork = proposer.fork;
979976

980-
let signature_is_valid = {
981-
let pubkey_cache = get_validator_pubkey_cache(chain)?;
982-
let pubkey = pubkey_cache
983-
.get(block.message().proposer_index() as usize)
984-
.ok_or_else(|| BlockError::UnknownValidator(block.message().proposer_index()))?;
985-
block.verify_signature(
986-
Some(block_root),
987-
pubkey,
988-
&fork,
989-
chain.genesis_validators_root,
990-
&chain.spec,
991-
)
992-
};
977+
let pubkey_cache = get_validator_pubkey_cache(chain)?;
978+
let pubkey = pubkey_cache
979+
.get(block.message().proposer_index() as usize)
980+
.ok_or_else(|| BlockError::UnknownValidator(block.message().proposer_index()))?;
981+
let signature_is_valid = block.verify_signature(
982+
Some(block_root),
983+
pubkey,
984+
&fork,
985+
chain.genesis_validators_root,
986+
&chain.spec,
987+
);
993988

994989
if !signature_is_valid {
995990
return Err(BlockError::InvalidSignature(
@@ -1121,14 +1116,14 @@ impl<T: BeaconChainTypes> SignatureVerifiedBlock<T> {
11211116

11221117
let pubkey_cache = get_validator_pubkey_cache(chain)?;
11231118

1124-
let mut signature_verifier = get_signature_verifier(&state, &pubkey_cache, &chain.spec);
1125-
11261119
let mut consensus_context =
11271120
ConsensusContext::new(block.slot()).set_current_block_root(block_root);
11281121

1122+
let mut signature_verifier = get_signature_verifier(&state, &pubkey_cache, &chain.spec);
11291123
signature_verifier.include_all_signatures(block.as_block(), &mut consensus_context)?;
1124+
let signatures_valid = signature_verifier.verify().is_ok();
11301125

1131-
if signature_verifier.verify().is_ok() {
1126+
if signatures_valid {
11321127
Ok(Self {
11331128
consensus_context,
11341129
block,

beacon_node/beacon_chain/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,6 @@ where
10511051
self.kzg.clone(),
10521052
store,
10531053
Arc::new(custody_context),
1054-
&self.chain_config.test_config,
10551054
self.spec,
10561055
)
10571056
.map_err(|e| format!("Error initializing DataAvailabilityChecker: {:?}", e))?,

beacon_node/beacon_chain/src/chain_config.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ pub struct ChainConfig {
121121
pub disable_get_blobs: bool,
122122
/// The node's custody type, determining how many data columns to custody and sample.
123123
pub node_custody_type: NodeCustodyType,
124-
/// TESTING ONLY: Disable certain functionality to speed up tests
125-
pub test_config: TestConfig,
126-
}
127-
128-
#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
129-
pub struct TestConfig {
130-
/// FOR TESTING ONLY: Disable crypto verification to speed up tests
131-
pub disable_crypto: bool,
132124
}
133125

134126
impl Default for ChainConfig {
@@ -170,9 +162,6 @@ impl Default for ChainConfig {
170162
invalid_block_roots: HashSet::new(),
171163
disable_get_blobs: false,
172164
node_custody_type: NodeCustodyType::Fullnode,
173-
test_config: TestConfig {
174-
disable_crypto: false,
175-
},
176165
}
177166
}
178167
}

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ mod error;
2929
mod overflow_lru_cache;
3030
mod state_lru_cache;
3131

32-
use crate::chain_config::TestConfig;
3332
use crate::data_availability_checker::error::Error;
3433
use crate::data_column_verification::{
3534
CustodyDataColumn, GossipVerifiedDataColumn, KzgVerifiedCustodyDataColumn,
@@ -87,7 +86,6 @@ pub struct DataAvailabilityChecker<T: BeaconChainTypes> {
8786
kzg: Arc<Kzg>,
8887
custody_context: Arc<CustodyContext<T::EthSpec>>,
8988
spec: Arc<ChainSpec>,
90-
disable_crypto: bool,
9189
}
9290

9391
pub type AvailabilityAndReconstructedColumns<E> = (Availability<E>, DataColumnSidecarList<E>);
@@ -126,7 +124,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
126124
kzg: Arc<Kzg>,
127125
store: BeaconStore<T>,
128126
custody_context: Arc<CustodyContext<T::EthSpec>>,
129-
test_config: &TestConfig,
130127
spec: Arc<ChainSpec>,
131128
) -> Result<Self, AvailabilityCheckError> {
132129
let inner = DataAvailabilityCheckerInner::new(
@@ -142,7 +139,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
142139
kzg,
143140
custody_context,
144141
spec,
145-
disable_crypto: test_config.disable_crypto,
146142
})
147143
}
148144

@@ -382,10 +378,8 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
382378
let (block_root, block, blobs, data_columns) = block.deconstruct();
383379
if self.blobs_required_for_block(&block) {
384380
return if let Some(blob_list) = blobs {
385-
if !self.disable_crypto {
386-
verify_kzg_for_blob_list(blob_list.iter(), &self.kzg)
387-
.map_err(AvailabilityCheckError::InvalidBlobs)?;
388-
}
381+
verify_kzg_for_blob_list(blob_list.iter(), &self.kzg)
382+
.map_err(AvailabilityCheckError::InvalidBlobs)?;
389383
Ok(MaybeAvailableBlock::Available(AvailableBlock {
390384
block_root,
391385
block,
@@ -399,15 +393,13 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
399393
}
400394
if self.data_columns_required_for_block(&block) {
401395
return if let Some(data_column_list) = data_columns.as_ref() {
402-
if !self.disable_crypto {
403-
verify_kzg_for_data_column_list(
404-
data_column_list
405-
.iter()
406-
.map(|custody_column| custody_column.as_data_column()),
407-
&self.kzg,
408-
)
409-
.map_err(AvailabilityCheckError::InvalidColumn)?;
410-
}
396+
verify_kzg_for_data_column_list(
397+
data_column_list
398+
.iter()
399+
.map(|custody_column| custody_column.as_data_column()),
400+
&self.kzg,
401+
)
402+
.map_err(AvailabilityCheckError::InvalidColumn)?;
411403
Ok(MaybeAvailableBlock::Available(AvailableBlock {
412404
block_root,
413405
block,
@@ -1203,7 +1195,6 @@ mod test {
12031195
kzg,
12041196
store,
12051197
custody_context,
1206-
&TestConfig::default(),
12071198
spec,
12081199
)
12091200
.expect("should initialise data availability checker")

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,16 +1030,12 @@ where
10301030
panic!("Should always be a full payload response");
10311031
};
10321032

1033-
let signed_block = Arc::new(if self.chain.config.test_config.disable_crypto {
1034-
SignedBeaconBlock::from_block(block_response.block, Signature::empty())
1035-
} else {
1036-
block_response.block.sign(
1037-
&self.validator_keypairs[proposer_index].sk,
1038-
&block_response.state.fork(),
1039-
block_response.state.genesis_validators_root(),
1040-
&self.spec,
1041-
)
1042-
});
1033+
let signed_block = Arc::new(block_response.block.sign(
1034+
&self.validator_keypairs[proposer_index].sk,
1035+
&block_response.state.fork(),
1036+
block_response.state.genesis_validators_root(),
1037+
&self.spec,
1038+
));
10431039

10441040
let block_contents: SignedBlockContentsTuple<E> =
10451041
if signed_block.fork_name_unchecked().deneb_enabled() {
@@ -1418,12 +1414,9 @@ where
14181414

14191415
let mut agg_sig = AggregateSignature::infinity();
14201416

1421-
// If disable_crypto is true keep the attestation signature as infinity
1422-
if !self.chain.config.test_config.disable_crypto {
1423-
agg_sig.add_assign(
1424-
&self.validator_keypairs[*validator_index].sk.sign(message),
1425-
);
1426-
}
1417+
agg_sig.add_assign(
1418+
&self.validator_keypairs[*validator_index].sk.sign(message),
1419+
);
14271420

14281421
agg_sig
14291422
};
@@ -1520,14 +1513,9 @@ where
15201513
let message = attestation.data().signing_root(domain);
15211514

15221515
let mut agg_sig = AggregateSignature::infinity();
1523-
1524-
// If disable_crypto is true keep the attestation signature as infinity
1525-
if !self.chain.config.test_config.disable_crypto {
1526-
agg_sig.add_assign(
1527-
&self.validator_keypairs[*validator_index].sk.sign(message),
1528-
);
1529-
}
1530-
1516+
agg_sig.add_assign(
1517+
&self.validator_keypairs[*validator_index].sk.sign(message),
1518+
);
15311519
agg_sig
15321520
};
15331521

beacon_node/network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = { workspace = true }
88
# NOTE: This can be run via cargo build --bin lighthouse --features network/disable-backfill
99
disable-backfill = []
1010
fork_from_env = ["beacon_chain/fork_from_env"]
11+
fake_crypto = ["bls/fake_crypto", "kzg/fake_crypto"]
1112
portable = ["beacon_chain/portable"]
1213
test_logger = []
1314

beacon_node/network/src/sync/tests/lookups.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ use crate::sync::{
77
manager::{BlockProcessType, BlockProcessingResult, SyncManager},
88
};
99
use beacon_chain::blob_verification::KzgVerifiedBlob;
10-
use beacon_chain::chain_config::TestConfig;
1110
use beacon_chain::custody_context::NodeCustodyType;
1211
use beacon_chain::{
13-
AvailabilityProcessingStatus, BlockError, ChainConfig, NotifyExecutionLayer,
12+
AvailabilityProcessingStatus, BlockError, NotifyExecutionLayer,
1413
block_verification_types::AsBlock,
1514
data_availability_checker::Availability,
1615
test_utils::{
@@ -170,12 +169,6 @@ impl TestRig {
170169
.mock_execution_layer()
171170
.testing_slot_clock(clock.clone())
172171
.node_custody_type(test_rig_config.fulu_test_type.we_node_custody_type())
173-
.chain_config(ChainConfig {
174-
test_config: TestConfig {
175-
disable_crypto: true,
176-
},
177-
..Default::default()
178-
})
179172
.build();
180173

181174
let chain = harness.chain.clone();
@@ -774,12 +767,7 @@ impl TestRig {
774767
.fresh_ephemeral_store()
775768
.mock_execution_layer()
776769
.testing_slot_clock(self.harness.chain.slot_clock.clone())
777-
.chain_config(ChainConfig {
778-
test_config: TestConfig {
779-
disable_crypto: true,
780-
},
781-
..Default::default()
782-
}) // Make the external harness a supernode so all columns are available
770+
// Make the external harness a supernode so all columns are available
783771
.node_custody_type(NodeCustodyType::Supernode)
784772
.build();
785773
// Ensure all blocks have data. Otherwise, the triggers for unknown blob parent and unknown

crypto/kzg/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ authors = ["Pawan Dhananjay <pawandhananjay@gmail.com>"]
55
edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[features]
9+
default = []
10+
fake_crypto = []
11+
812
[dependencies]
913
arbitrary = { workspace = true }
1014
c-kzg = { workspace = true }

crypto/kzg/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ impl Kzg {
134134
kzg_commitment: KzgCommitment,
135135
kzg_proof: KzgProof,
136136
) -> Result<(), Error> {
137+
#[cfg(feature = "fake_crypto")]
138+
{
139+
return Ok(());
140+
}
137141
if !self.trusted_setup.verify_blob_kzg_proof(
138142
blob,
139143
&kzg_commitment.into(),
@@ -155,6 +159,10 @@ impl Kzg {
155159
kzg_commitments: &[KzgCommitment],
156160
kzg_proofs: &[KzgProof],
157161
) -> Result<(), Error> {
162+
#[cfg(feature = "fake_crypto")]
163+
{
164+
return Ok(());
165+
}
158166
let commitments_bytes = kzg_commitments
159167
.iter()
160168
.map(|comm| Bytes48::from(*comm))
@@ -204,6 +212,10 @@ impl Kzg {
204212
y: &Bytes32,
205213
kzg_proof: KzgProof,
206214
) -> Result<bool, Error> {
215+
#[cfg(feature = "fake_crypto")]
216+
{
217+
return Ok(true);
218+
}
207219
self.trusted_setup
208220
.verify_kzg_proof(&kzg_commitment.into(), z, y, &kzg_proof.into())
209221
.map_err(Into::into)
@@ -240,6 +252,10 @@ impl Kzg {
240252
indices: Vec<CellIndex>,
241253
kzg_commitments: &[Bytes48],
242254
) -> Result<(), (Option<u64>, Error)> {
255+
#[cfg(feature = "fake_crypto")]
256+
{
257+
return Ok(());
258+
}
243259
let mut column_groups: HashMap<u64, Vec<(CellRef, Bytes48, Bytes48)>> = HashMap::new();
244260

245261
let expected_len = cells.len();

0 commit comments

Comments
 (0)