Skip to content

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

Merged
merged 5 commits into from
Apr 29, 2025

Conversation

glyh
Copy link
Member

@glyh glyh commented Apr 29, 2025

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 :)

@glyh glyh requested a review from a team as a code owner April 29, 2025 07:10
@glyh glyh force-pushed the corvo/fix-parse-old-pcb branch from 85a30ca to 8ee95f2 Compare April 29, 2025 07:11
@glyh glyh changed the title Parse Precomputed blocks correctly by allowing Field.t to be deserialized from decimals Parse Old Precomputed blocks correctly by allowing Field.t to be deserialized from decimals Apr 29, 2025
@glyh glyh requested review from svv232, cjjdespres and amc-ie April 29, 2025 07:13
@SanabriaRusso
Copy link
Member

!ci-build-me

@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

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

@glyh glyh changed the title Parse Old Precomputed blocks correctly by allowing Field.t to be deserialized from decimals Parse old precomputed blocks correctly by allowing Field.t to be deserialized from decimals Apr 29, 2025
@dkijania
Copy link
Member

@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 :)

Copy link
Member

@svv232 svv232 left a 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.

@glyh glyh requested a review from a team as a code owner April 29, 2025 10:26
@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

!ci-build-me

1 similar comment
@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

!ci-build-me

@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

wat

image

@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

!ci-build-me

1 similar comment
@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

!ci-build-me

@glyh
Copy link
Member Author

glyh commented Apr 29, 2025

!ci-build-me

| _ ->
Error "expected hex string"
Error "expected a hex string or a decimal string(for old PCBs)"
Copy link
Member

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

Copy link
Member

@cjjdespres cjjdespres left a 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.

@dannywillems
Copy link
Member

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 *)
Copy link
Member

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.

Copy link
Member

@dannywillems dannywillems left a 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

@dannywillems
Copy link
Member

I opened #17103

Copy link
Member

@dannywillems dannywillems left a 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.

@dannywillems dannywillems merged commit eb52fa6 into compatible Apr 29, 2025
50 checks passed
@dannywillems dannywillems deleted the corvo/fix-parse-old-pcb branch April 29, 2025 15:14
@robinbb
Copy link

robinbb commented Apr 29, 2025

Thanks for the credit, and for the PR, @glyh .

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.

7 participants