Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines ERC-191, a standard defining how to handle signed data used by contracts such as multisignature wallets.

The explanation below translates, summarizes, and expands on the original proposal.

I also cover a range of other ERCs.

Overview

This ERC specifies how signed data should be handled in Ethereum contracts.

Motivation

A multisignature contract allows multiple people to authorize an action collectively. Such contracts use presigned transactions, or data representing approval of an action in advance. This data includes the signature components r, s, and v. Ambiguity in how signed data is interpreted can introduce security vulnerabilities.

Multisignature contracts

A multisignature contract executes a particular action, such as transferring funds, once a configured number of people have approved it. This is useful when security is particularly important or when multiple stakeholders need to participate in decisions. The contract specifies the number of signatures required before an action can be executed.

Example 1: Corporate treasury management Giving one person complete authority over large corporate transfers creates risk. A company could configure a multisignature contract requiring approval from two of three board members. For example, the CEO, CFO, and head of accounting could hold keys, with two signatures required to authorize a transfer.

Example 2: Shared family savings Suppose a family manages its savings jointly. Two spouses could configure a 1-of-2 multisignature contract, allowing either person to withdraw funds. This provides flexibility in an emergency if one spouse is unavailable. However, a 1-of-2 threshold does not itself prevent either spouse from moving large amounts without the other's consent; that requires additional restrictions.

Example 3: Investment club Five members of an investment club could configure a 3-of-5 multisignature contract requiring at least three approvals for major investment decisions. This limits the ability of individual members to act unilaterally and supports collective investment decisions.

Multisignature contracts not only help secure funds but also formalize collective decision-making and improve transparency. Participants must understand the process and configure it appropriately.

The proposal identifies two major problems. First, a standard Ethereum transaction could be used directly as a presigned transaction because the transaction's RLPdata could also be interpreted as valid presigned transaction data.

Second, presigned transactions may not be bound to a particular contract, allowing the same signature to be misused in a different contract. For example, a transaction signed by users A and B for a 2/3 multisignature contract X could be reused against another contract Y.

These issues motivated improvements to the signed data format used by multisignature contracts.

Multisignature wallets

Multisignature wallets apply the same mechanism as multisignature contracts. They are digital wallets that require several approvals to execute an action such as a transfer. Instead of relying on one key, this security mechanism requires signatures from multiple keys.

For example, a corporate treasury may require authorization from several stakeholders, such as the CEO, CFO, and accounting staff, before making a large transaction. A multisignature wallet digitizes this process, allowing each participant to approve a transaction with a digital signature.

3-of-5 multisignature wallet The wallet has five distinct signing keys and requires at least three approvals to execute a transaction. In a company, three of five authorized officers must agree to the transaction. This reduces the risk of unilateral misconduct and distributes responsibility and authority.

2-of-2 family multisignature wallet Imagine a wallet holding shared family savings. It has two keys, and both approvals are required before funds can move. This is one way to protect shared savings.

Multisignature wallets are used for corporate treasuries, shared family wallets, investment clubs, and other applications because of their flexibility and security properties. However, operation can be complex and setup can take time, so adoption requires careful planning and understanding.

Specification

The proposal defines a particular signed data format to improve security. By placing the byte 0x19 at the beginning, it prevents the signed data from being interpreted as an ordinary Ethereum transaction.

text
0x19 <1 byte version> <version specific data> <data to sign>.

The format consists of 0x19, a one-byte version identifier, version-specific data, and the actual data to be signed.

For a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding.

The 0x19 byte is important because it ensures that the full signed payload is not a single valid RLP-encoded item. In RLP, a byte in the range [0x00, 0x7f] is a complete encoded item by itself. A payload beginning with 0x19 and followed by additional data therefore cannot be interpreted as a single RLP item representing a conventional Ethereum transaction.

RLP

RLP (Recursive Length Prefix) is an encoding method used in Ethereum. It serializes data structures such as transactions and blocks into sequences of bytes for transmission or storage. Its purpose is to encode arbitrarily nested arrays of binary data into a single binary string.

Basic principles of RLP

  • Single-byte data
    • A single byte with a value in [0x00, 0x7f] is its own RLP encoding.
    • This provides an efficient encoding for small values.
  • String encoding
    • Longer byte strings are encoded using a length prefix followed by their raw bytes.
    • The prefix depends on the length of the string.
  • List encoding
    • Lists begin with a prefix describing the length of the encoded list payload, followed by the concatenated encodings of their items.

