Skip to content

Commit 1074217

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

File tree

3 files changed

+64
-21
lines changed

3 files changed

+64
-21
lines changed

src/lib/transaction_logic/mina_transaction_logic.ml

Lines changed: 22 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,30 @@ 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_ignore_vk_txn_version (permissions : Permissions.t)
1296+
(a : t) =
1297+
let vk_txn_version = txn_version a in
1298+
let set_verification_key =
1299+
(fst permissions.set_verification_key, vk_txn_version)
1300+
in
1301+
{ a with permissions = { a.permissions with set_verification_key } }
1302+
1303+
let set_txn_version_to_current (a : t) =
1304+
{ a with
1305+
permissions =
1306+
{ a.permissions with
1307+
set_verification_key =
1308+
( fst a.permissions.set_verification_key
1309+
, Mina_numbers.Txn_version.current )
1310+
}
1311+
}
12941312
end
12951313

12961314
module Amount = struct

src/lib/transaction_logic/zkapp_command_logic.ml

Lines changed: 12 additions & 10 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
@@ -710,7 +706,13 @@ module type Account_intf = sig
710706

711707
val permissions : t -> Permissions.t
712708

713-
val set_permissions : Permissions.t -> t -> t
709+
val set_permissions_ignore_vk_txn_version : 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. *)
@@ -1808,7 +1810,7 @@ module Make (Inputs : Inputs_intf) = struct
18081810
Set_or_keep.set_or_keep ~if_:Account.Permissions.if_ permissions
18091811
(Account.permissions a)
18101812
in
1811-
let a = Account.set_permissions permissions a in
1813+
let a = Account.set_permissions_ignore_vk_txn_version permissions a in
18121814
(a, local_state)
18131815
in
18141816
(* Initialize account's pk, in case it is new. *)

src/lib/transaction_snark/transaction_snark.ml

Lines changed: 30 additions & 7 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,38 @@ 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 =
1070-
{ data = { a with permissions }; hash }
1069+
let set_permissions_ignore_vk_txn_version
1070+
(permissions : Permissions.t) ({ data = a; hash } as t : t) : t =
1071+
let vk_txn_version = txn_version t in
1072+
let set_verification_key =
1073+
(fst permissions.set_verification_key, vk_txn_version)
1074+
in
1075+
{ data =
1076+
{ a with
1077+
permissions = { a.permissions with set_verification_key }
1078+
}
1079+
; hash
1080+
}
1081+
1082+
let set_txn_version_to_current ({ data = a; hash } : t) : t =
1083+
{ With_hash.data =
1084+
{ a with
1085+
permissions =
1086+
{ a.permissions with
1087+
set_verification_key =
1088+
( fst a.permissions.set_verification_key
1089+
, Mina_numbers.Txn_version.current_checked )
1090+
}
1091+
}
1092+
; hash
1093+
}
10711094
end
10721095

10731096
module Opt = struct

0 commit comments

Comments
 (0)