Skip to content

Commit 37fd73a

Browse files
committed
update movy
1 parent d178117 commit 37fd73a

7 files changed

Lines changed: 447 additions & 384 deletions

File tree

crates/movy-replay/src/exec.rs

Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
use std::{ops::Deref, str::FromStr, sync::Arc};
22

33
use color_eyre::eyre::eyre;
4-
use itertools::Itertools;
54
use move_core_types::account_address::AccountAddress;
65
use move_trace_format::{format::MoveTraceBuilder, interface::Tracer};
76
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};
138
use movy_types::{error::MovyError, object::MoveOwner};
9+
use sui_adapter_latest::{
10+
adapter::substitute_package_id,
11+
execution_mode::{ExecutionMode, Normal},
12+
};
1413
use sui_move_natives_latest::all_natives;
1514
use sui_types::{
1615
TypeTag,
@@ -43,7 +42,6 @@ pub fn testing_proto() -> ProtocolConfig {
4342
#[derive(Clone)]
4443
pub struct SuiExecutor<T> {
4544
pub db: T,
46-
pub cheat_backend: CheatBackend,
4745
pub protocol_config: ProtocolConfig,
4846
pub metrics: Arc<LimitsMetrics>,
4947
pub registry: prometheus::Registry,
@@ -72,30 +70,26 @@ impl<T> SuiExecutor<T>
7270
where
7371
T: ObjectStore + BackingStore + ObjectSuiStoreCommit + ObjectStoreMintObject + ObjectStoreInfo,
7472
{
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> {
7674
let protocol_config = testing_proto();
7775
let registry = prometheus::Registry::new();
7876
let metrics = Arc::new(LimitsMetrics::new(&registry));
79-
let (cheat_backend, cheats) = all_cheates(storage);
8077
let movevm = Arc::new(
8178
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()),
8580
)
8681
.map_err(|e| eyre!("move vm err: {}", e))?,
8782
);
8883
Ok(Self {
8984
db,
90-
cheat_backend,
9185
protocol_config,
9286
metrics,
9387
registry,
9488
movevm,
9589
})
9690
}
9791
pub fn new(db: T) -> Result<Self, MovyError> {
98-
Self::new_with_cheats_storage(db, CachedSnapshot::default())
92+
Self::new_with_cheats_storage(db)
9993
}
10094

10195
pub fn run_tx_trace<R: Tracer>(
@@ -196,11 +190,9 @@ where
196190
None
197191
};
198192
trace!("Tx digest is {}", tx_data.digest());
199-
self.cheat_backend.inner_mut().reset();
193+
200194
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>(
204196
&self.db,
205197
CheckedInputObjects::new_for_replay(objects.into()),
206198
tx_data.gas_data().clone(),
@@ -285,25 +277,42 @@ where
285277
package_id, dependencies
286278
);
287279
// 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+
// }
297289

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();
305313
}
306314
}
315+
307316
let mut modules_bytes = vec![];
308317
for module in &modules {
309318
let mut buf = vec![];
@@ -349,3 +358,62 @@ where
349358
}
350359
}
351360
}
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

Comments
 (0)