What Happens After Crypto Wallet Signs Signature on Blockchain

Author

Reads 193

Crypto currency blockchain coins computer keyboard
Credit: pexels.com, Crypto currency blockchain coins computer keyboard

So, you've got your crypto wallet, and it's just signed a signature on the blockchain. This signature is like a digital fingerprint that confirms the transaction is legitimate.

The blockchain then verifies the signature, making sure it matches the public key associated with your wallet. This is a crucial step, as it ensures the transaction is secure and can't be tampered with.

Once verified, the transaction is broadcast to the network, where it's added to a block and linked to the previous block through a unique code called a hash. This creates a permanent and unalterable record of the transaction.

The new block is then added to the blockchain, making it a part of the permanent ledger.

What Happens After Signature

After a crypto wallet signs a signature, a smart contract can verify it. This is made possible by smart contracts like the one shown in the example, which uses the ecrecover function to recover the address of the private key that signed the message.

Credit: youtube.com, What Are Multi-Signature Wallets in Crypto (Animated)

The verified signature can then be used to execute commands, like sending Ether from one address to another. For example, a user could sign a message saying "Please send 1 Ether from my address to this address", and the smart contract can verify the signature and execute the command.

A smart contract can use this verified signature to interact with other contracts or even send transactions on behalf of the user, making it a trustless way to give a smart contract certain commands without sending a transaction.

Additional reading: Crypto Wallet Address Lookup

Issue #1 - What & Why

The blockchain space is crazy, and it's easy to get lost in the experiment phase. Things have been built rapidly, and the UX often gets overlooked.

The design problems in the blockchain space are real, and one of the most unique challenges is wallet signature request messages. This is an issue that's completely unique to blockchain.

As Ryan from Rimble design system team notes, the goal is to create an adaptable system of guidelines and components to support the best practices of dApp UX design. Built as an open-source project, the Web 3 Design System helps teams quickly build products that humans will use.

The blockchain community is tech-savvy, but the challenge is getting products into more hands than just this community. This is where design and UX come in – to make blockchain products accessible to everyone.

Signed Transactions

Credit: youtube.com, 5.8 Signing transactions

Signed transactions are a crucial part of the Ethereum network, and they work similarly to message signing.

Transactions are RLP encoded, and consist of all transaction parameters (nonce, gas price, gas limit, to, value, data) and the signature (v, r, s). A signed transaction looks like this:

If we enter this on MyCrypto’s broadcast signed transaction page, we will see all the transaction parameters:

The first group of bytes of the signed transaction contains the RLP encoded transaction parameters, and the last group of bytes contains the signature {r, s, v}.

To encode a signed transaction, we need to follow these steps:

  • Encode the transaction parameters: RLP(nonce, gasPrice, gasLimit, to, value, data, chainId, 0, 0).
  • Get the Keccak256 hash of the RLP-encoded, unsigned transaction.
  • Sign the hash with a private key using the ECDSA algorithm, according to the steps described above.
  • Encode the signed transaction: RLP(nonce, gasPrice, gasLimit, to, value, data, v, r, s).

By decoding the RLP-encoded transaction data, we can get the raw transaction parameters and signature again.

Verification Process

After a crypto wallet signs a signature, the verification process begins. The message verification method involves three main components: the message, address, and ECDSA signature. The Header byte in the signature dictates the verification algorithm used.

Explore further: Signature Sign

Credit: youtube.com, How To Prove That You Own Bitcoin (Signed Messages)

To verify a signature, you first need to set the DecodedSignature by Base64-decoding the Signature, and then set the HeaderByte to the first byte of the DecodedSignature. This is a preliminary step for all verification algorithms.

The verification process can be done using smart contracts, such as the basic contract implementation that verifies signatures. This is useful for trustless transactions and can be used in applications like multisig contracts, decentralized exchanges, and meta transactions.

Preliminary Steps for Verification Algorithms

To start the verification process, you need to take some preliminary steps. These steps are crucial to ensure that your verification algorithm runs smoothly.

