Currently, the multisig descriptor constructions are limited to 16 keys only possibly because of template parsing reasons. Under p2sh context, such scripts would be invalid anyway because of 520-byte rule, but we can support up to 20 keys for CHECKMULTISIG in witness script context. 


if (input_type == SIGHASH_ANYONECANPAY) {
        ss << tx_to.vin[in_pos].prevout;
        ss << cache.m_spent_outputs[in_pos];
        ss << tx_to.vin[in_pos].nSequence;
    } else {
        ss << in_pos;
    }
    if (have_annex) {
        ss << execdata.m_annex_hash;
    }
    
    if (output_type == SIGHASH_SINGLE) {
        if (in_pos >= tx_to.vout.size()) return false;
        CHashWriter sha_single_output(SER_GETHASH, 0);
        sha_single_output << tx_to.vout[in_pos];
        ss << sha_single_output.GetSHA256();
    }
    
    if (sigversion == SigVersion::TAPSCRIPT) {
        assert(execdata.m_tapleaf_hash_init);
        ss << execdata.m_tapleaf_hash;
        ss << key_version;
        assert(execdata.m_codeseparator_pos_init);
        ss << execdata.m_codeseparator_pos;
    }
    hash_out = ss.GetSHA256();
    return true;
}
template <class T>
uint256 SignatureHash(const CScript& scriptCode, const T& txTo, unsigned int nIn, int nHashType, const CAmount& amount, SigVersion sigversion, const PrecomputedTransactionData* cache)