Repository navigation
Expand file tree
/
Copy pathLockRequestable.sol
More file actions
53 lines (49 loc) · 1.79 KB
/
Copy pathLockRequestable.sol
File metadata and controls
53 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2020 Gemini Trust Company LLC. All Rights Reserved
pragma solidity ^0.8.0;
/** @title A contract for generating unique identifiers
*
* @notice A contract that provides a identifier generation scheme,
* guaranteeing uniqueness across all contracts that inherit from it,
* as well as unpredictability of future identifiers.
*
* @dev This contract is intended to be inherited by any contract that
* implements the callback software pattern for cooperative custodianship.
*
* @author Gemini Trust Company, LLC
*/
abstract contract LockRequestable {
// MEMBERS
/// @notice the count of all invocations of `generateLockId`.
uint256 public lockRequestCount;
// CONSTRUCTOR
constructor() {
lockRequestCount = 0;
}
// FUNCTIONS
/** @notice Returns a fresh unique identifier.
*
* @dev the generation scheme uses three components.
* First, the blockhash of the previous block.
* Second, the deployed address.
* Third, the next value of the counter.
* This ensure that identifiers are unique across all contracts
* following this scheme, and that future identifiers are
* unpredictable.
*
* @return lockId a 32-byte unique identifier.
*/
function generateLockId() internal returns (bytes32 lockId) {
unchecked {
// unchecked `-` is safe as this can never be evaluated in the genesis (0) block
// unchecked `++` is safe as it is infeasible to exhaust 256-bit integer counter
return keccak256(
abi.encodePacked(
blockhash(block.number - 1),
address(this),
++lockRequestCount
)
);
}
}
}