user129540: I'm reading Programming Bitcoin. And in Chapter7, the author talked about the way how signature hash is calculated by replacing the transaction's ScriptSig with the corresponding previous ScriptPubKey. I understand that we can't calculate the signature of a transaction with the signature inside it. But why not just drop the ScriptSig part instead of replace it with the previous ScriptPubKey? And by the way, the same confusion arise on me with the p2sh , where the ScriptSig is replaced with the corresponding RedeemScript.

user48884: Any data that is included in the sighash must be revealed to the signer. It also means that the signature itself directly commits to that information and so must be truthfully provided to the signer as otherwise an invalid signature would be created.
By including the scriptPubKey or the redeemScript, we ensure that the signers are aware of the script that their signature will be involved in. This removes a class of potential attacks where the signer is lied to about the script that is involved in that input. It may be that the signer does not want to sign for certain scripts, and so having the script be part of the signature means that the signer will always know what script it signed for.

129540: <p>I'm reading <a href="https://github.com/jimmysong/programmingbitcoin" rel="nofollow noreferrer">Programming Bitcoin</a>. And in Chapter7, the author talked about the way how signature hash is calculated by replacing the transaction's ScriptSig with the corresponding previous ScriptPubKey. I understand that we can't calculate the signature of a transaction with the signature inside it. But why not just drop the ScriptSig part instead of replace it with the previous ScriptPubKey? And by the way, the same confusion arise on me with the p2sh , where the ScriptSig is replaced with the corresponding RedeemScript.</p>
 48884: <p>Any data that is included in the sighash must be revealed to the signer. It also means that the signature itself directly commits to that information and so must be truthfully provided to the signer as otherwise an invalid signature would be created.</p>
<p>By including the scriptPubKey or the redeemScript, we ensure that the signers are aware of the script that their signature will be involved in. This removes a class of potential attacks where the signer is lied to about the script that is involved in that input. It may be that the signer does not want to sign for certain scripts, and so having the script be part of the signature means that the signer will always know what script it signed for.</p>
