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

audit: prevent reentrancy issues in execute function #207

Merged
merged 5 commits into from
Jun 19, 2023
Merged
Changes from 1 commit
Commits
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
8 changes: 5 additions & 3 deletions src/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,23 @@ contract Space is ISpace, Initializable, IERC4824, UUPSUpgradeable, OwnableUpgra
/// @inheritdoc ISpaceActions
function execute(uint256 proposalId, bytes calldata executionPayload) external override nonReentrant {
Proposal storage proposal = proposals[proposalId];
Proposal memory cachedProposal = proposal;
pscott marked this conversation as resolved.
Show resolved Hide resolved
_assertProposalExists(proposal);

// Set status before `execute` call to prevent reentrancy issues.
proposal.finalizationStatus = FinalizationStatus.Executed;

// We add reentrancy protection here to prevent this function being re-entered by the execution strategy.
pscott marked this conversation as resolved.
Show resolved Hide resolved
// We cannot use the Checks-Effects-Interactions pattern because the proposal status is checked inside
// the execution strategy (so essentially forced to do Checks-Interactions-Effects).
proposal.executionStrategy.execute(
proposal,
cachedProposal,
votePower[proposalId][Choice.For],
votePower[proposalId][Choice.Against],
votePower[proposalId][Choice.Abstain],
executionPayload
);

proposal.finalizationStatus = FinalizationStatus.Executed;

emit ProposalExecuted(proposalId);
}

Expand Down