light_system_program/
lib.rs

1use anchor_lang::{prelude::*, solana_program::pubkey::Pubkey};
2
3pub mod invoke;
4pub use invoke::instruction::*;
5pub mod invoke_cpi;
6pub use invoke_cpi::{initialize::*, instruction::*};
7pub mod constants;
8pub mod errors;
9pub mod sdk;
10pub mod utils;
11use errors::SystemProgramError;
12use sdk::event::PublicTransactionEvent;
13
14declare_id!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");
15
16#[cfg(not(feature = "no-entrypoint"))]
17solana_security_txt::security_txt! {
18    name: "light_system_program",
19    project_url: "lightprotocol.com",
20    contacts: "email:security@lightprotocol.com",
21    policy: "https://github.com/Lightprotocol/light-protocol/blob/main/SECURITY.md",
22    source_code: "https://github.com/Lightprotocol/light-protocol"
23}
24
25#[program]
26pub mod light_system_program {
27
28    use light_heap::{bench_sbf_end, bench_sbf_start};
29
30    use self::{
31        invoke::{processor::process, verify_signer::input_compressed_accounts_signer_check},
32        invoke_cpi::processor::process_invoke_cpi,
33    };
34    use super::*;
35
36    pub fn init_cpi_context_account(ctx: Context<InitializeCpiContextAccount>) -> Result<()> {
37        // Check that Merkle tree is initialized.
38        ctx.accounts.associated_merkle_tree.load()?;
39        ctx.accounts
40            .cpi_context_account
41            .init(ctx.accounts.associated_merkle_tree.key());
42        Ok(())
43    }
44
45    pub fn invoke<'a, 'b, 'c: 'info, 'info>(
46        ctx: Context<'a, 'b, 'c, 'info, InvokeInstruction<'info>>,
47        inputs: Vec<u8>,
48    ) -> Result<()> {
49        let inputs: InstructionDataInvoke =
50            InstructionDataInvoke::deserialize(&mut inputs.as_slice())?;
51
52        input_compressed_accounts_signer_check(
53            &inputs.input_compressed_accounts_with_merkle_context,
54            &ctx.accounts.authority.key(),
55        )?;
56        process(inputs, None, ctx, 0)
57    }
58
59    pub fn invoke_cpi<'a, 'b, 'c: 'info, 'info>(
60        ctx: Context<'a, 'b, 'c, 'info, InvokeCpiInstruction<'info>>,
61        inputs: Vec<u8>,
62    ) -> Result<()> {
63        bench_sbf_start!("cpda_deserialize");
64        let inputs: InstructionDataInvokeCpi =
65            InstructionDataInvokeCpi::deserialize(&mut inputs.as_slice())?;
66        bench_sbf_end!("cpda_deserialize");
67
68        process_invoke_cpi(ctx, inputs)
69    }
70
71    /// This function is a stub to allow Anchor to include the input types in
72    /// the IDL. It should not be included in production builds nor be called in
73    /// practice.
74    #[cfg(feature = "idl-build")]
75    pub fn stub_idl_build<'info>(
76        _ctx: Context<'_, '_, '_, 'info, InvokeInstruction<'info>>,
77        _inputs1: InstructionDataInvoke,
78        _inputs2: InstructionDataInvokeCpi,
79        _inputs3: PublicTransactionEvent,
80    ) -> Result<()> {
81        Err(SystemProgramError::InstructionNotCallable.into())
82    }
83}