remove WASM_MAGIC (#2832)

* remove WASM_MAGIC

* fix test warnings
This commit is contained in:
Robert Habermeier
2021-04-07 11:00:22 +02:00
committed by GitHub
parent e67f31cc49
commit 251b6ca7bf
5 changed files with 7 additions and 39 deletions
@@ -259,12 +259,7 @@ fn test_genesis_head(size: usize) -> HeadData {
}
fn test_validation_code(size: usize) -> ValidationCode {
let mut validation_code = vec![0u8; size as usize];
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
let _ = validation_code.splice(
..crate::WASM_MAGIC.len(),
crate::WASM_MAGIC.iter().cloned(),
).collect::<Vec<_>>();
let validation_code = vec![0u8; size as usize];
ValidationCode(validation_code)
}
-4
View File
@@ -59,10 +59,6 @@ pub use impls::ToAuthor;
pub type NegativeImbalance<T> = <pallet_balances::Pallet<T> as Currency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;
/// The sequence of bytes a valid wasm module binary always starts with. Apart from that it's also a
/// valid wasm module.
pub const WASM_MAGIC: &[u8] = &[0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00];
/// We assume that an on-initialize consumes 1% of the weight on average, hence a single extrinsic
/// will not be allowed to consume more than `AvailableBlockRatio - 1%`.
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
+1 -6
View File
@@ -160,12 +160,7 @@ impl<T: frame_system::Config> Registrar for TestRegistrar<T> {
#[cfg(test)]
fn worst_validation_code() -> ValidationCode {
let mut validation_code = vec![0u8; 1000];
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
let _ = validation_code.splice(
..crate::WASM_MAGIC.len(),
crate::WASM_MAGIC.iter().cloned(),
).collect::<Vec<_>>();
let validation_code = vec![0u8; 1000];
validation_code.into()
}
+5 -19
View File
@@ -17,7 +17,6 @@
//! Module to handle parathread/parachain registration and related fund management.
//! In essence this is a simple wrapper around `paras`.
use crate::WASM_MAGIC;
use sp_std::{prelude::*, result};
use frame_support::{
decl_storage, decl_module, decl_error, decl_event, ensure,
@@ -133,8 +132,6 @@ decl_error! {
CodeTooLarge,
/// Invalid para head data size.
HeadDataTooLarge,
/// The validation code provided doesn't start with the Wasm file magic string.
DefinitelyNotWasm,
/// Para is not a Parachain.
NotParachain,
/// Para is not a Parathread.
@@ -304,12 +301,7 @@ impl<T: Config> Registrar for Module<T> {
fn worst_validation_code() -> ValidationCode {
// TODO: Figure a way to allow bigger wasm in benchmarks?
let max_code_size = (T::MaxCodeSize::get()).min(4 * 1024 * 1024);
let mut validation_code = vec![0u8; max_code_size as usize];
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
let _ = validation_code.splice(
..crate::WASM_MAGIC.len(),
crate::WASM_MAGIC.iter().cloned(),
).collect::<Vec<_>>();
let validation_code = vec![0u8; max_code_size as usize];
validation_code.into()
}
@@ -378,7 +370,6 @@ impl<T: Config> Module<T> {
) -> Result<(ParaGenesisArgs, BalanceOf<T>), sp_runtime::DispatchError> {
ensure!(validation_code.0.len() <= T::MaxCodeSize::get() as usize, Error::<T>::CodeTooLarge);
ensure!(genesis_head.0.len() <= T::MaxHeadSize::get() as usize, Error::<T>::HeadDataTooLarge);
ensure!(validation_code.0.starts_with(WASM_MAGIC), Error::<T>::DefinitelyNotWasm);
let per_byte_fee = T::DataDepositPerByte::get();
let deposit = T::ParaDeposit::get()
@@ -557,12 +548,7 @@ mod tests {
}
fn test_validation_code(size: usize) -> ValidationCode {
let mut validation_code = vec![0u8; size as usize];
// Replace first bytes of code with "WASM_MAGIC" to pass validation test.
let _ = validation_code.splice(
..crate::WASM_MAGIC.len(),
crate::WASM_MAGIC.iter().cloned(),
).collect::<Vec<_>>();
let validation_code = vec![0u8; size as usize];
ValidationCode(validation_code)
}
@@ -811,7 +797,7 @@ mod tests {
Origin::signed(1),
1u32.into(),
vec![1; 3].into(),
WASM_MAGIC.to_vec().into(),
vec![1, 2, 3].into()
));
// 2 session changes to fully onboard.
@@ -827,7 +813,7 @@ mod tests {
Origin::signed(1),
1u32.into(),
vec![1; 3].into(),
WASM_MAGIC.to_vec().into(),
vec![1, 2, 3].into()
), Error::<Test>::AlreadyRegistered);
// By session 4, it is offboarded, and we can register again.
@@ -837,7 +823,7 @@ mod tests {
Origin::signed(1),
1u32.into(),
vec![1; 3].into(),
WASM_MAGIC.to_vec().into(),
vec![1, 2, 3].into()
));
});
}
@@ -16,7 +16,6 @@
//! A simple wrapper allowing `Sudo` to call into `paras` routines.
use crate::WASM_MAGIC;
use sp_std::prelude::*;
use frame_support::{
decl_error, decl_module, ensure,
@@ -47,8 +46,6 @@ decl_error! {
/// A DMP message couldn't be sent because it exceeds the maximum size allowed for a downward
/// message.
ExceedsMaxMessageSize,
/// The validation code provided doesn't start with the Wasm file magic string.
DefinitelyNotWasm,
/// Could not schedule para cleanup.
CouldntCleanup,
/// Not a parathread.
@@ -75,7 +72,6 @@ decl_module! {
genesis: ParaGenesisArgs,
) -> DispatchResult {
ensure_root(origin)?;
ensure!(genesis.validation_code.0.starts_with(WASM_MAGIC), Error::<T>::DefinitelyNotWasm);
runtime_parachains::schedule_para_initialize::<T>(id, genesis).map_err(|_| Error::<T>::ParaAlreadyExists)?;
Ok(())
}