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 2 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 @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

## v1.2.0

Expand Down
5 changes: 4 additions & 1 deletion packages/contracts/src/core/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155Upgradeable.so
import "@openzeppelin/contracts-upgradeable/token/ERC1155/IERC1155ReceiverUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol";
import "@openzeppelin/contracts/interfaces/IERC1271.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

import {PermissionManager} from "../permission/PermissionManager.sol";
import {CallbackHandler} from "../utils/CallbackHandler.sol";
Expand All @@ -31,7 +32,8 @@ contract DAO is
IDAO,
UUPSUpgradeable,
PermissionManager,
CallbackHandler
CallbackHandler,
ReentrancyGuardUpgradeable
{
using SafeERC20Upgradeable for IERC20Upgradeable;
using AddressUpgradeable for address;
Expand Down Expand Up @@ -175,6 +177,7 @@ contract DAO is
)
external
override
nonReentrant
auth(EXECUTE_PERMISSION_ID)
returns (bytes[] memory execResults, uint256 failureMap)
{
Expand Down
32 changes: 30 additions & 2 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,34 @@ describe('DAO', function () {
.withArgs(0);
});

it('reverts on re-entrant actions', async () => {
// Grant DAO execute permission on itself.
await dao.grant(
dao.address,
dao.address,
PERMISSION_IDS.EXECUTE_PERMISSION_ID
);

// Create a reentrant action calling `dao.execute` again.
const reentrantAction = {
to: dao.address,
data: dao.interface.encodeFunctionData('execute', [
ZERO_BYTES32,
[data.succeedAction],
0,
]),
value: 0,
};

// Create an action array with an normal action and an reentrant action.
const actions = [data.succeedAction, reentrantAction];

// Expect the second, reentrant action to fail.
heueristik marked this conversation as resolved.
Show resolved Hide resolved
await expect(dao.execute(ZERO_BYTES32, actions, 0))
.to.be.revertedWithCustomError(dao, 'ActionFailed')
.withArgs(1);
});

it('succeeds if action is failable but allowFailureMap allows it', async () => {
let num = ethers.BigNumber.from(0);
num = flipBit(0, num);
Expand Down Expand Up @@ -393,12 +421,12 @@ describe('DAO', function () {
ZERO_BYTES32,
[gasConsumingAction],
allowFailureMap
); // exact gas required: 495453
); // expectedGas = 520720 gas

// Providing less gas causes the `to.call` of the `gasConsumingAction` to fail, but is still enough for the overall `dao.execute` call to finish successfully.
await expect(
dao.execute(ZERO_BYTES32, [gasConsumingAction], allowFailureMap, {
gasLimit: expectedGas.sub(800),
gasLimit: expectedGas.sub(2800), // 2796 gas is the limit value for which the call cannot finish successfully anymore (520720 gas - 2796 gas = 517924 gas)
})
).to.be.revertedWithCustomError(dao, 'InsufficientGas');

Expand Down