Skip to content

Commit

Permalink
Fix manifest file path + better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed Apr 18, 2024
1 parent d5f7389 commit f021c1b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 4 additions & 2 deletions host/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ pub async fn execute<D: Prover>(
let res = D::run(input.clone(), output, config)
.await
.map(|proof| (input, proof))
.map_err(|e| HostError::GuestError(e.to_string()));
.map_err(|e| HostError::GuestError(e.to_string()))?;

measurement.stop_with("=> Proof generated");
memory::print_stats("Prover peak memory used: ");

total_proving_time.stop_with("====> Complete proof generated");
res

Ok(res)
}
Err(e) => {
warn!("Proving bad block construction!");
Expand Down
1 change: 1 addition & 0 deletions host/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl Handler {
.await;
let payload = match result {
Err(err) => {
println!("Error: {}", err.to_string());
serde_json::to_vec(&JsonRpcResponseError {
jsonrpc: "2.0".to_string(),
id: json_req.id,
Expand Down
35 changes: 24 additions & 11 deletions provers/sgx/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ impl Prover for SgxProver {
.get_or_init(|| async { cur_dir.join("secrets").join("priv.key") })
.await;
GRAMINE_MANIFEST_TEMPLATE
.get_or_init(|| async { cur_dir.join(CONFIG).join("sgx-guest.manifest.template") })
.get_or_init(|| async {
cur_dir
.join(CONFIG)
.join("sgx-guest.local.manifest.template")
})
.await;

// The gramine command (gramine or gramine-direct for testing in non-SGX environment)
Expand Down Expand Up @@ -168,28 +172,31 @@ async fn setup(cur_dir: &PathBuf, direct_mode: bool) -> ProverResult<(), String>
.output()
.await
.map_err(|e| handle_gramine_error("Could not generate manfifest", e))?;

print_output(&output, "Generate manifest");
handle_output(&output, "SGX generate manifest")?;

if !direct_mode {
// Generate a private key
let mut cmd = Command::new("gramine-sgx-gen-private-key");
cmd.current_dir(cur_dir.clone())
let output = cmd
.current_dir(cur_dir.clone())
.arg("-f")
.output()
.await
.map_err(|e| handle_gramine_error("Could not generate SGX private key", e))?;
handle_output(&output, "SGX private key")?;

// Sign the manifest
let mut cmd = Command::new("gramine-sgx-sign");
cmd.current_dir(cur_dir.clone())
let output = cmd
.current_dir(cur_dir.clone())
.arg("--manifest")
.arg("sgx-guest.manifest")
.arg("--output")
.arg("sgx-guest.manifest.sgx")
.output()
.await
.map_err(|e| handle_gramine_error("Could not sign manfifest", e))?;
handle_output(&output, "SGX manifest sign")?;
}

Ok(())
Expand All @@ -209,7 +216,7 @@ async fn bootstrap(dir: PathBuf, mut gramine_cmd: StdCommand) -> ProverResult<()
.arg("bootstrap")
.output()
.map_err(|e| handle_gramine_error("Could not run SGX guest bootstrap", e))?;
print_output(&output, "SGX bootstrap");
handle_output(&output, "SGX bootstrap")?;

Ok(())
})
Expand Down Expand Up @@ -238,10 +245,7 @@ async fn prove(
let output = child
.wait_with_output()
.map_err(|e| handle_gramine_error("Could not run SGX guest prover", e))?;
print_output(&output, "Sgx execution");
if !output.status.success() {
return ProverResult::Err(ProverError::GuestError(output.status.to_string()));
}
handle_output(&output, "SGX prove")?;
Ok(parse_sgx_result(output.stdout)?)
})
.await
Expand Down Expand Up @@ -283,7 +287,7 @@ fn handle_gramine_error(context: &str, err: std::io::Error) -> String {
}
}

fn print_output(output: &Output, name: &str) {
fn handle_output(output: &Output, name: &str) -> ProverResult<(), String> {
println!(
"{} stderr: {}",
name,
Expand All @@ -294,4 +298,13 @@ fn print_output(output: &Output, name: &str) {
name,
str::from_utf8(&output.stdout).unwrap()
);
if !output.status.success() {
return Err(format!(
"{} encountered an error {}: {}",
name,
output.status.to_string(),
String::from_utf8_lossy(&output.stderr),
));
}
Ok(())
}

0 comments on commit f021c1b

Please sign in to comment.