-
Notifications
You must be signed in to change notification settings - Fork 585
Parse old precomputed blocks correctly by allowing Field.t
to be deserialized from decimals
#17099
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
Conversation
85a30ca
to
8ee95f2
Compare
Field.t
to be deserialized from decimalsField.t
to be deserialized from decimals
!ci-build-me |
This is untested, though. We should put some old blocks in our unit tests, suggested by @cjjdespres But I think it would be even better if we just randomly sample some blocks from our archives and run the unit tests, which requires us to change the structure of our CI. WDYT? @SanabriaRusso @dkijania |
Field.t
to be deserialized from decimalsField.t
to be deserialized from decimals
…ements correspondingly
@glyh I'm always a fan of limited setup for every test. If this unit test requires old precomp block format, we should have dedicated test only for that case. IMHO it would be perfect if we can generate random precomputed block with old format. Such test will not only test the "Crème de la crème" but will have a good readability as it won't mislead us in the future into scratching out heads around why "real" and historic precomputed block is required for this. I think also that such test should be a part of this PR (or in PR train). If you need any assistance I'm yours to help :) |
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.
approved too soon, we want to test dynamically.
…ecimals to represent field elements
!ci-build-me |
1 similar comment
!ci-build-me |
!ci-build-me |
1 similar comment
!ci-build-me |
!ci-build-me |
| _ -> | ||
Error "expected hex string" | ||
Error "expected a hex string or a decimal string(for old PCBs)" |
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.
Small nitpick (feel free to change in separate PR if this would delay things too much) - these field elements can appear in more than just precomputed blocks, so the error might not want to mention PCBs in particular
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.
These changes should fix the precomputed block parsing issue introduced in #15964. I think it might go slightly further, because it was a custom of_yojson
just for Account_update.Authorization_kind.Proof
that was replaced in that PR:
| Proof of
(Field.t
[@version_asserted]
[@to_yojson fun t -> `String (Snark_params.Tick.Field.to_string t)]
[@of_yojson
function
| `String s ->
let field = Snark_params.Tick.Field.of_string s in
let s' = Snark_params.Tick.Field.to_string field in
if String.equal s s' then Ok field
else Error "Invalid JSON for field"
| _ ->
Error "expected JSON string"] )
That's just an observation - having the field element parser accept both decimal and hex is fine, and is a clean way of fixing the problem.
Though, I don't know why the original code round-trips the string and compares it to the one it was parsing. That seems unnecessary to me, unless that was a workaround for some quirk in that of_string
function.
Checking for crypto |
let parsed_bigint = | ||
if String.is_prefix ~prefix:"0x" s then Bigint.of_hex_string s | ||
else | ||
(* NOTE: we're dealing with a older precomputed block *) |
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.
Not sure it is relevant for future devs to mention "with an older precomputed block". Out of the context, it does not mean anything.
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.
Refusing the changes as it does allow values larger than the modulus. It does not also enforce the format given as inputs as in 127ea64
I opened #17103 |
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.
Approving for crypto. I would add a follow-up issue regarding the tests for the modulus. It seems to be out-of-scope of this fix, as the code is calling of_bigint
as before.
Thanks for the credit, and for the PR, @glyh . |
This is a revivial of #16922
This is encountered by JRWashburn on Discord. Context thread here.
Thank you @robinbb, sorry for us not being able to review your PR earlier :)