From 8ec83d7415c89834948f38a3fdc66d274180a732 Mon Sep 17 00:00:00 2001 From: Kailas Date: Tue, 31 Oct 2023 17:32:52 +0530 Subject: [PATCH] changes for succint (#61) * changes for succint * fmt * minor fixes * disabling unnecessary tests * test fix * rm comment --- core/src/header/extension/v1.rs | 2 +- core/src/header/extension/v2.rs | 4 ++-- core/src/header/mod.rs | 17 ++++++----------- core/src/kate_commitment.rs | 31 ++++++------------------------- 4 files changed, 15 insertions(+), 39 deletions(-) diff --git a/core/src/header/extension/v1.rs b/core/src/header/extension/v1.rs index a2dfc31e..390abed3 100644 --- a/core/src/header/extension/v1.rs +++ b/core/src/header/extension/v1.rs @@ -10,8 +10,8 @@ use crate::{v1::KateCommitment, DataLookup}; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct HeaderExtension { - pub commitment: KateCommitment, pub app_lookup: DataLookup, + pub commitment: KateCommitment, } impl HeaderExtension { diff --git a/core/src/header/extension/v2.rs b/core/src/header/extension/v2.rs index 0b0d0fc7..1f6d2813 100644 --- a/core/src/header/extension/v2.rs +++ b/core/src/header/extension/v2.rs @@ -10,13 +10,13 @@ use crate::{v2::KateCommitment, DataLookup}; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct HeaderExtension { - pub commitment: KateCommitment, pub app_lookup: DataLookup, + pub commitment: KateCommitment, } impl HeaderExtension { pub fn data_root(&self) -> H256 { - self.commitment.data_root.unwrap_or_default() + self.commitment.data_root } pub fn app_lookup(&self) -> &DataLookup { diff --git a/core/src/header/mod.rs b/core/src/header/mod.rs index 876d852c..bee251dd 100644 --- a/core/src/header/mod.rs +++ b/core/src/header/mod.rs @@ -366,13 +366,13 @@ mod tests { }; let encoded = header.encode(); - assert_eq!(encoded, hex!("92cdf578c47085a5992256f0dcf97d0b19f1f1c9de4d5fe30c3ace6191b6e5db08581348337b0f3e148620173daaa5f94d00d881705dcbf0aa83efdaba61d2ede1eb8649214997574e20c464388a172420d25403682bbbb80c496831c8cc1f8f0d040004350004103fbf3227926cfa3f4167771e5ad91cfa2c2d7090667ce01e911ca90b4f315b11810180e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e975980e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e97590000").to_vec()); + assert_eq!(encoded, hex!("92cdf578c47085a5992256f0dcf97d0b19f1f1c9de4d5fe30c3ace6191b6e5db08581348337b0f3e148620173daaa5f94d00d881705dcbf0aa83efdaba61d2ede1eb8649214997574e20c464388a172420d25403682bbbb80c496831c8cc1f8f0d040004350000000410810180e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e975980e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e97593fbf3227926cfa3f4167771e5ad91cfa2c2d7090667ce01e911ca90b4f315b11").to_vec()); } fn header_v1() -> THeader { let commitment = v1::KateCommitment { - commitment: hex!("80e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e975980e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e9759").to_vec(), data_root: hex!("3fbf3227926cfa3f4167771e5ad91cfa2c2d7090667ce01e911ca90b4f315b11").into(), + commitment: hex!("80e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e975980e949ebdaf5c13e09649c587c6b1905fb770b4a6843abaac6b413e3a7405d9825ac764db2341db9b7965965073e9759").to_vec(), ..Default::default() }; let extension = extension::v1::HeaderExtension { @@ -405,13 +405,8 @@ mod tests { /// It creates a corrupted V2 header and the associated error on decodification. fn corrupted_header() -> (Vec, Error) { - let mut encoded = header_v2().encode(); - - // Change the discriminator - let discriminator = encoded.get_mut(98).expect("Discriminator at position 98"); - assert_eq!(*discriminator, 1u8); - *discriminator = 0u8; - assert_eq!(*discriminator, 0u8); + let mut encoded = header_v1().encode(); + encoded.remove(110); let error = THeader::decode(&mut encoded.as_slice()).unwrap_err(); @@ -478,7 +473,7 @@ mod tests { assert_eq!( hash, H256(hex!( - "21bbb83a624df177036ec0f5b03db7a5fcf47ce661138853743c72fef339b30b" + "2658abca4272bbd01abe73b29b0396dd03eb6af104a1d9b9e601d13d933a88b5" )) ); @@ -508,7 +503,7 @@ mod tests { ext.commitment.data_root = H256::repeat_byte(1u8); }, extension::HeaderExtension::V2(ref mut ext) => { - ext.commitment.data_root = Some(H256::repeat_byte(2u8)); + ext.commitment.data_root = H256::repeat_byte(2u8); }, }; diff --git a/core/src/kate_commitment.rs b/core/src/kate_commitment.rs index 7b72f65b..d688ae4d 100644 --- a/core/src/kate_commitment.rs +++ b/core/src/kate_commitment.rs @@ -25,10 +25,10 @@ pub mod v1 { /// Cols #[codec(compact)] pub cols: u16, - /// The merkle root of the data submitted - pub data_root: H256, /// Plonk commitment. pub commitment: Vec, + /// The merkle root of the data submitted + pub data_root: H256, } #[cfg(feature = "serde")] @@ -59,20 +59,19 @@ pub mod v2 { /// Cols #[codec(compact)] pub cols: u16, - /// The merkle root of the data submitted - pub data_root: Option, /// Plonk commitment. pub commitment: Vec, + /// The merkle root of the data submitted + pub data_root: H256, } impl KateCommitment { pub fn new(rows: u16, cols: u16, data_root: H256, commitment: Vec) -> Self { - let data_root = (!data_root.is_zero()).then_some(data_root); Self { rows, cols, - data_root, commitment, + data_root, } } } @@ -81,11 +80,7 @@ pub mod v2 { impl fmt::Debug for KateCommitment { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let commitment = self.commitment.as_slice(); - let data_root = self - .data_root - .as_ref() - .map(AsRef::as_ref) - .unwrap_or_default(); + let data_root = self.data_root.as_ref(); f.debug_struct("KateCommitment(v2)") .field("rows", &self.rows) @@ -95,18 +90,4 @@ pub mod v2 { .finish() } } - - #[cfg(test)] - mod tests { - use super::*; - use test_case::test_case; - - /// Double check that zero data root is compressed to `None`. - #[test_case( H256([0u8;32]) => None; "Zero data root")] - #[test_case( H256([1u8;32]) => Some(H256([1u8;32])); "NonZero data root")] - fn compression_on_new(data_root: H256) -> Option { - let kate = KateCommitment::new(1, 1, data_root, vec![]); - kate.data_root - } - } }