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 explains signature replay vulnerabilities in smart contracts.
Signature replay can be difficult to understand at first, so we will work through a simple example. The subject is important for Solidity developers and bug bounty researchers.
If you are unfamiliar with bug bounties, start here.
[Solidity-Bug Bounty] A Beginner's Guide to Bug Bounties
What is signature replay?

Signature replay
A signature replay attack occurs when a previously valid signature is reused to authorize an operation that the signer did not intend to authorize again.
Imagine two people, Alice and Bob, whose approval is required for an operation. Each signs using their own private key. From here on, we refer to these approvals as signatures.
Suppose a smart contract allows a deposit of 1 ETH after both parties have approved it, as illustrated below.

In this arrangement, the illustrated process involves three transactions, meaning three separate contract calls.
Instead, Bob could give Alice his off-chain signature, and Alice could submit a single transaction containing both signatures and 1 ETH.

Fewer transactions can reduce the time required and the total gas cost.
However, the contract must prevent Alice from reusing Bob's signature for an unauthorized operation.
Imagine a withdrawal function that also requires signatures from both parties. If the contract does not bind signatures to their intended operations or prevent reuse, Alice might submit a previously obtained signature without seeking Bob's approval again.
The illustration shows how repeated or improperly scoped authorization could put the contract's ETH balance at risk.

A signature over a properly distinguished deposit message cannot automatically authorize a different withdrawal message. The specific risk depends on what the signed message contains and how the contract validates it.
Signature replay code
The following historical example is adapted from:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.5/contracts/utils/cryptography/ECDSA.sol";
contract Signature {
using ECDSA for bytes32;
// 2人のユーザーの署名を格納。
address[2] public owners;
// コントラクト実行時に検証用の署名を渡す
constructor(address[2] memory _owners) payable {
owners = _owners;
}
/// @notice 資金を預ける関数。
function deposit() external payable {}
/// @notice 2人の署名が正しいか確認して、資金を送る関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @param _sigs 2つの署名の配列。
function transfer(address _to, uint _amount, bytes[2] memory _sigs) external {
bytes32 txHash = getTxHash(_to, _amount);
require(_checkSigs(_sigs, txHash), "invalid sig");
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
/// @notice 受け取った情報からハッシュ値を生成する関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @return _toと_amountのハッシュ値。
function getTxHash(address _to, uint _amount) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_to, _amount));
}
/// @notice 2つの署名が正しいか検証する関数。
/// @param _sigs 2つの署名が格納された配列。
/// @param _txHash _toと_amountのハッシュ値。
function _checkSigs(
bytes[2] memory _sigs,
bytes32 _txHash
) private view returns (bool) {
bytes32 ethSignedHash = _txHash.toEthSignedMessageHash();
for (uint i = 0; i < _sigs.length; i++) {
address signer = ethSignedHash.recover(_sigs[i]);
bool valid = signer == owners[i];
if (!valid) {
return false;
}
}
return true;
}
}constructor
The constructor stores the addresses of the two authorized signers in the owners array. These are addresses, not signatures.
deposit
Accepts deposits of funds.
transfer
Computes a transaction hash, verifies that the two required signers approved it, and sends the specified amount of ETH to the recipient address _to.
getTxHash
Computes a hash from the address supplied in _to and the amount supplied in _amount.
_checkSigs
Verifies the two signatures.
The ECDSA recover function returns the address recovered from the signed message hash and signature.
The toEthSignedMessageHash function applies the Ethereum signed-message prefix and hashes the result, matching the corresponding signed-message format.
Security risk
The vulnerability is that the same authorization can be reused. The hash includes the recipient and amount, but it does not uniquely identify a particular authorized execution.
Once both valid signatures for a given recipient and amount are available, the example does not prevent repeated execution with that same authorization.
Mitigating signature replay

