anchor icon indicating copy to clipboard operation
anchor copied to clipboard

AccountSysvarMismatch while using SlotHashes sysvar

Open mentalrob opened this issue 1 year ago • 10 comments

Program:

use anchor_lang::prelude::*;

declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");

#[program]
mod sysvars_test {
    use super::*;
    pub fn sysvars(_ctx: Context<Sysvars>) -> Result<()> {
        Ok(())
    }
}

#[derive(Accounts)]
pub struct Sysvars<'info> {
    pub clock: Sysvar<'info, Clock>,
    pub rent: Sysvar<'info, Rent>,
    pub stake_history: Sysvar<'info, StakeHistory>,
    pub slot_hashes: Sysvar<'info, SlotHashes>,
}

Test:

import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { SysvarsTest } from "../target/types/sysvars_test";

describe("sysvars-test", () => {
  // Configure the client to use the local cluster.
  anchor.setProvider(anchor.AnchorProvider.env());

  const program = anchor.workspace.SysvarsTest as Program<SysvarsTest>;

  it("Is initialized!", async () => {
    const tx = await program.methods
      .sysvars()
      .accounts({
        clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
        rent: anchor.web3.SYSVAR_RENT_PUBKEY,
        stakeHistory: anchor.web3.SYSVAR_STAKE_HISTORY_PUBKEY,
        slotHashes: anchor.web3.SYSVAR_SLOT_HASHES_PUBKEY
      })
      .rpc();
    console.log("Your transaction signature", tx);
  });
});

throws an error Error: AnchorError caused by account: slot_hashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar. while using anchor-test. If i remove SYSVAR_SLOT_HASHES_PUBKEY and slot_hashes it works.

mentalrob avatar Aug 03 '22 13:08 mentalrob

closing for now...might be a local issue, cannot reproduce. consider rimraffing and getting a fresh clone of the repository.

feel free to reopen if the issue persists.

callensm avatar Aug 19 '22 15:08 callensm

@mentalrob Hello, did you figure the issue? I am getting the same issue as above.

  ).accounts({
    player: provider.wallet.publicKey,
    playerStats: playerStatsPDA,
    game: playerGamePDA,
    depositWallet: depositWallet,
    slotHashes: anchor.web3.SYSVAR_SLOT_HASHES_PUBKEY,
  }).rpc().catch((err) => {
    pub system_program: Program<'info, System>,

    pub slot_hashes: Sysvar<'info, SlotHashes>
}
       Is initialized!:
     Error: AnchorError caused by account: slot_hashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar.

nash90 avatar Aug 30 '22 17:08 nash90

I couldn't fixed it, used a nasty workaround

mentalrob avatar Aug 30 '22 17:08 mentalrob

@mentalrob thanks for quick reply. Is it possible to share the workaround?

@callensm Can we reopen this ticket?

nash90 avatar Aug 30 '22 23:08 nash90

I get the slothash offchain and giving it to the program as a parameter

mentalrob avatar Aug 31 '22 02:08 mentalrob

I get the slothash offchain and giving it to the program as a parameter

oh okay, is there a way to validate/verify the hash sent from client offchain is not fake?

nash90 avatar Aug 31 '22 03:08 nash90

I am still getting this error when trying to use Sysvar SlotHashes

> Program log: AnchorError caused by account: recent_slothashes. Error Code: AccountSysvarMismatch. Error Number: 3015. Error Message: The given public key does not match the required sysvar.```

0xlarry avatar Nov 01 '23 19:11 0xlarry

Getting this error as well. Only for this sysvar.

HardhatChad avatar Jan 10 '24 23:01 HardhatChad

Ah, here is why. SlotHashes doesn't support from_account_info.

https://github.com/solana-labs/solana/blob/e9a6bb35e2636275137fc47837f5afce4dbcf630/sdk/program/src/sysvar/slot_hashes.rs#L61

HardhatChad avatar Jan 11 '24 00:01 HardhatChad

The goal of this sysvar is to be used off chain

Aursen avatar Jan 11 '24 00:01 Aursen