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

Util: Add support for EIP-1559 in ecsign() method #1597

Open
jonathansmirnoff opened this issue Dec 7, 2021 · 7 comments
Open

Util: Add support for EIP-1559 in ecsign() method #1597

jonathansmirnoff opened this issue Dec 7, 2021 · 7 comments

Comments

@jonathansmirnoff
Copy link

For EIP-1559, the signature v value is now a simple parity bit ("signature Y parity"), which is either 0 or 1, depending on which point on the elliptic curve should be used.
The ecsign does not support EIP-1559 because the it never returns the corresponding v value.

@jochem-brouwer
Copy link
Member

Hi, you are right that ecsign does not directly report this. However, note that in this line, we add 27 to the reported value of whatever ecdsaSign reports. In fact, that function returns a value which is either 0 or 1. So, what we should "just" do, is subtract 27 from the reported value in case that chainId is 0, or correct otherwise.

Please take a look at our EIP1559 transaction as well to see how we use this.

@jonathansmirnoff
Copy link
Author

@jochem-brouwer we thought of doing that thanks!
But it would be great to a support it ;)

@jochem-brouwer
Copy link
Member

Out of interest: for what reason would you like to use ecsign directly? For production purposes this usually uses our library and not the utility library (which is low/mid level) directly. I agree the interface should be enhanced, but I am really wondering about a practical purpose of this feature.

@jonathansmirnoff
Copy link
Author

Can you provide the link to the other library? Maybe I don't know there was an alternative for production.
We use this basically to work with EIP-712, for signing the hashed message.

@holgerd77
Copy link
Member

See also my comment here: #1607 (comment)

If you want, you can also just use the ethereum-cryptography library directly, please double check but the code in your case should be as simple as:

import { ecdsaSign } from 'ethereum-cryptography/secp256k1'

const { signature, recid: v } = ecdsaSign(msgHash, privateKey)
const r = Buffer.from(signature.slice(0, 32))
const s = Buffer.from(signature.slice(32, 64))

(maybe usage is also a bit simpler, in doubt have a closer look and experiment a bit with the ethereum-cryptography library)

@jonathansmirnoff
Copy link
Author

@holgerd77 so if we work with legacy tx we have to add 27 to v and for EIP-1559 we don't have to do anything, right?

@holgerd77
Copy link
Member

@jonathansmirnoff ah, you do also want to work with legacy txs and the like? Then it might be better if you do use the Util library, and then for now just subtract 27 for the typed tx cases until we have a bit cleaner version of this released

@holgerd77 holgerd77 changed the title Add support for EIP-1559 Util: Add support for EIP-1559 in ecsign() method Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants