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

Upgrade to Polkadot v0.9.42 #1263

Merged
merged 9 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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,117 changes: 689 additions & 428 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ members = [
# TODO.kevin: Move back to crates.io once it released 1.0
derive_more = { version = "0.99.17", git = "https://github.com/JelteF/derive_more" }

sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-core-hashing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-core-hashing = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }

# For pink-extension-runtime, it will introduce Substrate from crates-io which usually different with polkadot-branch
pink-extension = { path = "crates/pink/pink-extension" }
Expand Down
20 changes: 10 additions & 10 deletions crates/phactory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ prpc = { path = "../prpc" }
pink = { path = "../pink/runner", package = "pink-runner" }
pink-extension-runtime = { path = "../pink/pink-extension-runtime" }

sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", features = ["disable_target_static_assertions"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", features = ["disable_panic_handler", "disable_oom", "disable_allocator"] }
sp-runtime-interface = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", features = ["disable_target_static_assertions"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
parity-scale-codec = { package = "parity-scale-codec", version = "3.3", default-features = false, features = ["derive", "full", "chain-error"] }
scopeguard = { version = "1.1", default-features = false }

Expand All @@ -56,11 +56,11 @@ derive_more = "0.99.0"
hash-db = { version = "0.16.0", default-features = false }
num = { package = "num-traits", version = "0.2", default-features = false }
finality-grandpa = { version = "0.16.1", default-features = false, features = ["derive-codec"] }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }

fixed = "1.9.0"
fixed-sqrt = "0.2.4"
Expand Down
10 changes: 5 additions & 5 deletions crates/phactory/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ phala-crypto = { path = "../../../crates/phala-crypto" }
phala-mq = { path = "../../../crates/phala-mq" }
chain = { path = "../../../standalone/runtime", default-features = false, package = "phala-node-runtime" }

sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false, features = ["full_crypto"] }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false, features = ["full_crypto"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-consensus-grandpa = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false, features = ["full_crypto"] }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false, features = ["full_crypto"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
phala-git-revision = { path = "../../phala-git-revision" }

# for pruntime_client
Expand Down
32 changes: 24 additions & 8 deletions crates/phactory/api/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use alloc::vec;
use alloc::vec::Vec;
use parity_scale_codec::{Decode, Encode, Error as CodecError};
use sp_core::ByteArray as _;

use crate::prpc::{Signature, SignatureType};
pub use phala_crypto::{aead, ecdh, CryptoError};
Expand Down Expand Up @@ -39,6 +40,7 @@ impl EncryptedData {

#[derive(Clone, Debug)]
pub enum SignatureVerifyError {
InvalidPublic,
InvalidSignatureType,
InvalidSignature,
CertificateMissing,
Expand Down Expand Up @@ -97,11 +99,11 @@ impl Signature {
}
}

fn verify<T>(pubkey: &[u8], sig: &[u8], msg: &[u8]) -> bool
fn verify<T>(pubkey: &T::Public, sig: &T::Signature, msg: &[u8]) -> bool
where
T: sp_core::crypto::Pair,
{
T::verify_weak(sig, msg, pubkey)
T::verify(sig, msg, pubkey)
}

/// Wraps the message in the same format as it defined in Polkadot.js extension:
Expand Down Expand Up @@ -130,23 +132,37 @@ impl CertificateBody {
) -> Result<(), SignatureVerifyError> {
let valid = match sig_type {
SignatureType::Ed25519 => {
verify::<sp_core::ed25519::Pair>(&self.pubkey, signature, msg)
let public = sp_core::ed25519::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::ed25519::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::ed25519::Pair>(&public, &signature, msg)
}
SignatureType::Sr25519 => {
verify::<sp_core::sr25519::Pair>(&self.pubkey, signature, msg)
let public = sp_core::sr25519::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::sr25519::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::sr25519::Pair>(&public, &signature, msg)
}
SignatureType::Ecdsa => verify::<sp_core::ecdsa::Pair>(&self.pubkey, signature, msg),
SignatureType::Ecdsa => {
let public = sp_core::ecdsa::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::ecdsa::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::ecdsa::Pair>(&public, &signature, msg)
},
SignatureType::Ed25519WrapBytes => {
let wrapped = wrap_bytes(msg);
verify::<sp_core::ed25519::Pair>(&self.pubkey, signature, &wrapped)
let public = sp_core::ed25519::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::ed25519::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::ed25519::Pair>(&public, &signature, &wrapped)
}
SignatureType::Sr25519WrapBytes => {
let wrapped = wrap_bytes(msg);
verify::<sp_core::sr25519::Pair>(&self.pubkey, signature, &wrapped)
let public = sp_core::sr25519::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::sr25519::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::sr25519::Pair>(&public, &signature, &wrapped)
}
SignatureType::EcdsaWrapBytes => {
let wrapped = wrap_bytes(msg);
verify::<sp_core::ecdsa::Pair>(&self.pubkey, signature, &wrapped)
let public = sp_core::ecdsa::Public::from_slice(&self.pubkey).map_err(|_| SignatureVerifyError::InvalidPublic)?;
let signature = sp_core::ecdsa::Signature::from_slice(signature).ok_or(SignatureVerifyError::InvalidSignature)?;
verify::<sp_core::ecdsa::Pair>(&public, &signature, &wrapped)
}
};
if valid {
Expand Down
6 changes: 5 additions & 1 deletion crates/phactory/src/prpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use phala_types::{
WorkerEndpointPayload, WorkerPublicKey, WorkerRegistrationInfoV2,
};
use sp_application_crypto::UncheckedFrom;
use sp_core::ByteArray;
use tracing::{error, info};

type RpcResult<T> = Result<T, RpcError>;
Expand Down Expand Up @@ -1944,10 +1945,13 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> PhactoryApi for Rpc
signature,
} = req;
let receiver = try_decode_hex(&receiver).map_err(|_| from_display("Invalid receiver"))?;
let receiver = sr25519::Public::from_slice(&receiver).map_err(|_| from_display("Invalid receiver"))?;
let signature =
try_decode_hex(&signature).map_err(|_| from_display("Invalid signature"))?;
let signature = sr25519::Signature::from_slice(&signature).ok_or(from_display("Invalid signature"))?;

// Check the validity of the state request with the remote public key
if !sr25519::Pair::verify_weak(
if !sr25519::Pair::verify(
&signature,
wrap_content_to_sign(
&min_block_number.to_be_bytes(),
Expand Down
4 changes: 2 additions & 2 deletions crates/phala-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ edition = "2018"
resolver = "2"

[dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }

ring = { version = "0.16.20", default-features = false, features = ["alloc"] }
curve25519-dalek = { version = "2.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/phala-mq/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ hex = { version = "0.4.3", default-features = false, features = ['alloc'] }
derive_more = { version = "0.99", default-features = false, features = ["display"] }
parity-scale-codec = { version = "3.3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive"] }

spin = { version = "0.9", default-features = false, features = ["mutex", "use_ticket_mutex"], optional = true }
Expand Down
12 changes: 6 additions & 6 deletions crates/phala-node-rpc-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ codec = { package = "parity-scale-codec", version = "3.3" }
scale-info = { version = "2.3", default-features = false }

# primitives
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }

# client dependencies
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }

phala-mq = { path = "../../crates/phala-mq" }
phala-pallets = { path = "../../pallets/phala" }
Expand Down
2 changes: 1 addition & 1 deletion crates/phala-serde-more/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
serde = { version = "1.0.130", default-features = false, features = ["derive", "alloc"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
scale = { package = "parity-scale-codec", version = "3.3", default-features = false }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

Expand Down
10 changes: 5 additions & 5 deletions crates/phala-trie-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ repository = "https://github.com/Phala-Network/phala-blockchain"
[dependencies]
parity-scale-codec = { version = "3.3", default-features = false }
scale-info = { version = "2.3", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", features = ["full_crypto"] }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", features = ["full_crypto"] }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }

serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
hash-db = "0.16.0"
Expand All @@ -21,8 +21,8 @@ im = { version = "15", features = ["serde"] }
log = "0.4"

[dev-dependencies]
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", features = ["full_crypto"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", features = ["full_crypto"] }
hash256-std-hasher = { version = "0.15", default-features = false }
hex = "0.4"
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/phala-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hex = { version = "0.4", default-features = false, features = ["alloc"] }
serde = { version = "1.0.101", default-features = false, optional = true }
codec = { package = "parity-scale-codec", version = "3.3", default-features = false, features = ["full"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }

phala-mq = { path = "../../crates/phala-mq", default-features = false }
prpc = { path = "../../crates/prpc", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions crates/phaxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ phala-types = { path = "../phala-types" }
phala-node-rpc-ext-types = { path = "../phala-node-rpc-ext/types" }
phala-pallets = { path = "../../pallets/phala" }
jsonrpsee = "0.16.2"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41", default-features = false }
primitive-types = { version = "0.12.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
primitive-types = { version = "0.12.1", default-features = false }
2 changes: 1 addition & 1 deletion crates/pink-libs/subrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ base58 = { version = "0.2.0", default-features = false }

[dev-dependencies]
pink-extension-runtime = { version = "0.4", path = "../../pink/pink-extension-runtime" }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.41", default-features = false, features = ["std"] }
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42", default-features = false, features = ["std"] }

[features]
default = ["std"]
Expand Down
4 changes: 2 additions & 2 deletions crates/pink/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.41" }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
pink-extension = { path = "../pink-extension" }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [
"derive",
Expand Down
2 changes: 1 addition & 1 deletion crates/pink/pink-extension-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
[dependencies]
pink-extension = { version = "0.4.2", path = "../pink-extension" }
reqwest-env-proxy = { version = "0.1", path = "../../reqwest-env-proxy" }
sp-core = { version = "7" }
sp-core = { version = "7", features = ["full_crypto"] }
sp-runtime-interface = { version = "7", features = ["disable_target_static_assertions"] }
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls", "socks", "blocking"] }
log = "0.4"
Expand Down
8 changes: 5 additions & 3 deletions crates/pink/pink-extension-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@ impl<T: PinkRuntimeEnv, E: From<&'static str>> PinkExtBackend for DefaultPinkExt
) -> Result<bool, Self::Error> {
macro_rules! verify_with {
($sigtype:ident) => {{
sp_core::$sigtype::Pair::verify_weak(&signature, &message, &pubkey)
let pubkey = sp_core::$sigtype::Public::from_slice(&pubkey).map_err(|_| "Invalid public key")?;
let signature = sp_core::$sigtype::Signature::from_slice(&signature).ok_or("Invalid signature")?;
Ok(sp_core::$sigtype::Pair::verify(&signature, message, &pubkey))
}};
}
Ok(match sigtype {
match sigtype {
SigType::Sr25519 => verify_with!(sr25519),
SigType::Ed25519 => verify_with!(ed25519),
SigType::Ecdsa => verify_with!(ecdsa),
})
}
}

fn derive_sr25519_key(&self, salt: Cow<[u8]>) -> Result<Vec<u8>, Self::Error> {
Expand Down
Loading