@@ -865,6 +865,11 @@ async function verifyAccountUpdate(
865
865
866
866
let verificationKey = account . zkapp ?. verificationKey ?. data ! ;
867
867
isValidProof = await verify ( proof . toJSON ( ) , verificationKey ) ;
868
+ if ( ! isValidProof ) {
869
+ throw Error (
870
+ `Invalid proof for account update\n${ JSON . stringify ( update ) } `
871
+ ) ;
872
+ }
868
873
} catch ( error ) {
869
874
errorTrace += '\n\n' + ( error as Error ) . message ;
870
875
isValidProof = false ;
@@ -888,6 +893,8 @@ async function verifyAccountUpdate(
888
893
}
889
894
}
890
895
896
+ let verified = false ;
897
+
891
898
function checkPermission ( p : Types . Json . AuthRequired , field : string ) {
892
899
if ( p == 'None' ) return ;
893
900
@@ -897,7 +904,6 @@ async function verifyAccountUpdate(
897
904
) ;
898
905
}
899
906
900
- let verified = false ;
901
907
if ( p == 'Signature' || p == 'Either' ) {
902
908
verified ||= isValidSignature ;
903
909
}
@@ -932,4 +938,14 @@ async function verifyAccountUpdate(
932
938
let p = permissionForUpdate ( 'incrementNonce' ) ;
933
939
checkPermission ( p , 'incrementNonce' ) ;
934
940
}
941
+
942
+ // this checks for an edge case where an account update can be authorized using proofs but
943
+ // a) the proof is invalid (bad verification key)
944
+ // and b) there are no state changes initiate so no permissions will be checked
945
+ // however, if the verification key changes, the proof should still be invalid
946
+ if ( errorTrace && ! verified ) {
947
+ throw Error (
948
+ `One or more proofs were invalid and no other form of authorization was provided.\n${ errorTrace } `
949
+ ) ;
950
+ }
935
951
}
0 commit comments