Skip to content

Commit 6d69c26

Browse files
committed
fix: introduce IntermediateBlobRepresentation.
1 parent 860b76b commit 6d69c26

File tree

7 files changed

+80
-71
lines changed

7 files changed

+80
-71
lines changed

protocol-units/da/m1/light-node-verifier/src/celestia/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{Error, Verified, VerifierOperations};
22
use celestia_rpc::Client;
33
use celestia_types::{nmt::Namespace, Blob};
4-
use m1_da_light_node_util::inner_blob::InnerBlob;
4+
use m1_da_light_node_util::ir_blob::IntermediateBlobRepresentation;
55
use std::sync::Arc;
66

77
#[derive(Clone)]
@@ -19,13 +19,13 @@ impl Verifier {
1919
}
2020

2121
#[tonic::async_trait]
22-
impl VerifierOperations<Blob, InnerBlob> for Verifier {
23-
/// Verifies a Celestia Blob as a Valid InnerBlob
24-
async fn verify(&self, blob: Blob, _height: u64) -> Result<Verified<InnerBlob>, Error> {
25-
// Only assert that we can indeed get an InnerBlob from the Blob
26-
let inner_blob = InnerBlob::try_from(blob).map_err(|e| Error::Internal(e.to_string()))?;
22+
impl VerifierOperations<Blob, IntermediateBlobRepresentation> for Verifier {
23+
/// Verifies a Celestia Blob as a Valid IntermediateBlobRepresentation
24+
async fn verify(&self, blob: Blob, _height: u64) -> Result<Verified<IntermediateBlobRepresentation>, Error> {
25+
// Only assert that we can indeed get an IntermediateBlobRepresentation from the Blob
26+
let ir_blob = IntermediateBlobRepresentation::try_from(blob).map_err(|e| Error::Internal(e.to_string()))?;
2727

28-
Ok(Verified::new(inner_blob))
28+
Ok(Verified::new(ir_blob))
2929
}
3030
}
3131

protocol-units/da/m1/light-node-verifier/src/celestia/pessimistic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{Error, Verified, VerifierOperations};
22
use celestia_rpc::Client;
33
use celestia_rpc::{BlobClient, HeaderClient};
44
use celestia_types::{nmt::Namespace, Blob};
5-
use m1_da_light_node_util::inner_blob::InnerBlob;
5+
use m1_da_light_node_util::ir_blob::IntermediateBlobRepresentation;
66
use std::sync::Arc;
77

88
#[derive(Clone)]
@@ -20,9 +20,9 @@ impl Verifier {
2020
}
2121

2222
#[tonic::async_trait]
23-
impl VerifierOperations<Blob, InnerBlob> for Verifier {
24-
/// Verifies a Celestia Blob as a Valid InnerBlob
25-
async fn verify(&self, blob: Blob, height: u64) -> Result<Verified<InnerBlob>, Error> {
23+
impl VerifierOperations<Blob, IntermediateBlobRepresentation> for Verifier {
24+
/// Verifies a Celestia Blob as a Valid IntermediateBlobRepresentation
25+
async fn verify(&self, blob: Blob, height: u64) -> Result<Verified<IntermediateBlobRepresentation>, Error> {
2626
//@l-monninger: the light node itself does most of the work of verify blobs. The verification under the feature flag below is useful in zero-trust environments.
2727

2828
blob.validate().map_err(|e| Error::Validation(e.to_string()))?;
@@ -61,8 +61,8 @@ impl VerifierOperations<Blob, InnerBlob> for Verifier {
6161
})?;
6262
}
6363

64-
let inner_blob = InnerBlob::try_from(blob).map_err(|e| Error::Internal(e.to_string()))?;
64+
let ir_blob = IntermediateBlobRepresentation::try_from(blob).map_err(|e| Error::Internal(e.to_string()))?;
6565

66-
Ok(Verified::new(inner_blob))
66+
Ok(Verified::new(ir_blob))
6767
}
6868
}

protocol-units/da/m1/light-node-verifier/src/permissioned_signers/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ecdsa::{
1717
hazmat::{DigestPrimitive, SignPrimitive, VerifyPrimitive},
1818
SignatureSize,
1919
};
20-
use m1_da_light_node_util::inner_blob::InnerBlob;
20+
use m1_da_light_node_util::ir_blob::IntermediateBlobRepresentation;
2121
use std::sync::Arc;
2222

2323
/// A verifier of Celestia blobs for permissioned signers
@@ -61,15 +61,15 @@ where
6161
}
6262

6363
#[tonic::async_trait]
64-
impl<C> VerifierOperations<CelestiaBlob, InnerBlob> for Verifier<C>
64+
impl<C> VerifierOperations<CelestiaBlob, IntermediateBlobRepresentation> for Verifier<C>
6565
where
6666
C: PrimeCurve + CurveArithmetic + DigestPrimitive + PointCompression,
6767
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
6868
SignatureSize<C>: ArrayLength<u8>,
6969
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
7070
FieldBytesSize<C>: ModulusSize,
7171
{
72-
async fn verify(&self, blob: CelestiaBlob, height: u64) -> Result<Verified<InnerBlob>, Error> {
72+
async fn verify(&self, blob: CelestiaBlob, height: u64) -> Result<Verified<IntermediateBlobRepresentation>, Error> {
7373
let verified_blob = self.celestia.verify(blob, height).await?;
7474
self.known_signers.verify(verified_blob.into_inner(), height).await
7575
}

protocol-units/da/m1/light-node-verifier/src/signed/mod.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use ecdsa::{
1111
hazmat::{DigestPrimitive, SignPrimitive, VerifyPrimitive},
1212
SignatureSize,
1313
};
14-
use m1_da_light_node_util::inner_blob::InnerBlob;
14+
use m1_da_light_node_util::ir_blob::IntermediateBlobRepresentation;
1515
use std::collections::HashSet;
1616
use tracing::info;
1717

@@ -42,15 +42,15 @@ where
4242
}
4343

4444
#[tonic::async_trait]
45-
impl<C> VerifierOperations<InnerBlob, InnerBlob> for Verifier<C>
45+
impl<C> VerifierOperations<IntermediateBlobRepresentation, IntermediateBlobRepresentation> for Verifier<C>
4646
where
4747
C: PrimeCurve + CurveArithmetic + DigestPrimitive + PointCompression,
4848
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
4949
SignatureSize<C>: ArrayLength<u8>,
5050
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
5151
FieldBytesSize<C>: ModulusSize,
5252
{
53-
async fn verify(&self, blob: InnerBlob, _height: u64) -> Result<Verified<InnerBlob>, Error> {
53+
async fn verify(&self, blob: IntermediateBlobRepresentation, _height: u64) -> Result<Verified<IntermediateBlobRepresentation>, Error> {
5454
blob.verify_signature::<C>().map_err(|e| Error::Validation(e.to_string()))?;
5555

5656
Ok(Verified::new(blob))
@@ -97,31 +97,31 @@ where
9797
}
9898

9999
#[tonic::async_trait]
100-
impl<C> VerifierOperations<InnerBlob, InnerBlob> for InKnownSignersVerifier<C>
100+
impl<C> VerifierOperations<IntermediateBlobRepresentation, IntermediateBlobRepresentation> for InKnownSignersVerifier<C>
101101
where
102102
C: PrimeCurve + CurveArithmetic + DigestPrimitive + PointCompression,
103103
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
104104
SignatureSize<C>: ArrayLength<u8>,
105105
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
106106
FieldBytesSize<C>: ModulusSize,
107107
{
108-
async fn verify(&self, blob: InnerBlob, height: u64) -> Result<Verified<InnerBlob>, Error> {
109-
let inner_blob = self.inner_verifier.verify(blob, height).await?;
108+
async fn verify(&self, blob: IntermediateBlobRepresentation, height: u64) -> Result<Verified<IntermediateBlobRepresentation>, Error> {
109+
let ir_blob = self.inner_verifier.verify(blob, height).await?;
110110
info!("Verified inner blob");
111-
let signer = inner_blob.inner().signer_hex();
111+
let signer = ir_blob.inner().signer_hex();
112112
if !self.known_signers_sec1_bytes_hex.contains(&signer) {
113113
return Err(Error::Validation("signer not in known signers".to_string()));
114114
}
115115

116-
Ok(inner_blob)
116+
Ok(ir_blob)
117117
}
118118
}
119119

120120
#[cfg(test)]
121121
pub mod tests {
122122
/*use ecdsa::SigningKey;
123123
use k256::Secp256k1;
124-
use m1_da_light_node_util::inner_blob::{InnerSignedBlobV1, InnerSignedBlobV1Data, InnerBlob};
124+
use m1_da_light_node_util::ir_blob::{InnerSignedBlobV1, InnerSignedBlobV1Data, IntermediateBlobRepresentation};
125125
use std::iter::FromIterator;
126126
127127
#[tokio::test]
@@ -130,14 +130,14 @@ pub mod tests {
130130
// rand_core
131131
&mut rand::rngs::OsRng,
132132
);
133-
let blob : InnerBlob = InnerSignedBlobV1::tr
133+
let blob : IntermediateBlobRepresentation = InnerSignedBlobV1::tr
134134
135-
let inner_blob = create_inner_blob("known_signer");
136-
let verified = verifier.verify(inner_blob, 0).await.unwrap();
135+
let ir_blob = create_ir_blob("known_signer");
136+
let verified = verifier.verify(ir_blob, 0).await.unwrap();
137137
assert_eq!(verified.inner().signer_hex(), "known_signer");
138138
139-
let inner_blob = create_inner_blob("unknown_signer");
140-
let verified = verifier.verify(inner_blob, 0).await;
139+
let ir_blob = create_ir_blob("unknown_signer");
140+
let verified = verifier.verify(ir_blob, 0).await;
141141
assert!(verified.is_err());
142142
}*/
143143
}

protocol-units/da/m1/light-node/src/v1/passthrough.rs

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use m1_da_light_node_util::inner_blob::InnerBlob;
1+
use m1_da_light_node_util::ir_blob::IntermediateBlobRepresentation;
22
use std::fmt::{self, Debug, Formatter};
33
use std::sync::Arc;
44
use tokio_stream::{Stream, StreamExt};
@@ -12,7 +12,7 @@ use m1_da_light_node_grpc::light_node_service_server::LightNodeService;
1212
use m1_da_light_node_grpc::*;
1313
use m1_da_light_node_util::{
1414
config::Config,
15-
inner_blob::{celestia::CelestiaInnerBlob, InnerSignedBlobV1Data},
15+
ir_blob::{celestia::CelestiaIntermediateBlobRepresentation, InnerSignedBlobV1Data},
1616
};
1717
use m1_da_light_node_verifier::{permissioned_signers::Verifier, VerifierOperations};
1818

@@ -42,7 +42,9 @@ where
4242
pub config: Config,
4343
pub celestia_namespace: Namespace,
4444
pub default_client: Arc<Client>,
45-
pub verifier: Arc<Box<dyn VerifierOperations<CelestiaBlob, InnerBlob> + Send + Sync>>,
45+
pub verifier: Arc<
46+
Box<dyn VerifierOperations<CelestiaBlob, IntermediateBlobRepresentation> + Send + Sync>,
47+
>,
4648
pub signing_key: SigningKey<C>,
4749
}
4850

@@ -119,7 +121,8 @@ where
119121
let data = InnerSignedBlobV1Data::new(data, timestamp).try_to_sign(&self.signing_key)?;
120122

121123
// create the celestia blob
122-
CelestiaInnerBlob(data.into(), self.celestia_namespace.clone()).try_into()
124+
CelestiaIntermediateBlobRepresentation(data.into(), self.celestia_namespace.clone())
125+
.try_into()
123126
}
124127

125128
/// Submits a CelestiaBlob to the Celestia node.
@@ -155,10 +158,10 @@ where
155158
}
156159

157160
/// Gets the blobs at a given height.
158-
pub async fn get_inner_blobs_at_height(
161+
pub async fn get_ir_blobs_at_height(
159162
&self,
160163
height: u64,
161-
) -> Result<Vec<InnerBlob>, anyhow::Error> {
164+
) -> Result<Vec<IntermediateBlobRepresentation>, anyhow::Error> {
162165
let blobs = self.default_client.blob_get_all(height, &[self.celestia_namespace]).await;
163166

164167
if let Err(e) = &blobs {
@@ -186,10 +189,10 @@ where
186189

187190
#[tracing::instrument(target = "movement_timing", level = "debug")]
188191
async fn get_blobs_at_height(&self, height: u64) -> Result<Vec<Blob>, anyhow::Error> {
189-
let inner_blobs = self.get_inner_blobs_at_height(height).await?;
192+
let ir_blobs = self.get_ir_blobs_at_height(height).await?;
190193
let mut blobs = Vec::new();
191-
for inner_blob in inner_blobs {
192-
let blob = Self::inner_blob_to_blob(inner_blob, height)?;
194+
for ir_blob in ir_blobs {
195+
let blob = Self::ir_blob_to_blob(ir_blob, height)?;
193196
// todo: update logging here
194197
blobs.push(blob);
195198
}
@@ -277,26 +280,29 @@ where
277280
as std::pin::Pin<Box<dyn Stream<Item = Result<Blob, anyhow::Error>> + Send>>)
278281
}
279282

280-
pub fn inner_blob_to_blob(inner_blob: InnerBlob, height: u64) -> Result<Blob, anyhow::Error> {
283+
pub fn ir_blob_to_blob(
284+
ir_blob: IntermediateBlobRepresentation,
285+
height: u64,
286+
) -> Result<Blob, anyhow::Error> {
281287
Ok(Blob {
282-
data: inner_blob.blob().to_vec(),
283-
signature: inner_blob.signature().to_vec(),
284-
timestamp: inner_blob.timestamp(),
285-
signer: inner_blob.signer().to_vec(),
286-
blob_id: inner_blob.id().to_vec(),
288+
data: ir_blob.blob().to_vec(),
289+
signature: ir_blob.signature().to_vec(),
290+
timestamp: ir_blob.timestamp(),
291+
signer: ir_blob.signer().to_vec(),
292+
blob_id: ir_blob.id().to_vec(),
287293
height,
288294
})
289295
}
290296

291297
pub fn celestia_blob_to_blob(blob: CelestiaBlob, height: u64) -> Result<Blob, anyhow::Error> {
292-
let inner_blob: InnerBlob = blob.try_into()?;
298+
let ir_blob: IntermediateBlobRepresentation = blob.try_into()?;
293299

294300
Ok(Blob {
295-
data: inner_blob.blob().to_vec(),
296-
signature: inner_blob.signature().to_vec(),
297-
timestamp: inner_blob.timestamp(),
298-
signer: inner_blob.signer().to_vec(),
299-
blob_id: inner_blob.id().to_vec(),
301+
data: ir_blob.blob().to_vec(),
302+
signature: ir_blob.signature().to_vec(),
303+
timestamp: ir_blob.timestamp(),
304+
signer: ir_blob.signer().to_vec(),
305+
blob_id: ir_blob.id().to_vec(),
300306
height,
301307
})
302308
}

protocol-units/da/m1/util/src/inner_blob.rs protocol-units/da/m1/util/src/ir_blob.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -95,38 +95,38 @@ impl InnerSignedBlobV1 {
9595
}
9696

9797
#[derive(Debug, Clone, Serialize, Deserialize)]
98-
pub enum InnerBlob {
98+
pub enum IntermediateBlobRepresentation {
9999
SignedV1(InnerSignedBlobV1),
100100
}
101101

102-
impl From<InnerSignedBlobV1> for InnerBlob {
102+
impl From<InnerSignedBlobV1> for IntermediateBlobRepresentation {
103103
fn from(inner: InnerSignedBlobV1) -> Self {
104-
InnerBlob::SignedV1(inner)
104+
IntermediateBlobRepresentation::SignedV1(inner)
105105
}
106106
}
107107

108-
impl InnerBlob {
108+
impl IntermediateBlobRepresentation {
109109
pub fn blob(&self) -> &[u8] {
110110
match self {
111-
InnerBlob::SignedV1(inner) => inner.data.blob.as_slice(),
111+
IntermediateBlobRepresentation::SignedV1(inner) => inner.data.blob.as_slice(),
112112
}
113113
}
114114

115115
pub fn signature(&self) -> &[u8] {
116116
match self {
117-
InnerBlob::SignedV1(inner) => inner.signature.as_slice(),
117+
IntermediateBlobRepresentation::SignedV1(inner) => inner.signature.as_slice(),
118118
}
119119
}
120120

121121
pub fn timestamp(&self) -> u64 {
122122
match self {
123-
InnerBlob::SignedV1(inner) => inner.data.timestamp,
123+
IntermediateBlobRepresentation::SignedV1(inner) => inner.data.timestamp,
124124
}
125125
}
126126

127127
pub fn signer(&self) -> &[u8] {
128128
match self {
129-
InnerBlob::SignedV1(inner) => inner.signer.as_slice(),
129+
IntermediateBlobRepresentation::SignedV1(inner) => inner.signer.as_slice(),
130130
}
131131
}
132132

@@ -136,7 +136,7 @@ impl InnerBlob {
136136

137137
pub fn id(&self) -> &[u8] {
138138
match self {
139-
InnerBlob::SignedV1(inner) => inner.id.as_slice(),
139+
IntermediateBlobRepresentation::SignedV1(inner) => inner.id.as_slice(),
140140
}
141141
}
142142

@@ -149,19 +149,19 @@ impl InnerBlob {
149149
FieldBytesSize<C>: ModulusSize,
150150
{
151151
match self {
152-
InnerBlob::SignedV1(inner) => inner.try_verify::<C>(),
152+
IntermediateBlobRepresentation::SignedV1(inner) => inner.try_verify::<C>(),
153153
}
154154
}
155155
}
156156

157157
pub mod celestia {
158158

159-
use super::InnerBlob;
159+
use super::IntermediateBlobRepresentation;
160160
use anyhow::Context;
161161
use celestia_types::{nmt::Namespace, Blob as CelestiaBlob};
162162
use tracing::info;
163163

164-
impl TryFrom<CelestiaBlob> for InnerBlob {
164+
impl TryFrom<CelestiaBlob> for IntermediateBlobRepresentation {
165165
type Error = anyhow::Error;
166166

167167
// todo: it would be nice to have this be self describing over the compression and serialization format
@@ -178,20 +178,23 @@ pub mod celestia {
178178
}
179179
}
180180

181-
pub struct CelestiaInnerBlob(pub InnerBlob, pub Namespace);
181+
pub struct CelestiaIntermediateBlobRepresentation(
182+
pub IntermediateBlobRepresentation,
183+
pub Namespace,
184+
);
182185

183-
/// Tries to form a CelestiaBlob from a CelestiaInnerBlob
184-
impl TryFrom<CelestiaInnerBlob> for CelestiaBlob {
186+
/// Tries to form a CelestiaBlob from a CelestiaIntermediateBlobRepresentation
187+
impl TryFrom<CelestiaIntermediateBlobRepresentation> for CelestiaBlob {
185188
type Error = anyhow::Error;
186189

187-
fn try_from(inner_blob: CelestiaInnerBlob) -> Result<Self, Self::Error> {
188-
info!("converting CelestiaInnerBlob to CelestiaBlob");
190+
fn try_from(ir_blob: CelestiaIntermediateBlobRepresentation) -> Result<Self, Self::Error> {
191+
info!("converting CelestiaIntermediateBlobRepresentation to CelestiaBlob");
189192

190193
// Extract the inner blob and namespace
191-
let CelestiaInnerBlob(inner_blob, namespace) = inner_blob;
194+
let CelestiaIntermediateBlobRepresentation(ir_blob, namespace) = ir_blob;
192195

193196
// Serialize the inner blob with bcs
194-
let serialized_blob = bcs::to_bytes(&inner_blob).context("failed to serialize blob")?;
197+
let serialized_blob = bcs::to_bytes(&ir_blob).context("failed to serialize blob")?;
195198

196199
// Compress the serialized data with zstd
197200
let compressed_blob = zstd::encode_all(serialized_blob.as_slice(), 0)

protocol-units/da/m1/util/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pub mod config;
22
pub use config::*;
3-
pub mod inner_blob;
3+
pub mod ir_blob;

0 commit comments

Comments
 (0)