metaplex-foundation / mpl-core

https://mpl-core-js-docs.vercel.app
Other
34 stars 24 forks source link

Trying to use Burn Authority to burn asset owned by random wallet yields errors #118

Open daoplays opened 3 months ago

daoplays commented 3 months ago

Hi, I created an asset with the below code via CPI:


CreateV1CpiBuilder::new(ctx.accounts.core_program)
            .authority(Some(ctx.accounts.program_pda))
            .asset(ctx.accounts.asset_account)
            .collection(Some(ctx.accounts.collection_account))
            .payer(ctx.accounts.user)
            .owner(Some(ctx.accounts.program_pda))
            .data_state(mpl_core::types::DataState::AccountState)
            .name(args.name.to_string())
            .uri(args.uri.to_string())
            .plugins(vec![
                mpl_core::types::PluginAuthorityPair {
                    plugin: mpl_core::types::Plugin::PermanentBurnDelegate(
                        mpl_core::types::PermanentBurnDelegate {},
                    ),
                    authority: Some(mpl_core::types::PluginAuthority::Address {
                        address: *ctx.accounts.program_pda.key,
                    }),
                },
                mpl_core::types::PluginAuthorityPair {
                    plugin: mpl_core::types::Plugin::PermanentTransferDelegate(
                        mpl_core::types::PermanentTransferDelegate {},
                    ),
                    authority: Some(mpl_core::types::PluginAuthority::Address {
                        address: *ctx.accounts.program_pda.key,
                    }),
                },
            ])
            .system_program(ctx.accounts.system_program)
            .invoke_signed(&[&[b"pda", &[pda_bump_seed]]])
            .unwrap();

This asset was then transferred to a random wallet. In a separate interaction with the program i tried to burn it using the program_pda account that was set as the permanent burn authority:

mpl_core::instructions::BurnV1CpiBuilder::new(ctx.accounts.core_program)
            .asset(ctx.accounts.asset_account)
            .collection(Some(ctx.accounts.collection_account))
            .authority(Some(ctx.accounts.program_pda))
            .payer(ctx.accounts.user)
            .system_program(Some(ctx.accounts.system_program))
            .invoke_signed(&[&[b"pda", &[pda_bump_seed]]])
            .unwrap();

This yielded the following error: Program invoked: Unknown Program (CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d) Program logged: "Instruction: Burn" Program logged: "PermanentBurnDelegate: ForceApproved" Program consumed: 13654 of 164453 compute units Program returned error: "instruction changed the balance of a read-only account"

which i don't understand because all the accounts are writable.

I thought it might be because the burn deposits sol in the owners account, but that isn't passed in the above burn instruction, so i tried adding the owner as an extra account, but that gave a different error, that the owner wasn't a signer.

My expectation is that the program, designated as the burn authority, should be able to burn any asset, but i'm not sure how.

danenbm commented 2 months ago

We previously had an issue where we were sending the SOL back to the authority, and the authority wasn't writable. At first we accidentally made the owner writable, but later fixed it to be the intended design which is send the SOL back to the payer, which is writable and a signer.

Its a bit confusing since we had multiple changes for this. The PR where we get it into the right state is: https://github.com/metaplex-foundation/mpl-core/pull/134. I think it could have also been confused by various clients which might have been different from the program.

But at this point it should be fixed, and the funds go back to the payer. Are you still having an issue with this?