Skip to content

Commit 3350797

Browse files
committed
implement zkapp permission fallback for access
1 parent 175b391 commit 3350797

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

src/lib/mina_base/permissions.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ module Auth_required = struct
7272
| t ->
7373
t
7474

75+
let access_perm_fallback_to_signature_with_older_version = function
76+
| Proof ->
77+
Signature
78+
| t ->
79+
t
80+
7581
(* permissions such that [check permission (Proof _)] is true *)
7682
let gen_for_proof_authorization : t Quickcheck.Generator.t =
7783
Quickcheck.Generator.of_list [ None; Either; Proof ]
@@ -294,11 +300,21 @@ module Auth_required = struct
294300
that the proof should verify. *)
295301
(result, `proof_must_verify (didn't_fail_yet &&& not signature_sufficient))
296302

303+
(* proof/either/impossible -> signature *)
297304
let verification_key_perm_fallback_to_signature_with_older_version
298305
({ signature_sufficient; _ } as t : t) =
299306
if_
300307
Pickles.Impls.Step.Boolean.(not signature_sufficient)
301308
~then_:(constant Signature) ~else_:t
309+
310+
(* proof/either -> signature *)
311+
let access_perm_fallback_to_signature_with_older_version
312+
({ signature_sufficient; constant = signature_is_constant; _ } as t : t)
313+
=
314+
if_
315+
Pickles.Impls.Step.Boolean.(
316+
(not signature_sufficient) && not signature_is_constant)
317+
~then_:(constant Signature) ~else_:t
302318
end
303319

304320
let typ =

src/lib/mina_base/permissions.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ module Auth_required : sig
2727

2828
val verification_key_perm_fallback_to_signature_with_older_version : t -> t
2929

30+
val access_perm_fallback_to_signature_with_older_version : t -> t
31+
3032
module Checked : sig
3133
type t
3234

@@ -44,6 +46,8 @@ module Auth_required : sig
4446
-> Boolean.var * [ `proof_must_verify of Boolean.var ]
4547

4648
val verification_key_perm_fallback_to_signature_with_older_version : t -> t
49+
50+
val access_perm_fallback_to_signature_with_older_version : t -> t
4751
end
4852

4953
val typ : (Checked.t, t) Typ.t

src/lib/transaction_logic/mina_transaction_logic.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,10 @@ module Make (L : Ledger_intf.S) :
10061006
let verification_key_perm_fallback_to_signature_with_older_version =
10071007
Permissions.Auth_required
10081008
.verification_key_perm_fallback_to_signature_with_older_version
1009+
1010+
let access_perm_fallback_to_signature_with_older_version =
1011+
Permissions.Auth_required
1012+
.access_perm_fallback_to_signature_with_older_version
10091013
end
10101014

10111015
module Txn_version = struct

src/lib/transaction_logic/zkapp_command_logic.ml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,8 @@ module type Controller_intf = sig
550550
val check : proof_verifies:bool -> signature_verifies:bool -> t -> bool
551551

552552
val verification_key_perm_fallback_to_signature_with_older_version : t -> t
553+
554+
val access_perm_fallback_to_signature_with_older_version : t -> t
553555
end
554556

555557
module type Txn_version_intf = sig
@@ -1546,11 +1548,19 @@ module Make (Inputs : Inputs_intf) = struct
15461548
This must be done before updating zkApp fields!
15471549
*)
15481550
let a = Account.make_zkapp a in
1551+
let auth_with_fallback ~fallback_logic auth =
1552+
Account.Permissions.set_verification_key_txn_version a
1553+
|> Txn_version.older_than_current
1554+
|> Controller.if_ ~then_:(fallback_logic auth) ~else_:auth
1555+
in
15491556
(* Check that the account can be accessed with the given authorization. *)
15501557
let local_state =
15511558
let has_permission =
1552-
Controller.check ~proof_verifies ~signature_verifies
1553-
(Account.Permissions.access a)
1559+
Account.Permissions.access a
1560+
|> auth_with_fallback
1561+
~fallback_logic:
1562+
Controller.access_perm_fallback_to_signature_with_older_version
1563+
|> Controller.check ~proof_verifies ~signature_verifies
15541564
in
15551565
Local_state.add_check local_state Update_not_permitted_access
15561566
has_permission
@@ -1614,21 +1624,13 @@ module Make (Inputs : Inputs_intf) = struct
16141624
let verification_key =
16151625
Account_update.Update.verification_key account_update
16161626
in
1617-
let older_than_current_version =
1618-
Txn_version.older_than_current
1619-
(Account.Permissions.set_verification_key_txn_version a)
1620-
in
1621-
let original_auth = Account.Permissions.set_verification_key_auth a in
1622-
let auth =
1623-
Controller.if_ older_than_current_version
1624-
~then_:
1625-
(Controller
1626-
.verification_key_perm_fallback_to_signature_with_older_version
1627-
original_auth )
1628-
~else_:original_auth
1629-
in
16301627
let has_permission =
1631-
Controller.check ~proof_verifies ~signature_verifies auth
1628+
Account.Permissions.set_verification_key_auth a
1629+
|> auth_with_fallback
1630+
~fallback_logic:
1631+
Controller
1632+
.verification_key_perm_fallback_to_signature_with_older_version
1633+
|> Controller.check ~proof_verifies ~signature_verifies
16321634
in
16331635
let local_state =
16341636
Local_state.add_check local_state Update_not_permitted_verification_key

src/lib/transaction_snark/transaction_snark.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,10 @@ module Make_str (A : Wire_types.Concrete) = struct
14731473
let verification_key_perm_fallback_to_signature_with_older_version =
14741474
Permissions.Auth_required.Checked
14751475
.verification_key_perm_fallback_to_signature_with_older_version
1476+
1477+
let access_perm_fallback_to_signature_with_older_version =
1478+
Permissions.Auth_required.Checked
1479+
.access_perm_fallback_to_signature_with_older_version
14761480
end
14771481

14781482
module Txn_version = struct

0 commit comments

Comments
 (0)