From c8eab17366f0651645da37daacf0a53408b92016 Mon Sep 17 00:00:00 2001 From: Stefan Neamtu Date: Fri, 8 Nov 2024 12:02:03 +0100 Subject: [PATCH] remove verify_partial_witness_signature --- chain/chain/src/test_utils/kv_runtime.rs | 7 ------- chain/client/src/stateless_validation/validate.rs | 4 +++- chain/epoch-manager/src/adapter.rs | 14 -------------- chain/epoch-manager/src/tests/mod.rs | 8 +++++--- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/chain/chain/src/test_utils/kv_runtime.rs b/chain/chain/src/test_utils/kv_runtime.rs index d65808e79b4..2ed312d2f31 100644 --- a/chain/chain/src/test_utils/kv_runtime.rs +++ b/chain/chain/src/test_utils/kv_runtime.rs @@ -1022,13 +1022,6 @@ impl EpochManagerAdapter for MockEpochManager { Ok(true) } - fn verify_partial_witness_signature( - &self, - _partial_witness: &PartialEncodedStateWitness, - ) -> Result { - Ok(true) - } - fn verify_witness_contract_accesses_signature( &self, _accesses: &ChunkContractAccesses, diff --git a/chain/client/src/stateless_validation/validate.rs b/chain/client/src/stateless_validation/validate.rs index c8b1cb5f1b7..1fa08916b15 100644 --- a/chain/client/src/stateless_validation/validate.rs +++ b/chain/client/src/stateless_validation/validate.rs @@ -62,7 +62,9 @@ pub fn validate_partial_encoded_state_witness( return Ok(false); } - if !epoch_manager.verify_partial_witness_signature(&partial_witness)? { + let chunk_producer = + epoch_manager.get_chunk_producer_info(&partial_witness.chunk_production_key())?; + if !partial_witness.verify(chunk_producer.public_key()) { return Err(Error::InvalidPartialChunkStateWitness("Invalid signature".to_string())); } diff --git a/chain/epoch-manager/src/adapter.rs b/chain/epoch-manager/src/adapter.rs index 510f5bb14c0..f58fc63eb7c 100644 --- a/chain/epoch-manager/src/adapter.rs +++ b/chain/epoch-manager/src/adapter.rs @@ -491,11 +491,6 @@ pub trait EpochManagerAdapter: Send + Sync { endorsement: &ChunkEndorsement, ) -> Result; - fn verify_partial_witness_signature( - &self, - partial_witness: &PartialEncodedStateWitness, - ) -> Result; - fn verify_witness_contract_accesses_signature( &self, accesses: &ChunkContractAccesses, @@ -1177,15 +1172,6 @@ impl EpochManagerAdapter for EpochManagerHandle { Ok(endorsement.verify(validator.public_key())) } - fn verify_partial_witness_signature( - &self, - partial_witness: &PartialEncodedStateWitness, - ) -> Result { - let chunk_producer = - self.read().get_chunk_producer_info(&partial_witness.chunk_production_key())?; - Ok(partial_witness.verify(chunk_producer.public_key())) - } - fn verify_witness_contract_accesses_signature( &self, accesses: &ChunkContractAccesses, diff --git a/chain/epoch-manager/src/tests/mod.rs b/chain/epoch-manager/src/tests/mod.rs index 87bd02b3061..363ba205af8 100644 --- a/chain/epoch-manager/src/tests/mod.rs +++ b/chain/epoch-manager/src/tests/mod.rs @@ -3360,11 +3360,13 @@ fn test_verify_partial_witness_signature() { 7, signer.as_ref(), ); - assert!(epoch_manager.verify_partial_witness_signature(&partial_witness).unwrap()); + let chunk_producer = + epoch_manager.get_chunk_producer_info(&partial_witness.chunk_production_key()).unwrap(); + assert!(partial_witness.verify(chunk_producer.public_key())); // Check invalid chunk state witness signature. partial_witness.signature = Signature::default(); - assert!(!epoch_manager.verify_partial_witness_signature(&partial_witness).unwrap()); + assert!(!partial_witness.verify(chunk_producer.public_key())); // Check chunk state witness invalidity when signer is not a chunk validator. let bad_signer = Arc::new(create_test_signer("test2")); @@ -3376,7 +3378,7 @@ fn test_verify_partial_witness_signature() { 7, bad_signer.as_ref(), ); - assert!(!epoch_manager.verify_partial_witness_signature(&bad_partial_witness).unwrap()); + assert!(!bad_partial_witness.verify(chunk_producer.public_key())); } /// Simulate the blockchain over a few epochs and verify that possible_epochs_of_height_around_tip()