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

SM-781: extracted common Ecrecover func #73

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zakharenkodmytro
Copy link

Proposed Changes

We want to extract the Ecrecover function to shared, as it is already used in several places like benthos-plugin, devices-api and vehicle-signal-decoding.

Copy link

linear bot commented Jul 3, 2024

@zakharenkodmytro zakharenkodmytro marked this pull request as ready for review July 3, 2024 14:54
@zakharenkodmytro zakharenkodmytro requested a review from a team as a code owner July 3, 2024 14:54
crypto/crypto.go Outdated Show resolved Hide resolved
// Ecrecover mimics the ecrecover opcode, returning the address that signed
// hash with signature. sig must have length 65 and the last byte, the recovery
// byte usually denoted v, must be 27 or 28.
func Ecrecover(hash, sig []byte) (common.Address, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why not take in a Hash?

Copy link
Author

Choose a reason for hiding this comment

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

crypto/crypto.go Outdated
func VerifySignature(payload []byte, signature string, ethAddr string) (bool, error) {
addr := common.HexToAddress(ethAddr)
sig := common.FromHex(signature)
hash := crypto.Keccak256Hash(payload)
Copy link
Member

Choose a reason for hiding this comment

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

If you just want bytes, you could use crypto.Keccak256.

Copy link
Author

Choose a reason for hiding this comment

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

updated

crypto/crypto.go Outdated
// ethAddr string The Ethereum address of the signer.
// @return bool Indicates whether the signature is valid or not.
// @return error If there was an issue during the verification process.
func VerifySignature(payload []byte, signature string, ethAddr string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

signature could be []byte, ethAddr could be common.Address. I don't have a huge opinion on this.

Copy link
Member

Choose a reason for hiding this comment

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

I do like using common.Address across the board.

Copy link
Author

Choose a reason for hiding this comment

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

updated signature, make sense to me

crypto/crypto.go Outdated
Comment on lines 49 to 50
addr := common.HexToAddress(ethAddr)
sig := common.FromHex(signature)
Copy link
Member

Choose a reason for hiding this comment

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

If we are going to take in strings, and we do have an error return, maybe we could check that these are valid?

Copy link
Author

Choose a reason for hiding this comment

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

I think we will delegate validation to the client code

@zakharenkodmytro
Copy link
Author

@elffjs , once you have time, please take another look

Copy link
Member

@JamesReate JamesReate left a comment

Choose a reason for hiding this comment

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

moves refactoring forward. Open to using a Hash type as what Dylan said - on the client side don't know if that makes it easier or harder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants