Skip to content

Commit

Permalink
refactor: mark relay call signature as used
Browse files Browse the repository at this point in the history
  • Loading branch information
b00ste committed Aug 9, 2023
1 parent 3e7e2b8 commit 1e2c0d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions contracts/LSP6KeyManager/LSP6Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
11 changes: 10 additions & 1 deletion contracts/LSP6KeyManager/LSP6KeyManagerCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
InvalidERC725Function,
CannotSendValueToSetData,
RelayCallBeforeStartTime,
RelayCallExpired
RelayCallExpired,
CannotUseSignatureTwice
} from "./LSP6Errors.sol";

import {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -403,6 +410,8 @@ abstract contract LSP6KeyManagerCore is
_nonReentrantAfter();
}

signedMessages[keccak256(signature)] = 1;

return result;
}

Expand Down

0 comments on commit 1e2c0d2

Please sign in to comment.