Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding random values to IR #134

Merged
merged 5 commits into from
Feb 7, 2023
Merged

Adding random values to IR #134

merged 5 commits into from
Feb 7, 2023

Conversation

Fumuran
Copy link
Contributor

@Fumuran Fumuran commented Feb 2, 2023

Partly addressing #86.

  • Added support for random values in IR.
  • Added indexed access to random values by custom name.
  • Added integration test for random values.

@Fumuran Fumuran force-pushed the andrew-ir-random-values branch from 8d52e1c to 5cb4acc Compare February 2, 2023 21:35
Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you @Overcastan! I left several comments inline, but it's all small stuff

air-script/tests/aux_trace/aux_trace.air Outdated Show resolved Hide resolved
air-script/tests/random_values/random_values.air Outdated Show resolved Hide resolved
air-script/tests/main.rs Outdated Show resolved Hide resolved
air-script/tests/random_values/random_values_simple.air Outdated Show resolved Hide resolved
ir/src/symbol_table.rs Outdated Show resolved Hide resolved
ir/src/symbol_table.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tohrnii tohrnii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Overcastan, looks good to me. I just left a few small nits inline.

ir/src/constraints/graph.rs Show resolved Hide resolved
ir/src/symbol_table.rs Outdated Show resolved Hide resolved
@@ -20,6 +20,9 @@ pub(super) enum IdentifierType {
PeriodicColumn(usize, usize),
/// an identifier for an integrity variable, containing its name and value
IntegrityVariable(Variable),
/// an identifier for random value, containing its index in the random values array and its
/// length if this value is an array. For non-array random values second parameter is always 1.
RandomValue(usize, usize),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If this can represent an array, should this be called RandomValues instead?

Copy link
Contributor Author

@Fumuran Fumuran Feb 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we have a main array of random values (rand: [a, b, c, ... ]), so calling it RandomValues can be confusing, it will be unclear whether we mean the main array or its element, which is represented by an array. I agree with you that it would be better to rename it somehow, but I don't know yet which name would be better. Perhaps RandomValuesElement, but this name also does not reflect that this element can be an array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be RandomValuesBinding again, to be somewhat consistent with the AST?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about RandomValuesGroup?

ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
@Fumuran Fumuran force-pushed the andrew-ir-random-values branch from 873d374 to f4379f5 Compare February 3, 2023 15:56
@Fumuran Fumuran requested review from grjte and tohrnii February 3, 2023 15:58
Copy link
Contributor

@tohrnii tohrnii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Overcastan, looks good to me. I just left very minor things inline. One question is if we should handle #46 in this PR and the check that you suggested regarding returning an error if there are no aux trace columns but random values section is declared or if we should leave it for the next PR.

Comment on lines 382 to 501

let parsed = parse(source).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_ok());
}

#[test]
fn random_values_custom_name() {
let source = "
trace_columns:
main: [a, b[12]]
public_inputs:
stack_inputs: [16]
random_values:
alphas: [16]
integrity_constraints:
enf a' = $alphas[3] + 1
boundary_constraints:
enf a.first = $alphas[10] * 2
enf a.last = 1";

let parsed = parse(source).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_ok());
}

#[test]
fn random_values_ident_vector() {
let source = "
trace_columns:
main: [a, b[12]]
public_inputs:
stack_inputs: [16]
random_values:
rand: [c, d[4]]
integrity_constraints:
enf a' = c + d[2] + $rand[1]
boundary_constraints:
enf a.first = (d[1] - $rand[0]) * 2
enf a.last = c";

let parsed = parse(source).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_ok());
}

#[test]
fn error_random_values_out_of_bounds() {
let source_fixed_list = "
trace_columns:
main: [a, b[12]]
public_inputs:
stack_inputs: [16]
random_values:
rand: [4]
integrity_constraints:
enf a' = $rand[4] + 1
boundary_constraints:
enf a.first = $rand[10] * 2
enf a.last = 1";

let parsed = parse(source_fixed_list).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_err());

let source_ident_vector_sub_vec = "
trace_columns:
main: [a, b[12]]
public_inputs:
stack_inputs: [16]
random_values:
rand: [c, d[4]]
integrity_constraints:
enf a' = c + 1
boundary_constraints:
enf a.first = d[5] * 2
enf a.last = 1";

let parsed = parse(source_ident_vector_sub_vec).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_err());

let source_ident_vector_index = "
trace_columns:
main: [a, b[12]]
public_inputs:
stack_inputs: [16]
random_values:
rand: [c, d[4]]
integrity_constraints:
enf a' = c + 1
boundary_constraints:
enf a.first = $rand[10] * 2
enf a.last = 1";

let parsed = parse(source_ident_vector_index).expect("Parsing failed");
let result = AirIR::from_source(&parsed);
assert!(result.is_err());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change these so that random values are only used against auxiliary columns. We don't have a check for it yet but we should still have valid tests here for now. Also, do you think we should address #46 here as well or should we do that in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can do it in this PR, looks like it wouldn't involve a lot of changes. Just one question: should we also throw an error if random values are used against the main trace in integrity constraints?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I think we can have integrity constraints with random values and main trace column access but maybe it should be an error if there are random values but no auxiliary column access in a constraint? I'm not sure, maybe @grjte or @bobbinth could confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, something like this should be a warning - but since we don't have warnings, I'm not quite sure what's the best approach. Probably having it be an error is better - but if it creates a lot of extra work now, we can do it later too.

ir/src/symbol_table.rs Outdated Show resolved Hide resolved
@Fumuran
Copy link
Contributor Author

Fumuran commented Feb 6, 2023

I really don't like how I implemented additional checks, but my other ideas didn't work (it's too hard to implement them). Does anyone have suggestions how it can be done better?

@Fumuran Fumuran requested a review from tohrnii February 6, 2023 14:15
Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Overcastan! I left a few more comments inline. I think we can simplify and leave the validity checks for a future PR, since this one is good overall and I'd rather merge it sooner

ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/constraints/graph.rs Outdated Show resolved Hide resolved
ir/src/lib.rs Outdated Show resolved Hide resolved
ir/src/lib.rs Outdated Show resolved Hide resolved
ir/src/constraints/mod.rs Outdated Show resolved Hide resolved
ir/src/symbol_table.rs Outdated Show resolved Hide resolved
ir/src/symbol_table.rs Outdated Show resolved Hide resolved
ir/src/tests/mod.rs Outdated Show resolved Hide resolved
ir/src/tests/mod.rs Outdated Show resolved Hide resolved
@Fumuran Fumuran force-pushed the andrew-ir-random-values branch from 83cf6fe to a7eb8a3 Compare February 6, 2023 17:41
@Fumuran Fumuran requested review from grjte and bobbinth February 6, 2023 17:45
Copy link
Contributor

@tohrnii tohrnii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Overcastan, looks good to me. I just left a few very minor naming related nits but don't have strong opinion on those.

ir/src/symbol_table.rs Outdated Show resolved Hide resolved
@@ -379,6 +379,126 @@ fn transition_constraints_using_parens() {
assert!(result.is_ok());
}

#[test]
fn random_values_fixed_list() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should this be renamed to random_values_indexed_access or something like that?

}

#[test]
fn random_values_ident_vector() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should this be renamed to random_values_named_access or something similar?

Copy link
Contributor

@grjte grjte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @Overcastan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants