بلاگ
Ethereum: ECDSA: (v, r, s), what is v?
understanding of signature format ECDSA ECDSA
Regarding the signature of transactions in the Ethereum network, especially using the digital signature algorithm of the elliptical curve (ECDSA) in combination with the recovery verification function (RFC6979), a specific format should be followed. In this article, we dive in the details of you,
remains and is used in the signature of ECDS ECDS.
General presentation of ECDSA signature format
Before immersing ourselves in the specific value of “V”, it is essential to understand how ECDSA works in the context of Ethereum. ECDSA is a digital signature scheme that uses the cryptography of the elliptical curve to verify the authenticity and integrity of the messages. În Ethereum, ECDSA este utilizat împreună cu funcția de verificare a recuperării (RFC6979) pentru a semna tranzacții.
Determinare v
Când determinați v
, este necesar să înțelegeți ce reprezintă această valoare. Depending on the code fragment, v = 27 + (y % 2)
calculate v
. In other words, this formula adds two important components:
۱.
۲.
Interpretation of parity in ECDSA signatures
The ECDSA signatures use two values, RA and“ to, which are generated on the basis of a private user provided by the user. The "parity" of these values is decisive in understanding how it contributes to the total signature value. According to the Ethereum documentation:
- Ify % 2 == 0
, the result of the calculation for 'will grow with one.
- This means that if you are using ECDSA standard implementation, such as Pycryptodome, and generatesa
s to based on your private key (which should be generated with" E
in PKCS#1 V1 .5 Signature signature of the signature used here), then to determine the parity of these values for “in” add 2.
Example
To illustrate this, consider the example in which we generate a new Pycryptodome and RFC6979 transaction. In our case, we will use a private key with the “E” values of the generated public exponent 27 (a common choice for cryptographic purposes).
`Python
Import pycdse
Def generte_keypair ():
Generates a new pair of RSA
Key = pyecdse.rsrivatekey.Genere (2048)
Drain private and public exponents
E, d = pyecdse.rsapublickey.get_exponent (key)
Return (key, pyecdse.ecdsapublickey (e = e))
Now suppose we have a public key witheas 27:
Python
Dex gente_public_key (key):
Drain private and public exponents
D = pyecdse.rsrivatekey.Genere (2048)
Return (key, pyecdse.ecdsapublickey (D = D))
Generate a new pair of keys with E as 27.
(Key, ecps) = generte_keypair ()
Print ("e:", ecps.e)
Print ("D:", ecps.d)
With the values of it, we can then use them to generate our public exponent using a picriptodoma:
Python
Drain the public exponent
public_exponent = pyecdse.ecdsapublickey (e = 27, d = d) .gget_public_exponent ()
Print ("Public Exponent:", Public_exponent)
Now we can calculate "based on the parity of our values.
Calculation in
` Python
Calculate V = 27 + (y % 2) for each transaction.
For TX in transactions:
Signature = pyecdse.ecsasignature.generation (ECPS, TX)
Extract public and private exponents from signature
Signature_public_exponent = Signature.Get_public_exponent ()
Signature_private_exponent = signature.get_private_exponent ()
Verify that the transaction is signed by a message
If Signature_public_exponent <0:
Printing (“The transaction is signed by a message.