Skip to content

Commit

Permalink
add extra safety check to ensure messages aren't already spent
Browse files Browse the repository at this point in the history
  • Loading branch information
Voxelot committed Mar 9, 2023
1 parent 6baacd8 commit 41967f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,12 @@ where
Input::MessageSigned { message_id, .. }
| Input::MessagePredicate { message_id, .. } => {
// mark message id as spent
db.storage::<SpentMessages>().insert(message_id, &())?;
let was_already_spent =
db.storage::<SpentMessages>().insert(message_id, &())?;
// ensure message wasn't already marked as spent
if was_already_spent.is_some() {
return Err(ExecutorError::MessageAlreadySpent(*message_id))
}
// cleanup message contents
db.storage::<Messages>().remove(message_id)?;
}
Expand Down
2 changes: 2 additions & 0 deletions crates/types/src/services/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ pub enum Error {
InvalidBlockId,
#[error("No matching utxo for contract id ${0:#x}")]
ContractUtxoMissing(ContractId),
#[error("message already spent {0:#x}")]
MessageAlreadySpent(MessageId),
}

impl From<Backtrace> for Error {
Expand Down

0 comments on commit 41967f8

Please sign in to comment.