First, you need to set the DecodedSignature by decoding the Signature using the Base64Decode function. This is a necessary step to work with the signature data.

Next, you need to extract the first byte of the DecodedSignature, which is referred to as the HeaderByte. This byte is essential for further processing.

These two steps lay the foundation for the verification process, and they are essential for any verification algorithm.

Verifying Signatures with Smart Contracts

Credit: youtube.com, How to Verify Ethereum Smart Contracts

Verifying signatures with smart contracts is a powerful tool that allows users to give trustless commands to a contract without sending a transaction. This can be achieved through the use of smart contracts that implement the ecrecover function, which recovers the address of the private key that a message was signed with.

For example, a contract can be implemented to verify signatures and execute commands based on the signature, using a standard like EIP-712. This can be useful in applications such as multisig contracts, decentralized exchanges, and meta transactions.

A contract can also implement the ERC-1271 standard, which allows it to validate the signatures of other smart contracts. This is done by implementing the isValidSignature function, which can run arbitrary functions and return a magic value if the signature is valid.

In a multisig contract, for example, multiple users can sign a message and store the hash within the contract. The contract can then check if the hash provided to the isValidSignature function was signed internally, and if the signature is valid for one of the owners of the contract.

Credit: youtube.com, Signature Verification | Vyper (0.2)

Here are some examples of applications that use signature verification in smart contracts:

  • Multisig contracts (e.g., Gnosis Safe);
  • Decentralised exchanges;
  • Meta transactions and gas relayers (e.g., Gas Station Network).

Signature verification in smart contracts can be used to verify the authenticity of messages and prevent replay attacks. By using a standard like EIP-712, users can present the signed data in a human-readable way, making it more verifiable.

Recovery Identifier (V)

The recovery identifier, or "v", is a crucial part of the verification process. It's the last byte of the signature, and it's either 27 (0x1b) or 28 (0x1c).

In most implementations, the v is just 0 or 1 internally, but 27 was added as an arbitrary number for signing Bitcoin messages and Ethereum adapted that as well.

The v simply indicates which point to use when calculating the public key from the r and s values. This is necessary because multiple points on the curve can be calculated from r and s alone.

Since EIP-155, we also use the chain ID to calculate the v value, which prevents replay attacks across different chains.

Curious to learn more? Check out: Is Trust Wallet Easy to Use to Send Crypto

ECDSA Signing and Verification

Credit: youtube.com, Signing and verifying text with a Bitcoin address and key

ECDSA signing and verification is a crucial process in cryptocurrency transactions.

In ECDSA signing, a private key is used to create a digital signature for a message. The private key is used to calculate the signature, which is then combined with the message to create a signed message.

To verify an ECDSA signature, the public key corresponding to the private key used for signing is needed. The public key is used to calculate the signature, which is then compared to the signature provided in the signed message.

ECDSA verification can be performed using various algorithms, including P2WPKH-P2SH compressed address, P2WPKH uncompressed address, and P2PKH uncompressed and compressed addresses.

The process of ECDSA verification involves several steps, including decoding the signature, calculating the correct parity of y, and comparing the derived address to the provided address.

Here are the steps involved in ECDSA verification for P2WPKH-P2SH compressed address:

1. Set r = DecodedSignature[1:33]. If r ≥ n or r == 0, fail verification with an error similar to "Invalid ECDSA signature parameters".

For more insights, see: Private Crypto Wallet

Credit: youtube.com, ECDSA Signatures | How does ECDSA work and what are Elliptic Curves?

2. Set s = DecodedSignature[33:65]. If s ≥ n or s == 0, fail verification with an error similar to "Invalid ECDSA signature parameters".

3. Set z = SHA256(Message)

4. Set recID = Header AND 0x3

5. If recID AND 0x2 == 0, set x = r, else set x = r+n

6. Set x = (x^3 + 7) mod p

7. Set y = x^((p+1)/4) mod p

8. Calculate the correct parity of y using the 'recID':

9. Set R = (x,y)

10. Set e = (-int(z)) % n

