Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Toshiyuki-Tega opened this issue Oct 9, 2024 · 0 comments

Comments

@Toshiyuki-Tega
Copy link

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
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant