Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Add frame_support::crypto::ecdsa::Public.to_eth_address() (k256-based) and use it in pallets - #11087

Merged
agryaznov merged 33 commits into
masterfrom
ag-seal-to-eth-addr
Apr 16, 2022
Merged

Add frame_support::crypto::ecdsa::Public.to_eth_address() (k256-based) and use it in pallets#11087
agryaznov merged 33 commits into
masterfrom
ag-seal-to-eth-addr

Conversation

@agryaznov

@agryaznovagryaznov commented Mar 22, 2022

Copy link
Copy Markdown
Contributor

As a follow-up to #10883 and a pre-requisite to ink#1068, this PR:

  • adds pub fn to_eth_address(&self) -> Result<[u8; 20], ()> to sp_core::ecdsa::Publicframe_support::crypto::ecdsa
  • updates existing fn convert(a: beefy_primitives::crypto::AuthorityId) -> Vec<u8> in pallet-beefy-mmr to use it
  • adds seal_to_eth_address to pallet-contracts API which uses it

@agryaznovagryaznov added A0-please_review Pull request needs code review. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Mar 22, 2022

@atheiathei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round. Didn't look at the contracts changes, yet.

Comment threadprimitives/core/src/lib.rs
Comment threadprimitives/core/Cargo.toml Outdated
Comment threadprimitives/core/src/ecdsa.rs Outdated
Comment threadframe/beefy-mmr/src/lib.rs
Comment threadframe/beefy-mmr/src/lib.rs
@agryaznovagryaznov changed the title Add sp_core::ecdsa::Public.to_eth_address() (k256-based) and use it in palletsAdd frame_support::crypto::ecdsa::Public.to_eth_address() (k256-based) and use it in palletsMar 30, 2022
@agryaznov

Copy link
Copy Markdown
ContributorAuthor

Had to put this new function into frame_support, to keep crypto calculations out of runtime (wasm performs weakly on those), while still avoiding creation of a new host function.

@shawntabrizi please advise if the place for it is chosen correctly.

@agryaznov
agryaznov requested a review from atheiMarch 30, 2022 16:54

@atheiathei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests in the new ecdsa file.

Comment threadframe/support/src/crypto/ecdsa.rs Outdated
Comment threadframe/contracts/src/wasm/runtime.rs Outdated
Comment threadframe/contracts/src/wasm/runtime.rs Outdated
Comment threadframe/contracts/src/wasm/mod.rs Outdated
Comment threadframe/contracts/src/wasm/mod.rs Outdated
Comment threadframe/contracts/src/wasm/mod.rs Outdated
Comment threadframe/support/src/crypto/ecdsa.rs Outdated

@atheiathei left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the CI try to merge master and see if that helps.

@bkchrbkchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't check the benchmarking code in detail.

Some general points, please never use unwrap in the runtime! Either expect with a proof or remove. In your case here you need to remove all of them.

Comment threadframe/beefy-mmr/src/lib.rs Outdated
Comment threadframe/support/src/crypto.rs Outdated
Comment threadframe/support/src/crypto/ecdsa.rs Outdated
Comment threadframe/support/src/crypto/ecdsa.rs Outdated
Comment threadframe/support/src/crypto/ecdsa.rs Outdated
Comment threadframe/support/src/crypto/ecdsa.rs Outdated
@agryaznov
agryaznov requested a review from atheiApril 14, 2022 21:36
Comment threadframe/support/src/crypto/ecdsa.rs Outdated
<[u8; 20]>::try_from(
sp_io::hashing::keccak_256(&uncompressed.as_bytes()[1..])[12..].as_ref(),
)
.expect("failed to take last 20 bytes of a keccak_256 hash")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you still us an expect here? I already gave you a solution where you would not need this anymore.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your version didn't compile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it failed, but the solution wasn't that complicated. I pushed a commit to fix this.