The preceding example illustrates why signature validation alone does not establish whether an authorization has already been consumed.
The original article describes the following mitigations.
Mitigations
- Include a nonce when generating
txHash. - Track previously executed transaction hashes in a mapping and reject a hash that has already been used.
- Include the address of the contract authorized to release the funds when generating
txHash.
Include a nonce
A nonce allows otherwise identical intended transfers to have different message hashes. Each authorization must use a nonce according to the contract's uniqueness rules, and the nonce must be covered by the signatures.
Track executed transaction hashes
Record the generated transaction hash in a mapping when an authorization is consumed.
The contract can then determine whether the same hash has been used before and reject a repeated execution.
Include the contract address in the hash
Including the address of the contract that executes the withdrawal binds the authorization to that contract. In a multichain setting, chain ID and an appropriate signing domain are also important, because the same address can exist on different chains.
Code walkthrough
The original article presents the following code. It is retained for historical fidelity, but it contains compile-time inconsistencies and should not be treated as a working implementation.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.5/contracts/utils/cryptography/ECDSA.sol";
contract Signature {
using ECDSA for bytes32;
// 2人のユーザーの署名を格納。
address[2] public owners;
// txHashが使用されたか格納する配列。
mapping(bytes32 => bool) public executed;
// コントラクト実行時に検証用の署名を渡す
constructor(address[2] memory _owners) payable {
owners = _owners;
}
/// @notice 資金を預ける関数。
function deposit() external payable {}
/// @notice 2人の署名が正しいか確認して、資金を送る関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @param _sigs 2つの署名の配列。
function transfer(address _to, uint _amount, bytes[2] memory _sigs) external {
bytes32 txHash = getTxHash(_to, _amount);
// 既に使用されたtxHashではないかチェック。
require(!executed[txHash], "tx executed");
require(_checkSigs(_sigs, txHash), "invalid sig");
executed[txHash] = true;
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
/// @notice 受け取った情報からハッシュ値を生成する関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @param _nonce 毎回の取引で異なる値。
/// @return _toと_amountのハッシュ値。
function getTxHash(
address _to,
uint _amount,
uint _nonce
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(address(this), _to, _amount, _nonce));
}
/// @notice 2つの署名が正しいか検証する関数。
/// @param _sigs 2つの署名が格納された配列。
/// @param _txHash _toと_amountのハッシュ値。
function _checkSigs(
bytes[2] memory _sigs,
bytes32 _txHash
) private view returns (bool) {
bytes32 ethSignedHash = _txHash.toEthSignedMessageHash();
for (uint i = 0; i < _sigs.length; i++) {
address signer = ethSignedHash.recover(_sigs[i]);
bool valid = signer == owners[i];
if (!valid) {
return false;
}
}
return true;
}
}The mapping near line 13 records whether each transaction hash has been executed. The hash function near line 49 includes the contract address and nonce. The check near line 30 rejects an already executed hash before the external transfer.
There are two concrete issues in the preserved example: transfer calls getTxHash with two arguments even though the latter requires three, and getTxHash is marked pure while reading address(this). A functioning implementation must resolve both issues and ensure the nonce is signed and consumed correctly. The example has not been compiled or executed as part of this translation.
Conclusion

This article explained signature replay and the security problems caused by reusable authorizations.
Key points
- Understand what signature replay means.
- Recognize why signature replay is dangerous.
- Understand how to prevent replay through unique, scoped, single-use authorizations.
If you have questions, feel free to contact me on Twitter. I regularly write about Solidity, blockchain, and Web3, and share interesting articles there.
References
Signature Replay Vulnerabilities in Smart Contracts
https://coinsbench.com/signature-replay-hack-solidity-13-735997ad02e5
https://docs.openzeppelin.com/contracts/2.x/utilities
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.5/contracts/utils/cryptography/ECDSA.sol";
contract Signature {
using ECDSA for bytes32;
// 2人のユーザーの署名を格納。
address[2] public owners;
// txHashが使用されたか格納する配列。
mapping(bytes32 => bool) public executed;
// コントラクト実行時に検証用の署名を渡す
constructor(address[2] memory _owners) payable {
owners = _owners;
}
/// @notice 資金を預ける関数。
function deposit() external payable {}
/// @notice 2人の署名が正しいか確認して、資金を送る関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @param _sigs 2つの署名の配列。
function transfer(address _to, uint _amount, bytes[2] memory _sigs) external {
bytes32 txHash = getTxHash(_to, _amount);
// 既に使用されたtxHashではないかチェック。
require(!executed[txHash], "tx executed");
require(_checkSigs(_sigs, txHash), "invalid sig");
executed[txHash] = true;
(bool sent, ) = _to.call{value: _amount}("");
require(sent, "Failed to send Ether");
}
/// @notice 受け取った情報からハッシュ値を生成する関数。
/// @param _to 資金を受け取るアドレス。
/// @param _amount 引き出す資金。
/// @param _nonce 毎回の取引で異なる値。
/// @return _toと_amountのハッシュ値。
function getTxHash(
address _to,
uint _amount,
uint _nonce
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(address(this), _to, _amount, _nonce));
}
/// @notice 2つの署名が正しいか検証する関数。
/// @param _sigs 2つの署名が格納された配列。
/// @param _txHash _toと_amountのハッシュ値。
function _checkSigs(
bytes[2] memory _sigs,
bytes32 _txHash
) private view returns (bool) {
bytes32 ethSignedHash = _txHash.toEthSignedMessageHash();
for (uint i = 0; i < _sigs.length; i++) {
address signer = ethSignedHash.recover(_sigs[i]);
bool valid = signer == owners[i];
if (!valid) {
return false;
}
}
return true;
}
}