Understand the ECDSA signature format of Ethereum
With regard to the signature of transactions on the Ethereum network, in particular with the use of the digital signature algorithm of the Elliptical Curve (ECDSA) in combination with the recovery verification function (RFC6979), a specific format must be followed. In this article, we will immerse ourselves in the details of the v ',
r’ and the values used in the Ecdsa of Ethereum signature.
Presentation of the ECDSA signature format
Before diving into the specifics of the “V” value, 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 check the authenticity and integrity of messages. In Ethereum, ECDSA is used jointly with the recovery verification function (RFC6979) for the signature of transactions.
Determine V
When you determine the value of “V”, it is essential to understand what this value represents. According to the code extract provided, v = 27 + (y% 2)
Calculates v
. In other words, this formula adds two important components:
- The result of
y% 2
: this part determines whether it is a” signed “or not signed transaction is being created.
- The value of `
itself
: it is the final calculation which gives us the global signature value used for the signature of transactions with RFC6979.
Interpretation of parity in ECDSA signatures
The ECDSA signatures use two values,rand 'perfume, which are generated on the basis of a private key provided by the user. The "parity" of these values is crucial to understand how they contribute to the overall value of the signature. According to Ethereum documentation:
- Ify% 2 == 0
, the result of the calculation of" V
is increased by one.
- This means that if you use an ECDSA standard implementation, such as Pycryptodom, and you generate `
R 'and' S 'depending on your private key (which should be generated with the value
E' in the PKCS
1 V1.
Example
To illustrate this, consider an example where we generate a new transaction using PyCryptodom and RFC6979. In our case, we will use a private key with a generated public exhibitor.
Python
Import Pyecdsse
Def generate_keypair ():
Generate a new RSA pair
Key = pyecdsse.rsaprivatekey.generate (2048)
Driving private and public representatives
E, d = pyecdsse.rsapublickey.get_exponent (Key)
Return (key, pyecdsse.ecdsapublickey (e = e))
'
Suppose now that we have a public key with "e" like 27:
Python
Def generate_public_key (key):
Driving private and public representatives
D = Pyecdsse.rsaprivateKey.generate (2048)
Return (Key, Pyecdsse.ecdsapublicKey (D = D))
Generate a new pair of keys with the generated E value like 27.
(Key, Ecps) = generate_keypair ()
Print ("E:", Ecps.e)
Print ("D:", ECPS.D)
'
With the values of "E" and "d", we can then use them to generate our public exhibitor using Pycryptodom:
Python
Derivate the public exhibitor
public_exponent = pyecdsse.ecdsapublickey (E = 27, d = D) .Get_public_exponent ()
Print ("public exhibitor:", public_exponent)
'
We can now calculate "V" according to the parity of our values.
Calculation V
` Python
Calculate V = 27 + (y% 2) for each transaction.
For TX in transactions:
Signature = Pyecdsse.ecdsasignature.generate (ECPS, TX)
Extract public and private representatives from the signature
signature_public_exponent = signature.get_public_exponent ()
signature_private_exponent = signature.get_private_exponent ()
Check if the transaction is a signed message
If signature_public_exponent <0:
Print (“The transaction is a signed message.
Leave a Reply