@agryaznov
agryaznov requested a review from bkchrApril 15, 2022 07:16
@agryaznov
agryaznov merged commit a5cd385 into masterApr 16, 2022
@agryaznov
agryaznov deleted the ag-seal-to-eth-addr branch April 16, 2022 12:51
godcodehunter pushed a commit to sensoriumxr/substrate that referenced this pull request Jun 22, 2022
…ased) and use it in pallets (paritytech#11087)
* `ecdsa::Public::to_eth_address` + test, beefy-mmr `convert()` to use it, contracts Ext interface
* `seal_ecdsa_to_eth_address` all but benchmark done
* `seal_ecdsa_to_eth_address` + wasm test
* `seal_ecdsa_to_eth_address` + benchmark
* fixed dependencies
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes from review paritytech#1
* ecdsa::Public(*pk).to_eth_address() moved to frame_support and contracts to use it
* beefy-mmr to use newly added frame_support function for convertion
* a doc fix
* import fix
* benchmark fix-1 (still fails)
* benchmark fixed
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on Alex T feedback
* to_eth_address() put into extension trait for sp-core::ecdsa::Public
* Update frame/support/src/crypto/ecdsa.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Update frame/contracts/src/wasm/mod.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on issues pointed out in review
* benchmark errors fixed
* fmt fix
* EcdsaRecoverFailed err docs updated
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* make applied suggestions compile
* get rid of unwrap() in runtime
* Remove expect
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
DaviRain-Su pushed a commit to octopus-network/substrate that referenced this pull request Aug 23, 2022
…ased) and use it in pallets (paritytech#11087)
* `ecdsa::Public::to_eth_address` + test, beefy-mmr `convert()` to use it, contracts Ext interface
* `seal_ecdsa_to_eth_address` all but benchmark done
* `seal_ecdsa_to_eth_address` + wasm test
* `seal_ecdsa_to_eth_address` + benchmark
* fixed dependencies
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes from review #1
* ecdsa::Public(*pk).to_eth_address() moved to frame_support and contracts to use it
* beefy-mmr to use newly added frame_support function for convertion
* a doc fix
* import fix
* benchmark fix-1 (still fails)
* benchmark fixed
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on Alex T feedback
* to_eth_address() put into extension trait for sp-core::ecdsa::Public
* Update frame/support/src/crypto/ecdsa.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Update frame/contracts/src/wasm/mod.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on issues pointed out in review
* benchmark errors fixed
* fmt fix
* EcdsaRecoverFailed err docs updated
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* make applied suggestions compile
* get rid of unwrap() in runtime
* Remove expect
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
…ased) and use it in pallets (paritytech#11087)
* `ecdsa::Public::to_eth_address` + test, beefy-mmr `convert()` to use it, contracts Ext interface
* `seal_ecdsa_to_eth_address` all but benchmark done
* `seal_ecdsa_to_eth_address` + wasm test
* `seal_ecdsa_to_eth_address` + benchmark
* fixed dependencies
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes from review #1
* ecdsa::Public(*pk).to_eth_address() moved to frame_support and contracts to use it
* beefy-mmr to use newly added frame_support function for convertion
* a doc fix
* import fix
* benchmark fix-1 (still fails)
* benchmark fixed
* Apply suggestions from code review
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on Alex T feedback
* to_eth_address() put into extension trait for sp-core::ecdsa::Public
* Update frame/support/src/crypto/ecdsa.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* Update frame/contracts/src/wasm/mod.rs
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
* fixes on issues pointed out in review
* benchmark errors fixed
* fmt fix
* EcdsaRecoverFailed err docs updated
* Apply suggestions from code review
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
* make applied suggestions compile
* get rid of unwrap() in runtime
* Remove expect
Co-authored-by: Alexander Theißen <alex.theissen@me.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Bastian Köcher <info@kchr.de>
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A0-please_reviewPull request needs code review.C1-lowPR touches the given topic and has a low impact on builders.D2-notlive 💤PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.D5-nicetohaveaudit ⚠️PR contains trivial changes to logic that should be properly reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@agryaznov@athei@bkchr