diff --git a/Cargo.lock b/Cargo.lock index 6929b28..7e08104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "avail-core" -version = "0.6.1" +version = "0.6.2" dependencies = [ "avail-core", "binary-merkle-tree", @@ -2124,7 +2124,7 @@ dependencies = [ [[package]] name = "kate" -version = "0.9.0" +version = "0.9.1" dependencies = [ "avail-core", "criterion", @@ -2154,7 +2154,7 @@ dependencies = [ [[package]] name = "kate-recovery" -version = "0.9.3" +version = "0.10.0" dependencies = [ "avail-core", "derive_more", diff --git a/core/Cargo.toml b/core/Cargo.toml index c46cf34..8e11492 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "avail-core" -version = "0.6.1" +version = "0.6.2" authors = [] edition = "2021" license = "Apache-2.0" diff --git a/core/src/asdr.rs b/core/src/asdr.rs index 8c1bc2b..7343e83 100644 --- a/core/src/asdr.rs +++ b/core/src/asdr.rs @@ -55,7 +55,7 @@ use sp_std::alloc::format; /// the decoding fails. pub const EXTRINSIC_FORMAT_VERSION: u8 = 4; -/// The `SingaturePayload` of `UncheckedExtrinsic`. +/// The `SignaturePayload` of `UncheckedExtrinsic`. type SignaturePayload = (Address, Signature, Extra); /// An extrinsic right from the external world. This is unchecked and so can contain a signature. @@ -735,13 +735,12 @@ mod tests { use core::mem::transmute; let op = unsigned_to_opaque(); - let new_op = unsafe { + unsafe { // Using `transmute` because `OpaqueExtrinsic.0` is not public. let mut raw = transmute::>(op); raw.pop(); transmute::, OpaqueExtrinsic>(raw) - }; - new_op + } } #[test_case( unsigned_to_opaque() => true ; "Unsigned Ex")] diff --git a/core/src/constants.rs b/core/src/constants.rs index 640c88d..d1a11af 100644 --- a/core/src/constants.rs +++ b/core/src/constants.rs @@ -1,6 +1,6 @@ use core::num::NonZeroU32; use sp_arithmetic::Perbill; -use static_assertions::const_assert; +use static_assertions::{const_assert, const_assert_eq}; /// We allow `Normal` extrinsics to fill up the block up to 85%, the rest can be used /// by Operational extrinsics. @@ -14,7 +14,6 @@ const_assert!(BLOCK_CHUNK_SIZE.get() > 0); pub const BLOCK_CHUNK_SIZE: NonZeroU32 = unsafe { NonZeroU32::new_unchecked(32) }; /// Money matters. -// TODO: evaluate whether we should consider moving this into avail pub mod currency { pub type Balance = u128; @@ -22,8 +21,7 @@ pub mod currency { /// `AVAIL` has 18 decimal positions. pub const AVAIL: Balance = 1_000_000_000_000_000_000; - /// Cents of AVAIL has 16 decimal positions (100 Cents = $1) - /// 1 Cents = `10_000_000_000_000_000` + /// Cents of AVAIL has 16 decimal positions (100 Cents = 1) pub const CENTS: Balance = AVAIL / 100; /// Millicent of AVAIL has 13 decimal positions( 1000 mCents = 1 cent). @@ -41,3 +39,14 @@ pub mod currency { /// `PICO_AVAIL` has 6 decimal positions pub const PICO_AVAIL: Balance = NANO_AVAIL / 1_000; } + +pub mod kate { + use super::*; + pub const EXTENSION_FACTOR: u32 = 2; + pub const COMMITMENT_SIZE: usize = 48; + pub const DATA_CHUNK_SIZE: usize = 31; + pub const CHUNK_SIZE: usize = 32; + + const_assert_eq!(DATA_CHUNK_SIZE, CHUNK_SIZE - 1); + const_assert_eq!(CHUNK_SIZE, BLOCK_CHUNK_SIZE.get() as usize); +} diff --git a/core/src/data_lookup/mod.rs b/core/src/data_lookup/mod.rs index ccfdcc1..b637730 100644 --- a/core/src/data_lookup/mod.rs +++ b/core/src/data_lookup/mod.rs @@ -159,7 +159,7 @@ impl TryFrom for DataLookup { let last_range = offset..compacted.size; if !last_range.is_empty() { - index.push((prev_id, offset..compacted.size)); + index.push((prev_id, last_range)); } let lookup = DataLookup { index }; @@ -204,7 +204,7 @@ mod test { #[test_case( vec![(0, 15), (1, 20), (2, 150)] => Ok(vec![(0,0..15),(1, 15..35), (2, 35..185)]); "Valid case")] #[test_case( vec![(0, usize::MAX)] => Err(Error::OffsetOverflows); "Offset overflows at zero")] #[test_case( vec![(0, (u32::MAX -1) as usize), (1, 2)] => Err(Error::OffsetOverflows); "Offset overflows at non zero")] - #[test_case( vec![(1, 10), (0, 2)] => Err(Error::DataNotSorted); "Unsortend data")] + #[test_case( vec![(1, 10), (0, 2)] => Err(Error::DataNotSorted); "Unsorted data")] #[test_case( vec![] => Ok(vec![]); "Empty data")] fn from_id_and_len( id_len_data: Vec<(u32, usize)>, diff --git a/core/src/data_proof.rs b/core/src/data_proof.rs index 599eaea..2584130 100644 --- a/core/src/data_proof.rs +++ b/core/src/data_proof.rs @@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "runtime")] use sp_io::hashing::keccak_256; -/// Max data supported on bidge (Ethereum calldata limits) +/// Max data supported on bridge (Ethereum calldata limits) pub const BOUNDED_DATA_MAX_LENGTH: u32 = 102_400; /// Maximum size of data allowed in the bridge diff --git a/core/src/lib.rs b/core/src/lib.rs index a3e876b..b84f6b9 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -184,7 +184,7 @@ macro_rules! keccak256_concat_update { }}; } -/// Calculates the Kecck 256 of arguments with NO extra allocations to join inputs. +/// Calculates the Keccak 256 of arguments with NO extra allocations to join inputs. #[macro_export] macro_rules! keccak256_concat{ ($($arg:tt)*) => {{ diff --git a/kate/Cargo.toml b/kate/Cargo.toml index bce2a25..487731f 100644 --- a/kate/Cargo.toml +++ b/kate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kate" -version = "0.9.0" +version = "0.9.1" authors = ["Denis Ermolin "] edition = "2021" license = "Apache-2.0" diff --git a/kate/recovery/Cargo.toml b/kate/recovery/Cargo.toml index e794c0a..9e885d5 100644 --- a/kate/recovery/Cargo.toml +++ b/kate/recovery/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kate-recovery" -version = "0.9.3" +version = "0.10.0" authors = ["Denis Ermolin "] edition = "2018" license = "Apache-2.0" diff --git a/kate/recovery/src/com.rs b/kate/recovery/src/com.rs index 656ead8..8d3fd1a 100644 --- a/kate/recovery/src/com.rs +++ b/kate/recovery/src/com.rs @@ -1,17 +1,18 @@ use crate::matrix; +#[cfg(feature = "std")] +use crate::{data, sparse_slice_read::SparseSliceRead}; use core::{num::TryFromIntError, ops::Range}; +#[cfg(feature = "std")] +use avail_core::{ + constants::kate::{CHUNK_SIZE, DATA_CHUNK_SIZE}, + ensure, +}; use avail_core::{data_lookup::Error as DataLookupError, AppId, DataLookup}; use sp_std::prelude::*; use thiserror_no_std::Error; -#[cfg(feature = "std")] -use crate::data; -#[cfg(feature = "std")] -use crate::{config, sparse_slice_read::SparseSliceRead}; -#[cfg(feature = "std")] -use avail_core::ensure; #[cfg(feature = "std")] use codec::{Decode, IoReader}; #[cfg(feature = "std")] @@ -177,9 +178,9 @@ pub fn reconstruct_app_extrinsics( app_id: AppId, ) -> Result { let data = reconstruct_available(dimensions, cells)?; - const_assert!(config::CHUNK_SIZE as u64 <= u32::MAX as u64); + const_assert!(CHUNK_SIZE as u64 <= u32::MAX as u64); let range = index - .projected_range_of(app_id, config::CHUNK_SIZE as u32) + .projected_range_of(app_id, CHUNK_SIZE as u32) .ok_or(ReconstructionError::MissingId(app_id))?; Ok(unflatten_padded_data(vec![(app_id, range)], data)? @@ -203,8 +204,8 @@ pub fn reconstruct_extrinsics( ) -> Result, ReconstructionError> { let data = reconstruct_available(dimensions, cells)?; - const_assert!(config::CHUNK_SIZE as u64 <= u32::MAX as u64); - let ranges = lookup.projected_ranges(config::CHUNK_SIZE as u32)?; + const_assert!(CHUNK_SIZE as u64 <= u32::MAX as u64); + let ranges = lookup.projected_ranges(CHUNK_SIZE as u32)?; unflatten_padded_data(ranges, data).map_err(ReconstructionError::DataDecodingError) } @@ -218,7 +219,7 @@ pub fn reconstruct_extrinsics( pub fn reconstruct_columns( dimensions: matrix::Dimensions, cells: &[data::Cell], -) -> Result>, ReconstructionError> { +) -> Result>, ReconstructionError> { let cells: Vec = cells.iter().cloned().map(Into::into).collect::>(); let columns = map_cells(dimensions, cells)?; @@ -235,7 +236,7 @@ pub fn reconstruct_columns( let column = reconstruct_column(dimensions.extended_rows(), &cells)? .iter() .map(BlsScalar::to_bytes) - .collect::>(); + .collect::>(); Ok((col, column)) }) @@ -266,7 +267,7 @@ fn reconstruct_available( }) .collect::>, ReconstructionError>>()?; - let mut result: Vec = Vec::with_capacity(scalars.len() * config::CHUNK_SIZE); + let mut result: Vec = Vec::with_capacity(scalars.len() * CHUNK_SIZE); for (row, col) in dimensions.iter_data() { let bytes = scalars @@ -275,7 +276,7 @@ fn reconstruct_available( .map(Option::as_ref) .unwrap_or(None) .map(BlsScalar::to_bytes) - .unwrap_or_else(|| [0; config::CHUNK_SIZE]); + .unwrap_or_else(|| [0; CHUNK_SIZE]); result.extend(bytes); } Ok(result) @@ -318,14 +319,14 @@ pub fn decode_app_extrinsics( .and_then(|column| column.get(&row_number)) .filter(|cell| !cell.data.is_empty()) { - None => app_data.extend(vec![0; config::CHUNK_SIZE]), + None => app_data.extend(vec![0; CHUNK_SIZE]), Some(cell) => app_data.extend(cell.data), } } - const_assert!((config::CHUNK_SIZE as u64) <= (u32::MAX as u64)); + const_assert!((CHUNK_SIZE as u64) <= (u32::MAX as u64)); let ranges = index - .projected_range_of(app_id, config::CHUNK_SIZE as u32) + .projected_range_of(app_id, CHUNK_SIZE as u32) .map(|range| vec![(app_id, range)]) .unwrap_or_default(); @@ -363,20 +364,17 @@ pub fn unflatten_padded_data( ranges: Vec<(AppId, AppDataRange)>, data: Vec, ) -> Result, UnflattenError> { - ensure!( - data.len() % config::CHUNK_SIZE == 0, - UnflattenError::InvalidLen - ); + ensure!(data.len() % CHUNK_SIZE == 0, UnflattenError::InvalidLen); fn extract_encoded_extrinsic(range_data: &[u8]) -> SparseSliceRead { - const_assert_ne!(config::CHUNK_SIZE, 0); - const_assert_ne!(config::DATA_CHUNK_SIZE, 0); + const_assert_ne!(CHUNK_SIZE, 0); + const_assert_ne!(DATA_CHUNK_SIZE, 0); // INTERNAL: Chunk into 32 bytes (CHUNK_SIZE), then remove padding (0..30 bytes). SparseSliceRead::from_iter( range_data - .chunks_exact(config::CHUNK_SIZE) - .map(|chunk| &chunk[0..config::DATA_CHUNK_SIZE]), + .chunks_exact(CHUNK_SIZE) + .map(|chunk| &chunk[0..DATA_CHUNK_SIZE]), ) } @@ -577,7 +575,6 @@ pub fn reconstruct_column( let mut subset: Vec> = Vec::with_capacity(row_count_sz); // fill up vector in ordered fashion - // @note the way it's done should be improved for i in 0..row_count { subset.push(find_row_by_index(i, cells)); } diff --git a/kate/recovery/src/commitments.rs b/kate/recovery/src/commitments.rs index 9cde4d7..99806f5 100644 --- a/kate/recovery/src/commitments.rs +++ b/kate/recovery/src/commitments.rs @@ -1,10 +1,10 @@ -use crate::config::COMMITMENT_SIZE; +use avail_core::constants::kate::{CHUNK_SIZE, COMMITMENT_SIZE}; use core::{array::TryFromSliceError, convert::TryInto, num::TryFromIntError}; use sp_std::prelude::*; use thiserror_no_std::Error; #[cfg(feature = "std")] -use crate::{com, config, matrix}; +use crate::{com, matrix}; #[cfg(feature = "std")] use avail_core::{ensure, AppId, DataLookup}; #[cfg(feature = "std")] @@ -69,13 +69,13 @@ impl From for Error { #[cfg(feature = "std")] fn try_into_scalar(chunk: &[u8]) -> Result { - let sized_chunk = <[u8; config::CHUNK_SIZE]>::try_from(chunk)?; + let sized_chunk = <[u8; CHUNK_SIZE]>::try_from(chunk)?; BlsScalar::from_bytes(&sized_chunk).map_err(From::from) } #[cfg(feature = "std")] fn try_into_scalars(data: &[u8]) -> Result, Error> { - let chunks = data.chunks_exact(config::CHUNK_SIZE); + let chunks = data.chunks_exact(CHUNK_SIZE); ensure!(chunks.remainder().is_empty(), Error::BadLen); chunks .map(try_into_scalar) @@ -113,7 +113,6 @@ pub fn verify_equality( } let dim_cols = dimensions.width(); - // @TODO Opening Key here??? let (prover_key, _) = public_params.trim(dim_cols)?; let domain = EvaluationDomain::new(dim_cols)?; diff --git a/kate/recovery/src/config.rs b/kate/recovery/src/config.rs deleted file mode 100644 index c247f60..0000000 --- a/kate/recovery/src/config.rs +++ /dev/null @@ -1,5 +0,0 @@ -// TODO: Constants are copy from kate crate, we should move them to common place -pub const CHUNK_SIZE: usize = 32; -pub const DATA_CHUNK_SIZE: usize = 31; -pub const COMMITMENT_SIZE: usize = 48; -pub const EXTENSION_FACTOR: usize = 2; diff --git a/kate/recovery/src/couscous.rs b/kate/recovery/src/couscous.rs index 902e261..5a8b13b 100644 --- a/kate/recovery/src/couscous.rs +++ b/kate/recovery/src/couscous.rs @@ -3,5 +3,5 @@ use dusk_plonk::commitment_scheme::kzg10::PublicParameters; pub fn public_params() -> PublicParameters { let pp_bytes = include_bytes!("../../src/pp_1024.data"); PublicParameters::from_slice(pp_bytes) - .expect("Deserialising of public parameters should work for serialised pp") + .expect("Deserializing of public parameters should work for serialized pp") } diff --git a/kate/recovery/src/lib.rs b/kate/recovery/src/lib.rs index 174dced..deca212 100644 --- a/kate/recovery/src/lib.rs +++ b/kate/recovery/src/lib.rs @@ -2,7 +2,6 @@ pub mod com; pub mod commitments; -pub mod config; pub mod data; pub mod matrix; pub mod proof; diff --git a/kate/recovery/src/matrix.rs b/kate/recovery/src/matrix.rs index ee69732..1f61abd 100644 --- a/kate/recovery/src/matrix.rs +++ b/kate/recovery/src/matrix.rs @@ -1,4 +1,4 @@ -use crate::config::{self, CHUNK_SIZE}; +use avail_core::constants::kate::{CHUNK_SIZE, EXTENSION_FACTOR}; use core::{ convert::TryInto, fmt::{Display, Formatter, Result}, @@ -12,8 +12,6 @@ use sp_std::vec; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; -const EXTENSION_FACTOR_U32: u32 = config::EXTENSION_FACTOR as u32; - /// Position of a cell in the the matrix. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Default, Debug, Clone, Copy, Hash, Eq, PartialEq, Constructor)] @@ -52,7 +50,7 @@ impl Display for Position { } impl Position { - /// Refrence in format `block_number:column_number:row_number` + /// Reference in format `block_number:column_number:row_number` #[cfg(feature = "std")] pub fn reference(&self, block_number: u32) -> String { format!("{}:{}", block_number, self) @@ -77,7 +75,7 @@ pub struct Partition { pub struct RowIndex(pub u32); impl RowIndex { - /// Refrence in format `block_number:row_number` + /// Reference in format `block_number:row_number` #[cfg(feature = "std")] pub fn reference(&self, block_number: u32) -> String { format!("{}:{}", block_number, self.0) @@ -144,7 +142,7 @@ impl Dimensions { } /// Creates a `Dimension` without checking whether parameters are non-zero. This results in - /// undefined behaviour if any parameter is zero. + /// undefined behavior if any parameter is zero. /// /// # Safety /// Parameters `rows` and `cols` must not be zero. @@ -214,7 +212,7 @@ impl Dimensions { /// Extended matrix rows count. pub fn extended_rows(&self) -> u32 { - u32::from(self.rows.get()) * EXTENSION_FACTOR_U32 + u32::from(self.rows.get()) * EXTENSION_FACTOR } /// List of data row indexes in the extended matrix. @@ -228,7 +226,7 @@ impl Dimensions { let last_row = self.extended_data_row(cells.end - 1); let data = (first_row..=last_row) - .step_by(config::EXTENSION_FACTOR) + .step_by(EXTENSION_FACTOR as usize) .collect::>(); Some(data) } @@ -270,7 +268,7 @@ impl Dimensions { /// Extended matrix data row index of cell in the data matrix. fn extended_data_row(&self, cell: u32) -> u32 { - (cell / u32::from(self.cols.get())) * EXTENSION_FACTOR_U32 + (cell / u32::from(self.cols.get())) * EXTENSION_FACTOR } /// Extended matrix data position of a cell in the data matrix. @@ -318,7 +316,7 @@ impl Dimensions { pub fn iter_extended_data_positions(&self) -> impl Iterator { let rows: u32 = self.rows.get().into(); let cols = self.cols.get(); - (0..rows).flat_map(move |row| (0..cols).map(move |col| (row * EXTENSION_FACTOR_U32, col))) + (0..rows).flat_map(move |row| (0..cols).map(move |col| (row * EXTENSION_FACTOR, col))) } /// Generates cell positions for given block partition diff --git a/kate/recovery/src/proof.rs b/kate/recovery/src/proof.rs index ef81257..514e835 100644 --- a/kate/recovery/src/proof.rs +++ b/kate/recovery/src/proof.rs @@ -9,7 +9,8 @@ use dusk_plonk::{ }; use thiserror_no_std::Error; -use crate::{config::COMMITMENT_SIZE, data::Cell, matrix::Dimensions}; +use crate::{data::Cell, matrix::Dimensions}; +use avail_core::constants::kate::COMMITMENT_SIZE; #[derive(Error, Debug)] pub enum Error { diff --git a/kate/src/com.rs b/kate/src/com.rs index 328b7a8..df88738 100644 --- a/kate/src/com.rs +++ b/kate/src/com.rs @@ -10,6 +10,7 @@ use std::{ use avail_core::{ const_generic_asserts::{USizeGreaterOrEq, USizeSafeCastToU32, UsizeEven, UsizeNonZero}, + constants::kate::{DATA_CHUNK_SIZE, EXTENSION_FACTOR}, data_lookup::Error as DataLookupError, ensure, AppExtrinsic, AppId, BlockLengthColumns, BlockLengthRows, DataLookup, }; @@ -39,8 +40,8 @@ use thiserror_no_std::Error; use crate::{ com::kzg10::commitment::Commitment, config::{ - COL_EXTENSION, DATA_CHUNK_SIZE, EXTENSION_FACTOR, MAXIMUM_BLOCK_SIZE, MINIMUM_BLOCK_SIZE, - PROOF_SIZE, ROW_EXTENSION, SCALAR_SIZE, + COL_EXTENSION, MAXIMUM_BLOCK_SIZE, MINIMUM_BLOCK_SIZE, PROOF_SIZE, ROW_EXTENSION, + SCALAR_SIZE, }, metrics::Metrics, padded_len_of_pad_iec_9797_1, BlockDimensions, Seed, TryFromBlockDimensionsError, LOG_TARGET, @@ -90,7 +91,7 @@ pub enum Error { /// The base grid width, before extension, does not fit cleanly into a domain for FFTs BaseGridDomainSizeInvalid(usize), /// The extended grid width does not fit cleanly into a domain for FFTs - ExtendedGridDomianSizeInvalid(usize), + ExtendedGridDomainSizeInvalid(usize), IndexOutOfRange, ConversionFailed, } @@ -107,8 +108,8 @@ impl From for Error { } } -/// We cannot derive `PartialEq` becasue `PlonkError` does not support it in the current version. -/// and we only need to double check its discriminat for testing. +/// We cannot derive `PartialEq` because `PlonkError` does not support it in the current version. +/// and we only need to double check its discriminant for testing. /// Only needed on tests by now. #[cfg(test)] impl PartialEq for Error { @@ -304,7 +305,6 @@ fn extend_column_with_zeros(column: &[BlsScalar], height: usize) -> Vec Result { - // TODO: Better error type for BlsScalar case? let scalar_size_chunk = <[u8; SCALAR_SIZE]>::try_from(chunk).map_err(|_| Error::InvalidChunkLength)?; BlsScalar::from_bytes(&scalar_size_chunk).map_err(|_| Error::CellLengthExceeded) @@ -376,8 +376,6 @@ pub fn par_extend_data_matrix( Ok(ext_matrix) } -//TODO cache extended data matrix -//TODO explore faster Variable Base Multi Scalar Multiplication pub fn build_proof( public_params: &kzg10::PublicParameters, block_dims: BlockDimensions, @@ -451,7 +449,12 @@ pub fn build_proof( return; }; - // row has to be a power of 2, otherwise interpolate() function panics TODO: cache evaluations + // # SAFETY: "`interpolate` function panics if row length is not equal to + // `block_dims.cols.next_power_of_two()`, which is true if `COL_EXTENSION` is 1. + const_assert_eq!(COL_EXTENSION.get(), 1); + // # SAFETY: `interpolate` function panics if the following debug assertion is not met, + // so it would simplify the location of that error. + debug_assert_eq!(row.len(), cols.next_power_of_two()); let poly = Evaluations::from_vec_and_domain(row, row_eval_domain).interpolate(); let witness = prover_key.compute_single_witness(&poly, &row_dom_x_pts[c_index]); @@ -622,13 +625,16 @@ pub fn scalars_to_rows( #[cfg(test)] mod tests { - use avail_core::DataLookup; + use avail_core::{ + constants::kate::{CHUNK_SIZE, COMMITMENT_SIZE, DATA_CHUNK_SIZE}, + DataLookup, + }; use dusk_bytes::Serializable; use dusk_plonk::bls12_381::BlsScalar; use hex_literal::hex; use kate_recovery::{ com::*, - commitments, config, + commitments, data::{self, DataCell}, matrix::{Dimensions, Position}, proof, @@ -645,7 +651,6 @@ mod tests { use super::*; use crate::{ com::{pad_iec_9797_1, par_extend_data_matrix, BlockDimensions}, - config::DATA_CHUNK_SIZE, metrics::IgnoreMetrics, padded_len, }; @@ -737,7 +742,6 @@ mod tests { #[test] #[cfg(not(feature = "maximum-block-size"))] fn test_flatten_block() { - use kate_recovery::config::CHUNK_SIZE; use static_assertions::const_assert; let extrinsics: Vec = vec![ @@ -928,7 +932,7 @@ mod tests { #![proptest_config(ProptestConfig::with_cases(20))] #[test] // newapi done - fn verify_commitmnets_missing_row(ref xts in app_extrinsics_strategy()) { + fn verify_commitments_missing_row(ref xts in app_extrinsics_strategy()) { let (layout, commitments, dims, matrix) = par_build_commitments::(BlockLengthRows(64), BlockLengthColumns(16), xts, Seed::default(), &IgnoreMetrics{}).unwrap(); let index = DataLookup::from_id_and_len_iter(layout.into_iter()).unwrap(); @@ -1229,10 +1233,9 @@ Let's see how this gets encoded and then reconstructed by sampling only some dat assert_eq!(row.len(), len); println!("Row: {:?}", row); - let commitment: [u8; config::COMMITMENT_SIZE] = - commit(&prover_key, row_eval_domain, row.clone()) - .map(|com| com.to_bytes()) - .unwrap(); + let commitment: [u8; COMMITMENT_SIZE] = commit(&prover_key, row_eval_domain, row.clone()) + .map(|com| com.to_bytes()) + .unwrap(); println!("Commitment: {commitment:?}"); // We artificially extend the matrix by doubling values, this is not proper erasure coding. diff --git a/kate/src/gridgen/mod.rs b/kate/src/gridgen/mod.rs index afd9a1c..e61e381 100644 --- a/kate/src/gridgen/mod.rs +++ b/kate/src/gridgen/mod.rs @@ -4,7 +4,9 @@ use crate::pmp::{ merlin::Transcript, traits::Committer, }; -use avail_core::{app_extrinsic::AppExtrinsic, ensure, AppId, DataLookup}; +use avail_core::{ + app_extrinsic::AppExtrinsic, constants::kate::DATA_CHUNK_SIZE, ensure, AppId, DataLookup, +}; use codec::Encode; use core::{ cmp::{max, min}, @@ -25,7 +27,6 @@ use thiserror_no_std::Error; use crate::{ com::{Cell, Error}, - config::DATA_CHUNK_SIZE, Seed, }; @@ -84,7 +85,7 @@ impl EvaluationGrid { }, ); - // Convert each grup of extrinsics into scalars + // Convert each group of extrinsics into scalars let scalars_by_app = grouped .into_iter() .map(|(id, datas)| { @@ -392,7 +393,7 @@ pub fn multiproof_block( }) } -/// Dimensions of the multiproof grid. These are guarenteed to cleanly divide `grid_dims`. +/// Dimensions of the multiproof grid. These are guaranteed to cleanly divide `grid_dims`. /// `target_dims` must cleanly divide `grid_dims`. #[allow(clippy::arithmetic_side_effects)] pub fn multiproof_dims(grid: Dimensions, target: Dimensions) -> Option { diff --git a/kate/src/gridgen/tests/formatting.rs b/kate/src/gridgen/tests/formatting.rs index 76b0fed..dd93cc0 100644 --- a/kate/src/gridgen/tests/formatting.rs +++ b/kate/src/gridgen/tests/formatting.rs @@ -1,4 +1,4 @@ -use avail_core::{AppExtrinsic, AppId, DataLookup}; +use avail_core::{constants::kate::DATA_CHUNK_SIZE, AppExtrinsic, AppId, DataLookup}; use hex_literal::hex; use kate_recovery::{ com::{app_specific_cells, decode_app_extrinsics, reconstruct_extrinsics}, @@ -9,7 +9,6 @@ use nalgebra::base::DMatrix; use poly_multiproof::traits::AsBytes; use crate::{ - config::DATA_CHUNK_SIZE, gridgen::{tests::sample_cells, ArkScalar, EvaluationGrid}, Seed, }; diff --git a/kate/src/lib.rs b/kate/src/lib.rs index dfe68a1..5e575df 100644 --- a/kate/src/lib.rs +++ b/kate/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![deny(clippy::arithmetic_side_effects)] -use avail_core::{BlockLengthColumns, BlockLengthRows}; +use avail_core::{constants::kate::DATA_CHUNK_SIZE, BlockLengthColumns, BlockLengthRows}; use core::{ convert::TryInto, num::{NonZeroU32, TryFromIntError}, @@ -13,8 +13,6 @@ use sp_arithmetic::traits::SaturatedConversion; use static_assertions::const_assert_ne; use thiserror_no_std::Error; -use crate::config::DATA_CHUNK_SIZE; - pub const LOG_TARGET: &str = "kate"; pub const U32_USIZE_ERR: &str = "`u32` cast to `usize` overflows, unsupported platform"; @@ -29,14 +27,9 @@ pub mod config { use super::{BlockLengthColumns, BlockLengthRows}; use core::num::NonZeroU16; - // TODO: Delete this? not used anywhere - pub const SCALAR_SIZE_WIDE: usize = 64; - pub const SCALAR_SIZE: usize = 32; - pub const DATA_CHUNK_SIZE: usize = 31; // Actual chunk size is 32 after 0 padding is done - pub const EXTENSION_FACTOR: u32 = 2; pub const ROW_EXTENSION: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(2) }; - pub const COL_EXTENSION: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(1) }; + pub const COL_EXTENSION: NonZeroU16 = NonZeroU16::MIN; pub const PROVER_KEY_SIZE: u32 = 48; pub const PROOF_SIZE: usize = 48; // MINIMUM_BLOCK_SIZE, MAX_BLOCK_ROWS and MAX_BLOCK_COLUMNS have to be a power of 2 because of the FFT functions requirements