Skip to content

Commit 96dbba1

Browse files
wtdcodelbr77
andcommitted
TraceState integration to avoid BeforeInstruction
Co-authored-by: LiBr <me@nvme0n1p.dev>
1 parent 64af7d9 commit 96dbba1

26 files changed

Lines changed: 2120 additions & 1514 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -61,62 +61,62 @@ tonic = "0.14"
6161
url = "2.5.7"
6262

6363
# Sui dependencies
64-
move-binary-format = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
65-
move-trace-format = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
66-
move-package = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
67-
move-compiler = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
68-
move-disassembler = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
69-
move-ir-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
70-
move-core-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
71-
move-vm-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
72-
move-vm-stack = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
73-
move-vm-runtime = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz", features = ["tracing", "testing"]}
74-
move-model = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
75-
move-stackless-bytecode = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
76-
sui-move-build = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
77-
sui-json-rpc-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
78-
sui-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
79-
sui-package-management = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
80-
sui-sdk = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
81-
sui-config = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
82-
sui-storage = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
83-
sui-snapshot = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
84-
sui-core = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
85-
sui-execution = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz", features = ["testing"]}
86-
shared-crypto = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
87-
sui-move-natives-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
88-
sui-adapter-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
64+
# move-binary-format = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
65+
# move-trace-format = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
66+
# move-package = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
67+
# move-compiler = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
68+
# move-disassembler = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
69+
# move-ir-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
70+
# move-core-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
71+
# move-vm-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
72+
# move-vm-stack = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
73+
# move-vm-runtime = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz", features = ["tracing", "testing"]}
74+
# move-model = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
75+
# move-stackless-bytecode = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
76+
# sui-move-build = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
77+
# sui-json-rpc-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
78+
# sui-types = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
79+
# sui-package-management = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
80+
# sui-sdk = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
81+
# sui-config = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
82+
# sui-storage = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
83+
# sui-snapshot = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
84+
# sui-core = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
85+
# sui-execution = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz", features = ["testing"]}
86+
# shared-crypto = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
87+
# sui-move-natives-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
88+
# sui-adapter-latest = {git = "https://github.com/wtdcode/sui", branch = "v1.60.1-fuzz"}
8989

9090

9191
sui-rpc = { git = "https://github.com/MystenLabs/sui-rust-sdk.git", rev = "fb62af78b30f5dc64eeaec0094ab95b5ce5b7ce2" }
9292
sui-sdk-types = { git = "https://github.com/MystenLabs/sui-rust-sdk.git", rev = "fb62af78b30f5dc64eeaec0094ab95b5ce5b7ce2" }
9393
fastcrypto = { git = "https://github.com/MystenLabs/fastcrypto", rev = "09f86974195ec85d8aae386b1909d341d3ccfe52"} # sui use git dependency =/
9494

