Skip to content

Commit

Permalink
fix(da): make id an invariant of signed blob
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mzabaluev committed Feb 27, 2025
1 parent 7fa67ed commit 54c3b92
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions protocol-units/da/movement/protocol/util/src/blob/ir/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ pub struct InnerSignedBlobV1<C>
where
C: Curve,
{
pub data: InnerSignedBlobV1Data<C>,
pub signature: Vec<u8>,
pub signer: Vec<u8>,
pub id: Id,
data: InnerSignedBlobV1Data<C>,
signature: Vec<u8>,
signer: Vec<u8>,
id: Id,
}

impl<C> InnerSignedBlobV1<C>
where
C: Curve + Verify<C> + Digester<C>,
{
pub fn new(
pub(crate) fn new(
data: InnerSignedBlobV1Data<C>,
signature: Vec<u8>,
signer: Vec<u8>,
Expand Down Expand Up @@ -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::<Secp256k1>::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::*;
Expand Down

0 comments on commit 54c3b92

Please sign in to comment.