Skip to content

Commit cab5c82

Browse files
committed
zkapp account update: auto bump txn version to current on setting verification key
1 parent 08eb022 commit cab5c82

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/lib/transaction_logic/mina_transaction_logic.ml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,6 @@ module Make (L : Ledger_intf.S) :
11361136
let set_verification_key_auth : t -> Controller.t =
11371137
fun a -> fst a.permissions.set_verification_key
11381138

1139-
let set_verification_key_txn_version : t -> Txn_version.t =
1140-
fun a -> snd a.permissions.set_verification_key
1141-
11421139
let set_zkapp_uri : t -> Controller.t =
11431140
fun a -> a.permissions.set_zkapp_uri
11441141

@@ -1288,9 +1285,23 @@ module Make (L : Ledger_intf.S) :
12881285

12891286
let set_voting_for voting_for (a : t) = { a with voting_for }
12901287

1288+
type txn_version = Txn_version.t
1289+
1290+
let txn_version (a : t) : txn_version =
1291+
snd a.permissions.set_verification_key
1292+
12911293
let permissions (a : t) = a.permissions
12921294

1293-
let set_permissions permissions (a : t) = { a with permissions }
1295+
let set_permissions permissions (a : t) =
1296+
{ a with permissions }
1297+
1298+
let set_txn_version_to_current (a : t) =
1299+
let set_verification_key =
1300+
( fst a.permissions.set_verification_key
1301+
, Mina_numbers.Txn_version.current )
1302+
in
1303+
let permissions = { a.permissions with set_verification_key } in
1304+
{ a with permissions }
12941305
end
12951306

12961307
module Amount = struct

src/lib/transaction_logic/zkapp_command_logic.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,6 @@ module type Account_intf = sig
574574
module Permissions : sig
575575
type controller
576576

577-
type txn_version
578-
579577
val access : t -> controller
580578

581579
val edit_state : t -> controller
@@ -590,8 +588,6 @@ module type Account_intf = sig
590588

591589
val set_verification_key_auth : t -> controller
592590

593-
val set_verification_key_txn_version : t -> txn_version
594-
595591
val set_zkapp_uri : t -> controller
596592

597593
val edit_action_state : t -> controller
@@ -711,6 +707,12 @@ module type Account_intf = sig
711707
val permissions : t -> Permissions.t
712708

713709
val set_permissions : Permissions.t -> t -> t
710+
711+
type txn_version
712+
713+
val txn_version : t -> txn_version
714+
715+
val set_txn_version_to_current : t -> t
714716
end
715717

716718
module Eff = struct
@@ -825,7 +827,6 @@ module type Inputs_intf = sig
825827
and Account :
826828
(Account_intf
827829
with type Permissions.controller := Controller.t
828-
and type Permissions.txn_version := Txn_version.t
829830
and type timing := Timing.t
830831
and type balance := Balance.t
831832
and type receipt_chain_hash := Receipt_chain_hash.t
@@ -840,7 +841,8 @@ module type Inputs_intf = sig
840841
and type nonce := Nonce.t
841842
and type state_hash := State_hash.t
842843
and type token_id := Token_id.t
843-
and type account_id := Account_id.t)
844+
and type account_id := Account_id.t
845+
and type txn_version = Txn_version.t)
844846

845847
and Actions :
846848
(Actions_intf with type bool := Bool.t and type field := Field.t)
@@ -1549,8 +1551,7 @@ module Make (Inputs : Inputs_intf) = struct
15491551
*)
15501552
let a = Account.make_zkapp a in
15511553
let auth_with_fallback ~fallback_logic auth =
1552-
Account.Permissions.set_verification_key_txn_version a
1553-
|> Txn_version.older_than_current
1554+
Account.txn_version a |> Txn_version.older_than_current
15541555
|> Controller.if_ ~then_:(fallback_logic auth) ~else_:auth
15551556
in
15561557
(* Check that the account can be accessed with the given authorization. *)
@@ -1641,6 +1642,7 @@ module Make (Inputs : Inputs_intf) = struct
16411642
(Account.verification_key a)
16421643
in
16431644
let a = Account.set_verification_key verification_key a in
1645+
let a = Account.set_txn_version_to_current a in
16441646
(a, local_state)
16451647
in
16461648
(* Update action state. *)

src/lib/transaction_snark/transaction_snark.ml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,6 @@ module Make_str (A : Wire_types.Concrete) = struct
891891
module Permissions = struct
892892
type controller = Permissions.Auth_required.Checked.t
893893

894-
type txn_version = Mina_numbers.Txn_version.Checked.t
895-
896894
let edit_state : t -> controller =
897895
fun a -> a.data.permissions.edit_state
898896

@@ -911,9 +909,6 @@ module Make_str (A : Wire_types.Concrete) = struct
911909
let set_verification_key_auth : t -> controller =
912910
fun a -> fst a.data.permissions.set_verification_key
913911

914-
let set_verification_key_txn_version : t -> txn_version =
915-
fun a -> snd a.data.permissions.set_verification_key
916-
917912
let set_zkapp_uri : t -> controller =
918913
fun a -> a.data.permissions.set_zkapp_uri
919914

@@ -1064,10 +1059,25 @@ module Make_str (A : Wire_types.Concrete) = struct
10641059
let set_voting_for voting_for ({ data = a; hash } : t) : t =
10651060
{ data = { a with voting_for }; hash }
10661061

1062+
type txn_version = Mina_numbers.Txn_version.Checked.t
1063+
1064+
let txn_version ({ data = a; _ } : t) =
1065+
snd a.permissions.set_verification_key
1066+
10671067
let permissions (a : t) = a.data.permissions
10681068

1069-
let set_permissions permissions ({ data = a; hash } : t) : t =
1069+
let set_permissions (permissions : Permissions.t)
1070+
({ data = a; hash } : t) : t =
10701071
{ data = { a with permissions }; hash }
1072+
1073+
let set_txn_version_to_current ({ data = a; hash } : t) : t =
1074+
let set_verification_key =
1075+
( fst a.permissions.set_verification_key
1076+
, Mina_numbers.Txn_version.current_checked )
1077+
in
1078+
let permissions = { a.permissions with set_verification_key } in
1079+
let data = { a with permissions } in
1080+
{ data; hash }
10711081
end
10721082

10731083
module Opt = struct

0 commit comments

Comments
 (0)