Examples of RLP usage

  • Transactions
    • Ethereum transactions contain multiple fields, such as recipient, amount, and other parameters, with the sender recoverable from signature data.
    • RLP combines these fields into a continuous byte sequence for efficient transmission.
  • Blocks
    • Blocks also contain various kinds of information, such as transactions, timestamps, and historical proof-of-work difficulty and reward-related information.
    • RLP provides a consistent encoding for transmission and storage.

RLP is a fundamental Ethereum encoding method because of its simplicity and general applicability. It may be unfamiliar at first, but it is important for understanding Ethereum's internal operation.

The byte 0x19 is also consistent with the prefix used by the personal_sign function, "\x19Ethereum Signed Message:\n". This provides room for additional signed message formats, including version 0x45, corresponding to the character 'E'.

The proposal reduces the risk of incorrectly interpreting signed data as an Ethereum transaction, making signing and verification more explicit.

Version byte registry

Version bytes identify the format and intended use of signed data. The relevant Ethereum Improvement Proposals define the corresponding conventions.

Version byte EIP Description
0x00 191 Data with an intended validator.
0x01 712 Structured data.
0x45 191 personal_sign messages.

0x00 (EIP-191)

This version is used for data with an intended validator. For an operation authorized through a multisignature contract, the validator address can be the address of the multisignature contract itself. The signed payload can contain arbitrary data.

0x01 (EIP-712)

This version corresponds to structured data, allowing more complex data formats to be handled. EIP-712 defines that format and is suited to signing data containing more detailed information and structure.

For more on EIP-712, see the following article.

[EIP-712] Hashing and Signing Typed Structured Data

0x45 (EIP-191)

This version is used for personal_sign messages. The message prefix includes "Ethereum Signed Message:\n" and the message length. This version can also be used for arbitrary data.

NB: The E in Ethereum Signed Message refers to the version byte 0x45. The character E is 0x45 in hexadecimal which makes the remainder, thereum Signed Message:\n + len(message), the version-specific data.

The letter E in 'Ethereum Signed Message' is the version byte 0x45 in hexadecimal, leaving 'thereum Signed Message:\n + message length' (that is, the characters following E) as the version-specific data.

These version bytes make Ethereum signing and verification more explicit and allow applications to select formats appropriate to their requirements.

Example

The original article presents the following snippets as Solidity 0.8.0 examples.

Version 0x00
javascript
function signatureBasedExecution(address target, uint256 nonce, bytes memory payload, uint8 v, bytes32 r, bytes32 s) public payable {
        
    // Arguments when calculating hash to validate
    // 1: byte(0x19) - the initial 0x19 byte
    // 2: byte(0) - the version byte
    // 3: address(this) - the validator address
    // 4-6 : Application specific data

    bytes32 hash = keccak256(abi.encodePacked(byte(0x19), byte(0), address(this), msg.value, nonce, payload));

    // recovering the signer from the hash and the signature
    addressRecovered = ecrecover(hash, v, r, s);
   
    // logic of the wallet
    // if (addressRecovered == owner) executeOnTarget(target, payload);
}

Parameters

  • address target
    • The address targeted by the action.
  • uint256 nonce
    • A transaction sequence number used to prevent replay attacks when properly managed.
  • bytes memory payload
    • The data describing the action to execute.
  • uint8 v, bytes32 r, bytes32 s
    • The ECDSA signature components.

Hash calculation

javascript
`keccak256(abi.encodePacked(byte(0x19), byte(0), address(this), msg.value, nonce, payload))
  • This hash is used to verify the signature.
  • 0x19 is the magic byte indicating the signed data format, 0 is the version byte, address(this) is the contract's own address (the validator), msg.value is the amount of ETH sent with the transaction, nonce is its sequence number, and payload is the execution data.

Signature recovery

javascript
ecrecover(hash, v, r, s)
  • This function recovers an address from a hash and a signature.
  • Given a valid signature, it returns the signer's address.

Implementing the execution logic

  • The commented-out code represents the intended wallet logic.
  • Typically, an implementation checks that the recovered address matches an expected address, such as the owner. Only when that check passes does it execute an action at target using payload, such as a function call or ETH transfer.

This illustrates how an operation could be authorized in a multisignature wallet or another authentication-dependent application. A secure production implementation requires additional checks, including address validation, nonce management, and appropriate error handling. Any execution-relevant parameter, including the target, must be bound to the signature. The payable modifier allows the function to receive ETH.

Citation

Martin Holst Swende (@holiman), Nick Johnson arachnid@notdot.net, "ERC-191: Signed Data Standard," Ethereum Improvement Proposals, no. 191, January 2016. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-191.

Conclusion

This article covered ERC-191, a standard defining how signed data is handled in contracts such as multisignature wallets.

If you have questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/