Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-reentrant DAO executor #355

Merged
merged 114 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
dd7a0dc
feat: protect the DAO executor against reentrancy
heueristik Apr 17, 2023
ad2fd40
fix: remove console.log
heueristik Apr 17, 2023
616b8bf
fix: prevent storage corruption
heueristik Apr 17, 2023
e45854c
feat: refactored reentrancy guard into a modifier
heueristik Apr 18, 2023
2ac2262
feat: added tests and preliminary versioning
heueristik Apr 18, 2023
9fb0473
chore: cleaning
heueristik Apr 19, 2023
a025523
fix: remove empty comment
heueristik Apr 19, 2023
3fcc083
fix: refactor findEventTopicLog function
heueristik Apr 19, 2023
02711cc
fix: moved implementation slot and renamed file
heueristik Apr 19, 2023
360079c
fix: remove redundant includes
heueristik Apr 19, 2023
1b14d42
prepare package
Rekard0 Apr 25, 2023
9d73698
remember the branch
Rekard0 Apr 25, 2023
fe9fe0f
only artifact src
Rekard0 Apr 25, 2023
c8f10de
correct the paths
Rekard0 Apr 25, 2023
c878bf4
correct root path
Rekard0 Apr 25, 2023
f319e0c
update hashes
Rekard0 Apr 25, 2023
3575258
add logs
Rekard0 Apr 25, 2023
1c6b6f8
only copy typechain
Rekard0 Apr 25, 2023
9f961cc
generate typechain
Rekard0 Apr 25, 2023
e8d6590
setup rollup
Rekard0 Apr 25, 2023
930b436
update npm packages
Rekard0 Apr 25, 2023
049ecc6
Merge branch 'develop' into feature/OS-358-nonreentrant-executor
heueristik Apr 25, 2023
5db940f
update rollup index
Rekard0 Apr 26, 2023
4dc131e
add esm cjs
Rekard0 Apr 26, 2023
6005f06
add readme
Rekard0 Apr 26, 2023
748b382
remove gitIgnore
Rekard0 Apr 26, 2023
f78ad2c
Merge branch 'f/OS-380_npm_package_versions' into feature/OS-358-nonr…
heueristik Apr 27, 2023
f9858c7
update typechain
Rekard0 Apr 27, 2023
1653ca1
update typescript
Rekard0 Apr 27, 2023
03ad311
convert script to typescript
Rekard0 Apr 27, 2023
5dd35fe
change commit hash json
Rekard0 Apr 27, 2023
252b165
rename types to typechain
Rekard0 Apr 28, 2023
ab50a5e
add test
Rekard0 Apr 28, 2023
0ad3a4f
add json to rollup and export types
Rekard0 Apr 28, 2023
b9230a7
update usage test
Rekard0 Apr 28, 2023
30c9593
generate index.ts dynamically
Rekard0 Apr 28, 2023
50e094c
update readme
Rekard0 Apr 28, 2023
744f4f7
add empty line
Rekard0 Apr 28, 2023
1832124
Merge remote-tracking branch 'origin/f/OS-380_npm_package_versions' i…
heueristik Apr 28, 2023
ece3a1f
update commit hashes
heueristik Apr 28, 2023
62f5bdb
fix index.ts
Rekard0 Apr 28, 2023
559d154
chore: update test
heueristik Apr 28, 2023
d2e5456
Merge remote-tracking branch 'origin/f/OS-380_npm_package_versions' i…
heueristik Apr 28, 2023
cd35fe0
fix: removed redundant imports
heueristik Apr 28, 2023
57f755c
chore: remove legacy version files of DAO
heueristik Apr 28, 2023
8fb39df
fix: adapt contracts-version tests
heueristik Apr 28, 2023
c409409
fix: remove version in title as contracts will get a constant
heueristik Apr 28, 2023
403436c
fix: compile legacy contracts for regression testing
heueristik Apr 28, 2023
1043deb
Revert "fix: compile legacy contracts for regression testing "
heueristik Apr 28, 2023
757bc4c
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 2, 2023
1b224a2
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 2, 2023
c900797
revert versioning changes
heueristik May 2, 2023
9629728
adapt tests
heueristik May 2, 2023
6261b85
test with creating symbolic link
Rekard0 May 2, 2023
b2df3f0
correct path
Rekard0 May 2, 2023
abfa6af
Revert "chore: remove legacy version files of DAO"
heueristik Apr 28, 2023
3e25be2
add legacy versions
heueristik May 5, 2023
aaff5bd
fix: renaming of the versions
heueristik May 5, 2023
1ce07f3
chore: remove old CI task
heueristik May 5, 2023
857a9db
fix: version numbers
heueristik May 5, 2023
9d129f4
fix: imports
heueristik May 5, 2023
f437dbc
doc: clarified the origin of the implementation slot
heueristik May 8, 2023
168b55b
fix: versioning
heueristik May 8, 2023
dbe2134
fix: move files
heueristik May 8, 2023
5e209e3
Apply suggestions from code review
heueristik May 8, 2023
6cbc32e
chore: formatting
heueristik May 8, 2023
1b86fd0
chore: remove NatSpec version number from osx files
heueristik May 8, 2023
9b6a514
feat: added more tests
heueristik May 8, 2023
ebc96ac
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 8, 2023
c9c04f8
Applied review suggestion
heueristik May 10, 2023
706de67
feat: added test checking that execution is still possible after the …
heueristik May 10, 2023
9c80df2
Improved comments
heueristik May 10, 2023
0cabf6b
feat: initialize _rentrancyStatus
heueristik May 10, 2023
9599e38
doc: clarify comments
heueristik May 10, 2023
0dee336
fix: change version number
heueristik May 10, 2023
4e9e628
fix: use upgradeToAndCall and correct versions
heueristik May 10, 2023
6c814d2
feat: added initializeUpgradeFrom function and tests
heueristik May 10, 2023
f8ca50c
feat: improved function and added more tests
heueristik May 10, 2023
4ea9840
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 11, 2023
f8876fd
WIP
heueristik May 11, 2023
4c2573e
fix: tests
heueristik May 11, 2023
ad8fc66
fix: finalize tests
heueristik May 11, 2023
ca9a176
fix typechain and add a script
Rekard0 May 11, 2023
f689e6c
fix: typo
heueristik May 11, 2023
9303b42
feat: improve initializeUpgradeFrom
heueristik May 12, 2023
cf3b2c1
feat: added _initData parameter
heueristik May 12, 2023
9cd9e65
feat: added test
heueristik May 12, 2023
452c958
fix: wrong version number
heueristik May 12, 2023
c865dcb
WIP
Rekard0 May 12, 2023
758bceb
fix remaining tests
Rekard0 May 12, 2023
fec63aa
fix subgraph
Rekard0 May 12, 2023
559a756
add ref depth
Rekard0 May 12, 2023
df4a9e3
fix: replacing getContractFactory and getContractAt by typechain fact…
heueristik May 12, 2023
c1088ef
fix: test timings
heueristik May 12, 2023
728cb80
Merge branch 'fix/fix-typechain-and-contracts-tests' into feature/OS-…
heueristik May 12, 2023
099018a
fix: re-introduced yarn postinstall
heueristik May 12, 2023
1a15563
fix: remove redundant includes
heueristik May 12, 2023
ba71d52
fix: adapt upgrade tests
heueristik May 12, 2023
51c831c
feat: optimize if statements
heueristik May 12, 2023
1ab55d6
fix: tests
heueristik May 12, 2023
58a9250
feat: rename initializeUpgradeFrom to initializeFrom
heueristik May 12, 2023
b71193f
fix: correct test description
heueristik May 15, 2023
054bca1
fix: removed duplicate file
heueristik May 15, 2023
263bc1b
Merge remote-tracking branch 'origin/develop' into feature/OS-358-non…
heueristik May 16, 2023
0e1128a
fix: merge conflicts
heueristik May 16, 2023
3c64f8e
fix: re-order changelog entries
heueristik May 16, 2023
d08e1ee
fix: remove wrong/redundant import originating from merge
heueristik May 16, 2023
cc571dc
feat: improve upgrade version checks
heueristik May 16, 2023
649732b
fix: remove redundant ROOT_PERMISSION grant call
heueristik May 16, 2023
c275b62
feat: added more checks to the upgrade tests
heueristik May 16, 2023
a97a9ba
feat: more explicit variable naming
heueristik May 16, 2023
7c3e22c
fix: reworked initializeFrom logic
heueristik May 16, 2023
e77bdfe
fix: refactored test according to the logic change
heueristik May 17, 2023
114afb4
feat: added NatSpec and code comments mentioning the version of added…
heueristik May 17, 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
1 change: 1 addition & 0 deletions packages/contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added a `nonReentrant` modifier to the `execute` function in the `DAO` contract.
- Added `allowFailureMap` to `IDAO.Executed` event.