95-
# move-stackless-bytecode = {path = "../sui/external-crates/move/crates/move-stackless-bytecode"}
96-
# move-model = {path = "../sui/external-crates/move/crates/move-model"}
97-
# move-binary-format = {path = "../sui/external-crates/move/crates/move-binary-format"}
98-
# move-trace-format = {path = "../sui/external-crates/move/crates/move-trace-format"}
99-
# move-package = {path = "../sui/external-crates/move/crates/move-package"}
100-
# move-compiler = {path = "../sui/external-crates/move/crates/move-compiler"}
101-
# move-disassembler = {path = "../sui/external-crates/move/crates/move-disassembler"}
102-
# move-ir-types = {path = "../sui/external-crates/move/crates/move-ir-types"}
103-
# move-core-types = {path = "../sui/external-crates/move/crates/move-core-types"}
104-
# move-vm-types = {path = "../sui/external-crates/move/crates/move-vm-types"}
105-
# move-vm-stack = {path = "../sui/external-crates/move/crates/move-vm-stack"}
106-
# move-vm-runtime = {path = "../sui/external-crates/move/crates/move-vm-runtime", features = ["tracing", "testing"]}
107-
# sui-move-build = {path = "../sui/crates/sui-move-build"}
108-
# sui-json-rpc-types = {path = "../sui/crates/sui-json-rpc-types"}
109-
# sui-types = {path = "../sui/crates/sui-types"}
110-
# sui-package-management = {path = "../sui/crates/sui-package-management"}
111-
# sui-sdk = {path = "../sui/crates/sui-sdk"}
112-
# sui-config = {path = "../sui/crates/sui-config"}
113-
# sui-storage = {path = "../sui/crates/sui-storage"}
114-
# sui-snapshot = {path = "../sui/crates/sui-snapshot"}
115-
# sui-core = {path = "../sui/crates/sui-core"}
116-
# sui-execution = {path = "../sui/sui-execution", features = ["testing"]}
117-
# shared-crypto = {path = "../sui/crates/shared-crypto"}
118-
# sui-move-natives-latest = {path = "../sui/sui-execution/latest/sui-move-natives/"}
119-
# sui-adapter-latest = {path = "../sui/sui-execution/latest/sui-adapter/"}
95+
move-stackless-bytecode = {path = "../sui/external-crates/move/crates/move-stackless-bytecode"}
96+
move-model = {path = "../sui/external-crates/move/crates/move-model"}
97+
move-binary-format = {path = "../sui/external-crates/move/crates/move-binary-format"}
98+
move-trace-format = {path = "../sui/external-crates/move/crates/move-trace-format"}
99+
move-package = {path = "../sui/external-crates/move/crates/move-package"}
100+
move-compiler = {path = "../sui/external-crates/move/crates/move-compiler"}
101+
move-disassembler = {path = "../sui/external-crates/move/crates/move-disassembler"}
102+
move-ir-types = {path = "../sui/external-crates/move/crates/move-ir-types"}
103+
move-core-types = {path = "../sui/external-crates/move/crates/move-core-types"}
104+
move-vm-types = {path = "../sui/external-crates/move/crates/move-vm-types"}
105+
move-vm-stack = {path = "../sui/external-crates/move/crates/move-vm-stack"}
106+
move-vm-runtime = {path = "../sui/external-crates/move/crates/move-vm-runtime", features = ["tracing", "testing"]}
107+
sui-move-build = {path = "../sui/crates/sui-move-build"}
108+
sui-json-rpc-types = {path = "../sui/crates/sui-json-rpc-types"}
109+
sui-types = {path = "../sui/crates/sui-types"}
110+
sui-package-management = {path = "../sui/crates/sui-package-management"}
111+
sui-sdk = {path = "../sui/crates/sui-sdk"}
112+
sui-config = {path = "../sui/crates/sui-config"}
113+
sui-storage = {path = "../sui/crates/sui-storage"}
114+
sui-snapshot = {path = "../sui/crates/sui-snapshot"}
115+
sui-core = {path = "../sui/crates/sui-core"}
116+
sui-execution = {path = "../sui/sui-execution", features = ["testing"]}
117+
shared-crypto = {path = "../sui/crates/shared-crypto"}
118+
sui-move-natives-latest = {path = "../sui/sui-execution/latest/sui-move-natives/"}
119+
sui-adapter-latest = {path = "../sui/sui-execution/latest/sui-adapter/"}
120120

121121
# Aptos dependencies
122122

