Skip to content

Commit

Permalink
Fix #235: fix build/test errors when enabling 'sui_support' (#239)
Browse files Browse the repository at this point in the history
* merge  into  and remove

* fix: build failed when enabling

* Fix #235: fix build/test errors when enabling

* Fix #235: fix build/test errors when enabling 'sui_support'
  • Loading branch information
jacob-chia authored Oct 8, 2023
1 parent 5985e6d commit 2206dd8
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 108 deletions.
40 changes: 16 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@ use_presets = []
print_logs = []
z3_debug = []
sui_support = [
# "dep:move-binary-format",
# "dep:move-core-types",
# "dep:move-stdlib",
# "dep:move-vm-runtime",
# "dep:move-vm-types",
# "dep:sui-move-natives-latest",
# "dep:sui-protocol-config",
# "dep:sui-types",
"dep:sui",
"dep:move-binary-format",
"dep:move-core-types",
"dep:move-stdlib",
"dep:move-vm-runtime",
"dep:move-vm-types",
"dep:sui-move-natives-latest",
"dep:sui-protocol-config",
"dep:sui-types",
]
debug = []

Expand Down Expand Up @@ -88,18 +87,11 @@ revm-interpreter = { git = "https://github.com/fuzzland/revm", rev = "f9fdf3e66f
# external fuzzing-based abi decompiler
heimdall = { git = "https://github.com/fuzzland/heimdall-rs", rev = "32363c9c59cf14c6839e48e5548cc862dfc54842" }

sui = { git = "https://github.com/MystenLabs/sui.git", rev = "a0e136a04c5c09371f30255f7d4dac1793504ecb", optional = true }

# # from https://github.com/aptos-labs/aptos-core/blob/main/Cargo.toml#L452
# move-binary-format = { path = "../externals/sui/external-crates/move/move-binary-format", optional = true }
# move-core-types = { path = "../externals/sui/external-crates/move/move-core/types", features = [
# "address32",
# ], optional = true }
# move-stdlib = { path = "../externals/sui/external-crates/move/move-stdlib", optional = true }
# move-vm-runtime = { path = "../externals/sui/external-crates/move/move-vm/runtime", features = [
# "lazy_natives",
# ], optional = true }
# move-vm-types = { path = "../externals/sui/external-crates/move/move-vm/types", optional = true }
# sui-move-natives-latest = { path = "../externals/sui/sui-execution/latest/sui-move-natives", optional = true }
# sui-protocol-config = { path = "../externals/sui/crates/sui-protocol-config", optional = true }
# sui-types = { path = "../externals/sui/crates/sui-types", optional = true }
move-binary-format = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-binary-format", optional = true }
move-core-types = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-core-types", features = ["address32"], optional = true }
move-stdlib = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-stdlib", optional = true }
move-vm-runtime = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-vm-runtime", features = ["lazy_natives"], optional = true }
move-vm-types = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "move-vm-types", optional = true }
sui-move-natives-latest = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "sui-move-natives-latest", optional = true }
sui-protocol-config = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "sui-protocol-config", optional = true }
sui-types = { git = "https://github.com/fuzzland/ityfuzz-sui-fork.git", package = "sui-types", optional = true }
2 changes: 1 addition & 1 deletion src/move/corpus_initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ where
.expect("type tag info not found")
.clone();
for parameter_type in &function.parameter_types {
let tag = type_tag_info.get_type_tag(&parameter_type);
let tag = type_tag_info.get_type_tag(parameter_type);
let default_val = if let Some(tag) = tag && is_tx_context(&tag) {
MoveInputStatus::Complete(self.gen_tx_context(parameter_type.clone()))
} else {
Expand Down
157 changes: 79 additions & 78 deletions src/move/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,14 +843,16 @@ mod tests {
use move_core_types::u256;
use crate::input::VMInputT;
use crate::r#move::input::{CloneableValue, FunctionDefaultable, MoveFunctionInput, MoveFunctionInputT, StructAbilities};
use crate::r#move::movevm::{self, TypeTagInfoMeta};
use crate::r#move::types::MoveFuzzState;
use crate::state::FuzzState;
use crate::state_input::StagedVMState;
use std::rc::Rc;
use std::cell::RefCell;
use move_vm_runtime::loader::{Function, Scope};
use move_vm_runtime::loader::{Function, Scope, Loader};
use move_vm_types::loaded_data::runtime_types::{CachedStructIndex, Type};
use crate::r#move::vm_state::MoveVMState;
use move_vm_types::values::{Container, ContainerRef, Value, ValueImpl, values_impl};
use crate::r#move::vm_state::{MoveVMState, GatedValue, Gate};
use std::collections::HashMap;
use libafl::mutators::MutationResult;
use libafl::prelude::HasMetadata;
Expand All @@ -862,28 +864,7 @@ mod tests {
($tys: expr) => {
{
let mut f = FunctionDefaultable::default();
f.function = Some(
Arc::new(

Function {
file_format_version: 0,
index: Default::default(),
code: vec![],
parameters: Default::default(),
return_: Default::default(),
locals: Default::default(),
type_parameters: vec![],
native: None,
def_is_native: false,
def_is_friend_or_private: false,
scope: Scope::Module(ModuleId::new(AccountAddress::from([0; 32]), Identifier::new("test").unwrap())),
name: Identifier::new("test").unwrap(),
return_types: vec![],
local_types: vec![],
parameter_types: $tys,
}
)
);
f.function = Some(Arc::new(Function::new_dummy($tys)));
f
}
};
Expand All @@ -895,7 +876,7 @@ mod tests {
macro_rules! dummy_input {
($init_v: expr, $sstate: expr, $tys: expr) => {
{
let dummy_addr = AccountAddress::from([0; 32]);
let dummy_addr = AccountAddress::ZERO;
MoveFunctionInput {
module: ModuleId::new(dummy_addr.clone(), Identifier::new("test").unwrap()),
function: Identifier::new("test").unwrap(),
Expand All @@ -910,6 +891,7 @@ mod tests {
vm_state: $sstate,
vm_state_idx: 0,
_deps: Default::default(),
_resolved: true,
}
}
};
Expand All @@ -921,8 +903,11 @@ mod tests {

macro_rules! test_lb {
($init_v: expr, $tys: expr) => {
let mut state = MoveFuzzState::new(0);
state.metadata_map_mut().insert(TypeTagInfoMeta::new());

let mut v = dummy_input!($init_v, $tys);
v.mutate::<MoveFuzzState>(&mut Default::default());
v.mutate::<MoveFuzzState>(&mut state);
// println!("{:?}", v.args[0]);
let o = (v.args[0].value.equals(&Value($init_v)).expect("failed to compare"));
assert!(!o, "value was not mutated");
Expand Down Expand Up @@ -990,14 +975,11 @@ mod tests {
}

macro_rules! test_struct {
($init_v: expr, $tys: expr, $sstate: expr, $struct_abilities: expr) => {
($init_v: expr, $tys: expr, $sstate: expr, $struct_abilities: expr, $state: expr) => {
{
let mut state: MoveFuzzState = Default::default();
state.metadata_map_mut().insert($struct_abilities);

let (v, res) = {
let mut v = dummy_input!($init_v, $sstate, $tys);
let res = v.mutate::<MoveFuzzState>(&mut state);
let res = v.mutate::<MoveFuzzState>($state);
(v, res)
};
// println!("{:?}", v.args[0]);
Expand All @@ -1013,18 +995,20 @@ mod tests {
MoveVMState::new()
);

sstate.state.add_new_value(
Value(ValueImpl::Container(
let value = GatedValue {
v: Value(ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(5),
ValueImpl::U8(5),
]))
)
)),
&Type::Struct(CachedStructIndex(1)),
false,
);
gate: Gate::Own,
};

let mut state = setup_state();
sstate_add_new_value(&mut sstate, &mut state, value, &Type::Struct(CachedStructIndex(0)));

let (mutation_result, init_v, mutated_v, vm_state) = test_struct!(
ValueImpl::Container(
Expand All @@ -1035,18 +1019,17 @@ mod tests {
]))
)
),
vec![Type::Struct(CachedStructIndex(1))],
vec![Type::Struct(CachedStructIndex(0))],
sstate,
{
let mut abilities = StructAbilities::new();
abilities.set_ability(Type::Struct(CachedStructIndex(1)), AbilitySet(Ability::Copy as u8));
abilities.set_ability(Type::Struct(CachedStructIndex(0)), AbilitySet(Ability::Copy as u8));
abilities
}
},
&mut state
);
println!("initial value {:?}", init_v);
println!("mutated value {:?}", mutated_v);
println!("remaining value to drop {:?}", vm_state.state.value_to_drop);
println!("remaining useful_value {:?}", vm_state.state.useful_value);
println!("ref in use {:?}", vm_state.state.ref_in_use);
assert_eq!(mutation_result, MutationResult::Mutated);
}
Expand All @@ -1057,33 +1040,35 @@ mod tests {
MoveVMState::new()
);

sstate.state.add_new_value(
Value(ValueImpl::Container(
let value = GatedValue {
v: Value(ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(5),
ValueImpl::U8(5),
]))
)
)),
&Type::Struct(CachedStructIndex(1)),
false,
);
sstate.state.ref_in_use.push(
(
Type::Struct(CachedStructIndex(1)),
Value(
ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(0),
ValueImpl::U8(0),
]))
)
gate: Gate::Own,
};

let mut state = setup_state();
sstate_add_new_value(&mut sstate, &mut state, value, &Type::Struct(CachedStructIndex(0)));

let new_value = GatedValue {
v: Value(
ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(0),
ValueImpl::U8(0),
]))
)
)
)
);
),
gate: Gate::Ref,
};
sstate.state.ref_in_use.push((Type::Struct(CachedStructIndex(0)), new_value));

