From 935ded89e3514db7cd96b64e85c84590e1bf6b23 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sun, 24 Apr 2022 19:22:43 +0300 Subject: [PATCH 01/18] ink_eth_compatibility::to_eth_address() removed, as well as libsecp256k1 dep --- crates/eth_compatibility/Cargo.toml | 6 ---- crates/eth_compatibility/src/lib.rs | 45 ----------------------------- 2 files changed, 51 deletions(-) diff --git a/crates/eth_compatibility/Cargo.toml b/crates/eth_compatibility/Cargo.toml index 2c30a464b5f..a37ba1eeed9 100644 --- a/crates/eth_compatibility/Cargo.toml +++ b/crates/eth_compatibility/Cargo.toml @@ -17,12 +17,6 @@ include = ["Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] [dependencies] ink_env = { version = "3.0.1", path = "../env", default-features = false } -[target.'cfg(not(target_os = "windows"))'.dependencies] -# We do not include `libsecp256k1` on Windows, since it's incompatible. -# We have https://github.com/paritytech/ink/issues/1068 for removing -# this dependency altogether. -libsecp256k1 = { version = "0.7.0", default-features = false } - [features] default = ["std"] std = [ diff --git a/crates/eth_compatibility/src/lib.rs b/crates/eth_compatibility/src/lib.rs index f08dba141bc..9698dada592 100644 --- a/crates/eth_compatibility/src/lib.rs +++ b/crates/eth_compatibility/src/lib.rs @@ -73,51 +73,6 @@ impl From<[u8; 20]> for EthereumAddress { } impl ECDSAPublicKey { - /// Returns Ethereum address from the ECDSA compressed public key. - /// - /// # Example - /// - /// ``` - /// use ink_eth_compatibility::{ECDSAPublicKey, EthereumAddress}; - /// let pub_key: ECDSAPublicKey = [ - /// 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, - /// 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, - /// 152, - /// ].into(); - /// - /// let EXPECTED_ETH_ADDRESS: EthereumAddress = [ - /// 126, 95, 69, 82, 9, 26, 105, 18, 93, 93, 252, 183, 184, 194, 101, 144, 41, 57, 91, 223 - /// ].into(); - /// - /// assert_eq!(pub_key.to_eth_address().as_ref(), EXPECTED_ETH_ADDRESS.as_ref()); - /// ``` - // We do not include this function on Windows, since it depends on `libsecp256k1`, - // which is incompatible with Windows. - // We have https://github.com/paritytech/ink/issues/1068 for removing this - // dependency altogether. - #[cfg(not(target_os = "windows"))] - pub fn to_eth_address(&self) -> EthereumAddress { - use ink_env::hash; - use libsecp256k1::PublicKey; - - // Transform compressed public key into uncompressed. - let pub_key = PublicKey::parse_compressed(&self.0) - .expect("Unable to parse the compressed ECDSA public key"); - let uncompressed = pub_key.serialize(); - - // Hash the uncompressed public key by Keccak256 algorithm. - let mut hash = ::Type::default(); - // The first byte indicates that the public key is uncompressed. - // Let's skip it for hashing the public key directly. - ink_env::hash_bytes::(&uncompressed[1..], &mut hash); - - // Take the last 20 bytes as an Address - let mut result = EthereumAddress::default(); - result.as_mut().copy_from_slice(&hash[12..]); - - result - } - /// Returns the default Substrate's `AccountId` from the ECDSA compressed public key. /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. /// From 666d98fe15a137722a85644cf32a7e27734264a7 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sat, 30 Apr 2022 22:28:53 +0300 Subject: [PATCH 02/18] added edcsa_to_eth_address() (except offchain env) --- crates/env/src/api.rs | 7 +++++++ crates/env/src/backend.rs | 8 ++++++++ crates/env/src/engine/off_chain/impls.rs | 14 ++++++++++++++ crates/env/src/engine/on_chain/ext.rs | 15 +++++++++++++++ crates/env/src/engine/on_chain/impls.rs | 8 ++++++++ crates/lang/src/env_access.rs | 7 +++++++ 6 files changed, 59 insertions(+) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 706425390ef..4cbb59dc31f 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -500,6 +500,13 @@ pub fn ecdsa_recover( }) } +/// Returns Ethereum address from the ECDSA compressed public key. +pub fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result<()> { + ::on_instance(|instance| { + instance.ecdsa_to_eth_address(pubkey, output) + }) +} + /// Checks whether the specified account is a contract. /// /// # Errors diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index ede5d9bc472..531a75504b9 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -249,6 +249,14 @@ pub trait EnvBackend { output: &mut [u8; 33], ) -> Result<()>; + /// Retrieves Ethereum address from the ECDSA compressed `pubkey`, + /// and stores the result in `output`. + fn ecdsa_to_eth_address( + &mut self, + pubkey: &[u8; 33], + output: &mut [u8; 20], + ) -> Result<()>; + /// Low-level interface to call a chain extension method. /// /// Returns the output of the chain extension of the specified type. diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 0c4a43027f2..8026c92e830 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -287,6 +287,20 @@ impl EnvBackend for EnvInstance { } } + fn ecdsa_to_eth_address( + &mut self, + _pubkey: &[u8; 33], + _output: &mut [u8; 20], + ) -> Result<()> { + // use secp256k1::PublicKey as ECDSAPubkey; + // let pk = ECDSAPubkey::from_slice(pubkey).expect("Unable to parse the compressed ECDSA public key"); + // let uncompressed = pk.serialize(); + // let mut hash = ::Type::default(); + // ::(&uncompressed[1..], &mut hash) + + unimplemented!("off-chain environment does not support `ecdsa_to_eth_address`") + } + fn call_chain_extension( &mut self, func_id: u32, diff --git a/crates/env/src/engine/on_chain/ext.rs b/crates/env/src/engine/on_chain/ext.rs index 85c11543958..192abcfe895 100644 --- a/crates/env/src/engine/on_chain/ext.rs +++ b/crates/env/src/engine/on_chain/ext.rs @@ -348,6 +348,11 @@ mod sys { output_ptr: Ptr32Mut<[u8]>, ) -> ReturnCode; + pub fn seal_ecdsa_to_eth_address( + pubkey_ptr: Ptr32<[u8]>, + output_ptr: Ptr32Mut<[u8]>, + ) -> ReturnCode; + pub fn seal_set_code_hash(code_hash_ptr: Ptr32<[u8]>) -> ReturnCode; pub fn seal_code_hash( @@ -680,6 +685,16 @@ pub fn ecdsa_recover( ret_code.into() } +pub fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result { + let ret_code = unsafe { + sys::seal_ecdsa_to_eth_address( + Ptr32::from_slice(pubkey), + Ptr32Mut::from_slice(output), + ) + }; + ret_code.into() +} + pub fn is_contract(account_id: &[u8]) -> bool { let ret_val = unsafe { sys::seal_is_contract(Ptr32::from_slice(account_id)) }; ret_val.into_bool() diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 46aa162c3ba..84ea9d679c3 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -291,6 +291,14 @@ impl EnvBackend for EnvInstance { ext::ecdsa_recover(signature, message_hash, output).map_err(Into::into) } + fn ecdsa_to_eth_address( + &mut self, + pubkey: &[u8; 33], + output: &mut [u8; 20], + ) -> Result<()> { + ext::ecdsa_to_eth_address(pubkey, output).map_err(Into::into) + } + fn call_chain_extension( &mut self, func_id: u32, diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index fa843c6826a..8b57ebe3357 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -838,6 +838,13 @@ where .map_err(|_| Error::EcdsaRecoveryFailed) } + pub fn ecdsa_to_eth_address(self, pubkey: &[u8; 33]) -> Result<[u8; 20]> { + let mut output = [0; 20]; + ink_env::ecdsa_to_eth_address(pubkey, &mut output) + .map(|_| output) + .map_err(|_| Error::EcdsaRecoveryFailed) + } + /// Checks whether a specified account belongs to a contract. /// /// # Example From 615d029c0b31ea64187cc9f1d173b8a0535cec61 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sat, 30 Apr 2022 22:48:09 +0300 Subject: [PATCH 03/18] added off-chain impl --- crates/env/src/engine/off_chain/impls.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 8026c92e830..ab0f1213e98 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -289,16 +289,16 @@ impl EnvBackend for EnvInstance { fn ecdsa_to_eth_address( &mut self, - _pubkey: &[u8; 33], - _output: &mut [u8; 20], + pubkey: &[u8; 33], + output: &mut [u8; 20], ) -> Result<()> { - // use secp256k1::PublicKey as ECDSAPubkey; - // let pk = ECDSAPubkey::from_slice(pubkey).expect("Unable to parse the compressed ECDSA public key"); - // let uncompressed = pk.serialize(); - // let mut hash = ::Type::default(); - // ::(&uncompressed[1..], &mut hash) - - unimplemented!("off-chain environment does not support `ecdsa_to_eth_address`") + let pk = secp256k1::PublicKey::from_slice(pubkey) + .map_err(|_| Error::EcdsaRecoveryFailed)?; + let uncompressed = pk.serialize(); + let mut hash = ::Type::default(); + ::hash(&uncompressed[1..], &mut hash); + output.as_mut().copy_from_slice(&hash[12..]); + Ok(()) } fn call_chain_extension( From 434147242d8339f84b516223e7e2b10b6bc24b02 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sat, 30 Apr 2022 22:49:16 +0300 Subject: [PATCH 04/18] removed eth_compatibility crate --- Cargo.toml | 1 - crates/eth_compatibility/Cargo.toml | 24 ------- crates/eth_compatibility/LICENSE | 1 - crates/eth_compatibility/README.md | 1 - crates/eth_compatibility/src/lib.rs | 105 ---------------------------- 5 files changed, 132 deletions(-) delete mode 100644 crates/eth_compatibility/Cargo.toml delete mode 120000 crates/eth_compatibility/LICENSE delete mode 120000 crates/eth_compatibility/README.md delete mode 100644 crates/eth_compatibility/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index ded10b8e9da..154fbd1a1ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ members = [ "crates/primitives", "crates/engine", "crates/env", - "crates/eth_compatibility", "crates/storage", "crates/storage/derive", ] diff --git a/crates/eth_compatibility/Cargo.toml b/crates/eth_compatibility/Cargo.toml deleted file mode 100644 index a37ba1eeed9..00000000000 --- a/crates/eth_compatibility/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "ink_eth_compatibility" -version = "3.0.1" -authors = ["Parity Technologies "] -edition = "2021" - -license = "Apache-2.0" -readme = "README.md" -repository = "https://github.com/paritytech/ink" -documentation = "https://docs.rs/ink_eth_compatibility/" -homepage = "https://www.parity.io/" -description = "[ink!] Ethereum related stuff." -keywords = ["wasm", "parity", "webassembly", "blockchain", "ethereum"] -categories = ["no-std", "embedded"] -include = ["Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"] - -[dependencies] -ink_env = { version = "3.0.1", path = "../env", default-features = false } - -[features] -default = ["std"] -std = [ - "ink_env/std", -] diff --git a/crates/eth_compatibility/LICENSE b/crates/eth_compatibility/LICENSE deleted file mode 120000 index 30cff7403da..00000000000 --- a/crates/eth_compatibility/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../../LICENSE \ No newline at end of file diff --git a/crates/eth_compatibility/README.md b/crates/eth_compatibility/README.md deleted file mode 120000 index fe840054137..00000000000 --- a/crates/eth_compatibility/README.md +++ /dev/null @@ -1 +0,0 @@ -../../README.md \ No newline at end of file diff --git a/crates/eth_compatibility/src/lib.rs b/crates/eth_compatibility/src/lib.rs deleted file mode 100644 index 9698dada592..00000000000 --- a/crates/eth_compatibility/src/lib.rs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2018-2022 Parity Technologies (UK) Ltd. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#![no_std] - -use ink_env::{ - DefaultEnvironment, - Environment, -}; - -/// The ECDSA compressed public key. -#[derive(Debug, Copy, Clone)] -pub struct ECDSAPublicKey([u8; 33]); - -impl Default for ECDSAPublicKey { - fn default() -> Self { - // Default is not implemented for [u8; 33], so we can't derive it for ECDSAPublicKey - // But clippy thinks that it is possible. So it is workaround for clippy. - let empty = [0; 33]; - Self(empty) - } -} - -impl AsRef<[u8; 33]> for ECDSAPublicKey { - fn as_ref(&self) -> &[u8; 33] { - &self.0 - } -} - -impl AsMut<[u8; 33]> for ECDSAPublicKey { - fn as_mut(&mut self) -> &mut [u8; 33] { - &mut self.0 - } -} - -impl From<[u8; 33]> for ECDSAPublicKey { - fn from(bytes: [u8; 33]) -> Self { - Self(bytes) - } -} - -/// The address of an Ethereum account. -#[derive(Debug, Default, Copy, Clone)] -pub struct EthereumAddress([u8; 20]); - -impl AsRef<[u8; 20]> for EthereumAddress { - fn as_ref(&self) -> &[u8; 20] { - &self.0 - } -} - -impl AsMut<[u8; 20]> for EthereumAddress { - fn as_mut(&mut self) -> &mut [u8; 20] { - &mut self.0 - } -} - -impl From<[u8; 20]> for EthereumAddress { - fn from(bytes: [u8; 20]) -> Self { - Self(bytes) - } -} - -impl ECDSAPublicKey { - /// Returns the default Substrate's `AccountId` from the ECDSA compressed public key. - /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. - /// - /// # Example - /// - /// ``` - /// use ink_eth_compatibility::ECDSAPublicKey; - /// let pub_key: ECDSAPublicKey = [ - /// 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, - /// 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, - /// 152, - /// ].into(); - /// - /// const EXPECTED_ACCOUNT_ID: [u8; 32] = [ - /// 41, 117, 241, 210, 139, 146, 182, 232, 68, 153, 184, 59, 7, 151, 239, 82, - /// 53, 85, 62, 235, 126, 218, 160, 206, 162, 67, 193, 18, 140, 47, 231, 55, - /// ]; - /// - /// assert_eq!(pub_key.to_default_account_id(), EXPECTED_ACCOUNT_ID.into()); - pub fn to_default_account_id( - &self, - ) -> ::AccountId { - use ink_env::hash; - - let mut output = ::Type::default(); - ink_env::hash_bytes::(&self.0[..], &mut output); - - output.into() - } -} From 2680feaa1c1a41251779a55f4013fc814b991eee Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sat, 30 Apr 2022 22:54:03 +0300 Subject: [PATCH 05/18] removed dep on eth_compatibility --- crates/lang/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/lang/Cargo.toml b/crates/lang/Cargo.toml index f5a57d3dbee..a79f9a7aba1 100644 --- a/crates/lang/Cargo.toml +++ b/crates/lang/Cargo.toml @@ -20,7 +20,6 @@ ink_storage = { version = "3.0.1", path = "../storage", default-features = false ink_primitives = { version = "3.0.1", path = "../primitives", default-features = false } ink_metadata = { version = "3.0.1", path = "../metadata", default-features = false, optional = true } ink_prelude = { version = "3.0.1", path = "../prelude", default-features = false } -ink_eth_compatibility = { version = "3.0.1", path = "../eth_compatibility", default-features = false } ink_lang_macro = { version = "3.0.1", path = "macro", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full"] } From 7e49d88f925bf8d23417fa24bb6a13cc4c3e5f72 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Sat, 30 Apr 2022 23:04:09 +0300 Subject: [PATCH 06/18] fix: clean dependency on a struct from removed crate --- crates/lang/src/env_access.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index 8b57ebe3357..596abdfba7a 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -29,7 +29,6 @@ use ink_env::{ Error, Result, }; -use ink_eth_compatibility::ECDSAPublicKey; /// The API behind the `self.env()` and `Self::env()` syntax in ink!. /// @@ -831,10 +830,10 @@ where self, signature: &[u8; 65], message_hash: &[u8; 32], - ) -> Result { + ) -> Result<[u8; 33]> { let mut output = [0; 33]; ink_env::ecdsa_recover(signature, message_hash, &mut output) - .map(|_| output.into()) + .map(|_| output) .map_err(|_| Error::EcdsaRecoveryFailed) } From 801bb5c2dac36531680b20238f27a1c3811599d9 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 11:27:32 +0300 Subject: [PATCH 07/18] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Müller --- crates/env/src/api.rs | 22 +++++++++++++++++++++- crates/env/src/backend.rs | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 4cbb59dc31f..7e378452cd6 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -500,7 +500,27 @@ pub fn ecdsa_recover( }) } -/// Returns Ethereum address from the ECDSA compressed public key. +/// Returns an Ethereum address from the ECDSA compressed public key. +/// +/// # Example +/// +/// ``` +/// let pub_key = [ +/// 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, +/// 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, +/// 152, +/// ]; +/// +/// let EXPECTED_ETH_ADDRESS = [ +/// 126, 95, 69, 82, 9, 26, 105, 18, 93, 93, 252, 183, 184, 194, 101, 144, 41, 57, 91, 223 +/// ]; +/// +/// let mut output = [0; 33]; +/// ink_env::ecsda_to_eth_address(&pubkey, &mut output); +/// assert_eq!(output, Ok(EXPECTED_ETH_ADDRESS)); +/// ``` +/// +/// # Errors pub fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result<()> { ::on_instance(|instance| { instance.ecdsa_to_eth_address(pubkey, output) diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index 531a75504b9..b1df3d564e1 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -249,7 +249,7 @@ pub trait EnvBackend { output: &mut [u8; 33], ) -> Result<()>; - /// Retrieves Ethereum address from the ECDSA compressed `pubkey`, + /// Retrieves an Ethereum address from the ECDSA compressed `pubkey`, /// and stores the result in `output`. fn ecdsa_to_eth_address( &mut self, From 75a79235762d99375d2659f7be1c0e20ea68ca5a Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 14:23:46 +0300 Subject: [PATCH 08/18] save --- crates/env/src/api.rs | 16 +++++----------- crates/env/src/engine/on_chain/ext.rs | 5 +++++ examples/flipper/lib.rs | 1 + 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 59c968df13d..6d47f378162 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -516,19 +516,13 @@ pub fn ecdsa_recover( /// # Example /// /// ``` -/// let pub_key = [ -/// 2, 121, 190, 102, 126, 249, 220, 187, 172, 85, 160, 98, 149, 206, 135, 11, -/// 7, 2, 155, 252, 219, 45, 206, 40, 217, 89, 242, 129, 91, 22, 248, 23, -/// 152, -/// ]; +/// let pub_key = [2, 141, 181, 91, 5, 219, 134, 192, 177, 120, 108, 164, 159, 9, 93, 118, 52, 76, 158, 96, 86, 178, 240, 39, 1, 167, 231, 243, 194, 10, 171, 253, 145]; /// -/// let EXPECTED_ETH_ADDRESS = [ -/// 126, 95, 69, 82, 9, 26, 105, 18, 93, 93, 252, 183, 184, 194, 101, 144, 41, 57, 91, 223 -/// ]; +/// let EXPECTED_ETH_ADDRESS = [9, 35, 29, 167, 177, 154, 1, 111, 158, 87, 109, 35, 177, 98, 119, 6, 47, 77, 70, 168]; /// -/// let mut output = [0; 33]; -/// ink_env::ecsda_to_eth_address(&pubkey, &mut output); -/// assert_eq!(output, Ok(EXPECTED_ETH_ADDRESS)); +/// let mut output = [0; 20]; +/// ink_env::ecdsa_to_eth_address(&pub_key, &mut output); +/// assert_eq!(output, EXPECTED_ETH_ADDRESS); /// ``` /// /// # Errors diff --git a/crates/env/src/engine/on_chain/ext.rs b/crates/env/src/engine/on_chain/ext.rs index 7db60ada4fc..c59a1a7ac66 100644 --- a/crates/env/src/engine/on_chain/ext.rs +++ b/crates/env/src/engine/on_chain/ext.rs @@ -371,6 +371,11 @@ mod sys { output_ptr: Ptr32Mut<[u8]>, ) -> ReturnCode; + pub fn seal_ecdsa_to_eth_address( + public_key_ptr: Ptr32<[u8]>, + output_ptr: Ptr32Mut<[u8]>, + ) -> ReturnCode; + pub fn seal_contains_storage(key_ptr: Ptr32<[u8]>) -> ReturnCode; pub fn seal_set_storage( diff --git a/examples/flipper/lib.rs b/examples/flipper/lib.rs index ec8c3026533..344dc54f7ef 100644 --- a/examples/flipper/lib.rs +++ b/examples/flipper/lib.rs @@ -1,3 +1,4 @@ + #![cfg_attr(not(feature = "std"), no_std)] use ink_lang as ink; From 6606a2de1cfea5b17663a74700e6b46f74e3c928 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 14:55:06 +0300 Subject: [PATCH 09/18] bugfix for old offchain env impl of to_eth_address --- crates/env/src/engine/off_chain/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 3fadc37f969..63e312b9f58 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -300,7 +300,7 @@ impl EnvBackend for EnvInstance { ) -> Result<()> { let pk = secp256k1::PublicKey::from_slice(pubkey) .map_err(|_| Error::EcdsaRecoveryFailed)?; - let uncompressed = pk.serialize(); + let uncompressed = pk.serialize_uncompressed(); let mut hash = ::Type::default(); ::hash(&uncompressed[1..], &mut hash); output.as_mut().copy_from_slice(&hash[12..]); From fa5c856d43c686d2ef8e6afcbfe492c28d8b17bc Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 15:59:03 +0300 Subject: [PATCH 10/18] + doc comments --- crates/env/src/api.rs | 15 +++++++++---- crates/lang/src/env_access.rs | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 6d47f378162..dc8d226e3fa 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -516,16 +516,23 @@ pub fn ecdsa_recover( /// # Example /// /// ``` -/// let pub_key = [2, 141, 181, 91, 5, 219, 134, 192, 177, 120, 108, 164, 159, 9, 93, 118, 52, 76, 158, 96, 86, 178, 240, 39, 1, 167, 231, 243, 194, 10, 171, 253, 145]; -/// -/// let EXPECTED_ETH_ADDRESS = [9, 35, 29, 167, 177, 154, 1, 111, 158, 87, 109, 35, 177, 98, 119, 6, 47, 77, 70, 168]; -/// +/// let pub_key = [ +/// 2, 141, 181, 91, 5, 219, 134, 192, 177, 120, 108, 164, 159, 9, 93, 118, +/// 52, 76, 158, 96, 86, 178, 240, 39, 1, 167, 231, 243, 194, 10, 171, 253, +/// 145, +/// ]; +/// let EXPECTED_ETH_ADDRESS = [ +/// 9, 35, 29, 167, 177, 154, 1, 111, 158, 87, 109, 35, 177, 98, 119, 6, 47, +/// 77, 70, 168, +/// ]; /// let mut output = [0; 20]; /// ink_env::ecdsa_to_eth_address(&pub_key, &mut output); /// assert_eq!(output, EXPECTED_ETH_ADDRESS); /// ``` /// /// # Errors +/// +/// - if cannot retrieve ECDSA public key from the provided input pub fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result<()> { ::on_instance(|instance| { instance.ecdsa_to_eth_address(pubkey, output) diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index 596abdfba7a..29ce2534270 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -837,6 +837,48 @@ where .map_err(|_| Error::EcdsaRecoveryFailed) } + /// Returns an Ethereum address from the ECDSA compressed public key. + /// + /// # Example + /// + /// ``` + /// # use ink_lang as ink; + /// # #[ink::contract] + /// # pub mod my_contract { + /// # #[ink(storage)] + /// # pub struct MyContract { } + /// # + /// # impl MyContract { + /// # #[ink(constructor)] + /// # pub fn new() -> Self { + /// # Self {} + /// # } + /// # + /// #[ink(message)] + /// pub fn ecdsa_to_eth_address(&self) { + /// let pub_key = [ + /// 2, 141, 181, 91, 5, 219, 134, 192, 177, 120, 108, 164, 159, 9, 93, 118, + /// 52, 76, 158, 96, 86, 178, 240, 39, 1, 167, 231, 243, 194, 10, 171, 253, + /// 145, + /// ]; + /// let EXPECTED_ETH_ADDRESS = [ + /// 9, 35, 29, 167, 177, 154, 1, 111, 158, 87, 109, 35, 177, 98, 119, 6, 47, + /// 77, 70, 168, + /// ]; + /// let output = self + /// .env() + /// .ecdsa_to_eth_address(&pub_key) + /// .expect("Should get ETH address from compressed public key"); + /// assert_eq!(output, EXPECTED_ETH_ADDRESS); + /// } + /// # + /// # } + /// # } + /// ``` + /// + /// # Note + /// + /// For more details visit: [`ink_env::ecdsa_to_eth_address`] pub fn ecdsa_to_eth_address(self, pubkey: &[u8; 33]) -> Result<[u8; 20]> { let mut output = [0; 20]; ink_env::ecdsa_to_eth_address(pubkey, &mut output) From 70a91891eca3ffd8c625ce88697d792ee4a0fe9d Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 17:16:52 +0300 Subject: [PATCH 11/18] ecdsa_to_default_account_id func ported from ink_eth_compatibility crate --- crates/env/src/api.rs | 13 +++++++++++++ crates/env/src/backend.rs | 9 +++++++++ crates/env/src/engine/off_chain/impls.rs | 7 +++++++ crates/env/src/engine/on_chain/impls.rs | 16 ++++++++++++++++ crates/lang/src/env_access.rs | 11 +++++++++++ 5 files changed, 56 insertions(+) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index dc8d226e3fa..6f757d9a659 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -36,6 +36,7 @@ use crate::{ }, topics::Topics, types::Gas, + AccountId, Environment, Result, }; @@ -627,3 +628,15 @@ where pub fn set_code_hash(code_hash: &[u8; 32]) -> Result<()> { ::on_instance(|instance| instance.set_code_hash(code_hash)) } + +/// Returns the default Substrate's `AccountId` [u8;32] from the ECDSA compressed public key. +/// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. +/// +/// # Note +/// +/// This function implies a standart `AccountId` type which is [u8;32]. +pub fn ecdsa_to_default_account_id(pubkey: &[u8; 33]) -> AccountId { + ::on_instance(|instance| { + instance.ecdsa_to_default_account_id(pubkey) + }) +} diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index bae2195596b..dfd18210935 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -24,6 +24,7 @@ use crate::{ HashOutput, }, topics::Topics, + AccountId, Environment, Result, }; @@ -303,6 +304,14 @@ pub trait EnvBackend { /// /// - If the supplied `code_hash` cannot be found on-chain. fn set_code_hash(&mut self, code_hash: &[u8]) -> Result<()>; + + /// Returns the default Substrate's `AccountId` ([u8;32]) from the ECDSA compressed public key. + /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. + /// + /// # Note + /// + /// For more details visit: [`ecdsa_to_default_account_id`][`crate::ecdsa_to_default_account_id`] + fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId; } /// Environmental contract functionality. diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index 63e312b9f58..ffc5a9a3f82 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -32,6 +32,7 @@ use crate::{ Topics, TopicsBuilderBackend, }, + AccountId, Clear, EnvBackend, Environment, @@ -342,6 +343,12 @@ impl EnvBackend for EnvInstance { fn set_code_hash(&mut self, _code_hash: &[u8]) -> Result<()> { unimplemented!("off-chain environment does not support `set_code_hash`") } + + fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId { + let mut output = ::Type::default(); + ::hash(&pubkey[..], &mut output); + output.into() + } } impl TypedEnvBackend for EnvInstance { diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index e8a98d71c6f..4edc8121f9f 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -328,6 +328,12 @@ impl EnvBackend for EnvInstance { fn set_code_hash(&mut self, code_hash_ptr: &[u8]) -> Result<()> { ext::set_code_hash(code_hash_ptr).map_err(Into::into) } + + fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId { + let mut output = ::Type::default(); + ::hash(&pubkey[..], &mut output); + output.into() + } } impl TypedEnvBackend for EnvInstance { @@ -552,4 +558,14 @@ impl TypedEnvBackend for EnvInstance { let hash = scale::Decode::decode(&mut &output[..])?; Ok(hash) } + + fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> E::AccountId + where + H: CryptoHash, + E: Environment, + { + let mut output = ::Type::default(); + ::hash(pubkey[..], &mut output); + output.into() + } } diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index 29ce2534270..e5835df9b62 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -25,6 +25,7 @@ use ink_env::{ CryptoHash, HashOutput, }, + AccountId, Environment, Error, Result, @@ -1013,4 +1014,14 @@ where pub fn own_code_hash(self) -> Result { ink_env::own_code_hash::() } + + /// Returns the default Substrate's `AccountId` from the ECDSA compressed public key. + /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. + /// + /// # Note + /// + /// For more details visit: [`ink_env::ecdsa_to_default_account_id`] + pub fn ecdsa_to_default_account_id(self, pubkey: &[u8; 33]) -> AccountId { + ink_env::ecdsa_to_default_account_id(pubkey) + } } From 67c373ba23776d11e27a660f00f1a69dafec7a39 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 17:23:03 +0300 Subject: [PATCH 12/18] revert examples --- examples/flipper/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/flipper/lib.rs b/examples/flipper/lib.rs index 344dc54f7ef..ec8c3026533 100644 --- a/examples/flipper/lib.rs +++ b/examples/flipper/lib.rs @@ -1,4 +1,3 @@ - #![cfg_attr(not(feature = "std"), no_std)] use ink_lang as ink; From 5ee5f36a6d2d0af97241430aeb86cb3b80705dd7 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 17:52:24 +0300 Subject: [PATCH 13/18] fix --- crates/env/src/engine/on_chain/impls.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 4edc8121f9f..648ea607a42 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -37,6 +37,7 @@ use crate::{ Topics, TopicsBuilderBackend, }, + AccountId, Clear, EnvBackend, Environment, From 52977b2bcaab408e70daf2f3a4ece48d0f65029c Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 17:57:16 +0300 Subject: [PATCH 14/18] another fix --- crates/env/src/engine/on_chain/impls.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 648ea607a42..a6f9344b97b 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -559,14 +559,4 @@ impl TypedEnvBackend for EnvInstance { let hash = scale::Decode::decode(&mut &output[..])?; Ok(hash) } - - fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> E::AccountId - where - H: CryptoHash, - E: Environment, - { - let mut output = ::Type::default(); - ::hash(pubkey[..], &mut output); - output.into() - } } From ce22fb09e29c2933d28bd633a1bc8c605083da11 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Wed, 11 May 2022 18:07:42 +0300 Subject: [PATCH 15/18] more fix --- crates/env/src/api.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 6f757d9a659..891390d9efc 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -629,12 +629,12 @@ pub fn set_code_hash(code_hash: &[u8; 32]) -> Result<()> { ::on_instance(|instance| instance.set_code_hash(code_hash)) } -/// Returns the default Substrate's `AccountId` [u8;32] from the ECDSA compressed public key. +/// Returns the default Substrate's `AccountId` (`\[u8;32\]`) from the ECDSA compressed public key. /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. /// /// # Note /// -/// This function implies a standart `AccountId` type which is [u8;32]. +/// This function implies a standart `AccountId` type which is `\[u8;32\]`. pub fn ecdsa_to_default_account_id(pubkey: &[u8; 33]) -> AccountId { ::on_instance(|instance| { instance.ecdsa_to_default_account_id(pubkey) From a0e429affc2554c8ae1a66d31fe218c578b6d3f9 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Thu, 12 May 2022 10:13:20 +0300 Subject: [PATCH 16/18] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michael Müller --- crates/env/src/api.rs | 6 +++--- crates/env/src/backend.rs | 4 ++-- crates/lang/src/env_access.rs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 891390d9efc..4dfc343d51a 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -533,7 +533,7 @@ pub fn ecdsa_recover( /// /// # Errors /// -/// - if cannot retrieve ECDSA public key from the provided input +/// - If the ECDSA public key cannot be recovered from the provided public key. pub fn ecdsa_to_eth_address(pubkey: &[u8; 33], output: &mut [u8; 20]) -> Result<()> { ::on_instance(|instance| { instance.ecdsa_to_eth_address(pubkey, output) @@ -629,12 +629,12 @@ pub fn set_code_hash(code_hash: &[u8; 32]) -> Result<()> { ::on_instance(|instance| instance.set_code_hash(code_hash)) } -/// Returns the default Substrate's `AccountId` (`\[u8;32\]`) from the ECDSA compressed public key. +/// Returns the default Substrate `AccountId` (`[u8; 32]`) from the ECDSA compressed public key. /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. /// /// # Note /// -/// This function implies a standart `AccountId` type which is `\[u8;32\]`. +/// This function assumes an `AccountId` type of `[u8; 32]` for the Substrate chain. pub fn ecdsa_to_default_account_id(pubkey: &[u8; 33]) -> AccountId { ::on_instance(|instance| { instance.ecdsa_to_default_account_id(pubkey) diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index dfd18210935..9fe890e3bf7 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -254,7 +254,7 @@ pub trait EnvBackend { output: &mut [u8; 33], ) -> Result<()>; - /// Retrieves an Ethereum address from the ECDSA compressed `pubkey`, + /// Retrieves an Ethereum address from the ECDSA compressed `pubkey` /// and stores the result in `output`. fn ecdsa_to_eth_address( &mut self, @@ -305,7 +305,7 @@ pub trait EnvBackend { /// - If the supplied `code_hash` cannot be found on-chain. fn set_code_hash(&mut self, code_hash: &[u8]) -> Result<()>; - /// Returns the default Substrate's `AccountId` ([u8;32]) from the ECDSA compressed public key. + /// Returns the default Substrate `AccountId` (`[u8; 32]`) from the ECDSA compressed public key. /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. /// /// # Note diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index e5835df9b62..b6d99fd5d5e 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -869,7 +869,7 @@ where /// let output = self /// .env() /// .ecdsa_to_eth_address(&pub_key) - /// .expect("Should get ETH address from compressed public key"); + /// .expect("must return an Ethereum address for the compressed public key"); /// assert_eq!(output, EXPECTED_ETH_ADDRESS); /// } /// # @@ -1015,7 +1015,7 @@ where ink_env::own_code_hash::() } - /// Returns the default Substrate's `AccountId` from the ECDSA compressed public key. + /// Returns the default Substrate `AccountId` from the ECDSA compressed public key. /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. /// /// # Note From 487e0642b86ce40db3228434cc3fe9b887ae1bf7 Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Thu, 12 May 2022 14:43:07 +0300 Subject: [PATCH 17/18] Revert "ecdsa_to_default_account_id func ported from ink_eth_compatibility crate" This reverts commit 70a91891eca3ffd8c625ce88697d792ee4a0fe9d. --- crates/env/src/api.rs | 13 ------------- crates/env/src/backend.rs | 9 --------- crates/env/src/engine/off_chain/impls.rs | 7 ------- crates/env/src/engine/on_chain/impls.rs | 6 ------ crates/lang/src/env_access.rs | 11 ----------- 5 files changed, 46 deletions(-) diff --git a/crates/env/src/api.rs b/crates/env/src/api.rs index 4dfc343d51a..a39c348924c 100644 --- a/crates/env/src/api.rs +++ b/crates/env/src/api.rs @@ -36,7 +36,6 @@ use crate::{ }, topics::Topics, types::Gas, - AccountId, Environment, Result, }; @@ -628,15 +627,3 @@ where pub fn set_code_hash(code_hash: &[u8; 32]) -> Result<()> { ::on_instance(|instance| instance.set_code_hash(code_hash)) } - -/// Returns the default Substrate `AccountId` (`[u8; 32]`) from the ECDSA compressed public key. -/// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. -/// -/// # Note -/// -/// This function assumes an `AccountId` type of `[u8; 32]` for the Substrate chain. -pub fn ecdsa_to_default_account_id(pubkey: &[u8; 33]) -> AccountId { - ::on_instance(|instance| { - instance.ecdsa_to_default_account_id(pubkey) - }) -} diff --git a/crates/env/src/backend.rs b/crates/env/src/backend.rs index 9fe890e3bf7..43ee3252332 100644 --- a/crates/env/src/backend.rs +++ b/crates/env/src/backend.rs @@ -24,7 +24,6 @@ use crate::{ HashOutput, }, topics::Topics, - AccountId, Environment, Result, }; @@ -304,14 +303,6 @@ pub trait EnvBackend { /// /// - If the supplied `code_hash` cannot be found on-chain. fn set_code_hash(&mut self, code_hash: &[u8]) -> Result<()>; - - /// Returns the default Substrate `AccountId` (`[u8; 32]`) from the ECDSA compressed public key. - /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. - /// - /// # Note - /// - /// For more details visit: [`ecdsa_to_default_account_id`][`crate::ecdsa_to_default_account_id`] - fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId; } /// Environmental contract functionality. diff --git a/crates/env/src/engine/off_chain/impls.rs b/crates/env/src/engine/off_chain/impls.rs index ffc5a9a3f82..63e312b9f58 100644 --- a/crates/env/src/engine/off_chain/impls.rs +++ b/crates/env/src/engine/off_chain/impls.rs @@ -32,7 +32,6 @@ use crate::{ Topics, TopicsBuilderBackend, }, - AccountId, Clear, EnvBackend, Environment, @@ -343,12 +342,6 @@ impl EnvBackend for EnvInstance { fn set_code_hash(&mut self, _code_hash: &[u8]) -> Result<()> { unimplemented!("off-chain environment does not support `set_code_hash`") } - - fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId { - let mut output = ::Type::default(); - ::hash(&pubkey[..], &mut output); - output.into() - } } impl TypedEnvBackend for EnvInstance { diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index a6f9344b97b..9d3528cf95e 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -329,12 +329,6 @@ impl EnvBackend for EnvInstance { fn set_code_hash(&mut self, code_hash_ptr: &[u8]) -> Result<()> { ext::set_code_hash(code_hash_ptr).map_err(Into::into) } - - fn ecdsa_to_default_account_id(&mut self, pubkey: &[u8; 33]) -> AccountId { - let mut output = ::Type::default(); - ::hash(&pubkey[..], &mut output); - output.into() - } } impl TypedEnvBackend for EnvInstance { diff --git a/crates/lang/src/env_access.rs b/crates/lang/src/env_access.rs index b6d99fd5d5e..cc01db9cb51 100644 --- a/crates/lang/src/env_access.rs +++ b/crates/lang/src/env_access.rs @@ -25,7 +25,6 @@ use ink_env::{ CryptoHash, HashOutput, }, - AccountId, Environment, Error, Result, @@ -1014,14 +1013,4 @@ where pub fn own_code_hash(self) -> Result { ink_env::own_code_hash::() } - - /// Returns the default Substrate `AccountId` from the ECDSA compressed public key. - /// It hashes the compressed public key with the `blake2b_256` algorithm like in substrate. - /// - /// # Note - /// - /// For more details visit: [`ink_env::ecdsa_to_default_account_id`] - pub fn ecdsa_to_default_account_id(self, pubkey: &[u8; 33]) -> AccountId { - ink_env::ecdsa_to_default_account_id(pubkey) - } } From 388b136b061d71ee0737c4ceb3634006921f9ada Mon Sep 17 00:00:00 2001 From: Alexander Gryaznov Date: Thu, 12 May 2022 14:48:36 +0300 Subject: [PATCH 18/18] missed clean up --- crates/env/src/engine/on_chain/impls.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/env/src/engine/on_chain/impls.rs b/crates/env/src/engine/on_chain/impls.rs index 9d3528cf95e..e8a98d71c6f 100644 --- a/crates/env/src/engine/on_chain/impls.rs +++ b/crates/env/src/engine/on_chain/impls.rs @@ -37,7 +37,6 @@ use crate::{ Topics, TopicsBuilderBackend, }, - AccountId, Clear, EnvBackend, Environment,