Skip to content

Commit

Permalink
changes for succint (#61)
Browse files Browse the repository at this point in the history
* changes for succint

* fmt

* minor fixes

* disabling unnecessary tests

* test fix

* rm comment
  • Loading branch information
kroos47 committed Oct 31, 2023
1 parent 4ab4fbc commit 8ec83d7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/src/header/extension/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions core/src/header/extension/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 6 additions & 11 deletions core/src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -405,13 +405,8 @@ mod tests {

/// It creates a corrupted V2 header and the associated error on decodification.
fn corrupted_header() -> (Vec<u8>, 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();

Expand Down Expand Up @@ -478,7 +473,7 @@ mod tests {
assert_eq!(
hash,
H256(hex!(
"21bbb83a624df177036ec0f5b03db7a5fcf47ce661138853743c72fef339b30b"
"2658abca4272bbd01abe73b29b0396dd03eb6af104a1d9b9e601d13d933a88b5"
))
);

Expand Down Expand Up @@ -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);
},
};

Expand Down
31 changes: 6 additions & 25 deletions core/src/kate_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
/// The merkle root of the data submitted
pub data_root: H256,
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -59,20 +59,19 @@ pub mod v2 {
/// Cols
#[codec(compact)]
pub cols: u16,
/// The merkle root of the data submitted
pub data_root: Option<H256>,
/// Plonk commitment.
pub commitment: Vec<u8>,
/// 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<u8>) -> Self {
let data_root = (!data_root.is_zero()).then_some(data_root);
Self {
rows,
cols,
data_root,
commitment,
data_root,
}
}
}
Expand All @@ -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)
Expand All @@ -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<H256> {
let kate = KateCommitment::new(1, 1, data_root, vec![]);
kate.data_root
}
}
}

0 comments on commit 8ec83d7

Please sign in to comment.