light_compressed_pda/invoke_cpi/account.rs
1use crate::InstructionDataInvokeCpi;
2use aligned_sized::aligned_sized;
3use anchor_lang::prelude::*;
4// Security:
5// - checking the slot is not enough there can be multiple transactions in the same slot
6// - the CpiContextAccount must be derived from the first Merkle tree account as the current transaction
7// - to check that all data in the CpiSignature account is from the same transaction we compare the proof bytes
8// - I need to guaratee that all the data in the cpi signature account is from the same transaction
9// - if we just overwrite the data in the account if the proof is different we cannot be sure because the program could be malicious
10// - wouldn't the same proofs be enough, if you overwrite something then I discard everything that is in the account -> these utxos will not be spent
11// - do I need to check ownership before or after? before we need to check who invoked the program
12// - we need a transaction hash that hashes the complete instruction data, this will be a pain to produce offchain Sha256(proof, input_account_hashes, output_account_hashes, relay_fee, compression_lamports)
13// - the last tx passes the hash and tries to recalculate the hash
14/// collects invocations without proofs
15/// invocations are collected and processed when an invocation with a proof is received
16#[aligned_sized(anchor)]
17#[derive(Debug, PartialEq, Default)]
18#[account]
19pub struct CpiContextAccount {
20 pub associated_merkle_tree: Pubkey,
21 pub context: Vec<InstructionDataInvokeCpi>,
22}
23
24impl CpiContextAccount {
25 pub fn init(&mut self, associated_merkle_tree: Pubkey) {
26 self.associated_merkle_tree = associated_merkle_tree;
27 self.context = Vec::new();
28 }
29}