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

Remove constructors for account precondition #14117

Merged
merged 13 commits into from
Sep 21, 2023

Conversation

psteckler
Copy link
Member

@psteckler psteckler commented Sep 13, 2023

Remove the Full, Nonce, and Accept constructors for account preconditions. The type Account_update.Account_precondition.t is now the same as Zkapp_precondition.Account.t..

Add Zkapp_precondition.Account.nonce function, which takes a nonce, and creates a precondition that's the same as the accept precondition, with the nonce field set to Check with the same lower and upper bound. The is_nonce predicate returns true if the precondition has that form.

In the archive db, remove the zkapp_precondition_type and zkapp_account_precondition_values tables. The precondition is now saved directly to the zkapp_account_precondition table, eliminating a level of indirection.

The change at ~2024 in Transaction_pool is a bit subtle. The reviewer may wish to scrutinize that change closely (I've convinced myself of its correctness, for whatever that's worth).

Of note: the troublesome verification key integration test passes.

The version linter failure is expected and benign.

Closes #14114

@psteckler psteckler requested review from a team as code owners September 13, 2023 23:52
@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

let nonce : _ Numeric.t = Check { lower = n; upper = n } in
{ accept with nonce }

let is_nonce (t : t) =
Copy link
Member

Choose a reason for hiding this comment

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

This helper function seems misleading, and in the context where it is used (account_update.ml:1449), the logic is no longer the same. In order to check if a precondition is equivalent to the old Nonce precondition helper, you need to check that all other preconditions are set to Ignore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's what is_accept { t with nonce = Ignore } is doing, yes?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you are correct; that wasn't obvious to me when I read the code. Maybe this deserves a very brief comment?

Mina_numbers.Account_nonce.of_uint32 nonce
| Full _ | Accept ->
failwith "Expected a nonce for fee payer account precondition"
if Zkapp_precondition.Account.is_nonce preconditions.account then
Copy link
Member

Choose a reason for hiding this comment

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

This is logic is not equivalent to what it was before (see other comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

It is equivalent, as far as I see.

Copy link
Member

Choose a reason for hiding this comment

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

I think the difference is that, previously Nonce constructor made sure other fields were Ignore but now, the precondition could have Check for other fields and Ignore for the nonce field in which case it is not equivalent. The function should behave more like, is_nonce_only (that was implicit before)

Copy link
Member

Choose a reason for hiding this comment

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

My bad, as I look at the way is_nonce function is implemented, the logic is equivalent. @nholland94 could elaborate on what your expectation is here?

}
| Accept ->
Zkapp_precondition.Account.accept
let (_ :
Copy link
Member

Choose a reason for hiding this comment

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

Rather than having this explicit type equality check here, why not just specify the above type to just be Mina_wire_types.Mina_base.Account_update.Account_precondition.V1.t? The type checker will ensure that this type unifies with Zkapp_precondition.Account.Stable.V2.t if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's useful know that this type is the same as the other two types, not for the type checker, but for humans.

It might make sense to swap them between the type definition and the equality assertion.

(* we used to have 3 constructors, Full, Nonce, and Accept for the type t
nowadays, the generator creates these 3 different kinds of values, but all mapped to t
*)
let open Zkapp_basic in
Quickcheck.Generator.variant3 Zkapp_precondition.Account.gen
Account.Nonce.gen Unit.quickcheck_generator
|> Quickcheck.Generator.map ~f:(function
Copy link
Member

Choose a reason for hiding this comment

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

Why does this quickcheck generator still need to explicitly generate one of these 3 variants? It seems to make more sense to just quickcheck generate each precondition field separately. The set of generated values will still contain the nonce and accept cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't need to, the goal was to generate the nonce and accept cases with the same frequency as before. If we generate the components independently, those cases will be much rarer.

@psteckler
Copy link
Member Author

!ci-build-me

@georgeee
Copy link
Member

!ci-build-me

@georgeee
Copy link
Member

!ci-build-me

@psteckler
Copy link
Member Author

!ci-build-me

@deepthiskumar
Copy link
Member

!approved-for-mainnet

@deepthiskumar
Copy link
Member

!ci-nightly-me

@deepthiskumar
Copy link
Member

@deepthiskumar
Copy link
Member

All the zkapp integration tests have passed

@deepthiskumar deepthiskumar merged commit e13331e into berkeley Sep 21, 2023
34 of 36 checks passed
@deepthiskumar deepthiskumar deleted the feature/rm-acct-precondition-ctors branch September 21, 2023 20:51
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.

None yet

5 participants