Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ef52cdc
Remove the GovernorCompatibilyBravo module in favor of the simpler Go…
Amxx Jun 16, 2023
37f33a8
Update contracts/governance/README.adoc
Amxx Jun 16, 2023
0eb90ca
Apply suggestions from code review
Amxx Jun 20, 2023
fb35e92
wip
Amxx Jun 28, 2023
841c80d
Merge remote-tracking branch 'upstream' into feature/Governor-storage
Amxx Jun 28, 2023
4b97eb4
refactor state checking
Amxx Jun 28, 2023
0f89b6a
update docs
Amxx Jun 28, 2023
1d7e28c
fix lint
Amxx Jun 28, 2023
79ad539
_queue returns bool
Amxx Jun 29, 2023
c1a6eee
add changeset
Amxx Jun 29, 2023
51b37ec
bool → eta
Amxx Jun 29, 2023
f527b69
minimize change
Amxx Jun 29, 2023
1d60a50
split propose into public + internal
Amxx Jun 29, 2023
67f808a
split internals function
Amxx Jun 29, 2023
9b76c86
Update contracts/governance/extensions/GovernorStorage.sol
Amxx Jun 29, 2023
caf1fe8
wip
Amxx Jun 30, 2023
30eb76c
Merge remote-tracking branch 'upstream' into feature/Governor-storage
Amxx Jun 30, 2023
44e23cc
fix lint
Amxx Jul 3, 2023
18c1e35
test GovernorStorage
Amxx Jul 3, 2023
35d6359
coverage
Amxx Jul 3, 2023
aeae17e
lint
Amxx Jul 3, 2023
d4f858e
Merge remote-tracking branch 'upstream' into feature/Governor-storage
Amxx Jul 3, 2023
ce87721
move proposalEta to core
Amxx Jul 3, 2023
57cad90
Merge branch 'master' into feature/Governor-storage
Amxx Jul 5, 2023
8b7788b
fix lint
Amxx Jul 5, 2023
e7d2123
Merge remote-tracking branch 'upstream' into feature/Governor-storage
Amxx Jul 7, 2023
f2d55b0
Merge branch 'master' into feature/Governor-storage
ernestognw Jul 19, 2023
a67ce0e
remove proposalId from the internal function. It is now computed inte…
Amxx Jul 25, 2023
c8717b6
Merge branch 'master' into feature/Governor-storage
Amxx Jul 27, 2023
1b7a395
improve docs
frangio Jul 28, 2023
b97a4b7
rename implemented -> queued
frangio Jul 28, 2023
b828ced
rename _{queue,execute}Calls to _do{Queue,Execute}
frangio Jul 28, 2023
899b14b
typo
frangio Jul 28, 2023
edd9c35
edit docs section on GovStorage
frangio Jul 28, 2023
869836f
fix timelock id
frangio Jul 28, 2023
0091b82
remove proposalId and add descriptionHash to return values
frangio Jul 28, 2023
331f8e1
revert on unknown proposalId
frangio Jul 28, 2023
d44e090
lint
frangio Jul 29, 2023
ef1c20f
remove GovernorCompatibilityBravo.test.js
frangio Jul 29, 2023
11ca422
rename getters
frangio Jul 29, 2023
977083a
update changeset
frangio Jul 29, 2023
8084aa3
update changeset
frangio Jul 29, 2023
5645ec8
fix test helpers & remove clock from the governor interface id
Amxx Jul 31, 2023
9d2ac8b
_doQueue returns eta only
Amxx Jul 31, 2023
ccd0d47
Update docs/modules/ROOT/pages/governance.adoc
Amxx Jul 31, 2023
d3d2396
merge _proposals and _proposalsExtra mappings
Amxx Jul 31, 2023
440cedc
Apply suggestions from code review
frangio Aug 1, 2023
bdddeda
switch to custom error and add tests
frangio Aug 1, 2023
b2445f8
Batch GovernorStorage transactions setup
ernestognw Aug 1, 2023
2a8dfb3
improve _cancel docs
frangio Aug 1, 2023
02e43ff
add proposalThreshold in IGovernor
frangio Aug 1, 2023
92589ff
improve definition of ETA
frangio Aug 1, 2023
e313b71
remove redundant docs
frangio Aug 1, 2023
caf04b2
edit docs for queue
frangio Aug 1, 2023
b01dad5
add note on possible revert in _queue
frangio Aug 1, 2023
ec55fe1
Merge remote-tracking branch 'upstream/master' into feature/Governor-…
frangio Aug 1, 2023
6b352c4
add missing await
frangio Aug 1, 2023
6f99bc9
fix variable
frangio Aug 1, 2023
62f6fd6
Revert "add missing await"
frangio Aug 1, 2023
037831e
rename _do{Queue,Execute} to _{queue,execute}Operations
frangio Aug 1, 2023
5e74069
lint
frangio Aug 1, 2023
8cb38ed
remove internal _queue and _execute
frangio Aug 3, 2023
d861ec1
make governor into interface
frangio Aug 1, 2023
f9240de
turn IGovernor into interface
frangio Aug 3, 2023
9e7f04e
lint
frangio Aug 3, 2023
d1d8e83
lint
frangio Aug 3, 2023
ae58b64
fix docs
frangio Aug 3, 2023
d2e54af
Remove clock and CLOCK_Mode from IGovernor
Amxx Aug 3, 2023
1853702
document memory/storage insonsistency has beeing the result of gas co…
Amxx Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into feature/Governor-storage
  • Loading branch information
