From 0a61ec37fbe2fa8dfdfbf7b86d898f32484d6e4e Mon Sep 17 00:00:00 2001 From: y Date: Sun, 17 Sep 2023 12:47:58 -0400 Subject: [PATCH] zkas: fix panic occurring in nested function calls This issue was discovered by fuzzing. Change the `unimplemented()!` panic macro to error handling that informs the user that using Literals and Functions in nested function calls is not yet supported. This should be a slightly more friendly developer experience. Changing this from a panic to an error allows us to continue with further fuzzing. --- src/zkas/analyzer.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/zkas/analyzer.rs b/src/zkas/analyzer.rs index 973fbe64a..c50c52d2c 100644 --- a/src/zkas/analyzer.rs +++ b/src/zkas/analyzer.rs @@ -186,6 +186,8 @@ impl Analyzer { let mut rhs_inner = vec![]; for (inner_idx, i) in func.rhs.iter().enumerate() { + // TODO: Implement cases where `i` is type Arg::Literal + // TODO: Implement cases where `i` is type Arg::Func if let Arg::Var(v) = i { if let Some(var_ref) = self.lookup_var(&v.name) { let (var_type, ln, col) = match var_ref { @@ -218,8 +220,20 @@ impl Analyzer { v.line, v.column, )) + } else if let Arg::Lit(l) = i { + return Err(self.error.abort( + &format!("Expected argument `{}` to be of type Variable. Literals are not yet supported in nested function calls.", l.name), + l.line, + l.column, + )) + } else if let Arg::Func(f) = i { + return Err(self.error.abort( + &format!("Expected argument `{}` to be of type Variable. Nested function calls are not yet supported beyond a depth of 1.", Opcode::name(&f.opcode)), + f.line, + 0, + )) } else { - unimplemented!() + unreachable!(); } }