-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa016ae
commit 2d0a5e4
Showing
11 changed files
with
163 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,94 @@ | ||
use acvm::acir::circuit::opcodes::Opcode; | ||
use acvm::Language; | ||
use serde::Deserialize; | ||
use std::collections::HashSet; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::BackendError; | ||
|
||
pub(crate) struct InfoCommand { | ||
pub(crate) crs_path: PathBuf, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct InfoResponse { | ||
language: LanguageResponse, | ||
opcodes_supported: Vec<String>, | ||
black_box_functions_supported: Vec<String>, | ||
} | ||
|
||
#[derive(Deserialize)] | ||
struct LanguageResponse { | ||
name: String, | ||
width: Option<usize>, | ||
} | ||
|
||
impl InfoCommand { | ||
pub(crate) fn run( | ||
self, | ||
binary_path: &Path, | ||
) -> Result<(Language, Box<impl Fn(&Opcode) -> bool>), BackendError> { | ||
let mut command = std::process::Command::new(binary_path); | ||
|
||
command.arg("info").arg("-c").arg(self.crs_path).arg("-o").arg("-"); | ||
|
||
let output = command.output().expect("Failed to execute command"); | ||
|
||
if !output.status.success() { | ||
return Err(BackendError(String::from_utf8(output.stderr).unwrap())); | ||
} | ||
|
||
let backend_info: InfoResponse = | ||
serde_json::from_slice(&output.stdout).expect("Backend should return valid json"); | ||
let language: Language = match backend_info.language.name.as_str() { | ||
"PLONK-CSAT" => { | ||
let width = backend_info.language.width.unwrap(); | ||
Language::PLONKCSat { width } | ||
} | ||
"R1CS" => Language::R1CS, | ||
_ => panic!("Unknown langauge"), | ||
}; | ||
|
||
let opcodes_set: HashSet<String> = backend_info.opcodes_supported.into_iter().collect(); | ||
let black_box_functions_set: HashSet<String> = | ||
backend_info.black_box_functions_supported.into_iter().collect(); | ||
|
||
let is_opcode_supported = move |opcode: &Opcode| -> bool { | ||
match opcode { | ||
Opcode::Arithmetic(_) => opcodes_set.contains("arithmetic"), | ||
Opcode::Directive(_) => opcodes_set.contains("directive"), | ||
Opcode::Brillig(_) => opcodes_set.contains("brillig"), | ||
Opcode::MemoryInit { .. } => opcodes_set.contains("memory_init"), | ||
Opcode::MemoryOp { .. } => opcodes_set.contains("memory_op"), | ||
Opcode::BlackBoxFuncCall(func) => { | ||
black_box_functions_set.contains(func.get_black_box_func().name()) | ||
} | ||
} | ||
}; | ||
|
||
Ok((language, Box::new(is_opcode_supported))) | ||
} | ||
} | ||
|
||
#[test] | ||
#[serial_test::serial] | ||
fn info_command() { | ||
use acvm::acir::circuit::black_box_functions::BlackBoxFunc; | ||
use acvm::acir::circuit::opcodes::{BlackBoxFuncCall, Opcode}; | ||
|
||
use acvm::acir::native_types::Expression; | ||
|
||
let backend = crate::get_mock_backend(); | ||
let crs_path = backend.backend_directory(); | ||
|
||
let (language, is_opcode_supported) = | ||
InfoCommand { crs_path }.run(&backend.binary_path()).unwrap(); | ||
|
||
assert!(matches!(language, Language::PLONKCSat { width: 3 })); | ||
assert!(is_opcode_supported(&Opcode::Arithmetic(Expression::default()))); | ||
|
||
assert!(!is_opcode_supported(&Opcode::BlackBoxFuncCall( | ||
#[allow(deprecated)] | ||
BlackBoxFuncCall::dummy(BlackBoxFunc::Keccak256) | ||
))); | ||
} |
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
38 changes: 38 additions & 0 deletions
38
crates/acvm_backend_barretenberg/test-binaries/mock_backend/src/info_cmd.rs
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 clap::Args; | ||
use std::io::Write; | ||
use std::path::PathBuf; | ||
|
||
const INFO_RESPONSE: &str = r#"{ | ||
"language": { | ||
"name": "PLONK-CSAT", | ||
"width": 3 | ||
}, | ||
"opcodes_supported": ["arithmetic", "directive", "brillig", "memory_init", "memory_op"], | ||
"black_box_functions_supported": [ | ||
"and", | ||
"xor", | ||
"range", | ||
"sha256", | ||
"blake2s", | ||
"schnorr_verify", | ||
"pedersen", | ||
"hash_to_field_128_security", | ||
"ecdsa_secp256k1", | ||
"ecdsa_secp256r1", | ||
"fixed_base_scalar_mul", | ||
"recursive_aggregation" | ||
] | ||
}"#; | ||
|
||
#[derive(Debug, Clone, Args)] | ||
pub(crate) struct InfoCommand { | ||
#[clap(short = 'c')] | ||
pub(crate) crs_path: Option<PathBuf>, | ||
|
||
#[clap(short = 'o')] | ||
pub(crate) info_path: Option<PathBuf>, | ||
} | ||
|
||
pub(crate) fn run(_args: InfoCommand) { | ||
std::io::stdout().write_all(INFO_RESPONSE.as_bytes()).unwrap(); | ||
} |
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
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