11. Set PublicKey = (R*s + G*e) * modinv(r, n)

12. If is_even(y), compute EncodedPublicKey = "02" || hex(x). Else, compute EncodedPublicKey = "03" || hex(x)

13. Compute AddressHash = RIPEMD160(SHA256(EncodedPublicKey))

14. Compute RedeemScript = hex(00 14) || AddressHash

15. Compute RedeemScriptHash = RIPEMD160(SHA256(RedeemScript))

16. Compute DerivedAddress = Base58Check(hex(05) || RedeemScriptHash)

17. If DerivedAddress == Address, succeed verification. Else fail verification with an error similar to "Wrong address for signature".

Similarly, the steps involved in ECDSA verification for P2WPKH uncompressed address are:

1. Set r = DecodedSignature[1:33]. If r ≥ n or r == 0, fail verification with an error similar to "Invalid ECDSA signature parameters".

Credit: youtube.com, web crypto api ecdsa generate key sign verify message

2. Set s = DecodedSignature[33:65]. If s ≥ n or s == 0, fail verification with an error similar to "Invalid ECDSA signature parameters".

3. Set z = SHA256(Message)

4. Set recID = Header AND 0x3

5. If recID AND 0x2 == 0, set x = r, else set x = r+n

6. Set x = (x^3 + 7) mod p

7. Set y = x^((p+1)/4) mod p

8. Calculate the correct parity of y using the 'recID':

9. Set R = (x,y)

10. Set e = (-int(z)) % n

11. Set PublicKey = (R*s + G*e) * modinv(r, n)

12. Compute EncodedPublicKey = "04" || hex(x) || hex(y)

13. Compute AddressHash = RIPEMD160(SHA256(EncodedPublicKey))

14. Compute DerivedAddress = Base58Check(hex(00) || AddressHash)

15. If DerivedAddress == Address, succeed verification. Else fail verification with an error similar to "Wrong address for signature".

ECDSA verification can be performed using various algorithms, and the choice of algorithm depends on the type of address being verified.

Here are some examples of addresses and their corresponding verification algorithms:

  • P2WPKH-P2SH compressed address: Algorithm 1
  • P2WPKH uncompressed address: Algorithm 2
  • P2PKH uncompressed address: Algorithm 3
  • P2PKH compressed address: Algorithm 4

The Technical Bit

Credit: youtube.com, Bitcoin Transactions - from "Send" to "Receive"

A signature request in a crypto wallet is essentially a dApp sending a small piece of data to the wallet and asking the user to sign to confirm they've received it.

This data is a unique identifier, often a combination of letters and numbers, like d458fa15-dcab-4d85-a477-004d6febca12.

The user can't make sense of this data, but it can be converted into something more meaningful with the right tools.

Personal_sign is a signature type that allows developers to customize the message presented to the user, making it more user-friendly.

In the code, the customizable message is represented by a bolded section, where developers can input their own text.

Standards and Protocols

The Ethereum community has proposed several standards and protocols to improve the security and usability of digital signatures. EIP-191, also known as the Signed Data Standard, defines a version number and version-specific data, which helps prevent replay attacks.

EIP-191 has three versions: 0x00, 0x01, and 0x45. The version 0x01 is particularly interesting, as it uses structured data defined in EIP-712. This makes signing data more verifiable by presenting it in a human-readable way.

Credit: youtube.com, Why Does My Bitcoin Wallet Address Keep Changing? Bitcoin Wallets Explained.

EIP-712, also known as Ethereum typed structured data hashing and signing, is another proposal that makes signing data more verifiable. It defines a new method to replace personal_sign, called eth_signTypedData, which requires specifying all properties and their respective types.

EIP-712 implements EIP-191, so the data will start with 0x1901: 0x19 as set prefix, and 0x01 as version byte to indicate that it’s an EIP-712 signature. This helps prevent replay attacks by verifying the signature for one application cannot be used for another.

The EIP-712 specification is still a draft and not many applications support it yet. However, Ledger and Trezor lack support for EIP-712, which may prevent wider adoption of the specification.

ERC-1271 proposes a standard that would allow smart contracts to validate the signatures of other smart contracts. A contract must implement the isValidSignature function, which can run arbitrary functions to verify the signature.

Verification Methods

Verification Methods can be quite complex, but don't worry, we'll break it down. There are several methods to verify signatures, including using smart contracts, which can be useful for applications like multisig contracts and decentralized exchanges.

Credit: youtube.com, How To Prove That You're Satoshi

Smart contracts can verify signatures using the ecrecover function, which is a precompiled contract at address 0x1 in Solidity. This function recovers the address of the private key that a message was signed with.

To verify signatures in smart contracts, you can use a contract that implements the isValidSignature function, which can run arbitrary functions like the contract above. This allows any contract to verify the signature for a contract that implements ERC-1271.

Here are some ways to verify native segwit signatures:

  • Using the bitcoinjs-message package, which requires passing a specific parameter as true for correct verification.
  • By verifying signatures for native segwit addresses using the following code, which takes 5 parameters and the last one must be passed as true.

EIP-712 is another method for verifying signatures, which presents signed data in a human-readable way and makes signing data more verifiable. It defines a new method to replace personal_sign, called eth_signTypedData, which specifies all the properties and their respective types, as well as some basic information about the application, called the domain.

Message Verification Method

The message verification method involves verifying the authenticity of a message by checking its digital signature. To do this, you'll need the message itself, the address of the sender, and an ECDSA signature.

Credit: youtube.com, Why using SMS verification method is not secure

The Header byte in the signature dictates the verification algorithm used, so you'll need to check this first. Upon verification success, you should display a status message indicating that the message is genuine and came from the specified address.

Here are the steps to verify a message using the ECDSA signature:

  • The message (Message)
  • The address (Address)
  • An ECDSA signature (Signature)

This method ensures that the message is authentic and came from the intended sender. It's a crucial step in maintaining the integrity of digital communications.

The verification process involves checking the ECDSA signature against the message and the sender's address. If the signature is valid, the message is genuine and can be trusted. If not, the message may have been tampered with or sent by an imposter.

Verifying Native Segwit

Native segwit addresses require a specific verification method, which is not covered by the standard tools. They return "address or signature invalid" or "not correct" for certain inputs.

To verify signatures for native segwit addresses, you need to pass a boolean value of true as the fifth parameter in the verify() function.

The bitcoinjs-message package provides more information on signing and verification, which can be helpful for understanding the process.

Native segwit addresses start with the prefix bc1, as seen in the example address bc1qzzh67ch0ucgu5cg6qhvjfwfjly99x9k8ex5slp.

Overview

Credit: youtube.com, Multisignature Wallets Explained | Animation | Cryptomatics

In 2013, BitGo pioneered the multisignature signature protocol for bitcoin wallets. This marked a significant milestone in the development of secure cryptocurrency transactions.

BitGo has since expanded its support to other UTXO-based assets and even account-based assets through smart-contract wallets. This expansion has enabled users to enjoy the same level of security across various blockchain platforms.

The type of signature protocol used by a wallet is determined by the underlying blockchain. Here's a quick rundown of the most common protocols:

  • Account-based assets mostly use MPC, but some blockchains can use either MPC or multisignature.
  • UTXO-based assets mostly use multisignature, with Cardano being a notable exception that only uses MPC.

MPC is a cryptographic technique that allows multiple parties to jointly sign without revealing their private key material to each other. This process occurs off-chain and requires synchrony between cosigners.

Frequently Asked Questions

What is signed message on crypto wallet?

A signed message on a crypto wallet is a message verified by a wallet using a private key and address, proving ownership. This secure verification ensures the message's authenticity and origin.

Krystal Bogisich

Lead Writer

Krystal Bogisich is a seasoned writer with a passion for crafting informative and engaging content. With a keen eye for detail and a knack for storytelling, she has established herself as a versatile writer capable of tackling a wide range of topics. Her expertise spans multiple industries, including finance, where she has developed a particular interest in actuarial careers.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.