let (mutation_result, init_v, mutated_v, vm_state) = test_struct!(
ValueImpl::ContainerRef(
Expand All @@ -1096,18 +1081,17 @@ mod tests {
)
)
),
vec![Type::Reference(Box::new(Type::Struct(CachedStructIndex(1))))],
vec![Type::Reference(Box::new(Type::Struct(CachedStructIndex(0))))],
sstate,
{
let mut abilities = StructAbilities::new();
abilities.set_ability(Type::Struct(CachedStructIndex(1)), AbilitySet(Ability::Copy as u8));
abilities.set_ability(Type::Struct(CachedStructIndex(0)), AbilitySet(Ability::Copy as u8));
abilities
}
},
&mut state
);
println!("initial value {:?}", init_v);
println!("mutated value {:?}", mutated_v);
println!("remaining value to drop {:?}", vm_state.state.value_to_drop);
println!("remaining useful_value {:?}", vm_state.state.useful_value);
println!("ref in use {:?}", vm_state.state.ref_in_use);
assert!(vm_state.state.ref_in_use.len() > 0);
assert_eq!(mutation_result, MutationResult::Mutated);
Expand All @@ -1118,18 +1102,21 @@ mod tests {
let mut sstate = MoveStagedVMState::new_with_state(
MoveVMState::new()
);
sstate.state.add_new_value(
Value(ValueImpl::Container(

let value = GatedValue {
v: Value(ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(123),
ValueImpl::U8(123),
]))
)
)),
&Type::Struct(CachedStructIndex(1)),
false,
);
gate: Gate::Own,
};

