void SealEngineFace::verify(Strictness _s, BlockHeader const& _bi, BlockHeader const& _parent, bytesConstRef _block) const { _bi.verify(_s, _parent, _block); if (_s != CheckNothingNew) { if (_bi.difficulty() < chainParams().minimumDifficulty) BOOST_THROW_EXCEPTION( InvalidDifficulty() << RequirementError( bigint(chainParams().minimumDifficulty), bigint(_bi.difficulty()))); if (_bi.gasLimit() < chainParams().minGasLimit) BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError( bigint(chainParams().minGasLimit), bigint(_bi.gasLimit()))); if (_bi.gasLimit() > chainParams().maxGasLimit) BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError( bigint(chainParams().maxGasLimit), bigint(_bi.gasLimit()))); if (_bi.number() && _bi.extraData().size() > chainParams().maximumExtraDataSize) { BOOST_THROW_EXCEPTION( ExtraDataTooBig() << RequirementError(bigint(chainParams().maximumExtraDataSize), bigint(_bi.extraData().size())) << errinfo_extraData(_bi.extraData())); } u256 const& daoHardfork = chainParams().daoHardforkBlock; if (daoHardfork != 0 && daoHardfork + 9 >= daoHardfork && _bi.number() >= daoHardfork && _bi.number() <= daoHardfork + 9) if (_bi.extraData() != fromHex("0x64616f2d686172642d666f726b")) BOOST_THROW_EXCEPTION( ExtraDataIncorrect() << errinfo_comment("Received block from the wrong fork (invalid extradata).")); } if (_parent) { auto gasLimit = _bi.gasLimit(); auto parentGasLimit = _parent.gasLimit(); if (gasLimit < chainParams().minGasLimit || gasLimit > chainParams().maxGasLimit || gasLimit <= parentGasLimit - parentGasLimit / chainParams().gasLimitBoundDivisor || gasLimit >= parentGasLimit + parentGasLimit / chainParams().gasLimitBoundDivisor) BOOST_THROW_EXCEPTION( InvalidGasLimit() << errinfo_min( (bigint)((bigint)parentGasLimit - (bigint)(parentGasLimit / chainParams().gasLimitBoundDivisor))) << errinfo_got((bigint)gasLimit) << errinfo_max((bigint)((bigint)parentGasLimit + parentGasLimit / chainParams().gasLimitBoundDivisor))); } }
void Ethash::BlockHeaderRaw::verifyParent(BlockHeaderRaw const& _parent) { // Check difficulty is correct given the two timestamps. if (m_difficulty != calculateDifficulty(_parent)) BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError((bigint)calculateDifficulty(_parent), (bigint)m_difficulty)); if (m_gasLimit < c_minGasLimit || m_gasLimit <= _parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor || m_gasLimit >= _parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor) BOOST_THROW_EXCEPTION(InvalidGasLimit() << errinfo_min((bigint)_parent.m_gasLimit - _parent.m_gasLimit / c_gasLimitBoundDivisor) << errinfo_got((bigint)m_gasLimit) << errinfo_max((bigint)_parent.m_gasLimit + _parent.m_gasLimit / c_gasLimitBoundDivisor)); }
void Ethash::BlockHeaderRaw::populateFromHeader(RLP const& _header, Strictness _s) { m_mixHash = _header[BlockInfo::BasicFields].toHash<h256>(); m_nonce = _header[BlockInfo::BasicFields + 1].toHash<h64>(); // check it hashes according to proof of work or that it's the genesis block. if (_s == CheckEverything && m_parentHash && !verify()) { InvalidBlockNonce ex; ex << errinfo_nonce(m_nonce); ex << errinfo_mixHash(m_mixHash); ex << errinfo_seedHash(seedHash()); EthashProofOfWork::Result er = EthashAux::eval(seedHash(), hashWithout(), m_nonce); ex << errinfo_ethashResult(make_tuple(er.value, er.mixHash)); ex << errinfo_hash256(hashWithout()); ex << errinfo_difficulty(m_difficulty); ex << errinfo_target(boundary()); BOOST_THROW_EXCEPTION(ex); } else if (_s == QuickNonce && m_parentHash && !preVerify()) { InvalidBlockNonce ex; ex << errinfo_hash256(hashWithout()); ex << errinfo_difficulty(m_difficulty); ex << errinfo_nonce(m_nonce); BOOST_THROW_EXCEPTION(ex); } if (_s != CheckNothing) { if (m_difficulty < c_minimumDifficulty) BOOST_THROW_EXCEPTION(InvalidDifficulty() << RequirementError(bigint(c_minimumDifficulty), bigint(m_difficulty)) ); if (m_gasLimit < c_minGasLimit) BOOST_THROW_EXCEPTION(InvalidGasLimit() << RequirementError(bigint(c_minGasLimit), bigint(m_gasLimit)) ); if (m_number && m_extraData.size() > c_maximumExtraDataSize) BOOST_THROW_EXCEPTION(ExtraDataTooBig() << RequirementError(bigint(c_maximumExtraDataSize), bigint(m_extraData.size())) << errinfo_extraData(m_extraData)); } }