Skip to content

Improper macro expansion for instruction handler functions with a single expression #1290

@Toshiyuki-Tega

Description

@Toshiyuki-Tega

When defining a program module and instructions as follows

#[light_program]
#[program]
pub mod zktest {
    use super::*;

    pub fn compress01<'info>(
        ctx: LightContext<'_, '_, '_, 'info, Compress01<'info>>,
    ) -> Result<()> {
        ctx.light_accounts.compressed_user_record.user_authority = ctx.accounts.signer.key();
        Ok(())
    }

    // It doesn't work
    pub fn compress02<'info>(
        ctx: LightContext<'_, '_, '_, 'info, Compress02<'info>>,
    ) -> Result<()> {
        instructions::compress02(&mut ctx)
    }
}

the function body of compress02 is expanded like this:

        let mut ctx: ::light_sdk::context::LightContext<Compress02, LightCompress02> = ::light_sdk::context::LightContext::new(
            ctx,
            inputs,
            merkle_context,
            merkle_tree_root_index,
            address_merkle_context,
            address_merkle_tree_root_index,
        )?;
        let inputs = ParamsCompress02 {};
        ctx.check_constraints(&inputs)?;
        ctx.derive_address_seeds(address_merkle_context, &inputs);
        let ParamsCompress02 {} = inputs;
        ctx.verify(proof)?;
        instructions::compress02(&mut ctx)

and changes made to ctx in the instructions::compress02 function are not being reflected.

Current workaround is to assign the result into a temporary variable and return it.

    pub fn compress02<'info>(
        ctx: LightContext<'_, '_, '_, 'info, Compress02<'info>>,
    ) -> Result<()> {
        let retval = instructions::compress02(&mut ctx);
        retval
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions