ethereum / remix-project

Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
https://remix-ide.readthedocs.io
MIT License
2.41k stars 916 forks source link

NotFoundError: Key not found in database [h?n] #1414

Open CrimsonGlory opened 3 years ago

CrimsonGlory commented 3 years ago

Hi. I have this error transact to SaveLastBlockHash.save_last_hash errored: NotFoundError: Key not found in database [hn] when trying to interact with a deployed contract on Javascript VM (Berlin or London) using the online version of remix from a fresh chromium incognito session. Testing this with metamask on ropsten or with ganache-cli 6.12.2 (without remix) works fine.

Steps to reproduce:

  1. Enter remix ide and paste code
  2. Compile SaveLastBlockHash.sol (with 0.8.6 compiler)
  3. Deploy SaveLastBlockHash contract on Javascript VM (Berlin or London)
  4. Call last_block_hash. Will show all zeros
  5. Call save_last_hash (should not revert)
  6. Call last_block_hash. Will show random 32bytes in hex
  7. Call save_last_hash. It should crash.

SaveLastBlockHash.sol:

pragma solidity ^0.8.6;

contract SaveLastBlockHash {

    bytes32 public last_block_hash;
    constructor() {
    }

    function save_last_hash() public payable {
        last_block_hash = blockhash(block.number - 1);
    }
}
CrimsonGlory commented 3 years ago

I have found a simpler way to reproduce the exact same crash and edited the original post. My guess is that this error is because remix uses a quite old ganache version.