Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

18 changes: 18 additions & 0 deletions crates/movy-fuzz/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ where
stage_idx,
success,
};

if log::log_enabled!(log::Level::Debug) {
for ev in events.iter() {
if let Some((st, ev)) = state.fuzz_state().decode_sui_event(ev)? {
log::debug!(
"Event: {}({})",
st.to_canonical_string(true),
serde_json::to_string(&ev)
.unwrap_or_else(|e| format!("json err({}): {:?}", e, ev))
);
} else {
log::debug!(
"Event {} missing for decoding",
ev.type_.to_canonical_string(true)
);
}
}
}
let events: Vec<_> = events.into_iter().map(|e| e.into()).collect();

// Expose preliminary outcome so oracles can inspect events.
Expand Down
92 changes: 0 additions & 92 deletions crates/movy-fuzz/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,98 +649,6 @@ impl FuzzMetadata {
})
}

pub fn iter_functions(
&self,
) -> impl Iterator<
Item = (
&MoveAddress, // package_addr
&String, // module_name
&MoveModuleAbi, // module_data
&String, // func_name
&MoveFunctionAbi, // func_data
),
> {
self.abis.iter().flat_map(|(package_addr, package_meta)| {
package_meta.modules.iter().flat_map(move |module_data| {
module_data.functions.iter().map(move |func_data| {
(
package_addr,
&module_data.module_id.module_name,
module_data,
&func_data.name,
func_data,
)
})
})
})
}

pub fn get_package_metadata(&self, package_id: &MoveAddress) -> Option<&MovePackageAbi> {
self.testing_abis.get(
self.module_address_to_package
.get(package_id)
.unwrap_or(package_id),
)
}

pub fn get_function(
&self,
package_id: &MoveAddress,
module: &str,
function: &str,
) -> Option<&MoveFunctionAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.functions.iter().find(|f| f.name == function))
}

pub fn get_struct(
&self,
package_id: &MoveAddress,
module: &str,
struct_name: &str,
) -> Option<&MoveStructAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.structs.iter().find(|s| s.struct_name == struct_name))
}

pub fn get_enum(
&self,
package_id: &MoveAddress,
module: &str,
enum_name: &str,
) -> Option<&MoveStructAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.structs.iter().find(|s| s.struct_name == enum_name))
}

pub fn get_abilities(
&self,
package_id: &MoveAddress,
module: &str,
struct_name: &str,
) -> Option<MoveAbility> {
self.get_struct(package_id, module, struct_name)
.map(|s| s.abilities)
.or(self
.get_enum(package_id, module, struct_name)
.map(|e| e.abilities))
}

