Home > Back-end >  Why Error: Signature verification failed?
Why Error: Signature verification failed?

Time:08-11

I am writing a Solana Program using Anchor framework.

I can't seem to get rid of a signing error I'm having while testing.

Instruction Accounts validation:

#[derive(Accounts)]
pub struct InitializeAuction2<'info> {
    /// State of our auction program (up to you)
    #[account(
        init,
        payer = signer,
        space = 8   BoyncAuction::AUCTION_SIZE, 
    )]
    pub state: Account<'info, BoyncAuction>,

    #[account(mut)]
    pub signer: Signer<'info>,

    system_program: Program<'info, System>,
    rent: Sysvar<'info, Rent>,
}

Instruction Handler:}

    pub fn initialize2(ctx: Context<InitializeAuction2>, app_idx: i64, amount: u64) -> Result<()> {
        msg!("[BoyncProgram] Initializing new Boync Auction State");
        let auction_state = &mut ctx.accounts.state;

        auction_state.end_auction_at = app_idx; // App index is UnixTimestamp
        auction_state.authority = ctx.accounts.signer.key().clone();

        auction_state.state = AuctionState::create();

        Ok(())
    }

Test:

const mint = /* previously created mint account */
const user1 = new anchor.web3.Keypair();
const uid = new anchor.BN(parseInt((Date.now() / 1000).toString()));
const uidBuffer = uid.toBuffer("le", 8);


let [auctionStatePubKey, auctionStateBump] =
  await anchor.web3.PublicKey.findProgramAddress(
    [
      Buffer.from("auction"),
      user1.toBuffer(),
      mint.toBuffer(),
      uidBuffer,
     ],
   program.programId
);

const tx1 = await program.methods
  .initialize2(uid, amount)
  .accounts({
    state: auctionStatePubKey,
    signer: user1.publicKey,
    systemProgram: anchor.web3.SystemProgram.programId,
    rent: anchor.web3.SYSVAR_RENT_PUBKEY,
  })
  .signers([user1])
  .rpc();
...

I hope I did not miss anything. Please let me know if context is not enough. Anyway, I can't submit this program call transaction. It fails with:

     Error: Signature verification failed
      at Transaction.serialize (node_modules/@project-serum/anchor/node_modules/@solana/web3.js/src/transaction.ts:586:13)
      at Provider.send (node_modules/@project-serum/anchor/src/provider.ts:116:22)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at MethodsBuilder.rpc [as _rpcFn] (node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:25:23)

I tried making signer: provider.wallet.publickey, no go.

Any help as well as why this happens is greatly appreciated.

CodePudding user response:

This is a shot in the dark, but since you're not specifying state as a PDA, Anchor is probably expecting a signature from that account too. Try changing up your instruction definition to:

#[derive(Accounts)]
pub struct InitializeAuction2<'info> {
    /// State of our auction program (up to you)
    #[account(
        init,
        payer = signer,
        space = 8   BoyncAuction::AUCTION_SIZE,
        seeds = [b"auction", signer.key().as_ref(), mint.key().as_ref(), 8u64.to_le_bytes()], bump
    )]
    pub state: Account<'info, BoyncAuction>,

    #[account(mut)]
    pub signer: Signer<'info>,

    system_program: Program<'info, System>,
    rent: Sysvar<'info, Rent>,
}

You'll probably also need to pass in the mint and bump seed data.

  • Related