mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-28 12:45:26 +03:00
Merge #641
641: Bug/564 input array len not enforced r=collinc97 a=gluax Resolves #564, depends on #563. The changes for this branch have pulled from PR #638, which is the PR that fixes #563. Co-authored-by: gluaxspeed <jonathan.t.pavlik@gmail.com>
This commit is contained in:
commit
fa53e75f51
@ -25,7 +25,7 @@ use pest::Span;
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum InputValue {
|
||||
Address(String),
|
||||
Boolean(bool),
|
||||
|
@ -93,6 +93,15 @@ impl FunctionError {
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn invalid_input_array_dimensions(expected: usize, actual: usize, span: Span) -> Self {
|
||||
let message = format!(
|
||||
"Input array dimensions mismatch expected {}, found array dimensions {}",
|
||||
expected, actual
|
||||
);
|
||||
|
||||
Self::new_from_span(message, span)
|
||||
}
|
||||
|
||||
pub fn invalid_tuple(actual: String, span: Span) -> Self {
|
||||
let message = format!("Expected function input tuple, found `{}`", actual);
|
||||
|
||||
|
@ -41,6 +41,14 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
|
||||
match input_value {
|
||||
Some(InputValue::Array(arr)) => {
|
||||
if array_len != arr.len() {
|
||||
return Err(FunctionError::invalid_input_array_dimensions(
|
||||
arr.len(),
|
||||
array_len,
|
||||
span.clone(),
|
||||
));
|
||||
}
|
||||
|
||||
// Allocate each value in the current row
|
||||
for (i, value) in arr.into_iter().enumerate() {
|
||||
let value_name = format!("{}_{}", &name, &i.to_string());
|
||||
|
@ -37,7 +37,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
let mut members = Vec::with_capacity(section.len());
|
||||
|
||||
// Allocate each section definition as a circuit member value
|
||||
|
||||
for (parameter, option) in section.into_iter() {
|
||||
let section_members = expected_type.members.borrow();
|
||||
let expected_type = match section_members.get(¶meter.variable.name) {
|
||||
|
@ -0,0 +1,2 @@
|
||||
[main]
|
||||
x: [i16; 1] = [0i16; 1];
|
@ -1,3 +1,4 @@
|
||||
function main (x: [i16; 2]) {
|
||||
function main (x: [i16; 1]) {
|
||||
console.log("{}", x);
|
||||
console.assert(x[0] == 0);
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
function main(x: [i16; 2]){
|
||||
console.log("x: {}", x);
|
||||
}
|
@ -83,3 +83,13 @@ fn test_input_multiple() {
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_array_dimensions_mismatch() {
|
||||
let program_string = include_str!("main_array_fail.leo");
|
||||
let input_string = include_str!("input/main_array_fail.in");
|
||||
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
expect_fail(program);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user