Skip to content

Commit

Permalink
repaced
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Aug 27, 2023
1 parent ee4f738 commit 56f6167
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 73 deletions.
1 change: 1 addition & 0 deletions code/Cargo.lock

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

1 change: 1 addition & 0 deletions code/parachain/frame/composable-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion code/parachain/frame/composable-traits/src/centauri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<pallet_ibc::ics20::MemoData> {
pub fn try_from_xc_memo(value: Memo) -> Option<pallet_ibc::ics20::MemoData> {
value.forward.map(|value| {
let next: Option<Box<pallet_ibc::ics20::MemoData>> =
value.next.and_then(|e| Map::try_from_xc_memo(*e)).map(Box::new);
Expand Down
1 change: 0 additions & 1 deletion code/parachain/frame/composable-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 0 additions & 39 deletions code/parachain/frame/composable-traits/src/liquidation.rs

This file was deleted.

41 changes: 9 additions & 32 deletions code/parachain/frame/cosmwasm/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -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<T: Config> Pallet<T> {
pub(crate) fn do_secp256k1_recover_pubkey(
Expand Down Expand Up @@ -69,6 +68,11 @@ impl<T: Config> Pallet<T> {
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();

Expand All @@ -85,45 +89,18 @@ impl<T: Config> Pallet<T> {
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 {
let signature: ed25519::Signature = match signature.try_into() {
Ok(signature) => signature,
Err(_) => return false,
};


let public_key: ed25519::Public = match public_key.try_into() {
Ok(public_key) => public_key,
Expand Down
1 change: 1 addition & 0 deletions code/parachain/frame/cosmwasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ pub mod pallet {
gas: u64,
message: ContractMessageOf<T>,
) -> DispatchResultWithPostInfo {

T::ExecuteWasmOrigin::ensure_origin(origin.clone())?;
let who = ensure_signed(origin)?;
let mut shared = Self::do_create_vm_shared(gas, InitialStorageMutability::ReadWrite);
Expand Down

0 comments on commit 56f6167

Please sign in to comment.