@@ -4027,18 +4027,15 @@ pub mod zkapp_command {
40274027 let mut tbl = HashMap :: with_capacity ( 128 ) ;
40284028 // Keep track of the verification keys that have been set so far
40294029 // during this transaction.
4030- let mut vks_overridden = HashMap :: with_capacity ( 128 ) ;
4030+ let mut vks_overridden: HashMap < AccountId , Option < WithHash < VerificationKey > > > =
4031+ HashMap :: with_capacity ( 128 ) ;
40314032
40324033 let account_updates = account_updates. try_map_to ( |p| {
40334034 let account_id = p. account_id ( ) ;
40344035
4035- if let SetOrKeep :: Set ( vk_next) = & p. body . update . verification_key {
4036- vks_overridden. insert ( account_id. clone ( ) , Some ( vk_next. clone ( ) ) ) ;
4037- }
4038-
40394036 check_authorization ( p) ?;
40404037
4041- match ( & p. body . authorization_kind , is_failed) {
4038+ let result = match ( & p. body . authorization_kind , is_failed) {
40424039 ( AuthorizationKind :: Proof ( vk_hash) , false ) => {
40434040 let prioritized_vk = {
40444041 // only lookup _past_ vk setting, ie exclude the new one we
@@ -4071,7 +4068,15 @@ pub mod zkapp_command {
40714068 _ => {
40724069 Ok ( ( p. clone ( ) , None ) )
40734070 }
4071+ } ;
4072+
4073+ // NOTE: we only update the overriden map AFTER verifying the update to make sure
4074+ // that the verification for the VK update itself is done against the previous VK.
4075+ if let SetOrKeep :: Set ( vk_next) = & p. body . update . verification_key {
4076+ vks_overridden. insert ( p. account_id ( ) . clone ( ) , Some ( vk_next. clone ( ) ) ) ;
40744077 }
4078+
4079+ result
40754080 } ) ?;
40764081
40774082 Ok ( ZkAppCommand {
0 commit comments