-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add backend interface definition to convert proof/vk to fields
- Loading branch information
1 parent
6163a0d
commit aad35f3
Showing
4 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use acvm::FieldElement; | ||
|
||
use crate::BackendError; | ||
|
||
use super::string_from_stderr; | ||
|
||
/// `ProofAsFieldsCommand` will call the barretenberg binary | ||
/// to split a proof into a representation as [`FieldElement`]s. | ||
pub(crate) struct ProofAsFieldsCommand { | ||
pub(crate) proof_path: PathBuf, | ||
pub(crate) vk_path: PathBuf, | ||
} | ||
|
||
impl ProofAsFieldsCommand { | ||
pub(crate) fn run(self, binary_path: &Path) -> Result<Vec<FieldElement>, BackendError> { | ||
let mut command = std::process::Command::new(binary_path); | ||
|
||
command | ||
.arg("proof_as_fields") | ||
.arg("-p") | ||
.arg(self.proof_path) | ||
.arg("-k") | ||
.arg(self.vk_path) | ||
.arg("-o") | ||
.arg("-"); | ||
|
||
let output = command.output()?; | ||
if output.status.success() { | ||
let string_output = String::from_utf8(output.stdout).unwrap(); | ||
serde_json::from_str(&string_output) | ||
.map_err(|err| BackendError::CommandFailed(err.to_string())) | ||
} else { | ||
Err(BackendError::CommandFailed(string_from_stderr(&output.stderr))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use acvm::FieldElement; | ||
|
||
use crate::BackendError; | ||
|
||
use super::string_from_stderr; | ||
|
||
/// VkAsFieldsCommand will call the barretenberg binary | ||
/// to split a verification key into a representation as [`FieldElement`]s. | ||
/// | ||
/// The hash of the verification key will also be returned. | ||
pub(crate) struct VkAsFieldsCommand { | ||
pub(crate) vk_path: PathBuf, | ||
} | ||
|
||
impl VkAsFieldsCommand { | ||
pub(crate) fn run( | ||
self, | ||
binary_path: &Path, | ||
) -> Result<(FieldElement, Vec<FieldElement>), BackendError> { | ||
let mut command = std::process::Command::new(binary_path); | ||
|
||
command.arg("vk_as_fields").arg("-k").arg(self.vk_path).arg("-o").arg("-"); | ||
|
||
let output = command.output()?; | ||
if output.status.success() { | ||
let string_output = String::from_utf8(output.stdout).unwrap(); | ||
let mut fields: Vec<FieldElement> = serde_json::from_str(&string_output) | ||
.map_err(|err| BackendError::CommandFailed(err.to_string()))?; | ||
|
||
// The first element of this vector is the hash of the verification key, we want to split that off. | ||
let hash = fields.remove(0); | ||
Ok((hash, fields)) | ||
} else { | ||
Err(BackendError::CommandFailed(string_from_stderr(&output.stderr))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters