bool dev::verify(Public const& _p, Signature const& _s, h256 const& _hash) { if (!_p) return false; #ifdef ETH_HAVE_SECP256K1 return _p == recover(_s, _hash); #else return s_secp256k1pp.verify(_p, _s, _hash.ref(), true); #endif }
Public dev::recover(Signature const& _sig, h256 const& _message) { Public ret; #ifdef ETH_HAVE_SECP256K1 bytes o(65); int pubkeylen; if (!secp256k1_ecdsa_recover_compact(s_secp256k1, _message.data(), _sig.data(), o.data(), &pubkeylen, false, _sig[64])) return Public(); ret = FixedHash<64>(o.data() + 1, Public::ConstructFromPointer); #else ret = s_secp256k1pp.recover(_sig, _message.ref()); #endif if (ret == c_zeroKey) return Public(); return ret; }
OverlayDB State::openDB(std::string const& _basePath, h256 const& _genesisHash, WithExisting _we) { std::string path = _basePath.empty() ? Defaults::get()->m_dbPath : _basePath; if (_we == WithExisting::Kill) { cnote << "Killing state database (WithExisting::Kill)."; boost::filesystem::remove_all(path + "/state"); } path += "/" + toHex(_genesisHash.ref().cropped(0, 4)) + "/" + toString(c_databaseVersion); boost::filesystem::create_directories(path); DEV_IGNORE_EXCEPTIONS(fs::permissions(path, fs::owner_all)); ldb::Options o; o.max_open_files = 256; o.create_if_missing = true; ldb::DB* db = nullptr; ldb::Status status = ldb::DB::Open(o, path + "/state", &db); if (!status.ok() || !db) { if (boost::filesystem::space(path + "/state").available < 1024) { cwarn << "Not enough available space found on hard drive. Please free some up and then re-run. Bailing."; BOOST_THROW_EXCEPTION(NotEnoughAvailableSpace()); } else { cwarn << status.ToString(); cwarn << "Database " << (path + "/state") << "already open. You appear to have another instance of ethereum running. Bailing."; BOOST_THROW_EXCEPTION(DatabaseAlreadyOpen()); } } cnote << "Opened state DB."; return OverlayDB(db); }
static std::string minHex(h256 const& _h) { unsigned i = 0; for (; i < 31 && !_h[i]; ++i) {} return toHex(_h.ref().cropped(i)); }