pub fn generate_magic_number_pool(&self) -> BTreeSet<Vec<u8>> {
BTreeSet::new()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/movy-fuzz/src/mutators/object_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ where
.flat_map(|type_tag| {
meta_state
.type_graph
.find_consumers(&MoveAbiSignatureToken::from_type_tag(type_tag))
.find_consumers(&MoveAbiSignatureToken::from_type_tag_lossy(type_tag))
.iter()
.map(|(module_id, consumer_function)| {
FunctionIdent::new(
Expand Down
1 change: 1 addition & 0 deletions crates/movy-replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mdbx-derive = {workspace = true}
z3 = {workspace = true }
tokio-stream = {workspace = true}
tempfile = {workspace = true}
sui-json-rpc-types = {workspace = true}

movy-analysis = {workspace = true}
movy-types = {workspace = true}
Expand Down
163 changes: 161 additions & 2 deletions crates/movy-replay/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,28 @@ use crate::{
db::{ObjectStoreCachedStore, ObjectStoreInfo},
env::SuiTestingEnv,
};
use color_eyre::eyre::eyre;
use move_core_types::{
annotated_value::{MoveDatatypeLayout, MoveStruct, MoveValue},
language_storage::StructTag,
};
use movy_analysis::type_graph::MoveTypeGraph;
use movy_sui::database::cache::ObjectSuiStoreCommit;
use movy_types::{
abi::{MoveAbility, MovePackageAbi},
abi::{
MoveAbiSignatureToken, MoveAbility, MoveFunctionAbi, MoveModuleAbi, MoveModuleId,
MovePackageAbi, MoveStructAbi,
},
error::MovyError,
input::{FunctionIdent, MoveAddress, MoveStructTag, MoveTypeTag},
};
use serde::{Deserialize, Serialize};
use serde_json_any_key::*;
use sui_types::storage::{BackingPackageStore, BackingStore, ObjectStore};
use sui_json_rpc_types::type_and_fields_from_move_event_data;
use sui_types::{
event::Event,
storage::{BackingPackageStore, BackingStore, ObjectStore},
};

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct Metadata {
Expand All @@ -28,6 +40,8 @@ pub struct Metadata {
pub module_address_to_package: BTreeMap<MoveAddress, MoveAddress>,
pub ability_to_type_tag: BTreeMap<MoveAbility, Vec<MoveTypeTag>>,
pub function_name_to_idents: BTreeMap<String, Vec<FunctionIdent>>,
#[serde(with = "any_key_map")]
pub structs_mapping: BTreeMap<(MoveModuleId, String), MoveStructAbi>,
}

pub struct TargetPackages {
Expand All @@ -36,14 +50,148 @@ pub struct TargetPackages {
}

impl Metadata {
pub fn iter_functions(
&self,
) -> impl Iterator<
Item = (
&MoveAddress, // package_addr
&String, // module_name
&MoveModuleAbi, // module_data
&String, // func_name
&MoveFunctionAbi, // func_data
),
> {
self.abis.iter().flat_map(|(package_addr, package_meta)| {
package_meta.modules.iter().flat_map(move |module_data| {
module_data.functions.iter().map(move |func_data| {
(
package_addr,
&module_data.module_id.module_name,
module_data,
&func_data.name,
func_data,
)
})
})
})
}

pub fn get_package_metadata(&self, package_id: &MoveAddress) -> Option<&MovePackageAbi> {
self.testing_abis.get(
self.module_address_to_package
.get(package_id)
.unwrap_or(package_id),
)
}

pub fn get_original_package_metadata(
&self,
package_id: &MoveAddress,
) -> Option<&MovePackageAbi> {
self.abis.get(
self.module_address_to_package
.get(package_id)
.unwrap_or(package_id),
)
}

pub fn get_function(
&self,
package_id: &MoveAddress,
module: &str,
function: &str,
) -> Option<&MoveFunctionAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.functions.iter().find(|f| f.name == function))
}

pub fn get_struct(
&self,
package_id: &MoveAddress,
module: &str,
struct_name: &str,
) -> Option<&MoveStructAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.structs.iter().find(|s| s.struct_name == struct_name))
}

pub fn get_enum(
&self,
package_id: &MoveAddress,
module: &str,
enum_name: &str,
) -> Option<&MoveStructAbi> {
self.get_package_metadata(package_id)
.and_then(|pkg| {
pkg.modules
.iter()
.find(|m| m.module_id.module_name == module)
})
.and_then(|module| module.structs.iter().find(|s| s.struct_name == enum_name))
}

pub fn get_abilities(
&self,
package_id: &MoveAddress,
module: &str,
struct_name: &str,
) -> Option<MoveAbility> {
self.get_struct(package_id, module, struct_name)
.map(|s| s.abilities)
.or(self
.get_enum(package_id, module, struct_name)
.map(|e| e.abilities))
}

pub fn decode_sui_event(
&self,
event: &Event,
) -> Result<Option<(StructTag, serde_json::Value)>, MovyError> {
log::debug!("Decoding event {}", event.type_.to_canonical_string(true));
let id: MoveAddress = event.type_.address.into();
if let Some(st) =
self.get_struct(&id, event.type_.module.as_str(), event.type_.name.as_str())
{
let mut typs = vec![];
for ty in event.type_.type_params.iter() {
let ty = MoveTypeTag::from(ty.clone());
let abi_ty = MoveAbiSignatureToken::from_type_tag_lossy(&ty);
if let Some(typ) = abi_ty.to_move_type_layout(&[], &self.structs_mapping) {
typs.push(typ);
} else {
log::debug!("decode_event: abi_ty {} is mising", &abi_ty);
}
}
if let Some(layout) = st.to_move_struct_layout(&typs, &self.structs_mapping) {
let e = Event::move_event_to_move_value(
&event.contents,
MoveDatatypeLayout::Struct(Box::new(layout)),
)?;
return Ok(Some(type_and_fields_from_move_event_data(e)?));
} else {
log::debug!(
"can not convert to move struct layout for {} and {:?}",
st.struct_name,
&typs
);
}
} else {
log::debug!("the event struct is not known");
}

Ok(None)
}

pub async fn from_env_filtered<T>(
env: &SuiTestingEnv<T>,
local_abis: BTreeMap<MoveAddress, MovePackageAbi>,
Expand Down Expand Up @@ -150,6 +298,16 @@ impl Metadata {
type_graph.add_package(package);
}

let mut structs_mapping = BTreeMap::new();
for (pkg_id, pkg) in testing_abis.iter() {
for md in pkg.modules.iter() {
for st in md.structs.iter() {
structs_mapping
.insert((md.module_id.clone(), st.struct_name.clone()), st.clone());
}
}
}

let meta = Metadata {
type_graph,
abis,
Expand All @@ -161,6 +319,7 @@ impl Metadata {
.map(|(ability, tags)| (ability, tags.into_iter().collect()))
.collect(),
function_name_to_idents,
structs_mapping,
};
Ok(meta)
}
Expand Down
1 change: 1 addition & 0 deletions crates/movy-replay/src/tracer/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ where
frame.module.name(),
&frame.function_name
);
log::debug!("Entering {}", &package);
self.current_functions.push(FunctionIdent::new(
&(*frame.module.address()).into(),
&frame.module.name().to_string(),
Expand Down
Loading
Loading