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
9 changes: 6 additions & 3 deletions packages/contracts/src/core/dao/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ contract DAO is
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 The variable can of value `_NOT_ENTERED = 1` or `_ENTERED = 2` in usage and shoud be initialized with `_NOT_ENTERED`.
/// @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.
Expand Down Expand Up @@ -141,7 +144,7 @@ contract DAO is
address _trustedForwarder,
string calldata daoURI_
) external reinitializer(2) {
_reentrancyStatus = _NOT_ENTERED;
_reentrancyStatus = _NOT_ENTERED; // added in v1.3.0

_registerInterface(type(IDAO).interfaceId);
_registerInterface(type(IERC1271).interfaceId);
Expand All @@ -168,7 +171,7 @@ contract DAO is
revert ProtocolVersionUpgradeNotSupported(_previousProtocolVersion);
}

// Initialize `_reentrancyStatus` that was added in v1.3.0
// Initialize `_reentrancyStatus` that was added in v1.3.0.
if (_previousProtocolVersion[1] <= 2) {
_reentrancyStatus = _NOT_ENTERED;
}
Expand Down
82 changes: 62 additions & 20 deletions packages/contracts/test/core/dao/dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,22 +239,56 @@ describe('DAO', function () {
.withArgs([0, 1, 0]);
});

it('reverts if trying to upgrade to the same version', async () => {
it('initializes `_reentrancyStatus` for versions < 1.3.0', async () => {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);

await expect(uninitializedDao.initializeFrom([1, 3, 0], EMPTY_DATA))
.to.be.revertedWithCustomError(
dao,
'ProtocolVersionUpgradeNotSupported'
)
.withArgs([1, 3, 0]);
// Expect the contract to be uninitialized with `_initialized = 0` and `_reentrancyStatus = 0`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(0);
brickpop marked this conversation as resolved.
Show resolved Hide resolved
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(0);

// Call `initializeFrom` with version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
.not.be.reverted;

// Expect the contract to be initialized with `_initialized = 2` and `_reentrancyStatus = 1`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
OZ_INITIALIZED_SLOT_POSITION
)
).toNumber()
).to.equal(2);
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(1);
});

it('initializes upgrades for versions < 1.3.0', async () => {
it('does not initialize `_reentrancyStatus` for versions >= 1.3.0', async () => {
// Create an unitialized DAO.
const uninitializedDao = await deployWithProxy<DAO>(DAO);

// Expect the contract to be uninitialized with `_initialized = 0`.
// Expect the contract to be uninitialized with `_initialized = 0` and `_reentrancyStatus = 0`.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -263,20 +297,20 @@ describe('DAO', function () {
)
).toNumber()
).to.equal(0);
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(0);

// Call `initializeFrom` with the previous version 1.3.0 which is not supported.
await expect(uninitializedDao.initializeFrom([1, 3, 0], EMPTY_DATA))
.to.be.revertedWithCustomError(
dao,
'ProtocolVersionUpgradeNotSupported'
)
.withArgs([1, 3, 0]);

// Call `initializeFrom` with the previous version 1.2.0.
await expect(uninitializedDao.initializeFrom([1, 2, 0], EMPTY_DATA)).to
// Call `initializeFrom` with version 1.3.0.
await expect(uninitializedDao.initializeFrom([1, 3, 0], EMPTY_DATA)).to
.not.be.reverted;

// Expect the contract to be initialized with `_initialized = 2`
// Expect the contract to be initialized with `_initialized = 2` but `_reentrancyStatus` to remain unchanged.
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
Expand All @@ -285,6 +319,14 @@ describe('DAO', function () {
)
).toNumber()
).to.equal(2);
expect(
ethers.BigNumber.from(
await ethers.provider.getStorageAt(
uninitializedDao.address,
REENTRANCY_STATUS_SLOT_POSITION
)
).toNumber()
).to.equal(0);
});
});

Expand Down