Skip to content

Commit

Permalink
Oracle based
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacarte committed Aug 24, 2023
1 parent be78d16 commit 1e97c5d
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions host_based/stacking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ fn call_oracle(oracle: String, wasm_file: String) -> bool {
let command = oracle.split(" ").collect::<Vec<_>>();
/// The arguments are the rest of the command
let args = &command[1..];
eprintln!("Executing oracle {} {}", oracle, wasm_file);
/// We call a subprocess and check its exist code
let output = std::process::Command::new(&oracle)
let output = std::process::Command::new(&command[0])
.args(args)
.arg(wasm_file)
.stdin(std::process::Stdio::null())
Expand Down Expand Up @@ -510,10 +511,20 @@ fn main() -> Result<(), anyhow::Error> {
// TODO check if it was already serialized, avoid compiling again
let serialized = module.serialize().unwrap();
// Save it to disk, get the filename from the argument path
std::fs::write(format!("{}{}.cwasm", opts.output.to_str().unwrap(), hash), serialized).unwrap();
std::fs::write(format!("{}.{}.{}.chaos.cwasm", opts.output.to_str().unwrap(), hash2, hash), serialized).unwrap();

if let Some(oracle) = &opsclone.oracle {
if call_oracle(oracle.clone(), format!("{}{}.cwasm", opts.output.to_str().unwrap(), hash)) {
if call_oracle(oracle.clone(), format!("{}.{}.{}.chaos.cwasm", opts.output.to_str().unwrap(), hash2, hash)) {
// The oracle returned 1, we stop
let elapsed = now.elapsed();
eprintln!("Elapsed time until oracle: {}s", elapsed.as_millis());
eprintln!("Oracle returned 1, we stop");
std::process::exit(0);
}
}
} else {
if let Some(oracle) = &opsclone.oracle {
if call_oracle(oracle.clone(), format!("{}.{}.{}.chaos.wasm", opts.output.to_str().unwrap(), hash2, hash)) {
// The oracle returned 1, we stop
let elapsed = now.elapsed();
eprintln!("Elapsed time until oracle: {}s", elapsed.as_millis());
Expand Down Expand Up @@ -560,6 +571,16 @@ fn main() -> Result<(), anyhow::Error> {
std::process::exit(0);
}
}
}else {
if let Some(oracle) = &opsclone.oracle {
if call_oracle(oracle.clone(), format!("{}.{}.wasm", opts.output.to_str().unwrap(), index)) {
// The oracle returned 1, we stop
let elapsed = now.elapsed();
eprintln!("Elapsed time until oracle: {}s", elapsed.as_millis());
eprintln!("Oracle returned 1, we stop");
std::process::exit(0);
}
}
}

});
Expand Down Expand Up @@ -886,8 +907,11 @@ mod eval {
(Some((mem1, glob1, stdout1, stderr1, _mod1, instance1, time1)), Some((mem2, glob2, stdout2, stderr2, _mod2, instance2, time2)))
=> {

if stdout1 != stdout2 || stderr1 != stderr2 {
if (stdout1 != stdout2) || (stderr1 != stderr2) {
eprintln!("Std is not the same");
eprintln!("{:?}\n======\n{:?}", stdout1, stdout2);
eprintln!("Stderr is not the same");
eprintln!("{:?}\n======\n{:?}", stderr1, stderr2);
return None;
}
// Now we compare the stores
Expand Down

0 comments on commit 1e97c5d

Please sign in to comment.