Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substrate/upgrade v1.0.0 #39

Closed
wants to merge 4 commits into from
Closed
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
1,443 changes: 1,096 additions & 347 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ members = [
"nomad/merkle",
]
[patch.crates-io]
# Substrate (polkadot-v0.9.37).
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-core-hashing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-storage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-debug-derive = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-weights = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-staking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-state-machine = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }
# Substrate (polkadot-v1.0.0).
sp-core = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-core-hashing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-std = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-storage = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-debug-derive = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-weights = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
frame-support = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-inherents = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-staking = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-state-machine = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-tracing = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-version = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-wasm-interface = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

[profile.dev.package]
nalgebra = { opt-level = 3 }
Expand Down
7 changes: 3 additions & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static_assertions = "1.1.0"
thiserror-no-std = "2.0.2"

# Substrate
beefy-merkle-tree = { git = "https://github.com/paritytech/substrate.git/", branch = "polkadot-v0.9.37", default-features = false, optional = true }
binary-merkle-tree = { git = "https://github.com/paritytech/substrate.git/", branch = "polkadot-v1.0.0", default-features = false, optional = true }
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-arithmetic = { version = "*", default-features = false }
Expand Down Expand Up @@ -49,7 +49,7 @@ std = [
"sp-trie/std",
"sp-arithmetic/std",
"hash256-std-hasher/std",
"beefy-merkle-tree?/std",
"binary-merkle-tree?/std",
"derive_more/display",
"sp-runtime-interface?/std",
"sp-runtime?/std",
Expand All @@ -59,11 +59,10 @@ runtime = [
"sp-runtime-interface",
"sp-runtime",
"frame-support",
"beefy-merkle-tree",
"binary-merkle-tree",
]

header-backward-compatibility-test = []
try-runtime = [
"runtime",
"sp-runtime/try-runtime",
]
14 changes: 7 additions & 7 deletions core/src/data_proof.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#[cfg(feature = "runtime")]
use beefy_merkle_tree::MerkleProof;
use binary_merkle_tree::MerkleProof;
use codec::{Decode, Encode};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::H256;
use sp_std::vec::Vec;
use thiserror_no_std::Error;
/// Wrapper of `beefy-merkle-tree::MerkleProof` with codec support.
/// Wrapper of `binary-merkle-tree::MerkleProof` with codec support.
#[derive(Clone, Debug, PartialEq, Eq, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct DataProof {
Expand All @@ -30,7 +30,7 @@ pub struct DataProof {
pub leaf: H256,
}

/// Conversion error from `beefy-merkle-tree::MerkleProof`.
/// Conversion error from `binary-merkle-tree::MerkleProof`.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Error)]
pub enum DataProofTryFromError {
/// Root cannot be converted into `H256`.
Expand Down Expand Up @@ -125,7 +125,7 @@ mod test {
let leaves = leaves();
let index = min(leaf_index, leaves.len() - 1);

let mut proof = beefy_merkle_tree::merkle_proof::<Keccak256, _, _>(leaves, index);
let mut proof = binary_merkle_tree::merkle_proof::<Keccak256, _, _>(leaves, index);
proof.leaf_index = leaf_index;

proof
Expand Down Expand Up @@ -187,10 +187,10 @@ mod test {
#[test_case(merkle_proof_idx(6) => expected_data_proof_6(); "From merkle proof 6")]
#[test_case(merkle_proof_idx(7) => Err(DataProofTryFromError::InvalidLeafIndex); "From invalid leaf index")]
#[test_case(invalid_merkle_proof_zero_leaves() => Err(DataProofTryFromError::InvalidNumberOfLeaves); "From invalid number of leaves")]
fn from_beefy(
beefy_proof: MerkleProof<H256, Vec<u8>>,
fn from_binary(
binary_proof: MerkleProof<H256, Vec<u8>>,
) -> Result<DataProof, DataProofTryFromError> {
let data_proof = DataProof::try_from(&beefy_proof)?;
let data_proof = DataProof::try_from(&binary_proof)?;
Ok(data_proof)
}
}
2 changes: 1 addition & 1 deletion core/src/keccak256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sp_core::{Hasher, RuntimeDebug};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

/// Keccak 256 wrapper which supports `beefy-merkle-tree::Hasher`.
/// Keccak 256 wrapper which supports `binary-merkle-tree::Hasher`.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Keccak256 {}
Expand Down
2 changes: 1 addition & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(clippy::integer_arithmetic)]
#![deny(clippy::arithmetic_side_effects)]

use codec::{Decode, Encode, MaxEncodedLen};
use derive_more::{Add, Constructor, Deref, Display, Into, Mul};
Expand Down
2 changes: 1 addition & 1 deletion core/src/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::{Hasher, RuntimeDebug};

/// Sha2 256 wrapper which supports `beefy-merkle-tree::Hasher`.
/// Sha2 256 wrapper which supports `binary-merkle-tree::Hasher`.
#[derive(PartialEq, Eq, Clone, RuntimeDebug, TypeInfo)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct ShaTwo256 {}
Expand Down
3 changes: 2 additions & 1 deletion kate/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn flatten_and_pad_block(
assert_eq!(rem, 0);
}

#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
// SAFETY: `chunk_size` comes from `NonZeroU32::get(...)` so we can safetly use `/`.
let last = block_dims_size.saturating_sub(padded_block.len()) / chunk_size;
for _ in 0..last {
Expand Down Expand Up @@ -213,6 +213,7 @@ pub fn get_block_dimensions(
// we must minimize number of rows, to minimize header size
// (performance wise it doesn't matter)
let nz_max_cols = NonZeroU32::new(max_cols.0).ok_or(Error::ZeroDimension)?;
#[allow(clippy::arithmetic_side_effects)]
let (cols, rows) = if total_cells > max_cols.0 {
(max_cols, BlockLengthRows(total_cells / nz_max_cols))
} else {
Expand Down
16 changes: 9 additions & 7 deletions kate/src/gridgen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ impl EvaluationGrid {

/// Returns a list of `(index, row)` pairs for the underlying rows of an application.
/// Returns `None` if the `app_id` cannot be found, or if the provided `orig_dims` are invalid.
#[allow(clippy::type_complexity)]
pub fn app_rows(
&self,
app_id: AppId,
Expand All @@ -168,9 +169,9 @@ impl EvaluationGrid {
// SAFETY: `origin_dims.rows is NonZeroU16`
// Compiler checks that `Dimensions::rows()` returns a `NonZeroU16` using the expression
// `NonZeroU16::get(x)` instead of `x.get()`.
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
let h_mul: usize = rows / usize::from(NonZeroU16::get(orig_dims.rows()));
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
let row_from_lineal_index = |cols, lineal_index| {
let lineal_index =
usize::try_from(lineal_index).map_err(|_| AppRowError::LinealIndexOverflows)?;
Expand All @@ -189,7 +190,7 @@ impl EvaluationGrid {
// SAFETY: This won't overflow because `h_mul = rows / orig_dim.rows()` and `*_y < rows)
debug_assert!(start_y < rows);
debug_assert!(end_y < rows);
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
let (new_start_y, new_end_y) = (start_y * h_mul, end_y * h_mul);

let app_rows = (new_start_y..=new_end_y)
Expand Down Expand Up @@ -359,7 +360,7 @@ pub struct CellBlock {
/// `mp_grid_dims` is the size of the multiproof grid, which `x,y` lies in.
/// For example, a 256x256 grid could be converted to a 4x4 target size multiproof grid, by making 16 multiproofs
/// of size 64x64.
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
pub fn multiproof_block(
x: usize,
y: usize,
Expand Down Expand Up @@ -389,6 +390,7 @@ pub fn multiproof_block(

/// Dimensions of the multiproof grid. These are guarenteed 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<Dimensions> {
let cols = min(grid.cols(), target.cols());
let rows = min(grid.rows(), target.rows());
Expand Down Expand Up @@ -440,7 +442,7 @@ pub fn domain_points(n: usize) -> Result<Vec<ArkScalar>, Error> {
}

/// SAFETY: As `multiple` is a `NonZeroU16` we can safetly make the following ops.
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
fn round_up_to_multiple(input: usize, multiple: NonZeroU16) -> usize {
let multiple: usize = multiple.get().into();
let n_multiples = input.saturating_add(multiple - 1) / multiple;
Expand All @@ -458,7 +460,7 @@ pub(crate) fn pad_to_bls_scalar(a: impl AsRef<[u8]>) -> Result<ArkScalar, Error>
ArkScalar::from_bytes(&buf).map_err(Error::MultiproofError)
}

#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
pub(crate) fn random_scalar(rng: &mut ChaChaRng) -> ArkScalar {
let mut raw_scalar = [0u8; SCALAR_SIZE];

Expand All @@ -472,7 +474,7 @@ pub(crate) fn random_scalar(rng: &mut ChaChaRng) -> ArkScalar {
}

#[cfg(test)]
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
mod unit_tests {
use super::*;
use proptest::{prop_assert_eq, proptest};
Expand Down
6 changes: 3 additions & 3 deletions kate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(clippy::integer_arithmetic)]
#![deny(clippy::arithmetic_side_effects)]

use avail_core::{BlockLengthColumns, BlockLengthRows};
use core::{
Expand Down Expand Up @@ -179,7 +179,7 @@ pub mod gridgen;
/// There is a unit test to ensure this formula match with the current
/// IEC 9797 1 algorithm we implemented. See `fn pad_iec_9797_1`
#[inline]
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
fn padded_len_of_pad_iec_9797_1(len: u32) -> u32 {
let len_plus_one = len.saturating_add(1);
let offset = (DATA_CHUNK_SIZE - (len_plus_one as usize % DATA_CHUNK_SIZE)) % DATA_CHUNK_SIZE;
Expand All @@ -189,7 +189,7 @@ fn padded_len_of_pad_iec_9797_1(len: u32) -> u32 {
}

/// Calculates the padded len based of initial `len`.
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
pub fn padded_len(len: u32, chunk_size: NonZeroU32) -> u32 {
let iec_9797_1_len = padded_len_of_pad_iec_9797_1(len);

Expand Down
7 changes: 5 additions & 2 deletions nomad/signature/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ use k256::{
PublicKey as K256PublicKey,
};
use scale_info::TypeInfo;
use sp_core::{Hasher as _, H160, H256, U256};
use sp_runtime::{traits::Keccak256, RuntimeDebug};
use sp_core::{H160, H256, U256};
use sp_runtime::{
traits::{Hash, Keccak256},
RuntimeDebug,
};
use thiserror_no_std::Error;

#[cfg(feature = "std")]
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "nightly-2022-11-15"
channel = "nightly-2023-05-22"
components = ["rustfmt", "clippy", "llvm-tools-preview"]
profile = "minimal"
targets = ["wasm32-unknown-unknown"]
Loading