-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"devDependencies": { | ||
"@commitlint/cli": "17.0.3", | ||
"@commitlint/config-conventional": "17.0.3", | ||
"@openzeppelin/contracts": "^5.0.2", | ||
"dotenv-cli": "7.2.1", | ||
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0", | ||
"forge-std": "https://github.com/foundry-rs/forge-std.git#v1.7.3", | ||
|
@@ -48,5 +49,6 @@ | |
"solhint-plugin-defi-wonderland": "1.1.2", | ||
"sort-package-json": "2.4.1", | ||
"standard-version": "9.5.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
contract OracleTypehash { | ||
bytes32 internal constant PROPOSE_TYPEHASH = keccak256('ProposeResponse(Request _request, Response _response)'); | ||
bytes32 internal constant DISPUTE_TYPEHASH = | ||
keccak256('DisputeResponse(Request _request, Response _response, Dispute _dispute,)'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {IAccessControlModule} from '../interfaces/modules/accessControl/IAccessControlModule.sol'; | ||
import {Nonces} from '@openzeppelin/contracts/utils/Nonces.sol'; | ||
|
||
import {ECDSA} from '@openzeppelin/contracts/utils/cryptography/ECDSA.sol'; | ||
import {EIP712} from '@openzeppelin/contracts/utils/cryptography/EIP712.sol'; | ||
|
||
contract PermitAccessControl is Nonces, EIP712 { | ||
/** | ||
* @notice The access control struct | ||
* @param user The address of the user | ||
* @param data The data for access control validation | ||
*/ | ||
struct AccessControlData { | ||
uint256 nonce; | ||
uint256 deadline; | ||
uint8 v; | ||
bytes32 r; | ||
bytes32 s; | ||
} | ||
|
||
error ERC2612ExpiredSignature(uint256 deadline); | ||
error ERC2612InvalidSigner(address signer, address owner); | ||
|
||
/** | ||
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. | ||
* | ||
* It's a good idea to use the same `name` that is defined as the ERC-20 token name. | ||
*/ | ||
constructor( | ||
string memory name | ||
) EIP712(name, '1') {} | ||
|
||
function hasAccess( | ||
address, | ||
address _user, | ||
bytes32 _signature, | ||
bytes memory _params, | ||
bytes calldata _data | ||
) external returns (bool _hasAccess) { | ||
AccessControlData memory _permit = abi.decode(_data, (AccessControlData)); | ||
// I don't think you care about validating the _caller | ||
// You do care for repeatability, so a nonce is 100% necessary | ||
// You care about expiration, so a deadline is 100% necessary | ||
// You care abxout the function and the parameters that were approved | ||
if (block.timestamp > _permit.deadline) { | ||
revert ERC2612ExpiredSignature(_permit.deadline); | ||
} | ||
// signature, params (removing the last parameter for the access control), nonce, deadline | ||
bytes32 structHash = keccak256(abi.encode(_signature, _params, _useNonce(_user), _permit.deadline)); | ||
|
||
bytes32 hash = _hashTypedDataV4(structHash); | ||
|
||
address signer = ECDSA.recover(hash, _permit.v, _permit.r, _permit.s); | ||
|
||
if (signer != _user) { | ||
revert ERC2612InvalidSigner(signer, _user); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters