Skip to content

Commit 58cfa7d

Browse files
committed
Fix review comments
1 parent 671b478 commit 58cfa7d

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

crates/phactory/src/contracts/pink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl contracts::NativeContract for Pink {
161161

162162
impl NativeContractMore for Pink {
163163
fn id(&self) -> contracts::NativeContractId {
164-
Pink::address_to_id(&self.instance.address).into()
164+
Pink::address_to_id(&self.instance.address)
165165
}
166166

167167
fn set_on_block_end_selector(&mut self, selector: u32) {

crates/phactory/src/contracts/support.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ impl From<&[u8; 32]> for NativeContractId {
6565
}
6666

6767
impl NativeContractId {
68-
pub fn to_contract_id(&self, group: &phala_mq::ContractGroupId) -> phala_mq::ContractId {
69-
let mut buffer = group.encode();
70-
self.0.encode_to(&mut buffer);
71-
sp_core::blake2_256(&buffer).into()
68+
pub fn to_contract_id(&self, group_id: &phala_mq::ContractGroupId) -> phala_mq::ContractId {
69+
sp_core::blake2_256(&(group_id, &self.0).encode()).into()
7270
}
7371
}
7472

@@ -109,10 +107,8 @@ pub struct NativeContractWrapper<Con> {
109107

110108
impl<Con> NativeContractWrapper<Con> {
111109
pub fn new(inner: Con, deployer: sp_core::H256, salt: &[u8], id: u32) -> Self {
112-
let mut buffer = deployer.encode();
113-
buffer.extend_from_slice(&id.to_be_bytes());
114-
buffer.extend_from_slice(salt);
115-
let id = sp_core::blake2_256(&buffer).into();
110+
let encoded = (deployer, id, salt).encode();
111+
let id = sp_core::blake2_256(&encoded).into();
116112
NativeContractWrapper { inner, id }
117113
}
118114
}

crates/phactory/src/system/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,15 +856,16 @@ impl<Platform: pal::Platform> System<Platform> {
856856
use contracts::*;
857857
let salt = contract_info.salt;
858858
let deployer = phala_types::messaging::AccountId(contract_info.deployer.into());
859+
let ecdh_key = contract_key
860+
.0
861+
.derive_ecdh_key()
862+
.or(Err(anyhow::anyhow!("Invalid contract key")))?;
859863

860864
macro_rules! match_and_install_contract {
861865
($(($id: path => $contract: expr)),*) => {{
862866
match contract_id {
863867
$(
864868
$id => {
865-
let ecdh_key = contract_key
866-
.derive_ecdh_key()
867-
.expect("Derive ecdh_key should not fail");
868869
let contract = NativeContractWrapper::new(
869870
$contract,
870871
deployer,
@@ -891,10 +892,7 @@ impl<Platform: pal::Platform> System<Platform> {
891892
}};
892893
}
893894

894-
let ecdh_key = contract_key
895-
.0
896-
.derive_ecdh_key()
897-
.or(Err(anyhow::anyhow!("Invalid contract key")))?;
895+
let ecdh_pubkey = ecdh_key.public();
898896

899897
let contract_id = match_and_install_contract! {
900898
(DATA_PLAZA => data_plaza::DataPlaza::new()),
@@ -913,7 +911,7 @@ impl<Platform: pal::Platform> System<Platform> {
913911
id: contract_id,
914912
group_id,
915913
deployer,
916-
pubkey: EcdhPublicKey(ecdh_key.public()),
914+
pubkey: EcdhPublicKey(ecdh_pubkey),
917915
};
918916
info!("Native contract instantiate status: {:?}", message);
919917
self.egress.push_message(&message);

0 commit comments

Comments
 (0)