Today I was reading bitcoind src, and trying to find out where scriptPubKey is executed when a node received new block with transaction, for example transaction from new block may not be exist in mempool.
Find function that execute script:
https://github.com/bitcoin/bitcoin/search?utf8=%E2%9C%93&q=EvalScript
- src/script/interpreter.cpp in this file source code of EvalScript function
Used only in this 2 files:
src/policy/policy.cpp
src/script/sign.cpp
Review sign.cpp
Evalscript -> CombineSignatures -> /src/bitcoin-tx.cpp: MutateTxSign -> MutateTx -> CommandLineRawTx -> main
This functions used when we create new transactions
Review policy.cpp
Evalscript -> AreInputsStandard -> /src/main.cpp: AcceptToMemoryPool
AcceptToMemoryPool
src/main.cpp later
src/wallet/wallet.cpp -> CommitTransaction - this is create own transaction functional
src/rpcrawtransaction.cpp -> sendrawtrnsaction - rpc function send rawtx
src/txmempool.cpp -> no calls only comments
Last one is src/main.cpp
AcceptToMemoryPool -> ProcessMessage on message "tx" , new single tx to pool received AcceptToMemoryPool -> DisconnectTip
DisconnectTip -> InvalidateBlock invaludate block and send all transaction back to pool with all verifications and script eval
DisconnectTip -> ActivateBestChainStep :
// Disconnect active blocks which are no longer in the best chain.
bool fBlocksDisconnected = false;
while (chainActive.Tip() && chainActive.Tip() != pindexFork) {
if (!DisconnectTip(state))
return false;
fBlocksDisconnected = true;
}
If we have orphan take out transactions from orphan to pool with all verifications
NO more other links found
From this I can conclude that in case node with bitcoind received new block with transactions that not in mempool we add this tx to blockchain without scriptPubKey executing.
Consequently if same "honest" miner include tx with invalid script, at example incorrect signature that spent same one coins, all bitcoind nodes add it to blockchain without eval script and not detect this
It is not possible to be true! Where is my error?