diff --git a/code/Cargo.lock b/code/Cargo.lock index 405117a320e..1f68f4bd34d 100644 --- a/code/Cargo.lock +++ b/code/Cargo.lock @@ -2013,6 +2013,7 @@ dependencies = [ "sha2 0.10.7", "sp-arithmetic", "sp-core", + "sp-io", "sp-runtime", "sp-std 5.0.0", "thiserror-core", diff --git a/code/parachain/frame/composable-traits/Cargo.toml b/code/parachain/frame/composable-traits/Cargo.toml index 9cf42902669..23e38dbdcd3 100644 --- a/code/parachain/frame/composable-traits/Cargo.toml +++ b/code/parachain/frame/composable-traits/Cargo.toml @@ -15,6 +15,7 @@ polkadot-parachain = { workspace = true, default-features = false } proxy = { default-features = false, workspace = true } sp-arithmetic = { default-features = false, workspace = true } sp-core = { default-features = false, workspace = true } +sp-io = { default-features = false, workspace = true } sp-runtime = { default-features = false, workspace = true } sp-std = { default-features = false, workspace = true } xcm = { default-features = false, workspace = true } diff --git a/code/parachain/frame/composable-traits/src/centauri.rs b/code/parachain/frame/composable-traits/src/centauri.rs index dab577d8982..ab3d7a7001a 100644 --- a/code/parachain/frame/composable-traits/src/centauri.rs +++ b/code/parachain/frame/composable-traits/src/centauri.rs @@ -5,7 +5,7 @@ use xc_core::transport::ibc::ics20::Memo; pub struct Map; impl Map { - pub fn try_from_xc_memo(value: Memo) -> Option { + pub fn try_from_xc_memo(value: Memo) -> Option { value.forward.map(|value| { let next: Option> = value.next.and_then(|e| Map::try_from_xc_memo(*e)).map(Box::new); diff --git a/code/parachain/frame/composable-traits/src/lib.rs b/code/parachain/frame/composable-traits/src/lib.rs index 88ad71c2d0d..15490e6ed3a 100644 --- a/code/parachain/frame/composable-traits/src/lib.rs +++ b/code/parachain/frame/composable-traits/src/lib.rs @@ -54,7 +54,6 @@ pub mod fnft; pub mod governance; pub mod oracle; pub mod prelude; -pub mod liquidation; pub mod privilege; pub mod staking; pub mod storage; diff --git a/code/parachain/frame/composable-traits/src/liquidation.rs b/code/parachain/frame/composable-traits/src/liquidation.rs deleted file mode 100644 index 75f2e559a83..00000000000 --- a/code/parachain/frame/composable-traits/src/liquidation.rs +++ /dev/null @@ -1,39 +0,0 @@ -use codec::Encode; -use sp_runtime::DispatchError; -use sp_std::vec::*; - -use crate::defi::{DeFiEngine, Sell}; - -/// An object from which we can initiate liquidations from. -/// Does not cares if liquidation was completed or not, neither can reasonably provide that -/// information. Off-chain can join relevant ids if needed. -/// `configuration` - optional list of liquidations strategies -pub trait Liquidation: DeFiEngine { - type OrderId; - type LiquidationStrategyId; - - /// Initiate a liquidation, this operation should be executed as fast as possible. - fn liquidate( - from_to: &Self::AccountId, - order: Sell, - configuration: sp_std::vec::Vec, - ) -> Result; -} - -/// generic transaction which can target any pallet and any method in any parachain (local or -/// remote) -/// so it must be encoded in format with widest possible values to incorporate some chains we do -/// now (similar on how XCM is modelled) -#[derive(Encode)] -pub struct XcmLiquidation { - pallet: u8, - method: u8, - order: Sell, - strategy: Vec, -} - -impl XcmLiquidation { - pub fn new(pallet: u8, method: u8, order: Sell, strategy: Vec) -> Self { - Self { pallet, method, order, strategy } - } -} diff --git a/code/parachain/frame/cosmwasm/src/crypto.rs b/code/parachain/frame/cosmwasm/src/crypto.rs index 318d786472b..01a839f68ec 100644 --- a/code/parachain/frame/cosmwasm/src/crypto.rs +++ b/code/parachain/frame/cosmwasm/src/crypto.rs @@ -1,7 +1,6 @@ use crate::{Config, Pallet, SUBSTRATE_ECDSA_SIGNATURE_LEN}; use sp_std::{vec, vec::Vec}; -// TODO(cor): move these out of the `impl` as they do not refer to `self` or `Self`. use sp_core::{ecdsa, ed25519}; impl Pallet { pub(crate) fn do_secp256k1_recover_pubkey( @@ -69,6 +68,11 @@ impl Pallet { signatures: &[&[u8]], public_keys: &[&[u8]], ) -> bool { + + // https://substrate.stackexchange.com/questions/9754/sp-iocryptoed25519-batch-verify-was-removed-amid-polkadot-0-9-39-and-0-9-4 + + + let mut messages = messages.to_vec(); let mut public_keys = public_keys.to_vec(); @@ -85,38 +89,10 @@ impl Pallet { return false } - // Each batch verification process is started with `start_batch_verify` and ended with - // `finish_batch_verify`. When it is started, it needs to be properly finished. But this - // means `finish_batch_verify` will verify the previously pushed verification tasks. We - // converted all the public keys and signatures in-front not to unnecessarily verify - // previously pushed signatures. (Note that there is no function to ditch the batch - // verification early without doing any verification) - let mut verify_items = Vec::with_capacity(messages.len()); - for ((message, signature), public_key) in - messages.iter().zip(signatures.iter()).zip(public_keys.iter()) - { - match ((*signature).try_into(), (*public_key).try_into()) { - (Ok(signature), Ok(public_key)) => - verify_items.push((signature, message, public_key)), - _ => return false, - } - } + messages.iter().zip(signatures).zip(public_keys).all(|((m, s), p)| { + Self::do_ed25519_verify(m, s, p) + }) - //sp_io::crypto::start_batch_verify(); - - for (signature, message, public_key) in verify_items { - // This is very unlikely to fail. Because this only fails if the verification task - // cannot be spawned internally. Note that the actual verification is only done when - // `finish_batch_verify` is called. - return false; - // sp_io::Crypto::start_batch_verify(&mut self) - // if !sp_io::crypto::ed25519_batch_verify(&signature, message, &public_key) { - // let _ = sp_io::crypto::finish_batch_verify(); - // return false - // } - } - return true; - //sp_io::crypto::finish_batch_verify() } pub(crate) fn do_ed25519_verify(message: &[u8], signature: &[u8], public_key: &[u8]) -> bool { @@ -124,6 +100,7 @@ impl Pallet { Ok(signature) => signature, Err(_) => return false, }; + let public_key: ed25519::Public = match public_key.try_into() { Ok(public_key) => public_key, diff --git a/code/parachain/frame/cosmwasm/src/lib.rs b/code/parachain/frame/cosmwasm/src/lib.rs index 191223fde31..af1b4902316 100644 --- a/code/parachain/frame/cosmwasm/src/lib.rs +++ b/code/parachain/frame/cosmwasm/src/lib.rs @@ -462,6 +462,7 @@ pub mod pallet { gas: u64, message: ContractMessageOf, ) -> DispatchResultWithPostInfo { + T::ExecuteWasmOrigin::ensure_origin(origin.clone())?; let who = ensure_signed(origin)?; let mut shared = Self::do_create_vm_shared(gas, InitialStorageMutability::ReadWrite);