0

I am working on a program that invokes drift.

It all works fine, just adding assertions now.

I have changed this account:

#[account(mut)]
pub user_stats: AccountInfo<'info>,

To this:

#[account(
    mut,
    seeds = [b"user_stats", drift_adapter.key().as_ref()],
    bump,
    seeds::program = main.stored_program_id
)]
pub user_stats: AccountInfo<'info>,

user_stats is an account required for most of drift calls, it is derived from the PDA that deposits SPL tokens into drift.

After adding that validation everything breaks, and in a weird way.

This is the error I receive:

 'Instruction references an unknown account 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',

And after narrowing it down it refers to the account drift_vault which should have the pubkey JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw but for some reason it thinks it receives 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d.

Seems like an easy enough case of providing the wrong account, but logging in tests all accounts before providing them shows that I am provided correct account. Additionally there is no account 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d at all being derived, initialised or otherwise used.

Test log:

 console.log("driftVault:", driftVault.toBase58());

shows:

  driftVault: JCNCMFXo5M5qwUPg2Utu1u6YWp3MbygxqBsBeXXJfrw

But in the contract, the very first log:

  msg!("drift vault  {:?}", accounts.drift_vault.key());

shows:

 'Program log: drift vault  8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',

So right now, it seems to be that adding a PDA validation somehow swaps out what account is provided?

It really doesn't make much sense to me. Removing the validation allows for everything to go through. I will probably rederive the account myself instead of using a macro or store it hardcoded.

Has anyone else encountered something similar? I can't share much more code because this is a proprietary and unpolished contract, but any advice would be appreciated.

Thanks

3
  • A) I'm not getting how it's possible the program shows some info ('Program log: drift vault 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d',) when validation fails on sending the transaction. How it is? B) My first tip would be that the 8opHzTAnfzRufv99Kx52Z217GCQ8DB7RNU4SKGFTC1d is the address derived from the seeds = [b"user_stats", drift_adapter.key().as_ref()] and the program main.stored_program_id and that's the address that mentioned to be expected while a different address is passed in.
    – chalda
    Commented Oct 1 at 11:26
  • Yeah, it really perplexed me. Guessing dodgy local validator haha. Had no issues rederiving outside of macros and the fact that it would fail after passing the macro, yet would succeed without the macro and no other changes.. Commented Oct 1 at 12:04
  • When deriving the account does the stored_program_id match to what you expect?
    – chalda
    Commented Oct 1 at 12:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.