crates/movy-fuzz/src/executor.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ use libafl_bolts::tuples::{Handle, MatchNameRef, RefIndexable};
1010
use movy_replay::{
1111
db::{ObjectStoreInfo, ObjectStoreMintObject},
1212
exec::{ExecutionTracedResults, SuiExecutor},
13-
tracer::{concolic::ConcolicState, fuzz::SuiFuzzTracer, op::Log, oracle::SuiGeneralOracle},
13+
tracer::{
14+
concolic::ConcolicState,
15+
fuzz::{PackageResolvedCache, PackageResolver, SuiFuzzTracer},
16+
op::Log,
17+
oracle::SuiGeneralOracle,
18+
},
1419
};
1520
use movy_sui::database::cache::{CachedStore, ObjectSuiStoreCommit};
1621
use movy_types::{
@@ -72,6 +77,7 @@ pub struct SuiFuzzExecutor<T, OT, RT, I, S> {
7277
pub ob: OT,
7378
pub attacker: MoveAddress,
7479
pub oracles: RT,
80+
pub packages_cache: PackageResolvedCache,
7581
// pub minted_gas: Object,
7682
// pub log_tracer: Option<SuiLogTracer>,
7783
pub ph: PhantomData<(I, S)>,
@@ -99,7 +105,7 @@ where
99105
+ Clone
100106
+ 'static,
101107
OT: ObserversTuple<I, S>,
102-
RT: for<'a> SuiGeneralOracle<CachedStore<&'a T>, S>,
108+
RT: SuiGeneralOracle<S>,
103109
I: MoveInput,
104110
S: HasRand
105111
+ HasFuzzMetadata
@@ -127,15 +133,25 @@ where
127133
code_ob[0] = 1;
128134
}
129135

130-
let db = CachedStore::new(&self.executor.db);
131-
self.oracles.pre_execution(&db, state, input.sequence())?;
136+
self.oracles
137+
.pre_execution(&self.executor.db, state, input.sequence())?;
132138

133139
trace!("Executing input: {}", input.sequence());
134140
state.executions_mut().add_assign(1);
135141
let gas_id = state.fuzz_state().gas_id;
136-
let tracer = SuiFuzzTracer::new(&mut self.ob, state, &mut self.oracles, CODE_OBSERVER_NAME);
142+
let resolver = PackageResolver {
143+
db: &self.executor.db,
144+
cache: std::mem::take(&mut self.packages_cache),
145+
};
146+
let tracer = SuiFuzzTracer::new(
147+
&mut self.ob,
148+
state,
149+
&mut self.oracles,
150+
CODE_OBSERVER_NAME,
151+
resolver,
152+
);
137153

138-
let result = self.executor.run_ptb_with_gas(
154+
let result = self.executor.run_ptb_with_movy_tracer_gas(
139155
input.sequence().to_ptb()?,
140156
epoch,
141157
epoch_ms,
@@ -147,12 +163,13 @@ where
147163
let ExecutionTracedResults { results, tracer } = result;
148164
let effects = results.effects;
149165
let events = results.store.events.data.clone();
166+
let db = CachedStore::new(&self.executor.db);
150167
db.commit_store(results.store, &effects)
151168
.map_err(|e| libafl::Error::unknown(format!("commit store failed: {e}")))?;
169+
let mut tracer = tracer.expect("tracer should be present when tracing is enabled");
152170

153-
let mut trace_outcome = tracer
154-
.expect("tracer should be present when tracing is enabled")
155-
.outcome();
171+
self.packages_cache = std::mem::take(&mut tracer.resolver.cache);
172+
let mut trace_outcome = tracer.outcome();
156173

157174
trace!("Execution finished with status: {:?}", effects.status());
158175

crates/movy-fuzz/src/operations/sui_fuzz.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ use libafl_bolts::tuples::tuple_list;
2828
use movy_replay::db::{ObjectStoreCachedStore, ObjectStoreInfo};
2929
use movy_replay::env::SuiTestingEnv;
3030
use movy_replay::exec::SuiExecutor;
31+
use movy_replay::tracer::fuzz::PackageResolvedCache;
3132
use movy_replay::tracer::oracle::{CouldDisabledOralce, SuiGeneralOracle};
3233
use movy_sui::database::cache::{CachedStore, ObjectSuiStoreCommit};
3334
use movy_types::error::MovyError;
3435
use sui_types::storage::BackingStore;
3536
use sui_types::storage::{BackingPackageStore, ObjectStore};
3637
use tracing::{info, warn};
3738

38-
pub fn oracles<T, S, E>(
39+
pub fn oracles<S, E>(
3940
typed_bug_abort: bool,
4041
disable_profit_oracle: bool,
4142
disable_defects_oracle: bool,
42-
) -> impl for<'a> SuiGeneralOracle<CachedStore<&'a T>, S>
43+
) -> impl SuiGeneralOracle<S>
4344
where
44-
T: 'static + ObjectStore,
4545
S: HasMetadata + HasExtraState<ExtraState = ExtraNonSerdeFuzzState<E>> + HasFuzzMetadata,
4646
{
4747
tuple_list!(
@@ -60,6 +60,7 @@ fn fuzz_impl<T>(
6060
env: SuiTestingEnv<T>,
6161
output: &Option<PathBuf>,
6262
time_limit: Option<u64>,
63+
cycles_limit: Option<u64>,
6364
typed_bug_abort: bool,
6465
disable_profit_oracle: bool,
6566
disable_defects_oracle: bool,
@@ -136,6 +137,7 @@ where
136137
disable_profit_oracle,
137138
disable_defects_oracle,
138139
),
140+
packages_cache: PackageResolvedCache::default(),
139141
epoch: state.fuzz_state().epoch,
140142
epoch_ms: state.fuzz_state().epoch_ms,
141143
ph: std::marker::PhantomData,
@@ -204,7 +206,7 @@ where
204206
.unwrap();
205207

206208
let start = std::time::SystemTime::now();
207-
let mut cycle = 1usize;
209+
let mut cycle = 1u64;
208210
loop {
209211
if let Some(limit) = time_limit {
210212
let current = std::time::SystemTime::now();
@@ -215,6 +217,12 @@ where
215217
}
216218
}
217219

220+
if let Some(climit) = cycles_limit {
221+
if cycle >= climit {
222+
break;
223+
}
224+
}
225+
218226
if let Err(e) = fuzzer.fuzz_one(&mut stages, &mut executor, &mut state, &mut mgr) {
219227
warn!("Getting fuzz error: {:?}", e);
220228
break;
@@ -250,6 +258,7 @@ pub fn fuzz(
250258
>,
251259
output: &Option<PathBuf>,
252260
time_limit: Option<u64>,
261+
cycles_limit: Option<u64>,
253262
typed_bug_abort: bool,
254263
disable_profit_oracle: bool,
255264
disable_defects_oracle: bool,
@@ -259,6 +268,7 @@ pub fn fuzz(
259268
env,
260269
output,
261270
time_limit,
271+
cycles_limit,
262272
typed_bug_abort,
263273
disable_profit_oracle,
264274
disable_defects_oracle,

crates/movy-fuzz/src/operations/sui_replay.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use movy_replay::{
1313
db::{ObjectStoreCachedStore, ObjectStoreInfo, ObjectStoreMintObject},
1414
env::SuiTestingEnv,
1515
exec::SuiExecutor,
16-
tracer::tree::TreeTracer,
16+
tracer::{fuzz::PackageResolvedCache, tree::TreeTracer},
1717
};
1818
use movy_sui::database::cache::ObjectSuiStoreCommit;
1919
use movy_types::error::MovyError;
@@ -49,7 +49,7 @@ where
4949
let inner = env.into_inner();
5050
let executor = SuiExecutor::new(inner)?;
5151
let tracer = if trace { Some(TreeTracer::new()) } else { None };
52-
let out = executor.run_ptb_with_gas(
52+
let out = executor.run_ptb_with_movy_tracer_gas(
5353
seed.sequence.to_ptb()?,
5454
meta.epoch,
5555
meta.epoch_ms,
@@ -112,6 +112,7 @@ where
112112
ob: tuple_list!(code_observer),
113113
attacker,
114114
oracles: super::sui_fuzz::oracles(false, false, false),
115+
packages_cache: PackageResolvedCache::default(),
115116
epoch: state.fuzz_state().epoch,
116117
epoch_ms: state.fuzz_state().epoch_ms,
117118
ph: std::marker::PhantomData,

0 commit comments

Comments
 (0)