Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic caused by struct in verifier #3186

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
26 changes: 14 additions & 12 deletions moveos/moveos-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ fn struct_def_from_struct_handle<Resolver>(
verified_modules: &mut BTreeMap<ModuleId, CompiledModule>,
struct_name: &str,
db: &Resolver,
) -> Option<StructDefinition>
) -> Option<(StructDefinition, CompiledModule)>
where
Resolver: ModuleResolver,
{
Expand All @@ -1191,7 +1191,7 @@ where
let iterator_struct_name =
struct_full_name_from_sid(&struct_handle_idx, &current_module_bin_view);
if iterator_struct_name == struct_name {
return Some(struct_def.clone());
return Some((struct_def.clone(), current_module.clone()));
}
}

Expand All @@ -1202,7 +1202,7 @@ where
let iterator_struct_name =
struct_full_name_from_sid(&struct_handle_idx, &iterator_module_bin_view);
if iterator_struct_name == struct_name {
return Some(struct_def.clone());
return Some((struct_def.clone(), m.clone()));
}
}
}
Expand All @@ -1220,7 +1220,7 @@ where
let iterator_struct_name =
struct_full_name_from_sid(&struct_handle_idx, &target_module_bin_view);
if iterator_struct_name == struct_name {
return Some(struct_def.clone());
return Some((struct_def.clone(), target_module));
}
}
None
Expand Down Expand Up @@ -1455,7 +1455,7 @@ where
db,
);
match struct_def_opt {
Some(struct_def) => validate_struct_fields(
Some((struct_def, _)) => validate_struct_fields(
&struct_def,
current_module,
module_bin_view,
Expand Down Expand Up @@ -1910,19 +1910,21 @@ where
);

let mut struct_fields = Vec::new();
if let Some(struct_def) = struct_def_opt {
let field_count = struct_def.declared_field_count().unwrap();
for field_idx in 0..field_count {
let field_def = struct_def.field(field_idx as usize).unwrap().clone();
struct_fields.push(field_def);
}
let mut target_module = caller_module.clone();
if let Some((struct_def, m)) = struct_def_opt {
let v = match struct_def.field_information {
StructFieldInformation::Native => vec![],
StructFieldInformation::Declared(v) => v,
};
target_module = m.clone();
struct_fields.extend(v);
}

let formulas = struct_fields
.iter()
.map(|field_def| {
calculate_depth_of_type(
caller_module,
&target_module,
verified_modules,
db,
&field_def.signature.0.clone(),
Expand Down
Loading