Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 82 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions core/src/header/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@ impl HeaderExtension {
}
}

pub fn rows(&self) -> u16 {
forward_to_version!(self, rows)
pub fn rows(&self) -> u32 {
match self {
HeaderExtension::V3(ext) => ext.rows() as u32,
HeaderExtension::V4(ext) => ext.rows(),
}
}

pub fn cols(&self) -> u16 {
Expand Down
6 changes: 3 additions & 3 deletions core/src/header/extension/v4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{data_lookup::v4::DataLookup, v3::KateCommitment};
use crate::{data_lookup::v4::DataLookup, v4::KateCommitment};
use codec::{Decode, Encode};
use primitive_types::H256;
use scale_info::TypeInfo;
Expand All @@ -15,7 +15,7 @@ use sp_debug_derive::RuntimeDebug;
#[cfg_attr(feature = "runtime", derive(RuntimeDebug))]
pub struct HeaderExtension {
pub app_lookup: DataLookup,
// Using KateCommitment from v3 since it is the same structure, although the data_root contruction has changed
// Using KateCommitment from v4 as datatype for rows is u32
pub commitment: KateCommitment,
}

Expand All @@ -28,7 +28,7 @@ impl HeaderExtension {
&self.app_lookup
}

pub fn rows(&self) -> u16 {
pub fn rows(&self) -> u32 {
self.commitment.rows
}

Expand Down
47 changes: 47 additions & 0 deletions core/src/kate_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,53 @@ pub mod v3 {
}
}

impl fmt::Debug for KateCommitment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let commitment: &[u8] = self.commitment.as_slice();
let data_root: &[u8] = self.data_root.as_ref();

f.debug_struct("KateCommitment(v4)")
.field("rows", &self.rows)
.field("cols", &self.cols)
.field("commitment", &HexDisplay(commitment))
.field("data_root", &HexDisplay(data_root))
.finish()
}
}
}

pub mod v4 {
use super::*;

/// Customized extrinsics root to save the commitment.
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
pub struct KateCommitment {
/// Rows
#[codec(compact)]
pub rows: u32,
/// Cols
#[codec(compact)]
pub cols: u16,
/// Ark commitment.
pub commitment: Vec<u8>,
/// The merkle root of the data submitted
pub data_root: H256,
}

impl KateCommitment {
pub fn new(rows: u32, cols: u16, data_root: H256, commitment: Vec<u8>) -> Self {
Self {
rows,
cols,
commitment,
data_root,
}
}
}

impl fmt::Debug for KateCommitment {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let commitment: &[u8] = self.commitment.as_slice();
Expand Down
10 changes: 7 additions & 3 deletions core/tests/const_generics/usize_even_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
error[E0080]: evaluation of `avail_core::const_generic_asserts::UsizeEven::<1>::OK` failed
error[E0080]: evaluation panicked: must be even
--> src/const_generic_asserts.rs
|
| pub const OK: () = assert!(N % 2 == 0, "must be even");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'must be even', $DIR/src/const_generic_asserts.rs:12:24
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `avail_core::const_generic_asserts::UsizeEven::<1>::OK` failed here

note: erroneous constant encountered
--> tests/const_generics/usize_even_fail.rs:4:11
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
4 | let () = UsizeEven::<N>::OK;
| ^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn const_generic_even::<1>`
--> tests/const_generics/usize_even_fail.rs:8:2
Expand Down
10 changes: 7 additions & 3 deletions core/tests/const_generics/usize_greater_or_eq_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
error[E0080]: evaluation of `avail_core::const_generic_asserts::USizeGreaterOrEq::<1, 2>::OK` failed
error[E0080]: evaluation panicked: must be greater or equal
--> src/const_generic_asserts.rs
|
| pub const OK: () = assert!(N >= M, "must be greater or equal");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'must be greater or equal', $DIR/src/const_generic_asserts.rs:27:24
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `avail_core::const_generic_asserts::USizeGreaterOrEq::<1, 2>::OK` failed here

note: erroneous constant encountered
--> tests/const_generics/usize_greater_or_eq_fail.rs:4:11
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
4 | let () = USizeGreaterOrEq::<N,M>::OK;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn const_generic_ge::<1, 2>`
--> tests/const_generics/usize_greater_or_eq_fail.rs:8:2
Expand Down
10 changes: 7 additions & 3 deletions core/tests/const_generics/usize_non_zero_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
error[E0080]: evaluation of `avail_core::const_generic_asserts::UsizeNonZero::<0>::OK` failed
error[E0080]: evaluation panicked: must be non-zero
--> src/const_generic_asserts.rs
|
| pub const OK: () = assert!(N != 0, "must be non-zero");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'must be non-zero', $DIR/src/const_generic_asserts.rs:6:24
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `avail_core::const_generic_asserts::UsizeNonZero::<0>::OK` failed here

note: erroneous constant encountered
--> tests/const_generics/usize_non_zero_fail.rs:4:11
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
4 | let () = UsizeNonZero::<N>::OK;
| ^^^^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn const_generic_non_zero::<0>`
--> tests/const_generics/usize_non_zero_fail.rs:8:2
Expand Down
10 changes: 7 additions & 3 deletions core/tests/const_generics/usize_safe_cast_to_u32_fail.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
error[E0080]: evaluation of `avail_core::const_generic_asserts::USizeSafeCastToU32::<4294967296>::OK` failed
error[E0080]: evaluation panicked: must be safe to cast to u32
--> src/const_generic_asserts.rs
|
| pub const OK: () = assert!(
| ________________________^
| | size_of::<usize>() <= size_of::<u32>() || N <= u32::MAX as usize,
| | "must be safe to cast to u32"
| | );
| |_____^ the evaluated program panicked at 'must be safe to cast to u32', $DIR/src/const_generic_asserts.rs:18:24
| |_____^ evaluation of `avail_core::const_generic_asserts::USizeSafeCastToU32::<4294967296>::OK` failed here

note: erroneous constant encountered
--> tests/const_generics/usize_safe_cast_to_u32_fail.rs:4:11
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
4 | let () = USizeSafeCastToU32::<N>::OK;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

note: the above error was encountered while instantiating `fn const_generic_safe_cast_to_u32::<4294967296>`
--> tests/const_generics/usize_safe_cast_to_u32_fail.rs:8:2
Expand Down
5 changes: 5 additions & 0 deletions kate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ criterion.workspace = true
proptest.workspace = true
serde_json.workspace = true
test-case.workspace = true
divan = { version = "0.1" }

[features]
default = [ "std" ]
Expand Down Expand Up @@ -71,3 +72,7 @@ maximum-block-size = []
[[bench]]
name = "reconstruct"
harness = false

[[bench]]
name = "multiproof"
harness = false
Loading