Where in the source code do we check whether
hash(blockheader*nonce) < Difficulty
The function you are looking for is in
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
// Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
// Check proof of work matches claimed amount
if (UintToArith256(hash) > bnTarget)
a) this is not the code that miners use to perform the check; it probably is the validation on node-side ?
This is on the node side. Miners do not use Bitcoin Core software for mining, this check is implemented as part of the ASIC design, so not even software at all.
b) here the "hash" refers to what exactly ?
Here the hash is the function used to calculate the block hash. In Bitcoin, this is 2 rounds of sha256, sometimes called hash256. See Bitcoin Wiki - Bitcoin Hashing Algorithm
c) why is this value tested against nTarget ? rather than Difficulty ?
Difficulty is just an abstraction of the
nTarget, which represents the actual 256 bit value that the header must be less than (or equal to). The header is a 256 bit value, so it must be compared to
nTarget. The conversion between
nTarget and difficulty is
difficulty = difficulty_1_target / nTarget, where
difficulty_1_target is the target of the genesis block. See Bitcoin Wiki - Difficulty
d) this check is usually advertised in media as "<"less rather than "<=" less than equal. But seeing how this line is coded , it means HASH<= nTarget is OK.