Skip to content

Commit

Permalink
♻️ Make TimelockController Module-Friendly (#220)
Browse files Browse the repository at this point in the history
### 🕓 Changelog

This PR refactors the `TimelockController` contract to make it
module-friendly and ready for the breaking `0.4.0` release. Furthermore,
I amend the docs for the `Ownable2Step` contract.

---------

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio authored Apr 2, 2024
1 parent 87cabde commit 6753458
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 264 deletions.
168 changes: 84 additions & 84 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -658,94 +658,94 @@ SignatureCheckerTest:testFuzzEOAWithInvalidSignature(bytes,string) (runs: 257,
SignatureCheckerTest:testFuzzEOAWithInvalidSigner(string,string) (runs: 257, μ: 22170, ~: 22231)
SignatureCheckerTest:testFuzzEOAWithValidSignature(string,string) (runs: 257, μ: 21289, ~: 21350)
SignatureCheckerTest:testInitialSetup() (gas: 8315)
TimelockControllerInvariants:invariantExecutedLessThanOrEqualToScheduled() (runs: 256, calls: 3840, reverts: 1228)
TimelockControllerInvariants:invariantExecutedProposalCancellation() (runs: 256, calls: 3840, reverts: 1236)
TimelockControllerInvariants:invariantExecutingCancelledProposal() (runs: 256, calls: 3840, reverts: 1248)
TimelockControllerInvariants:invariantExecutingNotReadyProposal() (runs: 256, calls: 3840, reverts: 1194)
TimelockControllerInvariants:invariantOnceProposalExecution() (runs: 256, calls: 3840, reverts: 1211)
TimelockControllerInvariants:invariantProposalsExecutedMatchCount() (runs: 256, calls: 3840, reverts: 1228)
TimelockControllerInvariants:invariantSumOfProposals() (runs: 256, calls: 3840, reverts: 1228)
TimelockControllerTest:testAdminCannotBatchExecute() (gas: 750776)
TimelockControllerTest:testAdminCannotBatchSchedule() (gas: 748562)
TimelockControllerTest:testAdminCannotCancel() (gas: 13498)
TimelockControllerTest:testAdminCannotExecute() (gas: 18552)
TimelockControllerTest:testAdminCannotSchedule() (gas: 16224)
TimelockControllerTest:testBatchCancelFinished() (gas: 4641628)
TimelockControllerTest:testBatchEqualAndGreaterMinimumDelay() (gas: 6145274)
TimelockControllerTest:testBatchHasBeenExecuted() (gas: 4639618)
TimelockControllerTest:testBatchHasNotBeenExecuted() (gas: 3078886)
TimelockControllerTest:testBatchInsufficientDelay() (gas: 1532923)
TimelockControllerTest:testBatchMinimumDelayUpdate() (gas: 3086579)
TimelockControllerTest:testBatchOperationAlreadyScheduled() (gas: 4593561)
TimelockControllerTest:testBatchOperationIsNotReady() (gas: 4598878)
TimelockControllerTest:testBatchPendingIfExecuted() (gas: 4638232)
TimelockControllerTest:testBatchPendingIfNotYetExecuted() (gas: 3078894)
TimelockControllerTest:testBatchPredecessorInvalid() (gas: 4601231)
TimelockControllerTest:testBatchPredecessorMultipleNotExecuted() (gas: 6141917)
TimelockControllerTest:testBatchPredecessorNotExecuted() (gas: 7663188)
TimelockControllerTest:testBatchPredecessorNotScheduled() (gas: 6117091)
TimelockControllerTest:testBatchReadyAfterTheExecutionTime() (gas: 3079459)
TimelockControllerTest:testBatchReadyBeforeTheExecutionTime() (gas: 3079476)
TimelockControllerTest:testBatchReadyOnTheExecutionTime() (gas: 3079362)
TimelockControllerTest:testBatchScheduleAndExecuteWithEmptySalt() (gas: 4647416)
TimelockControllerTest:testBatchScheduleAndExecuteWithNonEmptySalt() (gas: 4650861)
TimelockControllerTest:testBatchTargetRevert() (gas: 9186542)
TimelockControllerTest:testBatchTimestampHasBeenExecuted() (gas: 4638070)
TimelockControllerTest:testBatchTimestampHasNotBeenExecuted() (gas: 3078714)
TimelockControllerInvariants:statefulFuzzExecutedLessThanOrEqualToScheduled() (runs: 256, calls: 3840, reverts: 1247)
TimelockControllerInvariants:statefulFuzzExecutedProposalCancellation() (runs: 256, calls: 3840, reverts: 1288)
TimelockControllerInvariants:statefulFuzzExecutingCancelledProposal() (runs: 256, calls: 3840, reverts: 1234)
TimelockControllerInvariants:statefulFuzzExecutingNotReadyProposal() (runs: 256, calls: 3840, reverts: 1227)
TimelockControllerInvariants:statefulFuzzOnceProposalExecution() (runs: 256, calls: 3840, reverts: 1224)
TimelockControllerInvariants:statefulFuzzProposalsExecutedMatchCount() (runs: 256, calls: 3840, reverts: 1247)
TimelockControllerInvariants:statefulFuzzSumOfProposals() (runs: 256, calls: 3840, reverts: 1247)
TimelockControllerTest:testAdminCannotBatchExecute() (gas: 750799)
TimelockControllerTest:testAdminCannotBatchSchedule() (gas: 748585)
TimelockControllerTest:testAdminCannotCancel() (gas: 13521)
TimelockControllerTest:testAdminCannotExecute() (gas: 18598)
TimelockControllerTest:testAdminCannotSchedule() (gas: 16247)
TimelockControllerTest:testBatchCancelFinished() (gas: 4641697)
TimelockControllerTest:testBatchEqualAndGreaterMinimumDelay() (gas: 6145366)
TimelockControllerTest:testBatchHasBeenExecuted() (gas: 4639664)
TimelockControllerTest:testBatchHasNotBeenExecuted() (gas: 3078909)
TimelockControllerTest:testBatchInsufficientDelay() (gas: 1532946)
TimelockControllerTest:testBatchMinimumDelayUpdate() (gas: 3086625)
TimelockControllerTest:testBatchOperationAlreadyScheduled() (gas: 4593607)
TimelockControllerTest:testBatchOperationIsNotReady() (gas: 4598924)
TimelockControllerTest:testBatchPendingIfExecuted() (gas: 4638278)
TimelockControllerTest:testBatchPendingIfNotYetExecuted() (gas: 3078917)
TimelockControllerTest:testBatchPredecessorInvalid() (gas: 4601277)
TimelockControllerTest:testBatchPredecessorMultipleNotExecuted() (gas: 6141986)
TimelockControllerTest:testBatchPredecessorNotExecuted() (gas: 7663257)
TimelockControllerTest:testBatchPredecessorNotScheduled() (gas: 6117137)
TimelockControllerTest:testBatchReadyAfterTheExecutionTime() (gas: 3079482)
TimelockControllerTest:testBatchReadyBeforeTheExecutionTime() (gas: 3079499)
TimelockControllerTest:testBatchReadyOnTheExecutionTime() (gas: 3079385)
TimelockControllerTest:testBatchScheduleAndExecuteWithEmptySalt() (gas: 4647531)
TimelockControllerTest:testBatchScheduleAndExecuteWithNonEmptySalt() (gas: 4650976)
TimelockControllerTest:testBatchTargetRevert() (gas: 9186634)
TimelockControllerTest:testBatchTimestampHasBeenExecuted() (gas: 4638116)
TimelockControllerTest:testBatchTimestampHasNotBeenExecuted() (gas: 3078737)
TimelockControllerTest:testCanReceiveEther() (gas: 15016)
TimelockControllerTest:testCancellerCanCancelOperation() (gas: 3065193)
TimelockControllerTest:testCompleteOperationWithAssignExecutorRoleToZeroAddress() (gas: 125339)
TimelockControllerTest:testCompletePipelineOperationMinimumDelayUpdate() (gas: 73717)
TimelockControllerTest:testCompletePipelineOperationSetRoleAdmin() (gas: 101140)
TimelockControllerTest:testExecutorCanBatchExecute() (gas: 3049657)
TimelockControllerTest:testExecutorCanExecute() (gas: 30232)
TimelockControllerTest:testExecutorCannotBatchSchedule() (gas: 1485781)
TimelockControllerTest:testExecutorCannotCancel() (gas: 15717)
TimelockControllerTest:testExecutorCannotSchedule() (gas: 19383)
TimelockControllerTest:testFuzzBatchValue(uint256) (runs: 257, μ: 4653472, ~: 4653589)
TimelockControllerTest:testFuzzHashOperation(address,uint256,bytes,bytes32,bytes32) (runs: 257, μ: 11069, ~: 10967)
TimelockControllerTest:testCancellerCanCancelOperation() (gas: 3065262)
TimelockControllerTest:testCompleteOperationWithAssignExecutorRoleToZeroAddress() (gas: 125385)
TimelockControllerTest:testCompletePipelineOperationMinimumDelayUpdate() (gas: 73832)
TimelockControllerTest:testCompletePipelineOperationSetRoleAdmin() (gas: 101209)
TimelockControllerTest:testExecutorCanBatchExecute() (gas: 3049703)
TimelockControllerTest:testExecutorCanExecute() (gas: 30324)
TimelockControllerTest:testExecutorCannotBatchSchedule() (gas: 1485827)
TimelockControllerTest:testExecutorCannotCancel() (gas: 15763)
TimelockControllerTest:testExecutorCannotSchedule() (gas: 19429)
TimelockControllerTest:testFuzzBatchValue(uint256) (runs: 257, μ: 4653491, ~: 4653635)
TimelockControllerTest:testFuzzHashOperation(address,uint256,bytes,bytes32,bytes32) (runs: 257, μ: 11092, ~: 10990)
TimelockControllerTest:testFuzzHashOperationBatch(address[],uint256[],bytes[],bytes32,bytes32) (runs: 257, μ: 1907784, ~: 1935381)
TimelockControllerTest:testFuzzOperationValue(uint256) (runs: 257, μ: 113831, ~: 113948)
TimelockControllerTest:testHandleERC1155() (gas: 41708457)
TimelockControllerTest:testHandleERC721() (gas: 7242387)
TimelockControllerTest:testHashOperation() (gas: 13089)
TimelockControllerTest:testFuzzOperationValue(uint256) (runs: 257, μ: 113896, ~: 114040)
TimelockControllerTest:testHandleERC1155() (gas: 41708480)
TimelockControllerTest:testHandleERC721() (gas: 7242410)
TimelockControllerTest:testHashOperation() (gas: 13112)
TimelockControllerTest:testHashOperationBatch() (gas: 1526310)
TimelockControllerTest:testInitialSetup() (gas: 4396244)
TimelockControllerTest:testInvalidOperation() (gas: 10719)
TimelockControllerTest:testOperationAlreadyScheduled() (gas: 52466)
TimelockControllerTest:testOperationCancelFinished() (gas: 102072)
TimelockControllerTest:testOperationEqualAndGreaterMinimumDelay() (gas: 90672)
TimelockControllerTest:testOperationHasBeenExecuted() (gas: 100095)
TimelockControllerTest:testOperationHasNotBeenExecuted() (gas: 52687)
TimelockControllerTest:testOperationInsufficientDelay() (gas: 19637)
TimelockControllerTest:testOperationMinimumDelayUpdate() (gas: 61720)
TimelockControllerTest:testOperationOperationIsNotReady() (gas: 57821)
TimelockControllerTest:testOperationPendingIfExecuted() (gas: 98665)
TimelockControllerTest:testOperationPendingIfNotYetExecuted() (gas: 52751)
TimelockControllerTest:testOperationPredecessorInvalid() (gas: 63001)
TimelockControllerTest:testOperationPredecessorMultipleNotExecuted() (gas: 92638)
TimelockControllerTest:testOperationPredecessorNotExecuted() (gas: 99399)
TimelockControllerTest:testOperationPredecessorNotScheduled() (gas: 66880)
TimelockControllerTest:testOperationReadyAfterTheExecutionTime() (gas: 53306)
TimelockControllerTest:testOperationReadyBeforeTheExecutionTime() (gas: 53249)
TimelockControllerTest:testOperationReadyOnTheExecutionTime() (gas: 53143)
TimelockControllerTest:testOperationTargetRevert() (gas: 110257)
TimelockControllerTest:testOperationTimestampHasBeenExecuted() (gas: 98439)
TimelockControllerTest:testOperationTimestampHasNotBeenExecuted() (gas: 52538)
TimelockControllerTest:testProposerCanBatchSchedule() (gas: 3088649)
TimelockControllerTest:testProposerCanCancel() (gas: 20647)
TimelockControllerTest:testProposerCanSchedule() (gas: 75567)
TimelockControllerTest:testProposerCannotBatchExecute() (gas: 1490192)
TimelockControllerTest:testProposerCannotExecute() (gas: 23909)
TimelockControllerTest:testInitialSetup() (gas: 4451537)
TimelockControllerTest:testInvalidOperation() (gas: 10742)
TimelockControllerTest:testOperationAlreadyScheduled() (gas: 52535)
TimelockControllerTest:testOperationCancelFinished() (gas: 102187)
TimelockControllerTest:testOperationEqualAndGreaterMinimumDelay() (gas: 90810)
TimelockControllerTest:testOperationHasBeenExecuted() (gas: 100187)
TimelockControllerTest:testOperationHasNotBeenExecuted() (gas: 52733)
TimelockControllerTest:testOperationInsufficientDelay() (gas: 19660)
TimelockControllerTest:testOperationMinimumDelayUpdate() (gas: 61789)
TimelockControllerTest:testOperationOperationIsNotReady() (gas: 57913)
TimelockControllerTest:testOperationPendingIfExecuted() (gas: 98757)
TimelockControllerTest:testOperationPendingIfNotYetExecuted() (gas: 52797)
TimelockControllerTest:testOperationPredecessorInvalid() (gas: 63093)
TimelockControllerTest:testOperationPredecessorMultipleNotExecuted() (gas: 92753)
TimelockControllerTest:testOperationPredecessorNotExecuted() (gas: 99537)
TimelockControllerTest:testOperationPredecessorNotScheduled() (gas: 66995)
TimelockControllerTest:testOperationReadyAfterTheExecutionTime() (gas: 53352)
TimelockControllerTest:testOperationReadyBeforeTheExecutionTime() (gas: 53295)
TimelockControllerTest:testOperationReadyOnTheExecutionTime() (gas: 53189)
TimelockControllerTest:testOperationTargetRevert() (gas: 110441)
TimelockControllerTest:testOperationTimestampHasBeenExecuted() (gas: 98531)
TimelockControllerTest:testOperationTimestampHasNotBeenExecuted() (gas: 52584)
TimelockControllerTest:testProposerCanBatchSchedule() (gas: 3088695)
TimelockControllerTest:testProposerCanCancel() (gas: 20693)
TimelockControllerTest:testProposerCanSchedule() (gas: 75613)
TimelockControllerTest:testProposerCannotBatchExecute() (gas: 1490238)
TimelockControllerTest:testProposerCannotExecute() (gas: 24001)
TimelockControllerTest:testReturnsLaterMinimumDelayForCalls() (gas: 20780)
TimelockControllerTest:testRevertWhenNotTimelock() (gas: 9249)
TimelockControllerTest:testScheduleAndExecuteWithEmptySalt() (gas: 107902)
TimelockControllerTest:testScheduleAndExecuteWithNonEmptySalt() (gas: 111259)
TimelockControllerTest:testStrangerCannotBatchExecute() (gas: 748795)
TimelockControllerTest:testStrangerCannotBatchSchedule() (gas: 746602)
TimelockControllerTest:testStrangerCannotCancel() (gas: 11494)
TimelockControllerTest:testStrangerCannotExecute() (gas: 16569)
TimelockControllerTest:testStrangerCannotSchedule() (gas: 14353)
TimelockControllerTest:testRevertWhenNotTimelock() (gas: 9295)
TimelockControllerTest:testScheduleAndExecuteWithEmptySalt() (gas: 108063)
TimelockControllerTest:testScheduleAndExecuteWithNonEmptySalt() (gas: 111420)
TimelockControllerTest:testStrangerCannotBatchExecute() (gas: 748818)
TimelockControllerTest:testStrangerCannotBatchSchedule() (gas: 746625)
TimelockControllerTest:testStrangerCannotCancel() (gas: 11517)
TimelockControllerTest:testStrangerCannotExecute() (gas: 16615)
TimelockControllerTest:testStrangerCannotSchedule() (gas: 14376)
TimelockControllerTest:testSupportsInterfaceInvalidInterfaceId() (gas: 8490)
TimelockControllerTest:testSupportsInterfaceInvalidInterfaceIdGasCost() (gas: 9280)
TimelockControllerTest:testSupportsInterfaceSuccess() (gas: 10814)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- [`AccessControl`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/auth/AccessControl.vy): Make `AccessControl` module-friendly. ([#216](https://github.com/pcaversaccio/snekmate/pull/216))
- [`Ownable`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/auth/Ownable.vy): Make `Ownable` module-friendly. ([#218](https://github.com/pcaversaccio/snekmate/pull/218))
- [`Ownable2Step`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/auth/Ownable2Step.vy): Make `Ownable2Step` module-friendly. ([#219](https://github.com/pcaversaccio/snekmate/pull/219))
- **Governance**
- [`TimelockController`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/src/snekmate/governance/TimelockController.vy): Make `TimelockController` module-friendly. ([#220](https://github.com/pcaversaccio/snekmate/pull/220))
- **Vyper Contract Deployer**
- [`VyperDeployer`](https://github.com/pcaversaccio/snekmate/blob/v0.1.0/lib/utils/VyperDeployer.sol): Improve error message in the event of a Vyper compilation error. ([#219](https://github.com/pcaversaccio/snekmate/pull/219))

Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@ src
│ ├── Ownable — "Owner-Based Access Control Functions"
│ ├── Ownable2Step — "2-Step Ownership Transfer Functions"
│ ├── AccessControl — "Multi-Role-Based Access Control Functions"
│ └── interfaces
│ └── IAccessControl — "AccessControl Interface Definition"
│ ├── interfaces
│ │ └── IAccessControl — "AccessControl Interface Definition"
│ └── mocks
│ ├── OwnableMock — "Ownable Module Reference Implementation"
│ ├── Ownable2StepMock — "Ownable2Step Module Reference Implementation"
│ └── AccessControlMock — "AccessControl Module Reference Implementation"
├── extensions
│ ├── ERC2981 — "ERC-721 and ERC-1155 Compatible ERC-2981 Reference Implementation"
│ ├── ERC4626 — "Modern and Gas-Efficient ERC-4626 Tokenised Vault Implementation"
│ └── interfaces
│ └── IERC2981 — "EIP-2981 Interface Definition"
├── governance
│ └── TimelockController — "Multi-Role-Based Timelock Controller Reference Implementation"
│ ├── TimelockController — "Multi-Role-Based Timelock Controller Reference Implementation"
│ └── mocks
│ └── TimelockControllerMock — "TimelockController Module Reference Implementation"
├── tokens
│ ├── ERC20 — "Modern and Gas-Efficient ERC-20 + EIP-2612 Implementation"
│ ├── ERC721 — "Modern and Gas-Efficient ERC-721 + EIP-4494 Implementation"
Expand Down
11 changes: 8 additions & 3 deletions src/snekmate/auth/Ownable2Step.vy
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
@notice These functions can be used to implement a basic access
control mechanism, where there is an account (an owner)
that can be granted exclusive access to specific functions.
By default, the owner account will be the one that deploys
the contract. This can later be changed with `transfer_ownership`
and `accept_ownership`.
This extension to the {Ownable} contract includes a two-step
ownership transfer mechanism where the new owner must call
`accept_ownership` to replace the old one. This can help
avoid common mistakes, such as ownership transfers to incorrect
accounts or to contracts that are unable to interact with
the permission system. By default, the owner account will
be the one that deploys the contract. This can later be
changed with `transfer_ownership` and `accept_ownership`.
The implementation is inspired by OpenZeppelin's implementation here:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable2Step.sol.
"""
Expand Down
18 changes: 9 additions & 9 deletions src/snekmate/auth/mocks/AccessControlMock.vy
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ from .. import AccessControl as ac
initializes: ac


# @dev The 32-byte minter role.
MINTER_ROLE: public(constant(bytes32)) = keccak256("MINTER_ROLE")


# @dev The 32-byte pauser role.
PAUSER_ROLE: public(constant(bytes32)) = keccak256("PAUSER_ROLE")


# @dev We export (i.e. the runtime bytecode exposes these
# functions externally, allowing them to be called using
# the ABI encoding specification) all `external` functions
Expand All @@ -42,8 +34,8 @@ PAUSER_ROLE: public(constant(bytes32)) = keccak256("PAUSER_ROLE")
# `immutable`, and state variables, for which Vyper automatically
# generates an `external` getter function for the variable.
exports: (
ac.supportsInterface,
ac.DEFAULT_ADMIN_ROLE,
ac.supportsInterface,
ac.hasRole,
ac.getRoleAdmin,
ac.grantRole,
Expand All @@ -53,6 +45,14 @@ exports: (
)


# @dev The 32-byte minter role.
MINTER_ROLE: public(constant(bytes32)) = keccak256("MINTER_ROLE")


# @dev The 32-byte pauser role.
PAUSER_ROLE: public(constant(bytes32)) = keccak256("PAUSER_ROLE")


@deploy
@payable
def __init__():
Expand Down
Loading

0 comments on commit 6753458

Please sign in to comment.