Skip to content

Commit fd6752a

Browse files
committed
Add check double spend and fix broken deser in old exec WASM
1 parent 62d84f2 commit fd6752a

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/services/executor/src/executor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ pub struct ExecutionOptions {
348348
pub backtrace: bool,
349349
}
350350

351+
#[derive(serde::Deserialize, Debug)]
352+
/// Execution options to maintain for backward compatibility.
353+
pub struct ExecutionOptionsDeserialized {
354+
pub forbid_fake_coins: bool,
355+
pub backtrace: bool,
356+
}
357+
351358
/// Per-block execution options
352359
#[derive(Clone, Default, Debug)]
353360
struct ExecutionOptionsInner {

crates/services/parallel-executor/src/scheduler/coin.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ use fuel_core_types::{
2222
},
2323
},
2424
};
25-
use fxhash::FxHashMap;
25+
use fxhash::{
26+
FxHashMap,
27+
FxHashSet,
28+
};
2629

2730
use super::SchedulerError;
2831

@@ -175,12 +178,14 @@ impl From<CoinInBatch> for CompressedCoin {
175178

176179
pub struct CoinDependencyChainVerifier {
177180
coins_registered: FxHashMap<UtxoId, (usize, CoinInBatch)>,
181+
coins_used: FxHashSet<UtxoId>,
178182
}
179183

180184
impl CoinDependencyChainVerifier {
181185
pub fn new() -> Self {
182186
Self {
183187
coins_registered: FxHashMap::default(),
188+
coins_used: FxHashSet::default(),
184189
}
185190
}
186191

@@ -195,15 +200,23 @@ impl CoinDependencyChainVerifier {
195200
}
196201

197202
pub fn verify_coins_used<'a, S>(
198-
&self,
203+
&mut self,
199204
batch_id: usize,
200205
coins_used: impl Iterator<Item = &'a CoinInBatch>,
201206
storage: &StorageTransaction<S>,
202207
) -> Result<(), SchedulerError>
203208
where
204209
S: KeyValueInspect<Column = Column> + Send,
205210
{
211+
// Check if the coins used are not already used and if they are valid
206212
for coin in coins_used {
213+
if self.coins_used.contains(coin.utxo()) {
214+
return Err(SchedulerError::InternalError(format!(
215+
"Coin {} is already used in the batch",
216+
coin.utxo(),
217+
)));
218+
}
219+
self.coins_used.insert(*coin.utxo());
207220
match storage.storage::<Coins>().get(coin.utxo()) {
208221
Ok(Some(db_coin)) => {
209222
// Coin is in the database

crates/services/upgradable-executor/wasm-executor/src/main.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use crate::utils::{
1919
WasmDeserializationBlockTypes,
2020
convert_to_v1_execution_result,
2121
};
22-
use fuel_core_executor::executor::ExecutionInstance;
22+
use fuel_core_executor::executor::{
23+
ExecutionInstance,
24+
ExecutionOptions,
25+
};
2326
use fuel_core_types::{
2427
blockchain::block::Block,
2528
services::{
@@ -91,7 +94,11 @@ pub fn execute_without_commit(input_len: u32) -> ReturnType {
9194
let instance = ExecutionInstance {
9295
relayer: WasmRelayer {},
9396
database: WasmStorage {},
94-
options,
97+
options: ExecutionOptions {
98+
forbid_unauthorized_inputs: options.forbid_fake_coins,
99+
forbid_fake_utxo: options.forbid_fake_coins,
100+
backtrace: options.backtrace,
101+
},
95102
};
96103

97104
match block {

crates/services/upgradable-executor/wasm-executor/src/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use fuel_core_executor::executor::ExecutionOptions;
1+
use fuel_core_executor::executor::{
2+
ExecutionOptions,
3+
ExecutionOptionsDeserialized,
4+
};
25
use fuel_core_storage::transactional::Changes;
36
use fuel_core_types::{
47
blockchain::block::Block,
@@ -60,7 +63,7 @@ pub enum InputSerializationType<'a> {
6063
pub enum InputDeserializationType {
6164
V1 {
6265
block: WasmDeserializationBlockTypes<()>,
63-
options: ExecutionOptions,
66+
options: ExecutionOptionsDeserialized,
6467
},
6568
}
6669

0 commit comments

Comments
 (0)