-
Notifications
You must be signed in to change notification settings - Fork 16
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
Conversation
8d52e1c
to
5cb4acc
Compare
There was a problem hiding this 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
There was a problem hiding this 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/symbol_table.rs
Outdated
@@ -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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about RandomValuesGroup
?
873d374
to
f4379f5
Compare
There was a problem hiding this 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.
ir/src/tests/mod.rs
Outdated
|
||
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()); | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
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? |
There was a problem hiding this 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
83cf6fe
to
a7eb8a3
Compare
There was a problem hiding this 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/tests/mod.rs
Outdated
@@ -379,6 +379,126 @@ fn transition_constraints_using_parens() { | |||
assert!(result.is_ok()); | |||
} | |||
|
|||
#[test] | |||
fn random_values_fixed_list() { |
There was a problem hiding this comment.
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?
ir/src/tests/mod.rs
Outdated
} | ||
|
||
#[test] | ||
fn random_values_ident_vector() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @Overcastan!
Partly addressing #86.