Skip to content

Commit

Permalink
Fix GarbleProgram::literal_arg for arrays with const size
Browse files Browse the repository at this point in the history
  • Loading branch information
fkettelhoit committed May 29, 2024
1 parent d8c210d commit 4560671
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'a> Evaluator<'a> {
}
}

fn resolve_const_type(ty: &Type, const_sizes: &HashMap<String, usize>) -> Type {
pub(crate) fn resolve_const_type(ty: &Type, const_sizes: &HashMap<String, usize>) -> Type {
match ty {
Type::Fn(params, ret_ty) => Type::Fn(
params
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use ast::{Expr, FnDef, Pattern, Program, Stmt, Type};
use check::TypeError;
use circuit::Circuit;
use compile::CompilerError;
use eval::{EvalError, Evaluator};
use eval::{resolve_const_type, EvalError, Evaluator};
use literal::Literal;
use parse::ParseError;
use scan::{scan, ScanError};
Expand Down Expand Up @@ -162,8 +162,9 @@ impl GarbleProgram {
let Some(param) = self.main.params.get(arg_index) else {
return Err(EvalError::InvalidArgIndex(arg_index));
};
if !literal.is_of_type(&self.program, &param.ty) {
return Err(EvalError::InvalidLiteralType(literal, param.ty.clone()));
let ty = resolve_const_type(&param.ty, &self.const_sizes);
if !literal.is_of_type(&self.program, &ty) {
return Err(EvalError::InvalidLiteralType(literal, ty));
}
Ok(GarbleArgument(literal, &self.program, &self.const_sizes))
}
Expand Down

0 comments on commit 4560671

Please sign in to comment.