Understanding the ECDSA signature format
The signature of Ethereum network events, especially with the use of the elliptical curve, with the use of the digital signature algorithm (ECDSA), with the refund certification function (RFC6979), must be followed. In this article, we explore the values of the V
,R
and S
used in Ethereum’s ECDSA signature.
Overview of the ECDSA signature form
Before dived into the „Vvalue special features, it is necessary to understand how ECDSA works in the context of Ethereum. ECDSA is a digital signature system that uses elliptical curve encryption fishing technology to check the authenticity and integrity of messages. In Ethereum, ECDSA: TA, together with the signature of the RFC6979) .
'v to determine
When determining the V
value, it is necessary to understand what this value represents. According to the code given, the V = 27 + (y % 2)
drops V
. In other words, this formula adds two important components:
- ‚Y % 2
Result: This section determines whether the "signed" or not signed event is created.
- itselfV
: The final calculation gives us a full signature value used to sign events on RFC6979.
Interpretation of Parity in ECDSA signatures
ECDSA signatures use two values,Rand
S, which are created based on the private key provided by the user. The "parity" of these values is crucial to understanding how they promote the signature value. According to Ethereum documentation:
- Ify % 2 == 0
, then the" V
calculation result is added by one.
- This means that if you are using a conventional ECDSA implementation such as Pycryptodome, and you create
r
ands on the basis of your private key (which should be created by
evalue PKCS#1 V1 .5 The signature system used here), then To determine the parity of these values for "V", you add 2.
Example
To illustrate this, we look at the example in which we read a new event using the Pycryptodome and RFC6979 program. In our case, we use the private key for the created public exponent "E" worth 27 (general choice for encryption issues).
Python
Bring pyecdse
Def Generate_KeyPair ():
Create a new RSA pair
Key = pyecdse.rsaprivatkeey.Geners (2048)
Lead private and public exponents
e, d = pyECDSE.RSAPUBLICKEY.GET_EXPONENT (Key)
Return (Key, Pyecdse.ECDSAPUBLICKEY (E = E))
`
Let’s assume now that we have a public key that the e
is 27:
`Python
Def Generate_public_key (Key):
Lead private and public exponents
d = pyecdse.rsaprivatkeey.Generate (2048)
Return (Key, Pyecdse.ECDSAPUBLICKEY (D = D))
Create a new pair of key with 27 created E -value.
(Key, ECPS) = Generate_KeyPair ()
Print („E:”, ECPS.E)
Print („D:”, ECPS)
`
With „e” and d
, we can then use them to create a public exponent with pycryptodom:
`Python
Lead a public exponent
public_exponent = pyecdse.ecdsapublickey (e = 27, d = d) .Get_public_exponent ()
Print („Public Exponent:”, Public_Exponent)
`
Now we can calculate V
based on parity.
count v
`Python
Calculate v = 27 + (y % 2) for each event.
For TX -TX:
Signature = pyecdse.ecdsasignature.Generate (ECPS, TX)
Pick out public and private exponents from signature
Signature_public_Exponent = Signature.get_public_Exponent ()
Signature_private_exponent = Signature.Get_private_Exponent ()
Check to see if the transaction is signed
If Signature_public_Exponent <0:
Print („The event is signed message.