|
1 | 1 | use std::{ops::Deref, str::FromStr, sync::Arc}; |
2 | 2 |
|
3 | 3 | use color_eyre::eyre::eyre; |
4 | | -use itertools::Itertools; |
5 | 4 | use move_core_types::account_address::AccountAddress; |
6 | 5 | use move_trace_format::{format::MoveTraceBuilder, interface::Tracer}; |
7 | 6 | use move_vm_runtime::move_vm::MoveVM; |
8 | | -use movy_sui::{ |
9 | | - cheats::{all_cheates, backend::CheatBackend}, |
10 | | - compile::SuiCompiledPackage, |
11 | | - database::cache::{CachedSnapshot, ObjectSuiStoreCommit}, |
12 | | -}; |
| 7 | +use movy_sui::{compile::SuiCompiledPackage, database::cache::ObjectSuiStoreCommit}; |
13 | 8 | use movy_types::{error::MovyError, object::MoveOwner}; |
| 9 | +use sui_adapter_latest::{ |
| 10 | + adapter::substitute_package_id, |
| 11 | + execution_mode::{ExecutionMode, Normal}, |
| 12 | +}; |
14 | 13 | use sui_move_natives_latest::all_natives; |
15 | 14 | use sui_types::{ |
16 | 15 | TypeTag, |
@@ -43,7 +42,6 @@ pub fn testing_proto() -> ProtocolConfig { |
43 | 42 | #[derive(Clone)] |
44 | 43 | pub struct SuiExecutor<T> { |
45 | 44 | pub db: T, |
46 | | - pub cheat_backend: CheatBackend, |
47 | 45 | pub protocol_config: ProtocolConfig, |
48 | 46 | pub metrics: Arc<LimitsMetrics>, |
49 | 47 | pub registry: prometheus::Registry, |
@@ -72,30 +70,26 @@ impl<T> SuiExecutor<T> |
72 | 70 | where |
73 | 71 | T: ObjectStore + BackingStore + ObjectSuiStoreCommit + ObjectStoreMintObject + ObjectStoreInfo, |
74 | 72 | { |
75 | | - pub fn new_with_cheats_storage(db: T, storage: CachedSnapshot) -> Result<Self, MovyError> { |
| 73 | + pub fn new_with_cheats_storage(db: T) -> Result<Self, MovyError> { |
76 | 74 | let protocol_config = testing_proto(); |
77 | 75 | let registry = prometheus::Registry::new(); |
78 | 76 | let metrics = Arc::new(LimitsMetrics::new(®istry)); |
79 | | - let (cheat_backend, cheats) = all_cheates(storage); |
80 | 77 | let movevm = Arc::new( |
81 | 78 | MoveVM::new( |
82 | | - all_natives(false, &protocol_config) |
83 | | - .into_iter() |
84 | | - .chain(cheats.into_iter()), |
| 79 | + all_natives(false, &protocol_config).into_iter(), // .chain(cheats.into_iter()), |
85 | 80 | ) |
86 | 81 | .map_err(|e| eyre!("move vm err: {}", e))?, |
87 | 82 | ); |
88 | 83 | Ok(Self { |
89 | 84 | db, |
90 | | - cheat_backend, |
91 | 85 | protocol_config, |
92 | 86 | metrics, |
93 | 87 | registry, |
94 | 88 | movevm, |
95 | 89 | }) |
96 | 90 | } |
97 | 91 | pub fn new(db: T) -> Result<Self, MovyError> { |
98 | | - Self::new_with_cheats_storage(db, CachedSnapshot::default()) |
| 92 | + Self::new_with_cheats_storage(db) |
99 | 93 | } |
100 | 94 |
|
101 | 95 | pub fn run_tx_trace<R: Tracer>( |
@@ -196,11 +190,9 @@ where |
196 | 190 | None |
197 | 191 | }; |
198 | 192 | trace!("Tx digest is {}", tx_data.digest()); |
199 | | - self.cheat_backend.inner_mut().reset(); |
| 193 | + |
200 | 194 | let (store, gas_status, effects, _timing, result) = |
201 | | - sui_adapter_latest::execution_engine::execute_transaction_to_effects::< |
202 | | - sui_adapter_latest::execution_mode::Normal, |
203 | | - >( |
| 195 | + sui_adapter_latest::execution_engine::execute_transaction_to_effects::<SuiFuzzMode>( |
204 | 196 | &self.db, |
205 | 197 | CheckedInputObjects::new_for_replay(objects.into()), |
206 | 198 | tx_data.gas_data().clone(), |
@@ -285,25 +277,42 @@ where |
285 | 277 | package_id, dependencies |
286 | 278 | ); |
287 | 279 | // rebase to zero address as sui publish requires |
288 | | - for it in modules.iter_mut() { |
289 | | - let self_handle = it.self_handle().clone(); |
290 | | - if let Some(address_mut) = it |
291 | | - .address_identifiers |
292 | | - .get_mut(self_handle.address.0 as usize) |
293 | | - && *address_mut != AccountAddress::ZERO |
294 | | - { |
295 | | - *address_mut = AccountAddress::ZERO; |
296 | | - } |
| 280 | + // for it in modules.iter_mut() { |
| 281 | + // let self_handle = it.self_handle().clone(); |
| 282 | + // if let Some(address_mut) = it |
| 283 | + // .address_identifiers |
| 284 | + // .get_mut(self_handle.address.0 as usize) |
| 285 | + // && *address_mut != AccountAddress::ZERO |
| 286 | + // { |
| 287 | + // *address_mut = AccountAddress::ZERO; |
| 288 | + // } |
297 | 289 |
|
298 | | - // TODO: Maybe unnecessary? |
299 | | - if package_id != ObjectID::ZERO { |
300 | | - for ident in it.address_identifiers.iter_mut() { |
301 | | - if ObjectID::from(*ident) == package_id { |
302 | | - *ident = AccountAddress::ZERO; |
303 | | - } |
304 | | - } |
| 290 | + // // TODO: Maybe unnecessary? |
| 291 | + // if package_id != ObjectID::ZERO { |
| 292 | + // for ident in it.address_identifiers.iter_mut() { |
| 293 | + // if ObjectID::from(*ident) == package_id { |
| 294 | + // *ident = AccountAddress::ZERO; |
| 295 | + // } |
| 296 | + // } |
| 297 | + // } |
| 298 | + // } |
| 299 | + |
| 300 | + if package_id == ObjectID::ZERO { |
| 301 | + // derive id |
| 302 | + let id = ObjectID::derive_id(digest, creation_num); |
| 303 | + substitute_package_id(&mut modules, id)?; |
| 304 | + } else { |
| 305 | + // ensure the modules has the expected id |
| 306 | + for it in modules.iter_mut() { |
| 307 | + let self_handle = it.self_handle().clone(); |
| 308 | + let self_address_idx = self_handle.address; |
| 309 | + |
| 310 | + let addrs = &mut it.address_identifiers; |
| 311 | + let address_mut = addrs.get_mut(self_address_idx.0 as usize).unwrap(); |
| 312 | + *address_mut = package_id.into(); |
305 | 313 | } |
306 | 314 | } |
| 315 | + |
307 | 316 | let mut modules_bytes = vec![]; |
308 | 317 | for module in &modules { |
309 | 318 | let mut buf = vec![]; |
@@ -349,3 +358,62 @@ where |
349 | 358 | } |
350 | 359 | } |
351 | 360 | } |
| 361 | + |
| 362 | +pub struct SuiFuzzMode; |
| 363 | + |
| 364 | +impl ExecutionMode for SuiFuzzMode { |
| 365 | + type ArgumentUpdates = <Normal as ExecutionMode>::ArgumentUpdates; |
| 366 | + type ExecutionResults = <Normal as ExecutionMode>::ExecutionResults; |
| 367 | + const TRACK_EXECUTION: bool = Normal::TRACK_EXECUTION; |
| 368 | + |
| 369 | + fn add_argument_update( |
| 370 | + resolver: &impl sui_adapter_latest::type_resolver::TypeTagResolver, |
| 371 | + acc: &mut Self::ArgumentUpdates, |
| 372 | + arg: Argument, |
| 373 | + new_value: &sui_adapter_latest::execution_value::Value, |
| 374 | + ) -> Result<(), sui_types::error::ExecutionError> { |
| 375 | + Normal::add_argument_update(resolver, acc, arg, new_value) |
| 376 | + } |
| 377 | + fn add_argument_update_v2( |
| 378 | + acc: &mut Self::ArgumentUpdates, |
| 379 | + arg: Argument, |
| 380 | + bytes: Vec<u8>, |
| 381 | + type_: TypeTag, |
| 382 | + ) -> Result<(), sui_types::error::ExecutionError> { |
| 383 | + Normal::add_argument_update_v2(acc, arg, bytes, type_) |
| 384 | + } |
| 385 | + |
| 386 | + fn allow_arbitrary_function_calls() -> bool { |
| 387 | + Normal::allow_arbitrary_function_calls() |
| 388 | + } |
| 389 | + fn allow_arbitrary_values() -> bool { |
| 390 | + Normal::allow_arbitrary_values() |
| 391 | + } |
| 392 | + fn empty_arguments() -> Self::ArgumentUpdates { |
| 393 | + Normal::empty_arguments() |
| 394 | + } |
| 395 | + fn empty_results() -> Self::ExecutionResults { |
| 396 | + Normal::empty_results() |
| 397 | + } |
| 398 | + fn finish_command( |
| 399 | + resolver: &impl sui_adapter_latest::type_resolver::TypeTagResolver, |
| 400 | + acc: &mut Self::ExecutionResults, |
| 401 | + argument_updates: Self::ArgumentUpdates, |
| 402 | + command_result: &[sui_adapter_latest::execution_value::Value], |
| 403 | + ) -> Result<(), sui_types::error::ExecutionError> { |
| 404 | + Normal::finish_command(resolver, acc, argument_updates, command_result) |
| 405 | + } |
| 406 | + fn finish_command_v2( |
| 407 | + acc: &mut Self::ExecutionResults, |
| 408 | + argument_updates: Vec<(Argument, Vec<u8>, TypeTag)>, |
| 409 | + command_result: Vec<(Vec<u8>, TypeTag)>, |
| 410 | + ) -> Result<(), sui_types::error::ExecutionError> { |
| 411 | + Normal::finish_command_v2(acc, argument_updates, command_result) |
| 412 | + } |
| 413 | + fn packages_are_predefined() -> bool { |
| 414 | + true |
| 415 | + } |
| 416 | + fn skip_conservation_checks() -> bool { |
| 417 | + Normal::skip_conservation_checks() |
| 418 | + } |
| 419 | +} |
0 commit comments