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 all commits
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
14 changes: 8 additions & 6 deletions src/Space.sol
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,21 @@ contract Space is ISpace, Initializable, IERC4824, UUPSUpgradeable, OwnableUpgra
Proposal storage proposal = proposals[proposalId];
_assertProposalExists(proposal);

// We add reentrancy protection here to prevent this function being re-entered by the execution strategy.
// 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).
// We cache the proposal because we will modify the *real* proposal's finalizationStatus before
// calling the `execute` function. We will use the `cachedProposal` as an argument to the `execute` function.
// This allows us to follow the CEI pattern to avoid reentrancy issues.
Proposal memory cachedProposal = proposal;

proposal.finalizationStatus = FinalizationStatus.Executed;

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