diff --git a/crates/uplc/src/parser.rs b/crates/uplc/src/parser.rs index d98a4d9c..79451837 100644 --- a/crates/uplc/src/parser.rs +++ b/crates/uplc/src/parser.rs @@ -203,16 +203,24 @@ peg::parser! { = b:$("True" / "False") { b == "True" } rule bytestring() -> Vec - = "#" i:ident()* { hex::decode(String::from_iter(i)).unwrap() } + = "#" i:ident()* {? + hex::decode(String::from_iter(i)).map_err(|_| "Invalid bytestring") + } rule bls_element() -> Vec - = "0x" i:ident()* { hex::decode(String::from_iter(i)).unwrap() } + = "0x" i:ident()* {? + hex::decode(String::from_iter(i)).map_err(|_| "Invalid bls element hex") + } rule g1_element() -> blst::blst_p1 - = element:bls_element() { blst::blst_p1::uncompress(&element).unwrap() } + = element:bls_element() {? + blst::blst_p1::uncompress(&element).map_err(|_| "Invalid bls g1 element encoding") + } rule g2_element() -> blst::blst_p2 - = element:bls_element() { blst::blst_p2::uncompress(&element).unwrap() } + = element:bls_element() {? + blst::blst_p2::uncompress(&element).map_err(|_| "Invalid bls g2 element encoding") + } rule string() -> String = "\"" s:character()* "\"" { String::from_iter(s) } diff --git a/crates/uplc/tests/conformance.rs b/crates/uplc/tests/conformance.rs index 8107a82e..fb2e1a8f 100644 --- a/crates/uplc/tests/conformance.rs +++ b/crates/uplc/tests/conformance.rs @@ -16,8 +16,10 @@ const EVALUATION_FAILURE: &str = "evaluation failure"; fn expected_to_program(expected_file: &PathBuf) -> Result, String> { let code = fs::read_to_string(expected_file).expect("Failed to read .uplc.expected file"); - if code == PARSE_ERROR || code == EVALUATION_FAILURE { - Err(code) + if code.contains(PARSE_ERROR) { + Err(PARSE_ERROR.to_string()) + } else if code.contains(EVALUATION_FAILURE) { + Err(EVALUATION_FAILURE.to_string()) } else { parser::program(&code).map_err(|_| code) }