### Changed
Expand Down
61 changes: 59 additions & 2 deletions packages/contracts/src/core/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,31 @@ contract DAO is
/// @notice The internal constant storing the maximal action array length.
uint256 internal constant MAX_ACTIONS = 256;

/// @notice The first out of two values to which the `_reentrancyStatus` state variable (used by the `nonReentrant` modifier) can be set inidicating that a function was not entered.
uint256 private constant _NOT_ENTERED = 1;

/// @notice The second out of two values to which the `_reentrancyStatus` state variable (used by the `nonReentrant` modifier) can be set inidicating that a function was entered.
uint256 private constant _ENTERED = 2;

/// @notice The [ERC-1271](https://eips.ethereum.org/EIPS/eip-1271) signature validator contract.
/// @dev Added in v1.0.0.
IERC1271 public signatureValidator;

/// @notice The address of the trusted forwarder verifying meta transactions.
/// @dev Added in v1.0.0.
heueristik marked this conversation as resolved.
Show resolved Hide resolved
address private trustedForwarder;

/// @notice The [EIP-4824](https://eips.ethereum.org/EIPS/eip-4824) DAO URI.
/// @dev Added in v1.0.0.
string private _daoURI;

/// @notice The state variable for the reentrancy guard of the `execute` function.
/// @dev Added in v1.3.0. The variable can be of value `_NOT_ENTERED = 1` or `_ENTERED = 2` in usage and is initialized with `_NOT_ENTERED`.
uint256 private _reentrancyStatus;

