Ethereum Ecdsa Signature Comprehension format
When it comes to signing operations on Ethereum, in particular the use of a digital signature algorithm of the elliptical curve (ECDSA) together with the recovery control function (RFC6979), it is necessary to follow a specific format. In this article, we will deepen the details of the values of “V”, “R” and “S” used by Ethereum Ecdsa.
Overview of the ECDSA signature format **
Before immersing the details of value V, it is necessary to understand how the Ecdsa works in the context of Ethereum. Ecdsa is a digital signature scheme that uses the encryption of the Ellisse curve to verify the authenticity and integrity of the messages. Ethereum Ecdsa is used in combination with the recovery control function (RFC6979) to sign the operations.
“V” Setting
When determining the V value, it is necessary to understand what this value means. On the basis of the fragment of code provided, V = 27 + (y % 2)
calculate V
. In other words, this formula adds two important components:
- “Y % 2” Result: this part determines whether the “signed” has been created or the operation is not written.
2.
Interpretation of equality Signature Ecdsa
Ecdsa signatures use two values: “R” and “S”, which are generated on the basis of a private key supplied by the user. The “equality” of these values is very important to understand how they contribute to the total value of the signature. According to Ethereum’s documentation:
- If
y % 2 == 0
, then the” V “calculation result increases one.
- This means that if the ECDSA standard implementation is used, such as PYCryPod and Create “R” and “S” based on your private key (which should be generated with E “and” Valte PKCS#1. Scheme), then add 2 to determine the equality of these “V” values.
Example
To illustrate this, we consider the example of creating a new operation using Pycryptodome and RFC6979. In our case, we will use a private key with a public exhibitor of E 27 (the usual choice for encryption).
`Python
Imported pyecdse
Def Generate_kepair ():
Create a new RSA couple
Key = pyecdse.rsaprivatekey.generate (2048)
Guide private and public exhibitors
and, d = pyecdse.Rersapubborkkey.get_exonent (Key)
Return (Key, pyecdse.ecdapubcckey (e = e))
`
Now let's say we have a public key with "and" as 27:
Python
Def Generate_public_key (Key):
Guide private and public exhibitors
D = pyecdse.rsaprivatekey.generate (2048)
Return (Key, pyecdse.ecdapublckkekeys (D = D))
Create a new pair of keys that has generated value and is 27.
(Key, ECPS) = Generate_kepair ()
Print (E :, ECPS.E)
Print (D :, ECPS.D)
`
So, with the values of "and" and D, we can use them to generate our public exhibitor using pycryptodome:
Python
Draw a public exhibition
Public_exonent = pyecdse.ecdsapublckey (E = 27, D = D) .Get_public_exonent ()
Print (“Public Exhibition:”, Public_exonent)
`
Now we can calculate "V" based on the equality of our values.
Calculate V
Python
Calculate V = 27 + (y % 2) for each operation.
For TX operations:
Signature = pyecdse.ecdsasignature.generate (ECPS, TX)
Extract public and private exhibitions from the signature
Signature_publc_exponsent = signature.get_public_exonent ()
Signature_private_exponent = signature.get_private_exonent ()
Check that the operation is signed
If I sign_publc_exonent <0:
Printed (“Message signed the operation.