ernestognw committed Jul 19, 2023
commit f2d55b0bff8b4d583f4b4c1a68c17b9d20f14c58
5 changes: 5 additions & 0 deletions .changeset/afraid-walls-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`ERC1155Receiver`: Removed in favor of `ERC1155Holder`.
5 changes: 5 additions & 0 deletions .changeset/eight-peaches-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`Proxy`: Removed redundant `receive` function.
5 changes: 5 additions & 0 deletions .changeset/empty-taxis-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`UUPSUpgradeable`, `TransparentUpgradeableProxy` and `ProxyAdmin`: Removed `upgradeTo` and `upgrade` functions, and made `upgradeToAndCall` and `upgradeAndCall` ignore the data argument if it is empty. It is no longer possible to invoke the receive function (or send value with empty data) along with an upgrade.
5 changes: 5 additions & 0 deletions .changeset/fluffy-countries-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`Arrays`: Optimize `findUpperBound` by removing redundant SLOAD.
5 changes: 5 additions & 0 deletions .changeset/hot-dingos-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`MessageHashUtils`: Add a new library for creating message digest to be used along with signing or recovery such as ECDSA or ERC-1271. These functions are moved from the `ECDSA` library.
5 changes: 5 additions & 0 deletions .changeset/proud-seals-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': patch
---

`BeaconProxy`: Use an immutable variable to store the address of the beacon. It is no longer possible for a `BeaconProxy` to upgrade by changing to another beacon.
5 changes: 5 additions & 0 deletions .changeset/purple-cats-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`GovernorTimelockControl`: Add the Governor instance address as part of the TimelockController operation `salt` to avoid operation id collisions between governors using the same TimelockController.
5 changes: 5 additions & 0 deletions .changeset/spicy-sheep-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`access`: Move `AccessControl` extensions to a dedicated directory.
5 changes: 5 additions & 0 deletions .changeset/tender-shirts-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`BeaconProxy`: Reject value in initialization unless a payable function is explicitly invoked.
5 changes: 5 additions & 0 deletions .changeset/wild-rockets-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': major
---

`Math`: Renamed members of `Rounding` enum, and added a new rounding mode for "away from zero".
1 change: 0 additions & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ jobs:
- uses: crytic/[email protected]
with:
node-version: 18.15
slither-version: 0.9.3