/// @notice Thrown if a call is reentrant.
error ReentrantCall();

/// @notice Thrown if the action array length is larger than `MAX_ACTIONS`.
error TooManyActions();

Expand All @@ -87,16 +103,33 @@ contract DAO is
/// @param actual The actual native token amount deposited.
error NativeTokenDepositAmountMismatch(uint256 expected, uint256 actual);

/// @notice Thrown if an upgrade is not supported from a specific protocol version .
error ProtocolVersionUpgradeNotSupported(uint8[3] protocolVersion);

/// @notice Emitted when a new DAO URI is set.
/// @param daoURI The new URI.
event NewURI(string daoURI);

/// @notice A modifier to protect a function from calling itself, directly or indirectly (reentrancy).
/// @dev Currently, this modifier is only applied to the `execute()` function. If this is used multiple times, private `_beforeNonReentrant()` and `_afterNonReentrant()` functions should be created to prevent code duplication.
modifier nonReentrant() {
if (_reentrancyStatus == _ENTERED) {
revert ReentrantCall();
}
_reentrancyStatus = _ENTERED;

_;

_reentrancyStatus = _NOT_ENTERED;
}

/// @notice Disables the initializers on the implementation contract to prevent it from being left uninitialized.
constructor() {
_disableInitializers();
}

/// @notice Initializes the DAO by
/// - setting the reentrancy status variable to `_NOT_ENTERED`
/// - registering the [ERC-165](https://eips.ethereum.org/EIPS/eip-165) interface ID
/// - setting the trusted forwarder for meta transactions
/// - giving the `ROOT_PERMISSION_ID` permission to the initial owner (that should be revoked and transferred to the DAO after setup).
Expand All @@ -110,7 +143,9 @@ contract DAO is
address _initialOwner,
address _trustedForwarder,
string calldata daoURI_
) external initializer {
) external reinitializer(2) {
_reentrancyStatus = _NOT_ENTERED; // added in v1.3.0

_registerInterface(type(IDAO).interfaceId);
_registerInterface(type(IERC1271).interfaceId);
_registerInterface(type(IEIP4824).interfaceId);
Expand All @@ -122,6 +157,26 @@ contract DAO is
__PermissionManager_init(_initialOwner);
}

/// @notice Initializes the DAO after an upgrade from a previous protocol version.
/// @param _previousProtocolVersion The semantic protocol version number of the previous DAO implementation contract this upgrade is transitioning from.
/// @param _initData The initialization data to be passed to via `upgradeToAndCall` (see [ERC-1967](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Upgrade)).
function initializeFrom(
uint8[3] calldata _previousProtocolVersion,
bytes calldata _initData
) external reinitializer(2) {
_initData; // Silences the unused function parameter warning.

// Check that the contract is not upgrading from a different major release.
if (_previousProtocolVersion[0] != 1) {
revert ProtocolVersionUpgradeNotSupported(_previousProtocolVersion);
}

// Initialize `_reentrancyStatus` that was added in v1.3.0.
if (_previousProtocolVersion[1] <= 2) {
_reentrancyStatus = _NOT_ENTERED;
}
}

/// @inheritdoc PermissionManager
function isPermissionRestrictedForAnyAddr(
bytes32 _permissionId
Expand Down Expand Up @@ -176,9 +231,11 @@ contract DAO is
)
external
override
nonReentrant
auth(EXECUTE_PERMISSION_ID)
returns (bytes[] memory execResults, uint256 failureMap)
{
// Check that the action array length is within bounds.
if (_actions.length > MAX_ACTIONS) {
revert TooManyActions();
}
Expand Down Expand Up @@ -356,5 +413,5 @@ contract DAO is
}

/// @notice This empty reserved space is put in place to allow future versions to add new variables without shifting down storage in the inheritance chain (see [OpenZeppelin's guide about storage gaps](https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps)).
uint256[47] private __gap;
uint256[46] private __gap;
}
Loading