From fc860735a7645b10ff4ac6e3d52b2dabd189e214 Mon Sep 17 00:00:00 2001 From: Razvan Barbascu Date: Mon, 20 Jan 2025 10:05:22 +0000 Subject: [PATCH] Refactor SignatureDifferentiator --- core/primitives/src/optimistic_block.rs | 3 +-- .../src/stateless_validation/chunk_endorsement.rs | 4 ++-- .../src/stateless_validation/contract_distribution.rs | 4 ++-- core/primitives/src/stateless_validation/mod.rs | 8 -------- .../src/stateless_validation/partial_witness.rs | 4 ++-- core/primitives/src/stateless_validation/state_witness.rs | 4 ++-- core/primitives/src/types.rs | 8 ++++++++ 7 files changed, 17 insertions(+), 18 deletions(-) diff --git a/core/primitives/src/optimistic_block.rs b/core/primitives/src/optimistic_block.rs index 9806d54f062..40ea2172229 100644 --- a/core/primitives/src/optimistic_block.rs +++ b/core/primitives/src/optimistic_block.rs @@ -3,8 +3,7 @@ use near_crypto::Signature; use crate::block::BlockHeader; use crate::hash::{hash, CryptoHash}; -use crate::stateless_validation::SignatureDifferentiator; -use crate::types::BlockHeight; +use crate::types::{BlockHeight, SignatureDifferentiator}; #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] pub struct OptimisticBlockInner { diff --git a/core/primitives/src/stateless_validation/chunk_endorsement.rs b/core/primitives/src/stateless_validation/chunk_endorsement.rs index d04e17b01a6..b36f7a1f5bb 100644 --- a/core/primitives/src/stateless_validation/chunk_endorsement.rs +++ b/core/primitives/src/stateless_validation/chunk_endorsement.rs @@ -1,14 +1,14 @@ use std::fmt::Debug; use crate::sharding::{ChunkHash, ShardChunkHeader}; -use crate::types::EpochId; +use crate::types::{EpochId, SignatureDifferentiator}; use crate::validator_signer::ValidatorSigner; use borsh::{BorshDeserialize, BorshSerialize}; use near_crypto::{PublicKey, Signature}; use near_primitives_core::types::{AccountId, BlockHeight, ShardId}; use near_schema_checker_lib::ProtocolSchema; -use super::{ChunkProductionKey, SignatureDifferentiator}; +use super::ChunkProductionKey; /// The endorsement of a chunk by a chunk validator. By providing this, a /// chunk validator has verified that the chunk state witness is correct. diff --git a/core/primitives/src/stateless_validation/contract_distribution.rs b/core/primitives/src/stateless_validation/contract_distribution.rs index 214b55e84bf..faabe79e980 100644 --- a/core/primitives/src/stateless_validation/contract_distribution.rs +++ b/core/primitives/src/stateless_validation/contract_distribution.rs @@ -9,12 +9,12 @@ use near_primitives_core::hash::{hash, CryptoHash}; use near_primitives_core::types::{AccountId, ShardId}; use near_schema_checker_lib::ProtocolSchema; +use super::ChunkProductionKey; #[cfg(feature = "solomon")] use crate::reed_solomon::{ReedSolomonEncoderDeserialize, ReedSolomonEncoderSerialize}; +use crate::types::SignatureDifferentiator; use crate::{utils::compression::CompressedData, validator_signer::ValidatorSigner}; -use super::{ChunkProductionKey, SignatureDifferentiator}; - // Data structures for chunk producers to send accessesed contracts to chunk validators. /// Contains contracts (as code-hashes) accessed during the application of a chunk. diff --git a/core/primitives/src/stateless_validation/mod.rs b/core/primitives/src/stateless_validation/mod.rs index d2871a39a67..272bfeef23e 100644 --- a/core/primitives/src/stateless_validation/mod.rs +++ b/core/primitives/src/stateless_validation/mod.rs @@ -12,14 +12,6 @@ pub mod state_witness; pub mod stored_chunk_state_transition_data; pub mod validator_assignment; -/// An arbitrary static string to make sure that this struct cannot be -/// serialized to look identical to another serialized struct. For chunk -/// production we are signing a chunk hash, so we need to make sure that -/// this signature means something different. -/// -/// This is a messy workaround until we know what to do with NEP 483. -pub type SignatureDifferentiator = String; - /// This struct contains combination of fields that uniquely identify chunk production. /// It means that for a given instance only one chunk could be produced. #[derive(Debug, Hash, PartialEq, Eq, Clone, BorshSerialize, BorshDeserialize, ProtocolSchema)] diff --git a/core/primitives/src/stateless_validation/partial_witness.rs b/core/primitives/src/stateless_validation/partial_witness.rs index 44d235b1657..cc944e36eea 100644 --- a/core/primitives/src/stateless_validation/partial_witness.rs +++ b/core/primitives/src/stateless_validation/partial_witness.rs @@ -1,8 +1,8 @@ use std::fmt::{Debug, Formatter}; -use super::{ChunkProductionKey, SignatureDifferentiator}; +use super::ChunkProductionKey; use crate::sharding::ShardChunkHeader; -use crate::types::EpochId; +use crate::types::{EpochId, SignatureDifferentiator}; use crate::validator_signer::ValidatorSigner; use borsh::{BorshDeserialize, BorshSerialize}; use bytesize::ByteSize; diff --git a/core/primitives/src/stateless_validation/state_witness.rs b/core/primitives/src/stateless_validation/state_witness.rs index f6c1aff510b..d5ed9d6d249 100644 --- a/core/primitives/src/stateless_validation/state_witness.rs +++ b/core/primitives/src/stateless_validation/state_witness.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::fmt::Debug; -use super::{ChunkProductionKey, SignatureDifferentiator}; +use super::ChunkProductionKey; use crate::bandwidth_scheduler::BandwidthRequests; use crate::challenge::PartialState; use crate::congestion_info::CongestionInfo; @@ -9,7 +9,7 @@ use crate::congestion_info::CongestionInfo; use crate::reed_solomon::{ReedSolomonEncoderDeserialize, ReedSolomonEncoderSerialize}; use crate::sharding::{ChunkHash, ReceiptProof, ShardChunkHeader, ShardChunkHeaderV3}; use crate::transaction::SignedTransaction; -use crate::types::EpochId; +use crate::types::{EpochId, SignatureDifferentiator}; use crate::utils::compression::CompressedData; use crate::validator_signer::EmptyValidatorSigner; use borsh::{BorshDeserialize, BorshSerialize}; diff --git a/core/primitives/src/types.rs b/core/primitives/src/types.rs index bf39509f232..dfb9d61548d 100644 --- a/core/primitives/src/types.rs +++ b/core/primitives/src/types.rs @@ -22,6 +22,14 @@ pub use chunk_validator_stats::ChunkStats; /// Hash used by to store state root. pub type StateRoot = CryptoHash; +/// An arbitrary static string to make sure that this struct cannot be +/// serialized to look identical to another serialized struct. For chunk +/// production we are signing a chunk hash, so we need to make sure that +/// this signature means something different. +/// +/// This is a messy workaround until we know what to do with NEP 483. +pub(crate) type SignatureDifferentiator = String; + /// Different types of finality. #[derive( serde::Serialize, serde::Deserialize, Default, Clone, Debug, PartialEq, Eq, arbitrary::Arbitrary,