Skip to content

Commit fa05fcf

Browse files
committed
auto bump txn version to current on setting verification key
1 parent 3350797 commit fa05fcf

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

src/lib/transaction_logic/mina_transaction_logic.ml

Lines changed: 14 additions & 3 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

@@ -1291,6 +1288,20 @@ module Make (L : Ledger_intf.S) :
12911288
let permissions (a : t) = a.permissions
12921289

12931290
let set_permissions permissions (a : t) = { a with permissions }
1291+
1292+
type txn_version = Txn_version.t
1293+
1294+
let txn_version (a : t) : txn_version =
1295+
snd a.permissions.set_verification_key
1296+
1297+
let set_txn_version_to_latest (a : t) =
1298+
let vk, _ = a.permissions.set_verification_key in
1299+
{ a with
1300+
permissions =
1301+
{ a.permissions with
1302+
set_verification_key = (vk, Mina_numbers.Txn_version.current)
1303+
}
1304+
}
12941305
end
12951306

12961307
module Amount = struct

src/lib/transaction_logic/zkapp_command_logic.ml

Lines changed: 11 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
@@ -607,6 +603,12 @@ module type Account_intf = sig
607603
include Iffable with type bool := bool
608604
end
609605

606+
type txn_version
607+
608+
val txn_version : t -> txn_version
609+
610+
val set_txn_version_to_latest : t -> t
611+
610612
type timing
611613

612614
type token_id
@@ -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,8 @@ 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+
(* When VK is set, always force update txn version *)
1646+
let a = Account.set_txn_version_to_latest a in
16441647
(a, local_state)
16451648
in
16461649
(* Update action state. *)

src/lib/transaction_snark/transaction_snark.ml

Lines changed: 18 additions & 5 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

@@ -1068,6 +1063,24 @@ module Make_str (A : Wire_types.Concrete) = struct
10681063

10691064
let set_permissions permissions ({ data = a; hash } : t) : t =
10701065
{ data = { a with permissions }; hash }
1066+
1067+
type txn_version = Mina_numbers.Txn_version.Checked.t
1068+
1069+
let txn_version ({ data = a; _ } : t) : txn_version =
1070+
snd a.permissions.set_verification_key
1071+
1072+
let set_txn_version_to_latest ({ data = a; hash } : t) : t =
1073+
let vk, _ = a.permissions.set_verification_key in
1074+
{ data =
1075+
{ a with
1076+
permissions =
1077+
{ a.permissions with
1078+
set_verification_key =
1079+
(vk, Mina_numbers.Txn_version.current_checked)
1080+
}
1081+
}
1082+
; hash
1083+
}
10711084
end
10721085

10731086
module Opt = struct

0 commit comments

Comments
 (0)