Skip to content

Commit

Permalink
fix(execution): prevent reentrancy attacks with cancelling proposal d…
Browse files Browse the repository at this point in the history
…uring execution
  • Loading branch information
vovacodes committed Jun 23, 2023
1 parent 2e4b79e commit 8416203
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anchor_lang::prelude::*;
use std::borrow::Borrow;

use crate::errors::*;
use crate::state::*;
Expand Down Expand Up @@ -146,6 +147,10 @@ impl BatchExecuteTransaction<'_> {
&ephemeral_signer_keys,
)?;

let current_status = proposal.status.clone();
// Set the proposal state to Executing to prevent reentrancy attacks (e.g. cancelling proposal) in the middle of execution.
proposal.status = ProposalStatus::Executing;

// Execute the transaction message instructions one-by-one.
executable_message.execute_message(
&vault_seeds
Expand All @@ -155,6 +160,9 @@ impl BatchExecuteTransaction<'_> {
&ephemeral_signer_seeds,
)?;

// Restore the proposal status after execution.
proposal.status = current_status;

// Increment the executed transaction index.
batch.executed_transaction_index = batch
.executed_transaction_index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ impl VaultTransactionExecute<'_> {
&ephemeral_signer_keys,
)?;

// Set the proposal state to Executing to prevent reentrancy attacks (e.g. cancelling proposal) in the middle of execution.
proposal.status = ProposalStatus::Executing;

// Execute the transaction message instructions one-by-one.
executable_message.execute_message(
&vault_seeds
Expand Down
2 changes: 2 additions & 0 deletions programs/multisig/src/state/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ pub enum ProposalStatus {
Rejected { timestamp: i64 },
/// Proposal has been approved and is pending execution.
Approved { timestamp: i64 },
/// Proposal is being executed. This is a transient state that always transitions to `Executed` in the span of a single transaction.
Executing,
/// Proposal has been executed.
Executed { timestamp: i64 },
/// Proposal has been cancelled.
Expand Down
3 changes: 3 additions & 0 deletions sdk/multisig/idl/multisig.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,9 @@
}
]
},
{
"name": "Executing"
},
{
"name": "Executed",
"fields": [
Expand Down
5 changes: 5 additions & 0 deletions sdk/multisig/src/generated/types/ProposalStatus.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8416203

Please sign in to comment.