From 54c3b92a08e3dd5d3cba114087dc32d8d3a30be9 Mon Sep 17 00:00:00 2001 From: Mikhail Zabaluev Date: Thu, 27 Feb 2025 21:10:06 +0200 Subject: [PATCH] fix(da): make id an invariant of signed blob InnerSignedBlobV1 does not need to expose its struct members as public. Making them private allows preserving the invariant of id being computed from the data on construction. --- .../protocol/util/src/blob/ir/blob.rs | 33 +++---------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/protocol-units/da/movement/protocol/util/src/blob/ir/blob.rs b/protocol-units/da/movement/protocol/util/src/blob/ir/blob.rs index fd81d9cec..d559e9c32 100644 --- a/protocol-units/da/movement/protocol/util/src/blob/ir/blob.rs +++ b/protocol-units/da/movement/protocol/util/src/blob/ir/blob.rs @@ -13,17 +13,17 @@ pub struct InnerSignedBlobV1 where C: Curve, { - pub data: InnerSignedBlobV1Data, - pub signature: Vec, - pub signer: Vec, - pub id: Id, + data: InnerSignedBlobV1Data, + signature: Vec, + signer: Vec, + id: Id, } impl InnerSignedBlobV1 where C: Curve + Verify + Digester, { - pub fn new( + pub(crate) fn new( data: InnerSignedBlobV1Data, signature: Vec, signer: Vec, @@ -165,29 +165,6 @@ where } } -#[cfg(test)] -pub mod test { - - use super::*; - use movement_da_light_node_signer::Signer; - use movement_signer::cryptography::secp256k1::Secp256k1; - use movement_signer_local::signer::LocalSigner; - - #[tokio::test] - async fn test_cannot_change_id_and_verify() -> Result<(), anyhow::Error> { - let blob = InnerSignedBlobV1Data::new(vec![1, 2, 3], 123); - let signer = Signer::new(LocalSigner::::random()); - let signed_blob = blob.try_to_sign(&signer).await?; - - let mut changed_blob = signed_blob.clone(); - changed_blob.id = Id::new(vec![1, 2, 3, 4]); - - assert!(changed_blob.try_verify().is_err()); - - Ok(()) - } -} - pub mod stream_read_response { use movement_da_light_node_proto::*;