codespell:
runs-on: ubuntu-latest
Expand Down
15 changes: 0 additions & 15 deletions .solhint.json

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ OpenZeppelin Contracts features a [stable API](https://docs.openzeppelin.com/con
$ forge install OpenZeppelin/openzeppelin-contracts
```

Add `@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/` in `remappings.txt.`

### Usage

Once installed, you can use the contracts in the library by importing them:
Expand Down
1 change: 0 additions & 1 deletion contracts/access/AccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pragma solidity ^0.8.19;

import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {Strings} from "../utils/Strings.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";

/**
Expand Down
6 changes: 5 additions & 1 deletion contracts/access/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This directory provides ways to restrict who can access the functions of a contr
- {AccessControl} provides a general role based access control mechanism. Multiple hierarchical roles can be created and assigned each to multiple accounts.
- {Ownable} is a simpler mechanism with a single owner "role" that can be assigned to a single account. This simpler mechanism can be useful for quick tests but projects with production concerns are likely to outgrow it.

== Authorization
== Core

{{Ownable}}

Expand All @@ -18,8 +18,12 @@ This directory provides ways to restrict who can access the functions of a contr

{{AccessControl}}

== Extensions

{{IAccessControlEnumerable}}

{{AccessControlEnumerable}}

{{IAccessControlDefaultAdminRules}}

{{AccessControlDefaultAdminRules}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

pragma solidity ^0.8.19;

import {AccessControl, IAccessControl} from "./AccessControl.sol";
import {IAccessControlDefaultAdminRules} from "./IAccessControlDefaultAdminRules.sol";
import {SafeCast} from "../utils/math/SafeCast.sol";
import {Math} from "../utils/math/Math.sol";
import {IERC5313} from "../interfaces/IERC5313.sol";
import {AccessControl, IAccessControl} from "../AccessControl.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {Math} from "../../utils/math/Math.sol";
import {IERC5313} from "../../interfaces/IERC5313.sol";

/**
* @dev Extension of {AccessControl} that allows specifying special rules to manage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
pragma solidity ^0.8.19;

import {IAccessControlEnumerable} from "./IAccessControlEnumerable.sol";
import {AccessControl} from "./AccessControl.sol";
import {EnumerableSet} from "../utils/structs/EnumerableSet.sol";
import {AccessControl} from "../AccessControl.sol";
import {EnumerableSet} from "../../utils/structs/EnumerableSet.sol";

/**
* @dev Extension of {AccessControl} that allows enumerating the members of each role.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pragma solidity ^0.8.19;

import {IAccessControl} from "./IAccessControl.sol";
import {IAccessControl} from "../IAccessControl.sol";

/**
* @dev External interface of AccessControlDefaultAdminRules declared to support ERC165 detection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pragma solidity ^0.8.19;

import {IAccessControl} from "./IAccessControl.sol";
import {IAccessControl} from "../IAccessControl.sol";

/**
* @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
Expand Down
7 changes: 3 additions & 4 deletions contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pragma solidity ^0.8.19;
import {AccessControl} from "../access/AccessControl.sol";
import {ERC721Holder} from "../token/ERC721/utils/ERC721Holder.sol";
import {ERC1155Holder} from "../token/ERC1155/utils/ERC1155Holder.sol";
import {ERC1155Receiver} from "../token/ERC1155/utils/ERC1155Receiver.sol";
import {Address} from "../utils/Address.sol";

/**
Expand Down Expand Up @@ -103,7 +102,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
/**
* @dev Initializes the contract with the following parameters:
*
* - `minDelay`: initial minimum delay for operations
* - `minDelay`: initial minimum delay in seconds for operations
* - `proposers`: accounts to be granted proposer and canceller roles
* - `executors`: accounts to be granted executor role
* - `admin`: optional account to be granted admin role; disable with zero address
Expand Down Expand Up @@ -160,7 +159,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(AccessControl, ERC1155Receiver) returns (bool) {
) public view virtual override(AccessControl, ERC1155Holder) returns (bool) {
return super.supportsInterface(interfaceId);
}

Expand Down Expand Up @@ -219,7 +218,7 @@ contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
}

/**
* @dev Returns the minimum delay for an operation to become valid.
* @dev Returns the minimum delay in seconds for an operation to become valid.
*
* This value can be changed by executing an operation that calls `updateDelay`.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pragma solidity ^0.8.19;

import {IGovernor, Governor} from "../Governor.sol";
import {SafeCast} from "../../utils/math/SafeCast.sol";
import {ICompoundTimelock} from "../../vendor/compound/ICompoundTimelock.sol";
import {IERC165} from "../../interfaces/IERC165.sol";
import {Address} from "../../utils/Address.sol";
Expand Down
17 changes: 14 additions & 3 deletions contracts/governance/extensions/GovernorTimelockControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ abstract contract GovernorTimelockControl is Governor {
) internal virtual override returns (bool, uint48) {
uint256 delay = _timelock.getMinDelay();

_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, descriptionHash);
_timelock.scheduleBatch(targets, values, calldatas, 0, descriptionHash, delay);
bytes32 salt = _timelockSalt(descriptionHash);
_timelockIds[proposalId] = _timelock.hashOperationBatch(targets, values, calldatas, 0, salt);
_timelock.scheduleBatch(targets, values, calldatas, 0, salt, delay);

return (true, SafeCast.toUint48(block.timestamp + delay));
}
Expand All @@ -97,7 +98,7 @@ abstract contract GovernorTimelockControl is Governor {
bytes32 descriptionHash
) internal virtual override {
// execute
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, descriptionHash);
_timelock.executeBatch{value: msg.value}(targets, values, calldatas, 0, _timelockSalt(descriptionHash));
// cleanup for refund
delete _timelockIds[proposalId];
}
Expand Down Expand Up @@ -148,4 +149,14 @@ abstract contract GovernorTimelockControl is Governor {
emit TimelockChange(address(_timelock), address(newTimelock));
_timelock = newTimelock;
}

/**
* @dev Computes the {TimelockController} operation salt.
*
* It is computed with the governor address itself to avoid collisions across governor instances using the
* same timelock.
*/
function _timelockSalt(bytes32 descriptionHash) private view returns (bytes32) {
return bytes20(address(this)) ^ descriptionHash;
}
}
12 changes: 6 additions & 6 deletions contracts/metatx/ERC2771Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
bytes signature;
}

bytes32 private constant _FORWARD_REQUEST_TYPEHASH =
bytes32 internal constant _FORWARD_REQUEST_TYPEHASH =
keccak256(
"ForwardRequest(address from,address to,uint256 value,uint256 gas,uint256 nonce,uint48 deadline,bytes data)"
);
Expand Down Expand Up @@ -255,7 +255,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
abi.encodePacked(request.data, request.from)
);

_checkForwardedGas(request);
_checkForwardedGas(gasleft(), request);

emit ExecutedForwardRequest(signer, currentNonce, success);
}
Expand All @@ -270,10 +270,10 @@ contract ERC2771Forwarder is EIP712, Nonces {
*
* It reverts consuming all the available gas if the forwarded gas is not the requested gas.
*
* IMPORTANT: This function should be called exactly the end of the forwarded call. Any gas consumed
* in between will make room for bypassing this check.
* IMPORTANT: The `gasLeft` parameter should be measured exactly at the end of the forwarded call.
* Any gas consumed in between will make room for bypassing this check.
*/
function _checkForwardedGas(ForwardRequestData calldata request) private view {
function _checkForwardedGas(uint256 gasLeft, ForwardRequestData calldata request) private pure {
// To avoid insufficient gas griefing attacks, as referenced in https://ronan.eth.limo/blog/ethereum-gas-dangers/
//
// A malicious relayer can attempt to shrink the gas forwarded so that the underlying call reverts out-of-gas
Expand All @@ -295,7 +295,7 @@ contract ERC2771Forwarder is EIP712, Nonces {
// - req.gas >= X * 63 / 64
// In other words if req.gas < X * 63 / 64 then req.gas / 63 <= gasleft(), thus if the relayer behaves honestly
// the forwarding does not revert.
if (gasleft() < request.gas / 63) {
if (gasLeft < request.gas / 63) {
// We explicitly trigger invalid opcode to consume all gas and bubble-up the effects, since
// neither revert or assert consume all gas since Solidity 0.8.0
// https://docs.soliditylang.org/en/v0.8.0/control-structures.html#panic-via-assert-and-error-via-require
Expand Down
12 changes: 12 additions & 0 deletions contracts/mocks/UpgreadeableBeaconMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IBeacon} from "../proxy/beacon/IBeacon.sol";

contract UpgradeableBeaconMock is IBeacon {
address public implementation;

constructor(address impl) {
implementation = impl;
}
}
4 changes: 2 additions & 2 deletions contracts/mocks/docs/ERC4626Fees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ abstract contract ERC4626Fees is ERC4626 {
}

function _feeOnRaw(uint256 assets, uint256 feeBasePoint) private pure returns (uint256) {
return assets.mulDiv(feeBasePoint, 1e5, Math.Rounding.Up);
return assets.mulDiv(feeBasePoint, 1e5, Math.Rounding.Ceil);
}

function _feeOnTotal(uint256 assets, uint256 feeBasePoint) private pure returns (uint256) {
return assets.mulDiv(feeBasePoint, feeBasePoint + 1e5, Math.Rounding.Up);
return assets.mulDiv(feeBasePoint, feeBasePoint + 1e5, Math.Rounding.Ceil);
}
}
2 changes: 1 addition & 1 deletion contracts/mocks/proxy/ClashingImplementation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma solidity ^0.8.19;
contract ClashingImplementation {
event ClashingImplementationCall();

function upgradeTo(address) external payable {
function upgradeToAndCall(address, bytes calldata) external payable {
emit ClashingImplementationCall();
}

Expand Down
6 changes: 1 addition & 5 deletions contracts/mocks/proxy/UUPSUpgradeableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@ contract UUPSUpgradeableMock is NonUpgradeableMock, UUPSUpgradeable {
}

contract UUPSUpgradeableUnsafeMock is UUPSUpgradeableMock {
function upgradeTo(address newImplementation) public override {
ERC1967Utils.upgradeToAndCall(newImplementation, bytes(""), false);
}

function upgradeToAndCall(address newImplementation, bytes memory data) public payable override {
ERC1967Utils.upgradeToAndCall(newImplementation, data, false);
ERC1967Utils.upgradeToAndCall(newImplementation, data);
}
}

Expand Down
1 change: 0 additions & 1 deletion contracts/mocks/token/ERC20PermitNoRevertMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.19;

import {ERC20} from "../../token/ERC20/ERC20.sol";
import {ERC20Permit} from "../../token/ERC20/extensions/ERC20Permit.sol";

abstract contract ERC20PermitNoRevertMock is ERC20Permit {
Expand Down
6 changes: 5 additions & 1 deletion contracts/proxy/ERC1967/ERC1967Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ contract ERC1967Proxy is Proxy {
*
* If `_data` is nonempty, it's used as data in a delegate call to `_logic`. This will typically be an encoded
* function call, and allows initializing the storage of the proxy like a Solidity constructor.
*
* Requirements:
*
* - If `data` is empty, `msg.value` must be zero.
*/
constructor(address _logic, bytes memory _data) payable {
ERC1967Utils.upgradeToAndCall(_logic, _data, false);
ERC1967Utils.upgradeToAndCall(_logic, _data);
}

/**
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.