let mut state = setup_state();
sstate_add_new_value(&mut sstate, &mut state, value, &Type::Struct(CachedStructIndex(0)));

let mut inp = dummy_input!(
ValueImpl::ContainerRef(
Expand All @@ -1143,9 +1130,9 @@ mod tests {
)
),
sstate,
vec![Type::Reference(Box::new(Type::Struct(CachedStructIndex(1))))]
vec![Type::Reference(Box::new(Type::Struct(CachedStructIndex(0))))]
);
inp.slash(&mut MoveFuzzState::default());
inp.slash(&mut state);
println!("{:?}", inp.args[0].value);
}

Expand All @@ -1154,18 +1141,21 @@ mod tests {
let mut sstate = MoveStagedVMState::new_with_state(
MoveVMState::new()
);
sstate.state.add_new_value(
Value(ValueImpl::Container(

let value = GatedValue {
v: Value(ValueImpl::Container(
Container::Struct(
Rc::new(RefCell::new(vec![
ValueImpl::U8(123),
ValueImpl::U8(123),
]))
)
)),
&Type::Struct(CachedStructIndex(1)),
false,
);
gate: Gate::Own,
};

let mut state = setup_state();
sstate_add_new_value(&mut sstate, &mut state, value, &Type::Struct(CachedStructIndex(0)));

let mut inp = dummy_input!(
ValueImpl::Container(
Expand All @@ -1185,9 +1175,9 @@ mod tests {
)
),
sstate,
vec![Type::Vector(Box::new(Type::Reference(Box::new(Type::Struct(CachedStructIndex(1))))))]
vec![Type::Vector(Box::new(Type::Reference(Box::new(Type::Struct(CachedStructIndex(0))))))]
);
inp.slash(&mut MoveFuzzState::default());
inp.slash(&mut state);
assert!(
inp.args[0].value.equals(
&Value(
Expand All @@ -1198,5 +1188,16 @@ mod tests {
)
}

fn setup_state() -> MoveFuzzState {
let mut state = MoveFuzzState::new(0);
state.metadata_map_mut().insert(TypeTagInfoMeta::new());
state.metadata_map_mut().insert(StructAbilities::new());
state
}

fn sstate_add_new_value(sstate: &mut MoveStagedVMState, state: &mut MoveFuzzState, value: GatedValue, ty: &Type) {
let loader = movevm::dummy_loader(state);
let resolver = movevm::dummy_resolver(&loader);
sstate.state.add_new_value(value, ty, &resolver, state);
}
}
8 changes: 4 additions & 4 deletions src/move/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub mod vm_state;

use clap::Parser;
use hex::{decode, encode};
use ityfuzz::fuzzers::move_fuzzer::{move_fuzzer, MoveFuzzConfig};
use ityfuzz::oracle::{Oracle, Producer};
use ityfuzz::r#const;
use ityfuzz::state::FuzzState;
use crate::fuzzers::move_fuzzer::{move_fuzzer, MoveFuzzConfig};
use crate::oracle::{Oracle, Producer};
use crate::r#const;
use crate::state::FuzzState;
use serde::Deserialize;
use std::cell::RefCell;
use std::collections::HashMap;
Expand Down
Loading

0 comments on commit 2206dd8

Please sign in to comment.