Skip to content

Commit 1701519

Browse files
committed
Validate accounts in zk-elgamal-proof process_close_proof_context
1 parent 6259ee4 commit 1701519

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/flamenco/runtime/program/zksdk/fd_zksdk.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,26 @@ fd_zksdk_process_close_context_state( fd_exec_instr_ctx_t * ctx ) {
5353
https://github.com/anza-xyz/agave/blob/master/programs/zk-elgamal-proof/src/lib.rs#L153-L154 */
5454
FD_TRY_BORROW_INSTR_ACCOUNT_DEFAULT_ERR_CHECK(ctx, ACC_IDX_PROOF, &proof_acc );
5555

56+
/* Check that the proof context account is owned by the zk-elgamal-proof program
57+
https://github.com/anza-xyz/agave/blob/v3.1.0-beta.0/programs/zk-elgamal-proof/src/lib.rs#167-L171 */
58+
if( FD_UNLIKELY( !fd_memeq( fd_borrowed_account_get_owner( &proof_acc ), &fd_solana_zk_elgamal_proof_program_id, sizeof(fd_pubkey_t) ) ) ) {
59+
return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_OWNER;
60+
}
61+
5662
/* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/zk-elgamal-proof/src/lib.rs#L161-L162
5763
Note: data also contains context data, but we only need the initial 33 bytes. */
5864
if( FD_UNLIKELY( fd_borrowed_account_get_data_len( &proof_acc ) < sizeof(fd_zksdk_proof_ctx_state_meta_t) ) ) {
5965
return FD_EXECUTOR_INSTR_ERR_INVALID_ACC_DATA;
6066
}
6167
fd_zksdk_proof_ctx_state_meta_t const * proof_ctx_state_meta = fd_type_pun_const( fd_borrowed_account_get_data( &proof_acc ) );
6268

69+
/* Check that the proof context account is initialized (proof_type != 0)
70+
ProofType::Uninitialized = 0
71+
https://github.com/anza-xyz/agave/blob/v3.1.0-beta.0/programs/zk-elgamal-proof/src/lib.rs#L161-L165 */
72+
if( FD_UNLIKELY( proof_ctx_state_meta->proof_type == 0 ) ) {
73+
return FD_EXECUTOR_INSTR_ERR_UNINITIALIZED_ACCOUNT;
74+
}
75+
6376
/* https://github.com/anza-xyz/agave/blob/v2.0.1/programs/zk-elgamal-proof/src/lib.rs#L155 */
6477
fd_pubkey_t const * expected_owner_addr = &proof_ctx_state_meta->ctx_state_authority;
6578

0 commit comments

Comments
 (0)