This is a backport of core#20833
https://github.com/bitcoin/bitcoin/pull/20833/commits/13650fe2e527bf0cf5d977bf5f3f1563b853ecdc
Note: this commit triggered a `m_sig_checks_standard’ may be used uninitialized` warning. As far as i can tell, this is a false positive. Nothing really changed in the way this atttribute is accessed after this change. To silence the warning, I initialized the attribute in the struct to 0. Otherwise, it would be initialized to 0 in `PreChecks -> CheckInputScripts > IsKeyInScriptCache > ScriptCacheElement(key, 0)`

Depends on D12126