From 1e2c0d299b698feb2dcfa470c79d9a8ea3e844c0 Mon Sep 17 00:00:00 2001 From: b00ste Date: Wed, 9 Aug 2023 12:41:30 +0300 Subject: [PATCH] refactor: mark relay call signature as used --- contracts/LSP6KeyManager/LSP6Errors.sol | 7 +++++++ contracts/LSP6KeyManager/LSP6KeyManagerCore.sol | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/contracts/LSP6KeyManager/LSP6Errors.sol b/contracts/LSP6KeyManager/LSP6Errors.sol index d3101ea0a..5a498453f 100644 --- a/contracts/LSP6KeyManager/LSP6Errors.sol +++ b/contracts/LSP6KeyManager/LSP6Errors.sol @@ -165,3 +165,10 @@ error RelayCallBeforeStartTime(); * @dev reverts when the period to execute the relay call has expired */ error RelayCallExpired(); + +/** + * @dev reverts when trying to use the same signature twice. + * @notice Cannot use signature: `signature` twice! + * @param signature The [EIP-191] signed data. + */ +error CannotUseSignatureTwice(bytes signature); diff --git a/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol b/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol index 4ac83fafa..447e17bad 100644 --- a/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol +++ b/contracts/LSP6KeyManager/LSP6KeyManagerCore.sol @@ -40,7 +40,8 @@ import { InvalidERC725Function, CannotSendValueToSetData, RelayCallBeforeStartTime, - RelayCallExpired + RelayCallExpired, + CannotUseSignatureTwice } from "./LSP6Errors.sol"; import { @@ -80,6 +81,9 @@ abstract contract LSP6KeyManagerCore is // https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.8/contracts/security/ReentrancyGuard.sol bool internal _reentrancyStatus; + // Mapping to keep track of all message hashes that have been approved by ALL REQUIRED owners + mapping(bytes32 => uint256) public signedMessages; + mapping(address => mapping(uint256 => uint256)) internal _nonceStore; function target() public view virtual returns (address) { @@ -347,6 +351,9 @@ abstract contract LSP6KeyManagerCore is uint256 msgValue, bytes calldata payload ) internal virtual returns (bytes memory) { + if (signedMessages[keccak256(signature)] == 1) { + revert CannotUseSignatureTwice(signature); + } if (payload.length < 4) { revert InvalidPayload(payload); } @@ -403,6 +410,8 @@ abstract contract LSP6KeyManagerCore is _nonReentrantAfter(); } + signedMessages[keccak256(signature)] = 1; + return result; }